@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
@@ -13,27 +13,26 @@
13
13
  */
14
14
  import type { TtsServiceApi } from "./interfaces.js";
15
15
  /** Only what a handoff needs, so a host passing a partial service still works. */
16
- type TtsHandoffSubscriber = Pick<TtsServiceApi, "onStateChange" | "offStateChange">;
17
- type TtsHandoffPlayback = Pick<TtsServiceApi, "isPlaying" | "pause">;
16
+ type TtsHandoffSubscriber = Pick<TtsServiceApi, "onStateChange">;
17
+ type TtsHandoffPlayback = Pick<TtsServiceApi, "getState" | "pause">;
18
18
  /**
19
19
  * Silence a media surface whenever read-aloud starts speaking.
20
20
  *
21
- * `LOADING` as well as `PLAYING`, so the pause lands before the first word rather
22
- * than a provider round-trip after it. A `LOADING` that then fails leaves media
23
- * paused, which costs the learner one press of play.
21
+ * Silenced on loading, so the pause lands before the first word rather than a
22
+ * provider round-trip after it. A load that then fails leaves media paused,
23
+ * which costs the learner one press of play.
24
24
  *
25
25
  * Returns the teardown, including where there was nothing to bind.
26
26
  */
27
27
  export declare function bindTtsAudioHandoff(args: {
28
28
  ttsService: Partial<TtsHandoffSubscriber> | null | undefined;
29
- /** Unique per surface: the service keys its listener sets by this. */
30
- listenerId: string;
31
29
  silence: () => void;
32
30
  }): () => void;
33
31
  /**
34
32
  * The other half: media audio has started, so read-aloud yields.
35
33
  *
36
34
  * Paused rather than stopped, so the learner keeps their place in the passage.
35
+ * A read still loading pauses too, and holds until the learner resumes it.
37
36
  */
38
37
  export declare function pauseTtsForMediaAudio(ttsService: Partial<TtsHandoffPlayback> | null | undefined): void;
39
38
  export {};
@@ -13,29 +13,34 @@
13
13
  */
14
14
  import { PlaybackState } from "./TTSService.js";
15
15
  const NOOP = () => { };
16
+ /**
17
+ * Read-aloud counts as speaking from the moment a read starts loading. A
18
+ * loading read sounds as soon as its audio arrives, so both halves treat it as
19
+ * a playing one.
20
+ */
21
+ function isSpeaking(state) {
22
+ return state === PlaybackState.PLAYING || state === PlaybackState.LOADING;
23
+ }
16
24
  /**
17
25
  * Silence a media surface whenever read-aloud starts speaking.
18
26
  *
19
- * `LOADING` as well as `PLAYING`, so the pause lands before the first word rather
20
- * than a provider round-trip after it. A `LOADING` that then fails leaves media
21
- * paused, which costs the learner one press of play.
27
+ * Silenced on loading, so the pause lands before the first word rather than a
28
+ * provider round-trip after it. A load that then fails leaves media paused,
29
+ * which costs the learner one press of play.
22
30
  *
23
31
  * Returns the teardown, including where there was nothing to bind.
24
32
  */
