@pie-players/pie-assessment-toolkit 0.3.74 → 1.0.0-beta.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 (257) hide show
  1. package/README.md +658 -714
  2. package/custom-elements.json +1315 -0
  3. package/dist/attempt/TestSession.d.ts +1 -21
  4. package/dist/attempt/TestSession.js +16 -102
  5. package/dist/components/ItemScope.custom-element.d.ts +1 -0
  6. package/dist/components/ItemScope.custom-element.js +1 -0
  7. package/dist/components/ItemToolBar.custom-element.js +1 -1
  8. package/dist/components/PieAssessmentToolkit.custom-element.js +14 -14
  9. package/dist/components/SectionToolBar.custom-element.js +1 -1
  10. package/dist/components/chunks/ItemToolBar-3zrc4p3d.js +4 -0
  11. package/dist/components/chunks/ItemToolBar-66hcwmfw.js +2 -0
  12. package/dist/components/chunks/ItemToolBar-9gqhfxtn.js +40 -0
  13. package/dist/components/chunks/ItemToolBar-hzc5wyjp.js +2 -0
  14. package/dist/components/chunks/{ItemToolBar-gmrryv2v.js → ItemToolBar-kkj69ptr.js} +1 -1
  15. package/dist/components/chunks/ItemToolBar-vdkyn9f3.js +2 -0
  16. package/dist/components/chunks/sre-engine-bj997w4b.js +1 -0
  17. package/dist/components/item-scope-element.d.ts +2 -0
  18. package/dist/components/item-scope-element.js +2 -0
  19. package/dist/context/assessment-toolkit-context.d.ts +33 -6
  20. package/dist/index.d.ts +25 -50
  21. package/dist/index.js +15 -45
  22. package/dist/policy/core/PolicySource.d.ts +2 -2
  23. package/dist/policy/core/ToolPolicyEngine.d.ts +118 -34
  24. package/dist/policy/core/ToolPolicyEngine.js +203 -56
  25. package/dist/policy/core/compose-decision.d.ts +28 -7
  26. package/dist/policy/core/compose-decision.js +95 -74
  27. package/dist/policy/core/decision-types.d.ts +98 -55
  28. package/dist/policy/core/feature-decision.d.ts +28 -19
  29. package/dist/policy/core/feature-decision.js +15 -11
  30. package/dist/policy/core/pnp-policy-inputs.d.ts +29 -35
  31. package/dist/policy/core/pnp-policy-inputs.js +40 -88
  32. package/dist/policy/core/provenance.d.ts +10 -5
  33. package/dist/policy/core/provenance.js +1 -1
  34. package/dist/policy/core/tool-parameters.d.ts +11 -0
  35. package/dist/policy/core/tool-parameters.js +15 -0
  36. package/dist/policy/engine.d.ts +7 -23
  37. package/dist/policy/engine.js +5 -20
  38. package/dist/policy/sources/PnpPolicySource.d.ts +43 -68
  39. package/dist/policy/sources/PnpPolicySource.js +133 -132
  40. package/dist/runtime/SectionControllerBinding.d.ts +283 -0
  41. package/dist/runtime/SectionControllerBinding.js +456 -0
  42. package/dist/runtime/SectionRuntimeEngine.d.ts +26 -289
  43. package/dist/runtime/SectionRuntimeEngine.js +30 -372
  44. package/dist/runtime/adapter/SectionEngineAdapter.d.ts +19 -80
  45. package/dist/runtime/adapter/SectionEngineAdapter.js +19 -92
  46. package/dist/runtime/adapter/dom-event-bridge.d.ts +15 -30
  47. package/dist/runtime/adapter/dom-event-bridge.js +17 -44
  48. package/dist/runtime/adapter/subscriber-fanout.d.ts +1 -3
  49. package/dist/runtime/adapter/subscriber-fanout.js +2 -6
  50. package/dist/runtime/catalog-context.d.ts +19 -0
  51. package/dist/runtime/catalog-context.js +28 -0
  52. package/dist/runtime/composition-emit-scheduler.d.ts +12 -18
  53. package/dist/runtime/composition-emit-scheduler.js +10 -16
  54. package/dist/runtime/content-language.d.ts +32 -0
  55. package/dist/runtime/content-language.js +46 -0
  56. package/dist/runtime/content-region.d.ts +13 -0
  57. package/dist/runtime/content-region.js +29 -0
  58. package/dist/runtime/content-registration.d.ts +13 -0
  59. package/dist/runtime/content-registration.js +25 -0
  60. package/dist/runtime/core/SectionEngineCore.d.ts +2 -4
  61. package/dist/runtime/core/SectionEngineCore.js +2 -6
  62. package/dist/runtime/core/cohort.d.ts +1 -6
  63. package/dist/runtime/core/cohort.js +1 -10
  64. package/dist/runtime/core/engine-input.d.ts +18 -30
  65. package/dist/runtime/core/engine-input.js +11 -12
  66. package/dist/runtime/core/engine-output.d.ts +17 -40
  67. package/dist/runtime/core/engine-output.js +9 -21
  68. package/dist/runtime/core/engine-readiness.d.ts +5 -37
  69. package/dist/runtime/core/engine-readiness.js +8 -41
  70. package/dist/runtime/core/engine-resolver.d.ts +46 -74
  71. package/dist/runtime/core/engine-resolver.js +18 -43
  72. package/dist/runtime/core/engine-state.d.ts +28 -36
  73. package/dist/runtime/core/engine-state.js +18 -21
  74. package/dist/runtime/core/engine-transition.d.ts +14 -19
  75. package/dist/runtime/core/engine-transition.js +74 -53
  76. package/dist/runtime/engine.d.ts +16 -19
  77. package/dist/runtime/engine.js +12 -19
  78. package/dist/runtime/page-warnings.d.ts +13 -0
  79. package/dist/runtime/page-warnings.js +22 -0
  80. package/dist/runtime/policy-input-forwarding.d.ts +25 -0
  81. package/dist/runtime/policy-input-forwarding.js +25 -0
  82. package/dist/runtime/registration-events.d.ts +22 -14
  83. package/dist/runtime/runtime-event-claim.d.ts +8 -0
  84. package/dist/runtime/runtime-event-claim.js +15 -0
  85. package/dist/runtime/runtime-id.d.ts +1 -1
  86. package/dist/runtime/runtime-id.js +1 -1
  87. package/dist/runtime/shell-event-bridge.d.ts +45 -0
  88. package/dist/runtime/shell-event-bridge.js +127 -0
  89. package/dist/runtime/shell-registration.d.ts +73 -0
  90. package/dist/runtime/shell-registration.js +95 -0
  91. package/dist/runtime/shell-scope.d.ts +68 -0
  92. package/dist/runtime/shell-scope.js +194 -0
  93. package/dist/runtime/tool-host-contract.d.ts +8 -14
  94. package/dist/runtime/tool-host-contract.js +12 -12
  95. package/dist/runtime/unclaimed-registration-watch.d.ts +7 -0
  96. package/dist/runtime/unclaimed-registration-watch.js +23 -0
  97. package/dist/services/AccessibilityCatalogResolver.d.ts +21 -31
  98. package/dist/services/AccessibilityCatalogResolver.js +29 -42
  99. package/dist/services/ElementToolStateStore.d.ts +42 -67
  100. package/dist/services/ElementToolStateStore.js +65 -71
  101. package/dist/services/HighlightCoordinator.d.ts +28 -40
  102. package/dist/services/HighlightCoordinator.js +459 -381
  103. package/dist/services/RangeSerializer.d.ts +11 -33
  104. package/dist/services/RangeSerializer.js +88 -59
  105. package/dist/services/SSMLExtractor.d.ts +8 -31
  106. package/dist/services/SSMLExtractor.js +18 -40
  107. package/dist/services/TTSService.d.ts +159 -119
  108. package/dist/services/TTSService.js +937 -822
  109. package/dist/services/ToolCoordinator.d.ts +42 -102
  110. package/dist/services/ToolCoordinator.js +178 -256
  111. package/dist/services/ToolRegistry.d.ts +152 -133
  112. package/dist/services/ToolRegistry.js +192 -178
  113. package/dist/services/ToolkitCoordinator.d.ts +233 -237
  114. package/dist/services/ToolkitCoordinator.js +615 -557
  115. package/dist/services/audio-handoff.d.ts +6 -7
  116. package/dist/services/audio-handoff.js +20 -14
  117. package/dist/services/catalog-owner.d.ts +0 -1
  118. package/dist/services/framework-error-bus.d.ts +3 -6
  119. package/dist/services/framework-error-bus.js +3 -6
  120. package/dist/services/framework-error.d.ts +51 -13
  121. package/dist/services/framework-error.js +19 -20
  122. package/dist/services/interfaces.d.ts +189 -184
  123. package/dist/services/section-controller-types.d.ts +7 -7
  124. package/dist/services/section-session-assignment.d.ts +21 -0
  125. package/dist/services/section-session-assignment.js +80 -0
  126. package/dist/services/spoken-audio-cards.d.ts +2 -6
  127. package/dist/services/spoken-audio-cards.js +2 -6
  128. package/dist/services/tool-config-defaults.d.ts +3 -3
  129. package/dist/services/tool-config-defaults.js +3 -3
  130. package/dist/services/tool-config-validation.d.ts +9 -12
  131. package/dist/services/tool-config-validation.js +47 -87
  132. package/dist/services/tool-context.d.ts +7 -31
  133. package/dist/services/tool-context.js +99 -65
  134. package/dist/services/tool-failure.d.ts +30 -0
  135. package/dist/services/tool-failure.js +11 -0
  136. package/dist/services/tool-icons.d.ts +5 -5
  137. package/dist/services/tool-icons.js +6 -5
  138. package/dist/services/tool-instance-id.d.ts +8 -7
  139. package/dist/services/tool-instance-id.js +12 -24
  140. package/dist/services/tool-providers/TTSToolProvider.d.ts +20 -58
  141. package/dist/services/tool-providers/TTSToolProvider.js +32 -85
  142. package/dist/services/tool-providers/ToolProviderApi.d.ts +10 -11
  143. package/dist/services/tool-providers/ToolProviderRegistry.d.ts +29 -60
  144. package/dist/services/tool-providers/ToolProviderRegistry.js +128 -144
  145. package/dist/services/tool-request.d.ts +31 -12
  146. package/dist/services/tool-request.js +31 -16
  147. package/dist/services/toolbar-decided-tools.d.ts +16 -0
  148. package/dist/services/toolbar-decided-tools.js +29 -0
  149. package/dist/services/toolbar-items.js +2 -5
  150. package/dist/services/tools-config-normalizer.d.ts +33 -29
  151. package/dist/services/tools-config-normalizer.js +26 -28
  152. package/dist/services/tts/browser-provider.d.ts +39 -6
  153. package/dist/services/tts/browser-provider.js +280 -160
  154. package/dist/services/tts/catalog-span-alignment.js +14 -7
  155. package/dist/services/tts/flat-tree.d.ts +64 -0
  156. package/dist/services/tts/flat-tree.js +269 -0
  157. package/dist/services/tts/generated-speech/assemble-plan.d.ts +3 -1
  158. package/dist/services/tts/generated-speech/assemble-plan.js +3 -1
  159. package/dist/services/tts/generated-speech/dom/build-dom-plan.d.ts +2 -0
  160. package/dist/services/tts/generated-speech/dom/build-dom-plan.js +1 -1
  161. package/dist/services/tts/generated-speech/dom/to-chunk-inputs.d.ts +2 -2
  162. package/dist/services/tts/generated-speech/index.d.ts +1 -1
  163. package/dist/services/tts/generated-speech/index.js +1 -1
  164. package/dist/services/tts/generated-speech/math-speech-cache.d.ts +3 -1
  165. package/dist/services/tts/generated-speech/math-speech-cache.js +5 -1
  166. package/dist/services/tts/generated-speech/types.d.ts +1 -1
  167. package/dist/services/tts/generated-speech/types.js +1 -1
  168. package/dist/services/tts/highlight-pipeline/create-highlight-plan.js +22 -16
  169. package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js +6 -4
  170. package/dist/services/tts/highlight-pipeline/readable-region.js +3 -2
  171. package/dist/services/tts/highlight-pipeline/types.d.ts +5 -0
  172. package/dist/services/tts/highlight-pipeline/visible-map-range.d.ts +12 -0
  173. package/dist/services/tts/highlight-pipeline/visible-map-range.js +73 -7
  174. package/dist/services/tts/highlight-target-resolver.d.ts +12 -0
  175. package/dist/services/tts/math-aware-text-processing.d.ts +5 -1
  176. package/dist/services/tts/math-aware-text-processing.js +42 -47
  177. package/dist/services/tts/math-control-names.d.ts +21 -0
  178. package/dist/services/tts/math-control-names.js +142 -0
  179. package/dist/services/tts/math-speech.d.ts +12 -1
  180. package/dist/services/tts/math-speech.js +54 -18
  181. package/dist/services/tts/mathml-sanitization.d.ts +7 -0
  182. package/dist/services/tts/mathml-sanitization.js +9 -1
  183. package/dist/services/tts/provider-options.d.ts +52 -0
  184. package/dist/services/tts/provider-options.js +1 -0
  185. package/dist/services/tts/ssml/spoken-text.d.ts +2 -26
  186. package/dist/services/tts/ssml/spoken-text.js +29 -0
  187. package/dist/services/tts/start-failure.d.ts +4 -0
  188. package/dist/services/tts/start-failure.js +19 -0
  189. package/dist/services/tts/text-processing.d.ts +9 -0
  190. package/dist/services/tts/text-processing.js +46 -33
  191. package/dist/services/tts/text-segmentation.d.ts +12 -0
  192. package/dist/services/tts/text-segmentation.js +60 -10
  193. package/dist/services/tts-runtime-config.d.ts +54 -26
  194. package/dist/services/tts-runtime-config.js +27 -112
  195. package/dist/tools/content-capability-resolution.d.ts +9 -11
  196. package/dist/tools/content-capability-resolution.js +8 -45
  197. package/dist/tools/registration.d.ts +59 -0
  198. package/dist/tools/registration.js +55 -0
  199. package/dist/tools/registrations/toolbar-registration-helpers.d.ts +6 -0
  200. package/dist/tools/registrations/toolbar-registration-helpers.js +8 -2
  201. package/dist/tools/tool-surface-host.d.ts +6 -10
  202. package/dist/tools/tool-surface-host.js +45 -50
  203. package/dist/tools/tool-tag-map.d.ts +5 -15
  204. package/dist/tools/tool-tag-map.js +6 -20
  205. package/dist/utils/structural-equality.d.ts +11 -0
  206. package/dist/utils/structural-equality.js +47 -0
  207. package/package.json +15 -29
  208. package/dist/attempt/adapters/activity-to-test-attempt-session.d.ts +0 -49
  209. package/dist/attempt/adapters/activity-to-test-attempt-session.js +0 -138
  210. package/dist/components/chunks/ItemToolBar-b9dz5jvd.js +0 -40
  211. package/dist/components/chunks/ItemToolBar-h4xap0t0.js +0 -4
  212. package/dist/components/chunks/ItemToolBar-wr2myaah.js +0 -2
  213. package/dist/components/chunks/sre-engine-wf9s43gg.js +0 -1
  214. package/dist/context/runtime-context-consumer.d.ts +0 -13
  215. package/dist/context/runtime-context-consumer.js +0 -18
  216. package/dist/item-loader.d.ts +0 -44
  217. package/dist/item-loader.js +0 -61
  218. package/dist/policy/core/engine-context.d.ts +0 -29
  219. package/dist/policy/core/engine-context.js +0 -27
  220. package/dist/policy/core/policy-source-tag.d.ts +0 -31
  221. package/dist/policy/core/policy-source-tag.js +0 -28
  222. package/dist/policy/internal.d.ts +0 -25
  223. package/dist/policy/internal.js +0 -25
  224. package/dist/runtime/adapter/coordinator-bridge.d.ts +0 -92
  225. package/dist/runtime/adapter/coordinator-bridge.js +0 -126
  226. package/dist/runtime/adapter/framework-error-bridge.d.ts +0 -36
  227. package/dist/runtime/adapter/framework-error-bridge.js +0 -46
  228. package/dist/runtime/adapter/instrumentation-bridge.d.ts +0 -31
  229. package/dist/runtime/adapter/instrumentation-bridge.js +0 -38
  230. package/dist/runtime/core/engine-stage-derivation.d.ts +0 -18
  231. package/dist/runtime/core/engine-stage-derivation.js +0 -29
  232. package/dist/runtime/engine-context.d.ts +0 -39
  233. package/dist/runtime/engine-context.js +0 -31
  234. package/dist/runtime/internal.d.ts +0 -43
  235. package/dist/runtime/internal.js +0 -45
  236. package/dist/runtime/section-runtime-engine-host-context.d.ts +0 -74
  237. package/dist/runtime/section-runtime-engine-host-context.js +0 -57
  238. package/dist/runtime/stage-emit-gate.d.ts +0 -92
  239. package/dist/runtime/stage-emit-gate.js +0 -82
  240. package/dist/services/ContextVariableStore.d.ts +0 -113
  241. package/dist/services/ContextVariableStore.js +0 -206
  242. package/dist/services/I18nService.d.ts +0 -47
  243. package/dist/services/I18nService.js +0 -84
  244. package/dist/services/ThemeProvider.d.ts +0 -95
  245. package/dist/services/ThemeProvider.js +0 -334
  246. package/dist/services/defaultPersonalNeedsProfile.d.ts +0 -21
  247. package/dist/services/defaultPersonalNeedsProfile.js +0 -26
  248. package/dist/services/pnp-standard-features.d.ts +0 -238
  249. package/dist/services/pnp-standard-features.js +0 -338
  250. package/dist/services/tts-control-events.d.ts +0 -13
  251. package/dist/services/tts-control-events.js +0 -7
  252. package/dist/tools/client.d.ts +0 -10
  253. package/dist/tools/client.js +0 -10
  254. package/dist/tools/internal.d.ts +0 -44
  255. package/dist/tools/internal.js +0 -39
  256. package/dist/utils/logger.d.ts +0 -6
  257. package/dist/utils/logger.js +0 -10
