@pie-players/pie-assessment-toolkit 0.3.30 → 0.3.32

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 (179) hide show
  1. package/README.md +289 -5
  2. package/dist/components/ItemToolBar.custom-element.js +165 -92
  3. package/dist/components/PieAssessmentToolkit.custom-element.js +604 -107
  4. package/dist/components/SectionToolBar.custom-element.js +0 -36
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/policy/core/PolicySource.d.ts +64 -0
  9. package/dist/policy/core/PolicySource.d.ts.map +1 -0
  10. package/dist/policy/core/PolicySource.js +17 -0
  11. package/dist/policy/core/PolicySource.js.map +1 -0
  12. package/dist/policy/core/ToolPolicyEngine.d.ts +123 -0
  13. package/dist/policy/core/ToolPolicyEngine.d.ts.map +1 -0
  14. package/dist/policy/core/ToolPolicyEngine.js +217 -0
  15. package/dist/policy/core/ToolPolicyEngine.js.map +1 -0
  16. package/dist/policy/core/compose-decision.d.ts +37 -0
  17. package/dist/policy/core/compose-decision.d.ts.map +1 -0
  18. package/dist/policy/core/compose-decision.js +332 -0
  19. package/dist/policy/core/compose-decision.js.map +1 -0
  20. package/dist/policy/core/decision-types.d.ts +142 -0
  21. package/dist/policy/core/decision-types.d.ts.map +1 -0
  22. package/dist/policy/core/decision-types.js +13 -0
  23. package/dist/policy/core/decision-types.js.map +1 -0
  24. package/dist/policy/core/engine-context.d.ts +30 -0
  25. package/dist/policy/core/engine-context.d.ts.map +1 -0
  26. package/dist/policy/core/engine-context.js +28 -0
  27. package/dist/policy/core/engine-context.js.map +1 -0
  28. package/dist/policy/core/policy-source-tag.d.ts +32 -0
  29. package/dist/policy/core/policy-source-tag.d.ts.map +1 -0
  30. package/dist/policy/core/policy-source-tag.js +29 -0
  31. package/dist/policy/core/policy-source-tag.js.map +1 -0
  32. package/dist/policy/core/provenance.d.ts +163 -0
  33. package/dist/policy/core/provenance.d.ts.map +1 -0
  34. package/dist/policy/core/provenance.js +232 -0
  35. package/dist/policy/core/provenance.js.map +1 -0
  36. package/dist/policy/core/qti-inputs.d.ts +67 -0
  37. package/dist/policy/core/qti-inputs.d.ts.map +1 -0
  38. package/dist/policy/core/qti-inputs.js +139 -0
  39. package/dist/policy/core/qti-inputs.js.map +1 -0
  40. package/dist/policy/engine.d.ts +28 -0
  41. package/dist/policy/engine.d.ts.map +1 -0
  42. package/dist/policy/engine.js +24 -0
  43. package/dist/policy/engine.js.map +1 -0
  44. package/dist/policy/internal.d.ts +26 -0
  45. package/dist/policy/internal.d.ts.map +1 -0
  46. package/dist/policy/internal.js +26 -0
  47. package/dist/policy/internal.js.map +1 -0
  48. package/dist/policy/sources/QtiPolicySource.d.ts +146 -0
  49. package/dist/policy/sources/QtiPolicySource.d.ts.map +1 -0
  50. package/dist/policy/sources/QtiPolicySource.js +270 -0
  51. package/dist/policy/sources/QtiPolicySource.js.map +1 -0
  52. package/dist/runtime/SectionRuntimeEngine.d.ts +145 -0
  53. package/dist/runtime/SectionRuntimeEngine.d.ts.map +1 -1
  54. package/dist/runtime/SectionRuntimeEngine.js +164 -3
  55. package/dist/runtime/SectionRuntimeEngine.js.map +1 -1
  56. package/dist/runtime/adapter/SectionEngineAdapter.d.ts +144 -0
  57. package/dist/runtime/adapter/SectionEngineAdapter.d.ts.map +1 -0
  58. package/dist/runtime/adapter/SectionEngineAdapter.js +183 -0
  59. package/dist/runtime/adapter/SectionEngineAdapter.js.map +1 -0
  60. package/dist/runtime/adapter/coordinator-bridge.d.ts +93 -0
  61. package/dist/runtime/adapter/coordinator-bridge.d.ts.map +1 -0
  62. package/dist/runtime/adapter/coordinator-bridge.js +127 -0
  63. package/dist/runtime/adapter/coordinator-bridge.js.map +1 -0
  64. package/dist/runtime/adapter/dom-event-bridge.d.ts +63 -0
  65. package/dist/runtime/adapter/dom-event-bridge.d.ts.map +1 -0
  66. package/dist/runtime/adapter/dom-event-bridge.js +95 -0
  67. package/dist/runtime/adapter/dom-event-bridge.js.map +1 -0
  68. package/dist/runtime/adapter/framework-error-bridge.d.ts +37 -0
  69. package/dist/runtime/adapter/framework-error-bridge.d.ts.map +1 -0
  70. package/dist/runtime/adapter/framework-error-bridge.js +47 -0
  71. package/dist/runtime/adapter/framework-error-bridge.js.map +1 -0
  72. package/dist/runtime/adapter/instrumentation-bridge.d.ts +32 -0
  73. package/dist/runtime/adapter/instrumentation-bridge.d.ts.map +1 -0
  74. package/dist/runtime/adapter/instrumentation-bridge.js +39 -0
  75. package/dist/runtime/adapter/instrumentation-bridge.js.map +1 -0
  76. package/dist/runtime/adapter/subscriber-fanout.d.ts +35 -0
  77. package/dist/runtime/adapter/subscriber-fanout.d.ts.map +1 -0
  78. package/dist/runtime/adapter/subscriber-fanout.js +60 -0
  79. package/dist/runtime/adapter/subscriber-fanout.js.map +1 -0
  80. package/dist/runtime/core/SectionEngineCore.d.ts +52 -0
  81. package/dist/runtime/core/SectionEngineCore.d.ts.map +1 -0
  82. package/dist/runtime/core/SectionEngineCore.js +81 -0
  83. package/dist/runtime/core/SectionEngineCore.js.map +1 -0
  84. package/dist/runtime/core/cohort.d.ts +40 -0
  85. package/dist/runtime/core/cohort.d.ts.map +1 -0
  86. package/dist/runtime/core/cohort.js +49 -0
  87. package/dist/runtime/core/cohort.js.map +1 -0
  88. package/dist/runtime/core/engine-input.d.ts +114 -0
  89. package/dist/runtime/core/engine-input.d.ts.map +1 -0
  90. package/dist/runtime/core/engine-input.js +19 -0
  91. package/dist/runtime/core/engine-input.js.map +1 -0
  92. package/dist/runtime/core/engine-output.d.ts +62 -0
  93. package/dist/runtime/core/engine-output.d.ts.map +1 -0
  94. package/dist/runtime/core/engine-output.js +27 -0
  95. package/dist/runtime/core/engine-output.js.map +1 -0
  96. package/dist/runtime/core/engine-readiness.d.ts +49 -0
  97. package/dist/runtime/core/engine-readiness.d.ts.map +1 -0
  98. package/dist/runtime/core/engine-readiness.js +47 -0
  99. package/dist/runtime/core/engine-readiness.js.map +1 -0
  100. package/dist/runtime/core/engine-resolver.d.ts +172 -0
  101. package/dist/runtime/core/engine-resolver.d.ts.map +1 -0
  102. package/dist/runtime/core/engine-resolver.js +170 -0
  103. package/dist/runtime/core/engine-resolver.js.map +1 -0
  104. package/dist/runtime/core/engine-stage-derivation.d.ts +19 -0
  105. package/dist/runtime/core/engine-stage-derivation.d.ts.map +1 -0
  106. package/dist/runtime/core/engine-stage-derivation.js +30 -0
  107. package/dist/runtime/core/engine-stage-derivation.js.map +1 -0
  108. package/dist/runtime/core/engine-state.d.ts +83 -0
  109. package/dist/runtime/core/engine-state.d.ts.map +1 -0
  110. package/dist/runtime/core/engine-state.js +49 -0
  111. package/dist/runtime/core/engine-state.js.map +1 -0
  112. package/dist/runtime/core/engine-transition.d.ts +49 -0
  113. package/dist/runtime/core/engine-transition.d.ts.map +1 -0
  114. package/dist/runtime/core/engine-transition.js +261 -0
  115. package/dist/runtime/core/engine-transition.js.map +1 -0
  116. package/dist/runtime/engine-context.d.ts +40 -0
  117. package/dist/runtime/engine-context.d.ts.map +1 -0
  118. package/dist/runtime/engine-context.js +32 -0
  119. package/dist/runtime/engine-context.js.map +1 -0
  120. package/dist/runtime/engine.d.ts +24 -0
  121. package/dist/runtime/engine.d.ts.map +1 -0
  122. package/dist/runtime/engine.js +24 -0
  123. package/dist/runtime/engine.js.map +1 -0
  124. package/dist/runtime/internal.d.ts +44 -0
  125. package/dist/runtime/internal.d.ts.map +1 -0
  126. package/dist/runtime/internal.js +46 -0
  127. package/dist/runtime/internal.js.map +1 -0
  128. package/dist/runtime/runtime-id.d.ts +8 -0
  129. package/dist/runtime/runtime-id.d.ts.map +1 -0
  130. package/dist/runtime/runtime-id.js +10 -0
  131. package/dist/runtime/runtime-id.js.map +1 -0
  132. package/dist/runtime/section-runtime-engine-host-context.d.ts +74 -0
  133. package/dist/runtime/section-runtime-engine-host-context.d.ts.map +1 -0
  134. package/dist/runtime/section-runtime-engine-host-context.js +96 -0
  135. package/dist/runtime/section-runtime-engine-host-context.js.map +1 -0
  136. package/dist/runtime/stage-emit-gate.d.ts +93 -0
  137. package/dist/runtime/stage-emit-gate.d.ts.map +1 -0
  138. package/dist/runtime/stage-emit-gate.js +83 -0
  139. package/dist/runtime/stage-emit-gate.js.map +1 -0
  140. package/dist/services/ToolkitCoordinator.d.ts +280 -7
  141. package/dist/services/ToolkitCoordinator.d.ts.map +1 -1
  142. package/dist/services/ToolkitCoordinator.js +412 -32
  143. package/dist/services/ToolkitCoordinator.js.map +1 -1
  144. package/dist/services/framework-error-bus.d.ts +73 -0
  145. package/dist/services/framework-error-bus.d.ts.map +1 -0
  146. package/dist/services/framework-error-bus.js +68 -0
  147. package/dist/services/framework-error-bus.js.map +1 -0
  148. package/dist/services/framework-error.d.ts +36 -1
  149. package/dist/services/framework-error.d.ts.map +1 -1
  150. package/dist/services/framework-error.js +37 -0
  151. package/dist/services/framework-error.js.map +1 -1
  152. package/dist/services/interfaces.d.ts +78 -0
  153. package/dist/services/interfaces.d.ts.map +1 -1
  154. package/dist/services/interfaces.js.map +1 -1
  155. package/dist/services/section-controller-types.d.ts +20 -0
  156. package/dist/services/section-controller-types.d.ts.map +1 -1
  157. package/dist/services/tools-config-normalizer.d.ts +23 -0
  158. package/dist/services/tools-config-normalizer.d.ts.map +1 -1
  159. package/dist/services/tools-config-normalizer.js +13 -1
  160. package/dist/services/tools-config-normalizer.js.map +1 -1
  161. package/dist/tools/client.d.ts +0 -1
  162. package/dist/tools/client.d.ts.map +1 -1
  163. package/dist/tools/client.js +0 -2
  164. package/dist/tools/client.js.map +1 -1
  165. package/dist/tools/types.d.ts +0 -26
  166. package/dist/tools/types.d.ts.map +1 -1
  167. package/package.json +23 -7
  168. package/dist/runtime/runtime-event-guards.d.ts +0 -2
  169. package/dist/runtime/runtime-event-guards.d.ts.map +0 -1
  170. package/dist/runtime/runtime-event-guards.js +0 -4
  171. package/dist/runtime/runtime-event-guards.js.map +0 -1
  172. package/dist/tools/tool-coordinator.d.ts +0 -72
  173. package/dist/tools/tool-coordinator.d.ts.map +0 -1
  174. package/dist/tools/tool-coordinator.js +0 -194
  175. package/dist/tools/tool-coordinator.js.map +0 -1
  176. package/dist/types/events.d.ts +0 -157
  177. package/dist/types/events.d.ts.map +0 -1
  178. package/dist/types/events.js +0 -11
  179. package/dist/types/events.js.map +0 -1