25
33
  export function bindTtsAudioHandoff(args) {
26
- const { ttsService, listenerId, silence } = args;
34
+ const { ttsService, silence } = args;
27
35
  if (typeof ttsService?.onStateChange !== "function")
28
36
  return NOOP;
29
- const onTtsState = (state) => {
30
- if (state !== PlaybackState.PLAYING && state !== PlaybackState.LOADING) {
31
- return;
32
- }
33
- silence();
34
- };
35
- ttsService.onStateChange(listenerId, onTtsState);
37
+ const unsubscribe = ttsService.onStateChange((state) => {
38
+ if (isSpeaking(state))
39
+ silence();
40
+ });
36
41
  return () => {
37
42
  try {
38
- ttsService.offStateChange?.(listenerId, onTtsState);
43
+ unsubscribe();
39
44
  }
40
45
  catch {
41
46
  // A torn-down service is not a failure to detach from.
@@ -46,11 +51,12 @@ export function bindTtsAudioHandoff(args) {
46
51
  * The other half: media audio has started, so read-aloud yields.
47
52
  *
48
53
  * Paused rather than stopped, so the learner keeps their place in the passage.
54
+ * A read still loading pauses too, and holds until the learner resumes it.
49
55
  */
50
56
  export function pauseTtsForMediaAudio(ttsService) {
51
57
  try {
52
- if (ttsService?.isPlaying?.())
53
- ttsService.pause?.();
58
+ if (isSpeaking(ttsService?.getState?.()))
59
+ ttsService?.pause?.();
54
60
  }
55
61
  catch {
56
62
  // A torn-down or uninitialized TTS service must not break playback.
@@ -6,7 +6,6 @@
6
6
  * adapter, while keeping the entity walk private to the resolver package.
7
7
  */
8
8
  import type { AccessibilityCatalog } from "@pie-players/pie-players-shared/types";
9
- export type CatalogOwnerKind = "global" | "passage" | "itemModel";
10
9
  interface CatalogOwnerScopeContext {
11
10
  assessmentId?: string;
12
11
  sectionId?: string;
@@ -48,12 +48,9 @@ export interface FrameworkErrorReporter {
48
48
  * before constructing the coordinator so the `coordinator-init`
49
49
  * failure path emits through the same bus.
50
50
  *
51
- * **Why not a public class.** This bus is constructed inside the toolkit
52
- * CE (`PieAssessmentToolkit.svelte`) and passed into
53
- * `ToolkitCoordinator`. Hosts subscribe via
54
- * `ToolkitCoordinatorApi.subscribeFrameworkErrors`, never via the bus
55
- * class itself. Keeping the class package-internal lets us iterate on
56
- * its shape without a public-API change.
51
+ * **Where it is constructed.** The toolkit CE (`PieAssessmentToolkit.svelte`)
52
+ * builds one and passes it into `ToolkitCoordinator`; hosts subscribe via
53
+ * `ToolkitCoordinatorApi.subscribeFrameworkErrors`.
57
54
  */
58
55
  export declare class FrameworkErrorBus implements FrameworkErrorPort, FrameworkErrorReporter {
59
56
  private readonly listeners;
@@ -20,12 +20,9 @@
20
20
  * before constructing the coordinator so the `coordinator-init`
21
21
  * failure path emits through the same bus.
22
22
  *
23
- * **Why not a public class.** This bus is constructed inside the toolkit
24
- * CE (`PieAssessmentToolkit.svelte`) and passed into
25
- * `ToolkitCoordinator`. Hosts subscribe via
26
- * `ToolkitCoordinatorApi.subscribeFrameworkErrors`, never via the bus
27
- * class itself. Keeping the class package-internal lets us iterate on
28
- * its shape without a public-API change.
23
+ * **Where it is constructed.** The toolkit CE (`PieAssessmentToolkit.svelte`)
24
+ * builds one and passes it into `ToolkitCoordinator`; hosts subscribe via
25
+ * `ToolkitCoordinatorApi.subscribeFrameworkErrors`.
29
26
  */
30
27
  export class FrameworkErrorBus {
31
28
  listeners = new Set();
@@ -1,5 +1,25 @@
1
- import type { ToolConfigDiagnostic } from "./tool-config-validation.js";
1
+ import type { ToolFailurePhase } from "./tool-failure.js";
2
2
  export type FrameworkErrorKind = "tool-config" | "runtime-init" | "runtime-dispose" | "coordinator-init" | "provider-init" | "provider-register" | "tts-init" | "tool-state-load" | "tool-state-save" | "section-controller-init" | "section-controller-dispose" | "tool-surface"
3
+ /**
4
+ * A toolbar could not load a tool's module. Recoverable unless policy grants
5
+ * the tool: the toolbar withholds the tool and the assessment goes on.
6
+ */
7
+ | "tool-module-load"
8
+ /**
9
+ * A toolbar threw opening a requested tool or answering whether it hosts one.
10
+ * Recoverable: the request goes unclaimed or passes the toolbar by.
11
+ */
12
+ | "tool-request"
13
+ /**
14
+ * A tool registration's relevance check or applicability gate threw.
15
+ * Recoverable: the toolbar applies the answer a missing check would give.
16
+ */
17
+ | "tool-registration"
18
+ /**
19
+ * A tool could not play, seek or change the rate of speech after it started.
20
+ * Recoverable: the tool stays available and the learner can retry.
21
+ */
22
+ | "tool-playback"
3
23
  /**
4
24
  * A timed-media section could not deliver a policy as authored: a media time
5
25
  * source missing `canPause` / `canRestrictSeeking` (recoverable — cues still
@@ -22,6 +42,21 @@ export type FrameworkErrorKind = "tool-config" | "runtime-init" | "runtime-dispo
22
42
  */
23
43
  | "element-preload" | "unknown";
24
44
  export type FrameworkErrorSeverity = "warning" | "error";
45
+ /**
46
+ * What a non-recoverable error takes down. `cohort`: the section it was reported
47
+ * for, so the section player's readiness recovers when the learner moves to
48
+ * another section. `runtime`: the coordinator or one of its tools, which every
49
+ * later section runs on, so readiness stays failed. Set by the report site.
50
+ */
51
+ export type FrameworkErrorScope = "cohort" | "runtime";
52
+ /**
53
+ * The section a `cohort`-scoped error was reported for. A section can fail after
54
+ * the learner has left it, so a reader holding another section ignores the error.
55
+ */
56
+ export interface FrameworkErrorCohort {
57
+ sectionId: string;
58
+ attemptId?: string;
59
+ }
25
60
  export interface FrameworkErrorModel {
26
61
  kind: FrameworkErrorKind;
27
62
  severity: FrameworkErrorSeverity;
@@ -29,6 +64,9 @@ export interface FrameworkErrorModel {
29
64
  message: string;
30
65
  details: string[];
31
66
  recoverable: boolean;
67
+ scope: FrameworkErrorScope;
68
+ /** Set on a `cohort`-scoped error whose report site knows its section. */
69
+ cohort?: FrameworkErrorCohort;
32
70
  cause?: unknown;
33
71
  }
34
72
  export declare function toFrameworkErrorModel(args: {
@@ -38,6 +76,9 @@ export declare function toFrameworkErrorModel(args: {
38
76
  message: string;
39
77
  details?: string[];
40
78
  recoverable?: boolean;
79
+ /** Defaults to `runtime`. */
80
+ scope?: FrameworkErrorScope;
81
+ cohort?: FrameworkErrorCohort;
41
82
  cause?: unknown;
42
83
  }): FrameworkErrorModel;
43
84
  export declare function frameworkErrorFromUnknown(args: {
@@ -45,6 +86,8 @@ export declare function frameworkErrorFromUnknown(args: {
45
86
  source: string;
46
87
  error: unknown;
47
88
  recoverable?: boolean;
89
+ scope?: FrameworkErrorScope;
90
+ cohort?: FrameworkErrorCohort;
48
91
  }): FrameworkErrorModel;
49
92
  /**
50
93
  * Coordinator-side error context shape consumed by
@@ -57,8 +100,8 @@ export declare function frameworkErrorFromUnknown(args: {
57
100
  * truth for coordinator code; values of that type satisfy this shape.
58
101
  */
59
102
  export interface FrameworkErrorCoordinatorContext {
60
- phase: "coordinator-ready" | "state-load" | "state-save" | "provider-register" | "provider-init" | "tts-init" | "section-controller-init" | "section-controller-dispose";
61
- providerId?: string;
103
+ phase: "coordinator-ready" | "state-load" | "state-save" | "provider-register" | "provider-init" | "tts-init" | "section-controller-init" | "section-controller-dispose" | ToolFailurePhase;
104
+ toolId?: string;
62
105
  details?: Record<string, unknown>;
63
106
  }
64
107
  /**
@@ -66,24 +109,19 @@ export interface FrameworkErrorCoordinatorContext {
66
109
  * context pair.
67
110
  *
68
111
  * Maps `context.phase` to the canonical {@link FrameworkErrorKind} and
69
- * synthesizes a `source` from `context.providerId` when present
70
- * (`pie-toolkit-coordinator/<providerId>`); falls back to a phase-tagged
112
+ * synthesizes a `source` from `context.toolId` when present
113
+ * (`pie-toolkit-coordinator/<toolId>`); falls back to a phase-tagged
71
114
  * source (`pie-toolkit-coordinator:<phase>`) otherwise. Forwards the
72
115
  * original `error` as `cause` so hosts that care about the underlying
73
116
  * `Error` keep getting it.
74
117
  *
75
- * Recoverable defaults to `false` (most coordinator-phase failures are
76
- * not auto-recovered today). Override with `recoverable: true` for the
77
- * phases where the coordinator continues operating after the failure.
118
+ * `recoverable` defaults to `false` and `scope` to `runtime`.
78
119
  */
79
120
  export declare function frameworkErrorFromCoordinatorContext(args: {
80
121
  error: unknown;
81
122
  context: FrameworkErrorCoordinatorContext;
82
123
  recoverable?: boolean;
83
- }): FrameworkErrorModel;
84
- export declare function frameworkErrorFromToolConfigDiagnostics(args: {
85
- source: string;
86
- diagnostics: ToolConfigDiagnostic[];
87
- recoverable?: boolean;
124
+ scope?: FrameworkErrorScope;
125
+ cohort?: FrameworkErrorCohort;
88
126
  }): FrameworkErrorModel;
89
127
  export declare function formatFrameworkErrorForConsole(error: FrameworkErrorModel): string;
@@ -6,6 +6,8 @@ export function toFrameworkErrorModel(args) {
6
6
  message: args.message,
7
7
  details: [...(args.details || [])],
8
8
  recoverable: args.recoverable === true,
9
+ scope: args.scope ?? "runtime",
10
+ ...(args.cohort ? { cohort: { ...args.cohort } } : {}),
9
11
  cause: args.cause,
10
12
  };
11
13
  }
@@ -18,6 +20,8 @@ export function frameworkErrorFromUnknown(args) {
18
20
  source: args.source,
19
21
  message,
20
22
  recoverable: args.recoverable,
23
+ scope: args.scope,
24
+ cohort: args.cohort,
21
25
  cause: args.error,
22
26
  });
23
27
  }
@@ -30,45 +34,40 @@ const COORDINATOR_PHASE_TO_KIND = {
30
34
  "tts-init": "tts-init",
31
35
  "section-controller-init": "section-controller-init",
32
36
  "section-controller-dispose": "section-controller-dispose",
37
+ "tool-module-load": "tool-module-load",
38
+ "tool-request-open": "tool-request",
39
+ "tool-request-host-check": "tool-request",
40
+ "tool-visibility": "tool-registration",
41
+ "tool-applicability": "tool-registration",
42
+ "tool-state-load": "tool-state-load",
43
+ "tool-state-save": "tool-state-save",
44
+ "tool-playback": "tool-playback",
33
45
  };
34
46
  /**
35
47
  * Build a {@link FrameworkErrorModel} from a coordinator-side error +
36
48
  * context pair.
37
49
  *
38
50
  * Maps `context.phase` to the canonical {@link FrameworkErrorKind} and
39
- * synthesizes a `source` from `context.providerId` when present
40
- * (`pie-toolkit-coordinator/<providerId>`); falls back to a phase-tagged
51
+ * synthesizes a `source` from `context.toolId` when present
52
+ * (`pie-toolkit-coordinator/<toolId>`); falls back to a phase-tagged
41
53
  * source (`pie-toolkit-coordinator:<phase>`) otherwise. Forwards the
42
54
  * original `error` as `cause` so hosts that care about the underlying
43
55
  * `Error` keep getting it.
44
56
  *
45
- * Recoverable defaults to `false` (most coordinator-phase failures are
46
- * not auto-recovered today). Override with `recoverable: true` for the
47
- * phases where the coordinator continues operating after the failure.
57
+ * `recoverable` defaults to `false` and `scope` to `runtime`.
48
58
  */
49
59
  export function frameworkErrorFromCoordinatorContext(args) {
50
60
  const kind = COORDINATOR_PHASE_TO_KIND[args.context.phase];
51
- const source = args.context.providerId
52
- ? `pie-toolkit-coordinator/${args.context.providerId}`
61
+ const source = args.context.toolId
62
+ ? `pie-toolkit-coordinator/${args.context.toolId}`
53
63
  : `pie-toolkit-coordinator:${args.context.phase}`;
54
64
  return frameworkErrorFromUnknown({
55
65
  kind,
56
66
  source,
57
67
  error: args.error,
58
68
  recoverable: args.recoverable,
59
- });
60
- }
61
- export function frameworkErrorFromToolConfigDiagnostics(args) {
62
- const details = args.diagnostics.map((diagnostic) => `${diagnostic.path}: ${diagnostic.message}`);
63
- const message = details.length > 0
64
- ? "Invalid tools config."
65
- : "Invalid tools config (no diagnostics details were provided).";
66
- return toFrameworkErrorModel({
67
- kind: "tool-config",
68
- source: args.source,
69
- message,
70
- details,
71
- recoverable: args.recoverable,
69
+ scope: args.scope,
70
+ cohort: args.cohort,
72
71
  });
73
72
  }
74
73
  export function formatFrameworkErrorForConsole(error) {