@@ -1,11 +1,9 @@
1
1
  /**
2
- * Section runtime engine resolver (M7).
2
+ * Section runtime engine resolver.
3
3
  *
4
4
  * Canonical home of `resolveRuntime`, `resolveToolsConfig`, and their
5
- * supporting helpers/types. As of M7 PR 7 the previous duplicates in
6
- * `packages/section-player/src/components/shared/section-player-runtime.ts`
7
- * have been deleted; section-player now consumes these helpers via
8
- * `@pie-players/pie-assessment-toolkit/runtime/internal`.
5
+ * supporting helpers/types; section-player consumes them through
6
+ * `@pie-players/pie-assessment-toolkit/runtime/engine`.
9
7
  *
10
8
  * What is NOT absorbed in this module:
11
9
  * - `resolvePlayerRuntime` stays in section-player because it depends on
@@ -18,22 +16,26 @@
18
16
  * `packages/section-player/src/components/shared/section-player-host-runtime.ts`)
19
17
  * hands its local implementation in.
20
18
  *
21
- * Runtime-owned configuration flows through `runtime.<key>`. Layout-only
22
- * inputs stay on the section-player host elements.
19
+ * Each input has one tier. `assessmentId`, the tools and player config and the
20
+ * `on*` callbacks arrive on `runtime`. The primitive inputs (`nds-icons`,
21
+ * `locale`, `tool-config-strictness`) are element attributes; the resolver takes
22
+ * `toolConfigStrictness` beside `runtime`.
23
23
  */