@@ -1,7 +1,73 @@
1
+ /**
2
+ * Section runtime engine — public facade (M7 — Variant C, layered).
3
+ *
4
+ * The facade is the narrow, stable entry point hosts use to mount,
5
+ * drive, and dispose a section runtime. It composes three layers
6
+ * introduced in earlier M7 PRs:
7
+ *
8
+ * - the **registry** (`RuntimeRegistry`) — registered item/passage
9
+ * shells in document order, used for canonical-id lookup;
10
+ * - the **adapter** (`SectionEngineAdapter`) — single I/O seam over
11
+ * the pure FSM core, fanning outputs to the DOM, framework-error
12
+ * bus, legacy events, instrumentation hook, and host subscribers;
13
+ * - the **resolver** (`resolveSectionEngineRuntimeState`) — the
14
+ * toolkit-side resolution helper that produces the effective
15
+ * runtime + tools snapshot a host feeds to the FSM core.
16
+ *
17
+ * **Two callsite generations.** During the M7 migration window the
18
+ * facade carries two surface generations side-by-side:
19
+ *
20
+ * 1. The **engine-side** surface (`attachHost`, `dispatchInput`,
21
+ * `subscribe`, `getState`, `getEffectiveRuntime`,
22
+ * `setInstrumentationHook`). This is what the kernel and the
23
+ * `pie-assessment-toolkit` CE will switch onto in M7 PR 5 and
24
+ * PR 6. Construction is lazy: `attachHost(...)` builds the
25
+ * adapter on first call, with the supplied host element,
26
+ * framework-error bus, and (optional) coordinator. After
27
+ * construction, host re-attachments (e.g. cohort change with a
28
+ * new layout shell) update the adapter's host element via
29
+ * `setHost(...)`.
30
+ *
31
+ * 2. The **legacy controller-side** surface (`initialize`,
32
+ * `register`, `unregister`, `handleContent*`, `updateItemSession`,
33
+ * `navigateToItem`, `persist`, `hydrate`, `dispose`). The
34
+ * `PieAssessmentToolkit.svelte` CE still drives the seed via this
35
+ * surface in PR 3 — observable behavior is identical to pre-PR 3.
36
+ * PR 6 deletes the toolkit's reliance on this surface; PR 7
37
+ * removes the methods that the engine FSM has fully absorbed.
38
+ *
39
+ * The two surfaces share `RuntimeRegistry` (the only piece both
40
+ * generations consult) and the resolved `SectionControllerHandle` the
41
+ * legacy generation holds inline. The adapter holds its own
42
+ * `coordinator-bridge` independently — the legacy `initialize(...)` and
43
+ * the engine-side `dispatchInput({ kind: "initialize" })` do **not**
44
+ * fight over the coordinator because PR 3 only activates one of them
45
+ * per host (legacy from the toolkit CE, engine-side from the PR 5+
46
+ * tests and the kernel/toolkit switches).
47
+ *
48
+ * **Why the legacy surface stays.** The plan's PR-3 acceptance criterion
49
+ * is "existing toolkit tests still pass; no section-player or toolkit
50
+ * CE code changes yet" — so PR 3 cannot delete the controller-side
51
+ * methods. PR 6 (toolkit switch) and PR 7 (rip-out) will remove them
52
+ * once the engine surface is the only consumer.
53
+ */
1
54
  import type { ToolkitCoordinator } from "../services/ToolkitCoordinator.js";