24
24
  import type { LoaderConfig } from "@pie-players/pie-players-shared/loader-config";
25
25
  import type { LoadingCompleteDetail, StageChangeDetail } from "@pie-players/pie-players-shared/pie";
26
26
  import type { FrameworkErrorModel } from "../../services/framework-error.js";
27
27
  import type { ToolConfigStrictness } from "../../services/tool-config-validation.js";
28
- export declare const DEFAULT_ASSESSMENT_ID = "section-demo-direct";
29
28
  export declare const DEFAULT_PLAYER_TYPE = "iife";
30
- export declare const DEFAULT_LAZY_INIT = true;
29
+ export declare const DEFAULT_LAZY_INIT = false;
31
30
  export declare const DEFAULT_ISOLATION = "inherit";
32
31
  export declare const DEFAULT_ENV: Record<string, unknown>;
33
32
  export type PlayerOverrides = {
33
+ /** The host has already loaded the item bundles; the player loads none. */
34
+ hosted?: boolean;
34
35
  loaderConfig?: LoaderConfig;
35
36
  loaderOptions?: Record<string, unknown>;
36
- [key: string]: unknown;
37
+ /** The item player's `backend` config, passed through unread. */
38
+ backend?: Record<string, unknown> | null;
37
39
  };
38
40
  export type FrameworkErrorHandler = (model: FrameworkErrorModel) => void;
39
41
  export type StageChangeHandler = (detail: StageChangeDetail) => void;
@@ -61,48 +63,34 @@ export type RuntimeConfig = {
61
63
  isolation?: string;
62
64
  env?: Record<string, unknown>;
63
65
  /**
64
- * Presentation flag: opt-in to the vendored `<nds-icon-button>` for the
65
- * toolbar tool buttons, the calculator shell controls, inline-TTS
66
- * play/pause, and the section scroll-hint. NDS icons render only when
67
- * this is explicitly `true`; unset/`false` keeps the plain `<button>`
68
- * markup (the default). Purely visual — no engine effect.
69
- */
70
- ndsIcons?: boolean;
71
- /**
72
- * Interface locale: a BCP-47 tag naming the language the player renders its own
73
- * UI in. Purely presentational — no engine effect.
74
- *
75
- * Distinct from content language, which describes the authored item and
76
- * travels on `env`. QTI 3's implementation guide states the independence
77
- * directly: a candidate may choose an interface language which may or may not
78
- * also be the language of the content.
66
+ * Content language: a BCP-47 tag naming the language the authored content is
67
+ * written in, which read-aloud speaks it in and catalog lookups select
68
+ * alternates by. A `lang` in the content's markup wins over it. Purely
69
+ * presentational — no engine effect.
79
70
  *
80
- * Unset renders `en-US`. POSIX (`nl_NL`) and bare (`nl`) forms both resolve.
71
+ * Unset reads as `en-US` wherever the markup names no language.
81
72
  */
82
- locale?: string;
83
- toolConfigStrictness?: ToolConfigStrictness;
73
+ contentLanguage?: string;
84
74
  onFrameworkError?: FrameworkErrorHandler;
75
+ /** Called with each `pie-stage-change` detail. */
85
76
  onStageChange?: StageChangeHandler;
77
+ /** Called with each `pie-loading-complete` detail. */
86
78
  onLoadingComplete?: LoadingCompleteHandler;
87
79
  };