55
+ import type { FrameworkErrorReporter } from "../services/framework-error-bus.js";
2
56
  import type { SectionControllerEvent, SectionControllerHandle } from "../services/section-controller-types.js";
57
+ import { type SectionEngineAdapterOptions } from "./adapter/SectionEngineAdapter.js";
58
+ import type { InstrumentationHook } from "./adapter/instrumentation-bridge.js";
59
+ import type { EngineOutputListener } from "./adapter/subscriber-fanout.js";
60
+ import type { SectionEngineInput } from "./core/engine-input.js";
61
+ import type { SectionEngineOutput } from "./core/engine-output.js";
62
+ import { type EffectiveRuntime, type RuntimeInputs } from "./core/engine-resolver.js";
63
+ import { type SectionEngineState } from "./core/engine-state.js";
3
64
  import type { RuntimeRegistrationDetail } from "./registration-events.js";
4
65
  import { RuntimeRegistry } from "./RuntimeRegistry.js";
66
+ /**
67
+ * Structural view of the resolved section controller, widened with the
68
+ * extra methods the toolkit's runtime CE calls directly. Optional so
69
+ * stub controllers used in tests do not need every entry point.
70
+ */
5
71
  interface RuntimeController extends SectionControllerHandle {
6
72
  getCompositionModel?: () => unknown;
7
73
  getCanonicalItemId?: (itemId: string) => string;
@@ -43,6 +109,12 @@ interface RuntimeController extends SectionControllerHandle {
43
109
  subscribe?: (listener: (event: SectionControllerEvent) => void) => () => void;
44
110
  navigateToItem?: (index: number) => unknown;
45
111
  }
112
+ /**
113
+ * Legacy initialize args. Pre-PR 6 callers (the toolkit CE) drive the
114
+ * coordinator + section controller through this method. PR 6 will
115
+ * delete this in favor of the engine-side `attachHost` +
116
+ * `dispatchInput({ kind: "initialize" })` flow.
117
+ */
46
118
  interface EngineInitArgs {
47
119
  coordinator: ToolkitCoordinator;
48
120
  section: unknown;
@@ -53,14 +125,87 @@ interface EngineInitArgs {
53
125
  createDefaultController: () => Promise<RuntimeController> | RuntimeController;
54
126
  onCompositionChanged?: (composition: unknown) => void;
55
127
  }
128
+ /**
129
+ * Engine-side `attachHost` args. The host element, framework-error bus,
130
+ * and `sourceCe` together let the adapter dispatch DOM events and bus
131
+ * fan-outs identically to the legacy kernel emit chain.
132
+ */
133
+ export interface SectionRuntimeEngineHostArgs {
134
+ host: EventTarget;
135
+ sourceCe: string;
136
+ frameworkErrorBus: FrameworkErrorReporter;
137
+ coordinator?: SectionEngineAdapterOptions["coordinator"];
138
+ instrumentationHook?: InstrumentationHook;
139
+ now?: () => string;
140
+ }
56
141
  export declare class SectionRuntimeEngine {
57
142
  private readonly registry;
143
+ private readonly runtimeId;
144
+ private adapter;
58
145
  private controller;
59
146
  private coordinator;
60
147
  private sectionId;
61
148
  private attemptId;
62
149
  private unsubscribeController;
63
150
  private activeInitToken;
151
+ /**
152
+ * Attach the host element + framework-error bus + sourceCe so the
153
+ * adapter can dispatch DOM events and bus errors. Required before
154
+ * `dispatchInput` / `subscribe` produce observable effects.
155
+ *
156
+ * Constructs the adapter on the first call. Subsequent calls keep
157
+ * the adapter and update its host element / instrumentation hook
158
+ * (used by layout-shell rollovers and instrumentation reconfig).
159
+ */
160
+ attachHost(args: SectionRuntimeEngineHostArgs): void;
161
+ /**
162
+ * Forward a host-constructed input to the FSM core via the adapter.
163
+ * Returns the outputs the transition produced (subscribers and the
164
+ * DOM/legacy/framework-error/instrumentation bridges have already
165
+ * received them).
166
+ *
167
+ * No-op (returns `[]`) before `attachHost(...)` so callers that
168
+ * dispatch optimistically during teardown do not throw.
169
+ */
170
+ dispatchInput(input: SectionEngineInput): readonly SectionEngineOutput[];
171
+ /**
172
+ * Subscribe to batched engine outputs (one batch per
173
+ * `dispatchInput`). Returns an idempotent disposer. Pre-`attachHost`
174
+ * subscriptions return a no-op disposer so callers can wire
175
+ * subscriptions early without lifecycle-ordering hazards.
176
+ */
177
+ subscribe(listener: EngineOutputListener): () => void;
178
+ /**
179
+ * Read-only snapshot of the FSM state. Returns the initial idle
180
+ * state before `attachHost` so callers can probe state without
181
+ * special-casing the pre-attach phase.
182
+ */
183
+ getState(): Readonly<SectionEngineState>;
184
+ /**
185
+ * Resolve the effective runtime + tools snapshot for the given
186
+ * two-tier inputs. This is a pure function over the resolver — it
187
+ * does not depend on adapter state — so callers can use it both
188
+ * pre- and post-`attachHost`. The kernel uses it to seed
189
+ * `dispatchInput({ kind: "initialize", effectiveRuntime, ... })`.
190
+ */
191
+ getEffectiveRuntime<P>(args: RuntimeInputs, deps: {
192
+ resolvePlayerRuntime: (resolverArgs: {
193
+ effectiveRuntime: Record<string, unknown>;
194
+ playerType: string;
195
+ env: Record<string, unknown> | null;
196
+ }) => P;
197
+ }): EffectiveRuntime;
198
+ /**
199
+ * Update the adapter's instrumentation hook. No-op pre-attach.
200
+ * Hosts that always want a hook should pass it via `attachHost`.
201
+ */
202
+ setInstrumentationHook(hook: InstrumentationHook | undefined): void;
203
+ /**
204
+ * Stable per-engine runtime id used to scope DOM-event details and
205
+ * registry telemetry. Exposed so tests and instrumentation can pin
206
+ * the value the bridges emit.
207
+ */
208
+ getRuntimeId(): string;
64
209
  initialize(args: EngineInitArgs): Promise<void>;
65
210
  register(detail: RuntimeRegistrationDetail): boolean;
66
211
  unregister(element: HTMLElement): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"SectionRuntimeEngine.d.ts","sourceRoot":"","sources":["../../src/runtime/SectionRuntimeEngine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAAuB,EACvB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,UAAU,iBAAkB,SAAQ,uBAAuB;IAC1D,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC;IACpC,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IAChD,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE;QAC5B,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,KAAK,IAAI,CAAC;IACX,uBAAuB,CAAC,EAAE,CAAC,IAAI,EAAE;QAChC,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;KACrB,KAAK,IAAI,CAAC;IACX,yBAAyB,CAAC,EAAE,CAAC,IAAI,EAAE;QAClC,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;KACrB,KAAK,IAAI,CAAC;IACX,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE;QAC9B,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAA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AE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,IAAI;IAIR,qBAAqB,CAAC,IAAI,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,OAAO,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,IAAI;IAIR,kBAAkB,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,aAAa,GAAG,iBAAiB,GAAG,SAAS,GAAG,YAAY,CAAC;QACrE,KAAK,EAAE,OAAO,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,IAAI;IAIR,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAK5D,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,WAAW,IAAI,eAAe;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB9B"}
@@ -1,12 +1,162 @@
1
+ /**
2
+ * Section runtime engine — public facade (M7 — Variant C, layered).
3
+ *
4
+ * The facade is the narrow, stable entry point hosts use to mount,
5
+ * drive, and dispose a section runtime. It composes three layers
6
+ * introduced in earlier M7 PRs:
7
+ *
8
+ * - the **registry** (`RuntimeRegistry`) — registered item/passage
9
+ * shells in document order, used for canonical-id lookup;
10
+ * - the **adapter** (`SectionEngineAdapter`) — single I/O seam over
11
+ * the pure FSM core, fanning outputs to the DOM, framework-error
12
+ * bus, legacy events, instrumentation hook, and host subscribers;
13
+ * - the **resolver** (`resolveSectionEngineRuntimeState`) — the
14
+ * toolkit-side resolution helper that produces the effective
15
+ * runtime + tools snapshot a host feeds to the FSM core.
16
+ *
17
+ * **Two callsite generations.** During the M7 migration window the
18
+ * facade carries two surface generations side-by-side:
19
+ *
20
+ * 1. The **engine-side** surface (`attachHost`, `dispatchInput`,
21
+ * `subscribe`, `getState`, `getEffectiveRuntime`,
22
+ * `setInstrumentationHook`). This is what the kernel and the
23
+ * `pie-assessment-toolkit` CE will switch onto in M7 PR 5 and
24
+ * PR 6. Construction is lazy: `attachHost(...)` builds the
25
+ * adapter on first call, with the supplied host element,
26
+ * framework-error bus, and (optional) coordinator. After
27
+ * construction, host re-attachments (e.g. cohort change with a
28
+ * new layout shell) update the adapter's host element via
29
+ * `setHost(...)`.
30
+ *
31
+ * 2. The **legacy controller-side** surface (`initialize`,
32
+ * `register`, `unregister`, `handleContent*`, `updateItemSession`,
33
+ * `navigateToItem`, `persist`, `hydrate`, `dispose`). The
34
+ * `PieAssessmentToolkit.svelte` CE still drives the seed via this
35
+ * surface in PR 3 — observable behavior is identical to pre-PR 3.
36
+ * PR 6 deletes the toolkit's reliance on this surface; PR 7
37
+ * removes the methods that the engine FSM has fully absorbed.
38
+ *
39
+ * The two surfaces share `RuntimeRegistry` (the only piece both
40
+ * generations consult) and the resolved `SectionControllerHandle` the
41
+ * legacy generation holds inline. The adapter holds its own
42
+ * `coordinator-bridge` independently — the legacy `initialize(...)` and
43
+ * the engine-side `dispatchInput({ kind: "initialize" })` do **not**
44
+ * fight over the coordinator because PR 3 only activates one of them
45
+ * per host (legacy from the toolkit CE, engine-side from the PR 5+
46
+ * tests and the kernel/toolkit switches).
47
+ *
48
+ * **Why the legacy surface stays.** The plan's PR-3 acceptance criterion
49
+ * is "existing toolkit tests still pass; no section-player or toolkit
50
+ * CE code changes yet" — so PR 3 cannot delete the controller-side
51
+ * methods. PR 6 (toolkit switch) and PR 7 (rip-out) will remove them
52
+ * once the engine surface is the only consumer.
53
+ */
54
+ import { SectionEngineAdapter, } from "./adapter/SectionEngineAdapter.js";
55
+ import { resolveSectionEngineRuntimeState, } from "./core/engine-resolver.js";
56
+ import { createInitialEngineState, } from "./core/engine-state.js";
1
57
  import { RuntimeRegistry } from "./RuntimeRegistry.js";
58
+ import { createRuntimeId } from "./runtime-id.js";
2
59
  export class SectionRuntimeEngine {
3
60
  registry = new RuntimeRegistry();
61
+ runtimeId = createRuntimeId("section-engine");
62
+ // Engine-side state (PR 3+).
63
+ adapter = null;
64
+ // Legacy controller-side state (until PR 6).
4
65
  controller = null;
5
66
  coordinator = null;
6
67
  sectionId = "";
7
68
  attemptId;
8
69
  unsubscribeController = null;
9
70
  activeInitToken = 0;
71
+ // ============================================================
72
+ // Engine-side surface (PR 3+; driven by the kernel from PR 5,
73
+ // by the toolkit CE from PR 6, and by the facade smoke test today).
74
+ // ============================================================
75
+ /**
76
+ * Attach the host element + framework-error bus + sourceCe so the
77
+ * adapter can dispatch DOM events and bus errors. Required before
78
+ * `dispatchInput` / `subscribe` produce observable effects.
79
+ *
80
+ * Constructs the adapter on the first call. Subsequent calls keep
81
+ * the adapter and update its host element / instrumentation hook
82
+ * (used by layout-shell rollovers and instrumentation reconfig).
83
+ */
84
+ attachHost(args) {
85
+ if (this.adapter) {
86
+ this.adapter.setHost(args.host);
87
+ if (args.instrumentationHook !== undefined) {
88
+ this.adapter.setInstrumentationHook(args.instrumentationHook);
89
+ }
90
+ return;
91
+ }
92
+ this.adapter = new SectionEngineAdapter({
93
+ host: args.host,
94
+ runtimeId: this.runtimeId,
95
+ sourceCe: args.sourceCe,
96
+ frameworkErrorBus: args.frameworkErrorBus,
97
+ coordinator: args.coordinator,
98
+ instrumentationHook: args.instrumentationHook,
99
+ now: args.now,
100
+ });
101
+ }
102
+ /**
103
+ * Forward a host-constructed input to the FSM core via the adapter.
104
+ * Returns the outputs the transition produced (subscribers and the
105
+ * DOM/legacy/framework-error/instrumentation bridges have already
106
+ * received them).
107
+ *
108
+ * No-op (returns `[]`) before `attachHost(...)` so callers that
109
+ * dispatch optimistically during teardown do not throw.
110
+ */
111
+ dispatchInput(input) {
112
+ return this.adapter?.dispatchInput(input) ?? [];
113
+ }
114
+ /**
115
+ * Subscribe to batched engine outputs (one batch per
116
+ * `dispatchInput`). Returns an idempotent disposer. Pre-`attachHost`
117
+ * subscriptions return a no-op disposer so callers can wire
118
+ * subscriptions early without lifecycle-ordering hazards.
119
+ */
120
+ subscribe(listener) {
121
+ return this.adapter?.subscribe(listener) ?? noopDispose;
122
+ }
123
+ /**
124
+ * Read-only snapshot of the FSM state. Returns the initial idle
125
+ * state before `attachHost` so callers can probe state without
126
+ * special-casing the pre-attach phase.
127
+ */
128
+ getState() {
129
+ return this.adapter?.getState() ?? createInitialEngineState();
130
+ }
131
+ /**
132
+ * Resolve the effective runtime + tools snapshot for the given
133
+ * two-tier inputs. This is a pure function over the resolver — it
134
+ * does not depend on adapter state — so callers can use it both
135
+ * pre- and post-`attachHost`. The kernel uses it to seed
136
+ * `dispatchInput({ kind: "initialize", effectiveRuntime, ... })`.
137
+ */
138
+ getEffectiveRuntime(args, deps) {
139
+ return resolveSectionEngineRuntimeState(args, deps).effectiveRuntime;
140
+ }
141
+ /**
142
+ * Update the adapter's instrumentation hook. No-op pre-attach.
143
+ * Hosts that always want a hook should pass it via `attachHost`.
144
+ */
145
+ setInstrumentationHook(hook) {
146
+ this.adapter?.setInstrumentationHook(hook);
147
+ }
148
+ /**
149
+ * Stable per-engine runtime id used to scope DOM-event details and
150
+ * registry telemetry. Exposed so tests and instrumentation can pin
151
+ * the value the bridges emit.
152
+ */
153
+ getRuntimeId() {
154
+ return this.runtimeId;
155
+ }
156
+ // ============================================================
157
+ // Legacy controller-side surface (kept until PR 6; behavior
158
+ // identical to pre-PR 3).
159
+ // ============================================================
10
160
  async initialize(args) {
11
161
  this.activeInitToken += 1;
12
162
  const token = this.activeInitToken;
@@ -30,9 +180,10 @@ export class SectionRuntimeEngine {
30
180
  this.unsubscribeController?.();
31
181
  this.controller = resolved;
32
182
  args.onCompositionChanged?.(resolved.getCompositionModel?.());
33
- this.unsubscribeController = resolved.subscribe?.(() => {
34
- args.onCompositionChanged?.(resolved.getCompositionModel?.());
35
- }) || null;
183
+ this.unsubscribeController =
184
+ resolved.subscribe?.(() => {
185
+ args.onCompositionChanged?.(resolved.getCompositionModel?.());
186
+ }) || null;
36
187
  }
37
188
  register(detail) {
38
189
  return this.registry.register(detail);
@@ -99,6 +250,16 @@ export class SectionRuntimeEngine {
99
250
  this.registry.clear();
100
251
  this.controller = null;
101
252
  this.coordinator = null;
253
+ // Tear down the engine-side adapter (if attached) last so any
254
+ // `dispose` FSM input flows through the bridges before they
255
+ // detach. Adapter disposal is idempotent and safe even when
256
+ // nothing is attached.
257
+ if (this.adapter) {
258
+ const adapter = this.adapter;
259
+ this.adapter = null;
260
+ await adapter.dispose();
261
+ }
102
262
  }
103
263
  }
264
+ const noopDispose = () => { };
104
265
  //# sourceMappingURL=SectionRuntimeEngine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SectionRuntimeEngine.js","sourceRoot":"","sources":["../../src/runtime/SectionRuntimeEngine.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAwDvD,MAAM,OAAO,oBAAoB;IACf,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IAC1C,UAAU,GAA6B,IAAI,CAAC;IAC5C,WAAW,GAA8B,IAAI,CAAC;IAC9C,SAAS,GAAG,EAAE,CAAC;IACf,SAAS,CAAqB;IAC9B,qBAAqB,GAAwB,IAAI,CAAC;IAClD,eAAe,GAAG,CAAC,CAAC;IAE5B,KAAK,CAAC,UAAU,CAAC,IAAoB;QACpC,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC;QACnC,IAAI,CA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AE,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,OAAO;QACZ,MAAM,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAO;QACZ,MAAM,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;IACpC,CAAC;IAED,WAAW;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,OAAO;QACZ,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAClC,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACxC,MAAM,IAAI,CAAC,WAAW,CAAC,wBAAwB,CAAC;gBAC/C,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,SAAS,EAAE,IAAI,CAAC,SAAS;aACzB,CAAC,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,8DAA8D;QAC9D,4DAA4D;QAC5D,4DAA4D;QAC5D,uBAAuB;QACvB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;IACF,CAAC;CACD;AAED,MAAM,WAAW,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Section runtime engine adapter (M7 — Variant C, layered).
3
+ *
4
+ * The adapter is the single I/O seam between the pure FSM core
5
+ * (`SectionEngineCore`) and the rest of the world (DOM, coordinator,
6
+ * framework-error bus, host subscribers, instrumentation). It does
7
+ * exactly two jobs:
8
+ *
9
+ * 1. Translate **host inputs** (from kernels, the toolkit CE, or
10
+ * direct facade callers) into `SectionEngineInput`s and forward
11
+ * them to the core via `core.dispatch(input)`.
12
+ *
13
+ * 2. Subscribe to the core's output stream and **route each output**
14
+ * through the bridges in a deterministic order so the public DOM
15
+ * surface, framework-error bus, instrumentation hook, and host
16
+ * subscribers all see exactly the same fan-out with
17
+ * byte-identical detail shapes.
18
+ *
19
+ * Output routing is a single exhaustive `switch` (`assertNever` on
20
+ * the default branch) so adding a new `SectionEngineOutput` kind in
21
+ * `engine-output.ts` is a compile error here until the adapter knows
22
+ * what to do with it.
23
+ *
24
+ * **Routing order per output:**
25
+ * - canonical DOM event (`pie-stage-change`, `pie-loading-complete`,
26
+ * `framework-error`)
27
+ * - framework-error bus (single fan-out for in-process subscribers)
28
+ * - instrumentation hook
29
+ * - public subscriber fan-out (batched, runs once per
30
+ * `core.dispatch`)
31
+ *
32
+ * The deprecated `readiness-change` / `interaction-ready` / `ready`
33
+ * DOM events and their `legacy-event-bridge.ts` were removed in the
34
+ * broad architecture review compat sweep; the corresponding output
35
+ * kinds are gone from `engine-output.ts`.
36
+ *
37
+ * **Layering constraint.** The adapter is plain TS. It must not
38
+ * import `svelte` — the M7 implementation plan and
39
+ * `scripts/check-engine-core-purity.mjs` enforce the core's purity;
40
+ * the adapter follows the same constraint by convention so it stays
41
+ * usable from non-Svelte hosts (Node tests, Storybook, or future
42
+ * non-Svelte consumers). `bun run check:custom-elements` already
43
+ * blocks `.svelte` imports in published `dist`; adding a Svelte
44
+ * dependency here would also leak through that gate.
45
+ */
46
+ import type { FrameworkErrorReporter } from "../../services/framework-error-bus.js";
47
+ import { SectionEngineCore } from "../core/SectionEngineCore.js";
48
+ import type { SectionEngineInput } from "../core/engine-input.js";
49
+ import type { SectionEngineOutput } from "../core/engine-output.js";
50
+ import type { SectionEngineState } from "../core/engine-state.js";
51
+ import { type CoordinatorPort, type ResolveSectionControllerArgs } from "./coordinator-bridge.js";
52
+ import { type InstrumentationHook } from "./instrumentation-bridge.js";
53
+ import { type EngineOutputListener } from "./subscriber-fanout.js";
54
+ export interface SectionEngineAdapterOptions {
55
+ /** Element on which DOM events are dispatched. */
56
+ host: EventTarget;
57
+ /** Stable runtime id for this engine instance. */
58
+ runtimeId: string;
59
+ /**
60
+ * Tag name of the host CE without the `--version-<encoded>` suffix.
61
+ */
62
+ sourceCe: string;
63
+ /**
64
+ * Framework-error bus (write side). Shared with the toolkit CE so
65
+ * subscribers via `coordinator.subscribeFrameworkErrors` see the
66
+ * same fan-out.
67
+ */
68
+ frameworkErrorBus: FrameworkErrorReporter;
69
+ /**
70
+ * Optional toolkit coordinator. When supplied, the adapter wires
71
+ * its framework-error subscription, controller resolution, and
72
+ * disposal through the coordinator-bridge. Standalone callers (no
73
+ * coordinator) can omit this and feed `framework-error` and
74
+ * `section-controller-resolved` inputs directly.
75
+ */
76
+ coordinator?: CoordinatorPort;
77
+ /** Optional one-shot observability hook. */
78
+ instrumentationHook?: InstrumentationHook;
79
+ /** Clock injection for the DOM bridge. Defaults to `Date.now()`. */
80
+ now?: () => string;
81
+ /**
82
+ * Optional pre-constructed core. Defaults to a fresh
83
+ * `SectionEngineCore`. Tests pass a mocked core to assert dispatch
84
+ * ordering; production callers use the default.
85
+ */
86
+ core?: SectionEngineCore;
87
+ }
88
+ export declare class SectionEngineAdapter {
89
+ private readonly core;
90
+ private readonly domEventBridge;
91
+ private readonly frameworkErrorBridge;
92
+ private readonly instrumentationBridge;
93
+ private readonly subscriberFanout;
94
+ private readonly coordinatorBridge;
95
+ private readonly unsubscribeCore;
96
+ private disposed;
97
+ constructor(options: SectionEngineAdapterOptions);
98
+ /**
99
+ * Read-only snapshot of the FSM state. Mirrors
100
+ * `SectionEngineCore.getState()`.
101
+ */
102
+ getState(): Readonly<SectionEngineState>;
103
+ /**
104
+ * Forward a host-constructed input to the core. Returns the outputs
105
+ * that resulted (the bridges have already received them).
106
+ */
107
+ dispatchInput(input: SectionEngineInput): readonly SectionEngineOutput[];
108
+ /**
109
+ * Subscribe to batched output streams, one batch per
110
+ * `dispatchInput`.
111
+ */
112
+ subscribe(listener: EngineOutputListener): () => void;
113
+ /**
114
+ * Update the host element after construction (e.g. when the kernel
115
+ * receives its host element via Svelte action / context).
116
+ */
117
+ setHost(host: EventTarget): void;
118
+ /**
119
+ * Update the instrumentation hook at runtime.
120
+ */
121
+ setInstrumentationHook(hook: InstrumentationHook | undefined): void;
122
+ /**
123
+ * Resolve a section controller through the configured coordinator.
124
+ *
125
+ * Throws if the adapter was constructed without a coordinator.
126
+ * Standalone callers should manually feed
127
+ * `{ kind: "section-controller-resolved" }` after their own
128
+ * controller resolution path completes.
129
+ */
130
+ resolveSectionController(args: ResolveSectionControllerArgs): Promise<void>;
131
+ /**
132
+ * Tear the adapter down. Safe to call more than once. Disposes the
133
+ * coordinator bridge (which in turn disposes the section
134
+ * controller for the current cohort), detaches the core
135
+ * subscription, and clears subscribers.
136
+ *
137
+ * Does **not** dispose the framework-error bus — its lifetime is
138
+ * owned by the toolkit CE / host.
139
+ */
140
+ dispose(): Promise<void>;
141
+ private routeOutputs;
142
+ private routeOne;
143
+ }
144
+ //# sourceMappingURL=SectionEngineAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SectionEngineAdapter.d.ts","sourceRoot":"","sources":["../../../src/runtime/adapter/SectionEngineAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EA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