88
80
  export type RuntimeInputs = {
89
- assessmentId?: string;
90
- toolConfigStrictness?: ToolConfigStrictness;
91
- onFrameworkError?: FrameworkErrorHandler;
92
- onStageChange?: StageChangeHandler;
93
- onLoadingComplete?: LoadingCompleteHandler;
94
81
  runtime: RuntimeConfig | null;
82
+ toolConfigStrictness?: ToolConfigStrictness;
95
83
  };
96
84
  /**
97
- * Resolve the canonical `onFrameworkError` handler from the two-tier
98
- * surface. Precedence (highest first): `runtime.onFrameworkError`,
99
- * then top-level `onFrameworkError`. Layout CEs and the kernel call
100
- * this so every entry point converges on the same handler.
85
+ * The id a section runs under: the host's `section-id`, else the section's own
86
+ * `identifier`, else one named after the assessment. The toolkit keys the
87
+ * section's controller by it, and the layout kernel its stage cohort.
101
88
  */
102
- export declare function resolveOnFrameworkError(args: {
103
- runtime: RuntimeConfig | null;
104
- onFrameworkError?: FrameworkErrorHandler;
105
- }): FrameworkErrorHandler | undefined;
89
+ export declare function resolveSectionId(args: {
90
+ sectionId?: string | null;
91
+ section?: unknown;
92
+ assessmentId?: string | null;
93
+ }): string;
106
94
  export declare function resolveToolsConfig(args: {
107
95
  runtime: RuntimeConfig | null;
108
96
  }): {
@@ -111,20 +99,18 @@ export declare function resolveToolsConfig(args: {
111
99
  };
112
100
  };
113
101
  export declare function resolveRuntime(args: {
114
- assessmentId: string;
115
102
  runtime: RuntimeConfig | null;
116
103
  effectiveToolsConfig: unknown;
117
104
  toolConfigStrictness?: ToolConfigStrictness;
118
- onFrameworkError?: FrameworkErrorHandler;
119
- onStageChange?: StageChangeHandler;
120
- onLoadingComplete?: LoadingCompleteHandler;
121
105
  }): {
122
- assessmentId: string | undefined;
123
106
  playerType: string;
124
107
  player: {
125
- [key: string]: unknown;
108
+ /** The host has already loaded the item bundles; the player loads none. */
109
+ hosted?: boolean;
126
110
  loaderConfig?: LoaderConfig;
127
111
  loaderOptions?: Record<string, unknown>;
112
+ /** The item player's `backend` config, passed through unread. */
113
+ backend?: Record<string, unknown> | null;
128
114
  } | null;
129
115
  lazyInit: boolean;
130
116
  accessibility: Record<string, unknown> | null;
@@ -132,39 +118,25 @@ export declare function resolveRuntime(args: {
132
118
  createSectionController: unknown;
133
119
  isolation: string;
134
120
  env: Record<string, unknown>;
135
- toolConfigStrictness: "off" | "error" | "warn";
136
- onFrameworkError: FrameworkErrorHandler | undefined;
137
- onStageChange: StageChangeHandler | undefined;
138
- onLoadingComplete: LoadingCompleteHandler | undefined;
121
+ toolConfigStrictness: ToolConfigStrictness;
139
122
  tools: unknown;
123
+ assessmentId?: string;
140
124
  toolContextResolvers?: Record<string, unknown> | null;
141
125
  /**
142
- * Presentation flag: opt-in to the vendored `<nds-icon-button>` for the
143
- * toolbar tool buttons, the calculator shell controls, inline-TTS
144
- * play/pause, and the section scroll-hint. NDS icons render only when
145
- * this is explicitly `true`; unset/`false` keeps the plain `<button>`
146
- * markup (the default). Purely visual — no engine effect.
147
- */
148
- ndsIcons?: boolean;
149
- /**
150
- * Interface locale: a BCP-47 tag naming the language the player renders its own
151
- * UI in. Purely presentational — no engine effect.
126
+ * Content language: a BCP-47 tag naming the language the authored content is
127
+ * written in, which read-aloud speaks it in and catalog lookups select
128
+ * alternates by. A `lang` in the content's markup wins over it. Purely
129
+ * presentational — no engine effect.
152
130
  *
153
- * Distinct from content language, which describes the authored item and
154
- * travels on `env`. QTI 3's implementation guide states the independence
155
- * directly: a candidate may choose an interface language which may or may not
156
- * also be the language of the content.
157
- *
158
- * Unset renders `en-US`. POSIX (`nl_NL`) and bare (`nl`) forms both resolve.
131
+ * Unset reads as `en-US` wherever the markup names no language.
159
132
  */
160
- locale?: string;
133
+ contentLanguage?: string;
134
+ onFrameworkError?: FrameworkErrorHandler;
135
+ /** Called with each `pie-stage-change` detail. */
136
+ onStageChange?: StageChangeHandler;
137
+ /** Called with each `pie-loading-complete` detail. */
138
+ onLoadingComplete?: LoadingCompleteHandler;
161
139
  };
162
- /**
163
- * Effective runtime returned by `resolveRuntime`. The shape is exposed
164
- * as `unknown` at the public boundary because consumers spread it into
165
- * arbitrary host props; downstream call sites narrow with the specific
166
- * keys they need.
167
- */
168
140
  export type EffectiveRuntime = ReturnType<typeof resolveRuntime>;
169
141
  /**
170
142
  * Engine-side orchestrator that powers `resolveSectionPlayerRuntimeState`
@@ -1,11 +1,9 @@
1
1
  /**
2
- * Section runtime engine resolver (M7).
2
+ * Section runtime engine resolver.
3
3
  *
4
4
  * Canonical home of `resolveRuntime`, `resolveToolsConfig`, and their
5
- * supporting helpers/types. As of M7 PR 7 the previous duplicates in
6
- * `packages/section-player/src/components/shared/section-player-runtime.ts`
7
- * have been deleted; section-player now consumes these helpers via
8
- * `@pie-players/pie-assessment-toolkit/runtime/internal`.
5
+ * supporting helpers/types; section-player consumes them through
6
+ * `@pie-players/pie-assessment-toolkit/runtime/engine`.
9
7
  *
10
8
  * What is NOT absorbed in this module:
11
9
  * - `resolvePlayerRuntime` stays in section-player because it depends on
@@ -18,33 +16,26 @@
18
16
  * `packages/section-player/src/components/shared/section-player-host-runtime.ts`)
19
17
  * hands its local implementation in.
20
18
  *
21
- * Runtime-owned configuration flows through `runtime.<key>`. Layout-only
22
- * inputs stay on the section-player host elements.
19
+ * Each input has one tier. `assessmentId`, the tools and player config and the
20
+ * `on*` callbacks arrive on `runtime`. The primitive inputs (`nds-icons`,
21
+ * `locale`, `tool-config-strictness`) are element attributes; the resolver takes
22
+ * `toolConfigStrictness` beside `runtime`.
23
23
  */
24
- export const DEFAULT_ASSESSMENT_ID = "section-demo-direct";
25
24
  export const DEFAULT_PLAYER_TYPE = "iife";
26
- export const DEFAULT_LAZY_INIT = true;
25
+ export const DEFAULT_LAZY_INIT = false;
27
26
  export const DEFAULT_ISOLATION = "inherit";
28
27
  export const DEFAULT_ENV = { mode: "gather", role: "student" };
29
28
  /**
30
- * Pick the runtime-tier value when defined, otherwise the prop/attribute
31
- * value. The strict mirror rule means every tier-1 surface is resolved
32
- * with this single helper; per-feature special-casing is forbidden.
29
+ * The id a section runs under: the host's `section-id`, else the section's own
30
+ * `identifier`, else one named after the assessment. The toolkit keys the
31
+ * section's controller by it, and the layout kernel its stage cohort.
33
32
  */
34
- function pick(runtimeVal, attrVal) {
35
- return runtimeVal !== undefined ? runtimeVal : attrVal;
36
- }
37
- /**
38
- * Resolve the canonical `onFrameworkError` handler from the two-tier
39
- * surface. Precedence (highest first): `runtime.onFrameworkError`,
40
- * then top-level `onFrameworkError`. Layout CEs and the kernel call
41
- * this so every entry point converges on the same handler.
42
- */
43
- export function resolveOnFrameworkError(args) {
44
- const r = args.runtime ?? {};
45
- if (r.onFrameworkError !== undefined)
46
- return r.onFrameworkError;
47
- return args.onFrameworkError;
33
+ export function resolveSectionId(args) {
34
+ const identifier = args.section
35
+ ?.identifier;
36
+ return (args.sectionId ||
37
+ (typeof identifier === "string" ? identifier : "") ||
38
+ `section-${args.assessmentId || "default"}`);
48
39
  }
49
40
  export function resolveToolsConfig(args) {
50
41
  const runtimeTools = (args.runtime?.tools || {});
@@ -58,7 +49,6 @@ export function resolveRuntime(args) {
58
49
  const runtimePlayer = r.player ? { ...r.player } : null;
59
50
  return {
60
51
  ...r,
61
- assessmentId: pick(r.assessmentId, args.assessmentId),
62
52
  playerType: r.playerType ?? DEFAULT_PLAYER_TYPE,
63
53
  player: runtimePlayer,
64
54
  lazyInit: r.lazyInit ?? DEFAULT_LAZY_INIT,
@@ -67,17 +57,7 @@ export function resolveRuntime(args) {
67
57
  createSectionController: r.createSectionController,
68
58
  isolation: r.isolation ?? DEFAULT_ISOLATION,
69
59
  env: r.env ?? DEFAULT_ENV,
70
- toolConfigStrictness: pick(r.toolConfigStrictness, args.toolConfigStrictness) ?? "error",
71
- // Runtime callback wins; top-level callback remains a layout CE event
72
- // convenience for hosts that do not use DOM listeners.
73
- onFrameworkError: resolveOnFrameworkError({
74
- runtime: args.runtime,
75
- onFrameworkError: args.onFrameworkError,
76
- }),
77
- // Runtime callback wins over the top-level callback prop.
78
- onStageChange: pick(r.onStageChange, args.onStageChange),
79
- // Runtime callback wins over the top-level callback prop.
80
- onLoadingComplete: pick(r.onLoadingComplete, args.onLoadingComplete),
60
+ toolConfigStrictness: args.toolConfigStrictness ?? "error",
81
61
  tools: args.effectiveToolsConfig,
82
62
  };
83
63
  }
@@ -88,18 +68,13 @@ export function resolveRuntime(args) {
88
68
  * stays free of host-coupled defaults (`DEFAULT_PLAYER_DEFINITIONS`).
89
69
  */
90
70
  export function resolveSectionEngineRuntimeState(args, deps) {
91
- const assessmentId = args.assessmentId ?? DEFAULT_ASSESSMENT_ID;
92
71
  const effectiveToolsConfig = resolveToolsConfig({
93
72
  runtime: args.runtime,
94
73
  });
95
74
  const effectiveRuntime = resolveRuntime({
96
- assessmentId,
97
75
  runtime: args.runtime,
98
76
  effectiveToolsConfig,
99
77
  toolConfigStrictness: args.toolConfigStrictness,
100
- onFrameworkError: args.onFrameworkError,
101
- onStageChange: args.onStageChange,
102
- onLoadingComplete: args.onLoadingComplete,
103
78
  });
104
79
  const playerRuntime = deps.resolvePlayerRuntime({
105
80
  effectiveRuntime: effectiveRuntime,
@@ -1,33 +1,30 @@
1
1
  /**
2
- * Section runtime engine state (M7 — Variant C, layered core).
2
+ * Section runtime engine state.
3
3
  *
4
- * The state object is the single source of truth for stage, cohort,
5
- * readiness signals, and the resolved coordinator/controller handles
6
- * across one engine instance. The transition function in
7
- * `engine-transition.ts` is the only legal mutator; the adapter (M7
8
- * PR 2) reads the state via `SectionEngineCore.getState()` and emits
9
- * the bundled `SectionEngineOutput[]` to its bridges.
4
+ * The state object is the single source of truth for stage, cohort and
5
+ * readiness signals across one engine instance. The transition function in
6
+ * `engine-transition.ts` is its only mutator; the adapter reads it through
7
+ * `SectionEngineCore.getState()`.
10
8
  *
11
- * Phases (the FSM). Adjustment A2 of the M7 implementation plan locks
12
- * this list to four phases that map 1:1 onto the M6 canonical stages:
9
+ * Phases map onto the canonical stages:
13
10
  *
14
- * `idle` → no cohort yet (before `initialize`).
15
- * `booting-section` → cohort known, controller resolution pending. Maps to stage `composed`.
16
- * `engine-ready` → controller resolved. Maps to stage `engine-ready`.
17
- * `interactive` → readiness gate satisfied. Maps to stage `interactive`.
18
- * `disposed` → engine torn down. Maps to stage `disposed`.
11
+ * `idle` → no cohort yet. No stage.
12
+ * `booting-section` → cohort known, controller pending. Stage `composed`.
13
+ * `engine-ready` → controller resolved. Stage `engine-ready`.
14
+ * `interactive` → readiness gate satisfied. Stage `interactive`.
15
+ * `failed` → a runtime error ended the cohort's chain before
16
+ * `interactive`. No stage of its own: the transition
17
+ * records the stages it did not reach as `failed` and
18
+ * `skipped`.
19
+ * `disposed` → engine torn down. Stage `disposed`.
19
20
  *
20
- * `loading-complete` is intentionally **not** an FSM phase — it is a
21
- * `SectionEngineOutput` emitted from the `interactive` phase when the
22
- * readiness signals satisfy `allLoadingComplete`. See
23
- * `engine-output.ts` for the output shape and the implementation
24
- * plan's Adjustment A2 fence.
21
+ * `loading-complete` is an output, emitted once per cohort when the readiness
22
+ * signals report every item loaded.
25
23
  */
26
24
  import type { CohortKey } from "./cohort.js";
27
25
  import type { EffectiveRuntime } from "./engine-resolver.js";
28
26
  import type { EngineReadinessSignals } from "./engine-readiness.js";
29
- import type { FrameworkErrorModel } from "../../services/framework-error.js";
30
- export type SectionEnginePhase = "idle" | "booting-section" | "engine-ready" | "interactive" | "disposed";
27
+ export type SectionEnginePhase = "idle" | "booting-section" | "engine-ready" | "interactive" | "failed" | "disposed";
31
28
  export type SectionEngineState = {
32
29
  /** Current FSM phase. The single source of truth for stage derivation. */
33
30
  phase: SectionEnginePhase;
@@ -45,13 +42,17 @@ export type SectionEngineState = {
45
42
  */
46
43
  controllerResolved: boolean;
47
44
  /**
48
- * Readiness signal snapshot. Updated by `update-readiness-signals`
49
- * inputs from the host (kernel) — the engine itself does not
50
- * compute these from scratch in PR 1. Strict-mode gating is
51
- * applied at derivation time via `createReadinessDetail`, not by
52
- * mutating the signals.
45
+ * Readiness signal snapshot, replaced by each `update-readiness-signals`
46
+ * input from the host. Strict-mode gating is applied at derivation time
47
+ * through `resolveReadinessGates`.
53
48
  */
54
49
  readinessSignals: EngineReadinessSignals;
50
+ /**
51
+ * Readiness mode of the last `update-readiness-signals` input. Kept with
52
+ * the signals so `section-controller-resolved` can apply a snapshot that
53
+ * arrived while the controller was pending.
54
+ */
55
+ readinessMode: "progressive" | "strict";
55
56
  /** Last resolved effective runtime (output of `resolveRuntime`). */
56
57
  effectiveRuntime: EffectiveRuntime | null;
57
58
  /** Last resolved tools config. */
@@ -63,17 +64,8 @@ export type SectionEngineState = {
63
64
  * preserved by gating emission on this flag in the transition.
64
65
  */
65
66
  loadingCompleteEmitted: boolean;
66
- /**
67
- * Most recent framework error, if any. The engine routes errors
68
- * through outputs, not through state — this field is kept so
69
- * subscribers asking for the latest snapshot (e.g. error banners)
70
- * can read it without replaying the output stream.
71
- */
72
- lastFrameworkError: FrameworkErrorModel | null;
73
- /** Number of items the host has registered for the current cohort. */
67
+ /** Number of items in the current cohort's composition. */
74
68
  itemCount: number;
75
- /** Number of items reported as loaded. */
76
- loadedCount: number;
77
69
  };
78
70
  /**
79
71
  * Initial state. Kept as a function so callers cannot mutate a shared
@@ -1,27 +1,25 @@
1
1
  /**
2
- * Section runtime engine state (M7 — Variant C, layered core).
2
+ * Section runtime engine state.
3
3
  *
4
- * The state object is the single source of truth for stage, cohort,
5
- * readiness signals, and the resolved coordinator/controller handles
6
- * across one engine instance. The transition function in
7
- * `engine-transition.ts` is the only legal mutator; the adapter (M7
8
- * PR 2) reads the state via `SectionEngineCore.getState()` and emits
9
- * the bundled `SectionEngineOutput[]` to its bridges.
4
+ * The state object is the single source of truth for stage, cohort and
5
+ * readiness signals across one engine instance. The transition function in
6
+ * `engine-transition.ts` is its only mutator; the adapter reads it through
7
+ * `SectionEngineCore.getState()`.
10
8
  *
11
- * Phases (the FSM). Adjustment A2 of the M7 implementation plan locks
12
- * this list to four phases that map 1:1 onto the M6 canonical stages:
9
+ * Phases map onto the canonical stages:
13
10
  *
14
- * `idle` → no cohort yet (before `initialize`).
15
- * `booting-section` → cohort known, controller resolution pending. Maps to stage `composed`.
16
- * `engine-ready` → controller resolved. Maps to stage `engine-ready`.
17
- * `interactive` → readiness gate satisfied. Maps to stage `interactive`.
18
- * `disposed` → engine torn down. Maps to stage `disposed`.
11
+ * `idle` → no cohort yet. No stage.
12
+ * `booting-section` → cohort known, controller pending. Stage `composed`.
13
+ * `engine-ready` → controller resolved. Stage `engine-ready`.
14
+ * `interactive` → readiness gate satisfied. Stage `interactive`.
15
+ * `failed` → a runtime error ended the cohort's chain before
16
+ * `interactive`. No stage of its own: the transition
17
+ * records the stages it did not reach as `failed` and
18
+ * `skipped`.
19
+ * `disposed` → engine torn down. Stage `disposed`.
19
20
  *
20
- * `loading-complete` is intentionally **not** an FSM phase — it is a
21
- * `SectionEngineOutput` emitted from the `interactive` phase when the
22
- * readiness signals satisfy `allLoadingComplete`. See
23
- * `engine-output.ts` for the output shape and the implementation
24
- * plan's Adjustment A2 fence.
21
+ * `loading-complete` is an output, emitted once per cohort when the readiness
22
+ * signals report every item loaded.
25
23
  */
26
24
  /**
27
25
  * Initial state. Kept as a function so callers cannot mutate a shared
@@ -38,11 +36,10 @@ export function createInitialEngineState() {
38
36
  allLoadingComplete: false,
39
37
  runtimeError: false,
40
38
  },
39
+ readinessMode: "progressive",
41
40
  effectiveRuntime: null,
42
41
  effectiveToolsConfig: null,
43
42
  loadingCompleteEmitted: false,
44
- lastFrameworkError: null,
45
43
  itemCount: 0,
46
- loadedCount: 0,
47
44
  };
48
45
  }
@@ -1,36 +1,31 @@
1
1
  /**
2
- * Pure transition function for the section runtime engine (M7 — Variant
3
- * C, layered core).
2
+ * Pure transition function for the section runtime engine.
4
3
  *
5
4
  * `transition(state, input)` is total over `(state, input)` pairs and
6
5
  * returns:
7
- * - the next `SectionEngineState` (immutable; the input state object
8
- * is never mutated);
9
- * - the ordered list of `SectionEngineOutput`s the adapter must
10
- * dispatch (DOM events, framework-error fan-out, etc.).
6
+ * - the next `SectionEngineState` (the input state object is never
7
+ * mutated);
8
+ * - the ordered list of `SectionEngineOutput`s the adapter dispatches.
11
9
  *
12
- * The function imports nothing from Svelte, the DOM, or the
13
- * coordinator. The `core/` constraint is enforced by the per-PR audit
14
- * step in the M7 implementation plan.
10
+ * The function imports nothing from Svelte, the DOM, or the coordinator;
11
+ * `scripts/check-engine-core-purity.mjs` enforces that.
15
12
  *
16
13
  * Phase machine (per `engine-state.ts`):
17
14
  * idle → booting-section → engine-ready → interactive → disposed
18
- * (cohort-change rolls back to booting-section for the new cohort
19
- * after emitting `disposed` for the outgoing cohort)
15
+ * booting-section | engine-ready → failed → disposed
16
+ * (cohort-change emits `disposed` for the outgoing cohort and restarts at
17
+ * booting-section for the new one)
18
+ *
19
+ * A readiness update that reports `runtimeError` before `interactive` ends the
20
+ * chain: the first stage the cohort did not reach is recorded as `failed` and
21
+ * any after it as `skipped`, so a host waiting on `engine-ready` or
22
+ * `interactive` always hears an answer.
20
23
  *
21
24
  * Output ordering invariants:
22
25
  * 1. `stage-change` for stage advancement fires before any
23
26
  * `loading-complete` triggered by the same input.
24
27
  * 2. `loading-complete` fires once per cohort, gated on
25
28
  * `state.loadingCompleteEmitted`.
26
- * 3. `framework-error` outputs are independent of the stage chain
27
- * and do not move the phase.
28
- *
29
- * Readiness alias output kinds (`readiness-change`,
30
- * `interaction-ready`, `ready`) and their DOM-event bridge were
31
- * removed in the broad architecture review compat sweep. Hosts that
32
- * need the readiness detail read it via the kernel's `selectReadiness`
33
- * / `getSnapshot` selectors or via `SectionEngineCore.getState()`.
34
29
  */
35
30
  import type { SectionEngineInput } from "./engine-input.js";
36
31
  import type { SectionEngineOutput } from "./engine-output.js";