@pie-players/pie-assessment-toolkit 0.3.61 → 0.3.63

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 (270) hide show
  1. package/dist/attempt/AssessmentSession.js +0 -1
  2. package/dist/attempt/TestSession.js +0 -1
  3. package/dist/attempt/adapters/activity-to-test-attempt-session.js +0 -1
  4. package/dist/components/ItemToolBar.custom-element.js +1 -10106
  5. package/dist/components/PieAssessmentToolkit.custom-element.js +48 -29930
  6. package/dist/components/SectionToolBar.custom-element.js +1 -14372
  7. package/dist/components/chunks/ItemToolBar-843902tp.js +51 -0
  8. package/dist/components/chunks/ItemToolBar-84nv78dy.js +22 -0
  9. package/dist/components/item-toolbar-element.js +0 -1
  10. package/dist/components/pie-assessment-toolkit-element.js +0 -1
  11. package/dist/components/section-toolbar-element.js +0 -1
  12. package/dist/context/assessment-toolkit-context.js +0 -1
  13. package/dist/context/runtime-context-consumer.js +0 -1
  14. package/dist/index.js +0 -1
  15. package/dist/item-loader.js +0 -1
  16. package/dist/policy/core/PolicySource.js +0 -1
  17. package/dist/policy/core/ToolPolicyEngine.js +0 -1
  18. package/dist/policy/core/compose-decision.js +0 -1
  19. package/dist/policy/core/decision-types.js +0 -1
  20. package/dist/policy/core/engine-context.js +0 -1
  21. package/dist/policy/core/pnp-policy-inputs.js +0 -1
  22. package/dist/policy/core/policy-source-tag.js +0 -1
  23. package/dist/policy/core/provenance.js +0 -1
  24. package/dist/policy/engine.js +0 -1
  25. package/dist/policy/internal.js +0 -1
  26. package/dist/policy/sources/PnpPolicySource.js +0 -1
  27. package/dist/runtime/RuntimeRegistry.js +0 -1
  28. package/dist/runtime/SectionRuntimeEngine.js +0 -1
  29. package/dist/runtime/adapter/SectionEngineAdapter.js +0 -1
  30. package/dist/runtime/adapter/coordinator-bridge.js +0 -1
  31. package/dist/runtime/adapter/dom-event-bridge.js +0 -1
  32. package/dist/runtime/adapter/framework-error-bridge.js +0 -1
  33. package/dist/runtime/adapter/instrumentation-bridge.js +0 -1
  34. package/dist/runtime/adapter/subscriber-fanout.js +0 -1
  35. package/dist/runtime/catalog-registration.js +0 -1
  36. package/dist/runtime/core/SectionEngineCore.js +0 -1
  37. package/dist/runtime/core/cohort.js +0 -1
  38. package/dist/runtime/core/engine-input.js +0 -1
  39. package/dist/runtime/core/engine-output.js +0 -1
  40. package/dist/runtime/core/engine-readiness.js +0 -1
  41. package/dist/runtime/core/engine-resolver.js +0 -1
  42. package/dist/runtime/core/engine-stage-derivation.js +0 -1
  43. package/dist/runtime/core/engine-state.js +0 -1
  44. package/dist/runtime/core/engine-transition.js +0 -1
  45. package/dist/runtime/engine-context.js +0 -1
  46. package/dist/runtime/engine.js +0 -1
  47. package/dist/runtime/internal.js +0 -1
  48. package/dist/runtime/registration-events.js +0 -1
  49. package/dist/runtime/runtime-id.js +0 -1
  50. package/dist/runtime/section-runtime-engine-host-context.js +0 -1
  51. package/dist/runtime/session-event-emitter-policy.js +0 -1
  52. package/dist/runtime/stage-emit-gate.js +0 -1
  53. package/dist/runtime/tool-host-contract.js +0 -1
  54. package/dist/services/AccessibilityCatalogResolver.js +0 -1
  55. package/dist/services/ContextVariableStore.js +0 -1
  56. package/dist/services/ElementToolStateStore.js +0 -1
  57. package/dist/services/HighlightCoordinator.js +35 -3
  58. package/dist/services/I18nService.js +0 -1
  59. package/dist/services/RangeSerializer.js +0 -1
  60. package/dist/services/SSMLExtractor.js +0 -1
  61. package/dist/services/TTSService.js +0 -1
  62. package/dist/services/ThemeProvider.js +0 -1
  63. package/dist/services/ToolConfigResolver.js +0 -1
  64. package/dist/services/ToolCoordinator.js +0 -1
  65. package/dist/services/ToolRegistry.js +0 -1
  66. package/dist/services/ToolkitCoordinator.js +0 -1
  67. package/dist/services/create-tools-config.js +0 -1
  68. package/dist/services/createDefaultToolRegistry.js +0 -1
  69. package/dist/services/defaultPersonalNeedsProfile.js +0 -1
  70. package/dist/services/framework-error-bus.js +0 -1
  71. package/dist/services/framework-error.js +0 -1
  72. package/dist/services/interfaces.js +0 -1
  73. package/dist/services/pnp-standard-features.js +0 -1
  74. package/dist/services/section-controller-types.js +0 -1
  75. package/dist/services/tool-config-defaults.js +0 -1
  76. package/dist/services/tool-config-validation.js +0 -1
  77. package/dist/services/tool-context.js +0 -1
  78. package/dist/services/tool-instance-id.js +0 -1
  79. package/dist/services/tool-providers/DesmosToolProvider.js +0 -1
  80. package/dist/services/tool-providers/TTSToolProvider.js +0 -1
  81. package/dist/services/tool-providers/ToolProviderApi.js +0 -1
  82. package/dist/services/tool-providers/ToolProviderRegistry.js +0 -1
  83. package/dist/services/tool-providers/index.js +0 -1
  84. package/dist/services/toolbar-items.js +0 -1
  85. package/dist/services/tools-config-normalizer.js +0 -1
  86. package/dist/services/tts/browser-provider.js +0 -1
  87. package/dist/services/tts/catalog-span-alignment.js +0 -1
  88. package/dist/services/tts/generated-speech/assemble-plan.js +0 -1
  89. package/dist/services/tts/generated-speech/dom/build-dom-plan.js +0 -1
  90. package/dist/services/tts/generated-speech/dom/to-chunk-inputs.js +0 -1
  91. package/dist/services/tts/generated-speech/dom/types.js +0 -1
  92. package/dist/services/tts/generated-speech/index.js +0 -1
  93. package/dist/services/tts/generated-speech/math-speech-cache.js +0 -1
  94. package/dist/services/tts/generated-speech/types.js +0 -1
  95. package/dist/services/tts/highlight-pipeline/boundary-normalizer.js +0 -1
  96. package/dist/services/tts/highlight-pipeline/create-highlight-plan.js +0 -1
  97. package/dist/services/tts/highlight-pipeline/highlight-policy.js +0 -1
  98. package/dist/services/tts/highlight-pipeline/index.js +0 -1
  99. package/dist/services/tts/highlight-pipeline/math-semantic-resolver.js +0 -1
  100. package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.js +0 -1
  101. package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js +0 -1
  102. package/dist/services/tts/highlight-pipeline/readable-region.js +0 -1
  103. package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.js +0 -1
  104. package/dist/services/tts/highlight-pipeline/types.js +0 -1
  105. package/dist/services/tts/highlight-pipeline/visible-map-range.js +0 -1
  106. package/dist/services/tts/highlight-target-resolver.js +0 -1
  107. package/dist/services/tts/math-alignment/index.js +0 -1
  108. package/dist/services/tts/math-alignment/mathml-tokenizer.js +0 -1
  109. package/dist/services/tts/math-alignment/range-resolver.js +0 -1
  110. package/dist/services/tts/math-alignment/sequence-aligner.js +0 -1
  111. package/dist/services/tts/math-alignment/speech-tokenizer.js +0 -1
  112. package/dist/services/tts/math-alignment/types.js +0 -1
  113. package/dist/services/tts/math-aware-text-processing.js +0 -1
  114. package/dist/services/tts/math-speech.js +0 -1
  115. package/dist/services/tts/mathml-sanitization.js +0 -1
  116. package/dist/services/tts/ssml/spoken-text.js +0 -1
  117. package/dist/services/tts/text-processing.js +0 -1
  118. package/dist/services/tts/text-segmentation.js +0 -1
  119. package/dist/services/tts/visual-line-ranges.js +0 -1
  120. package/dist/services/tts-control-events.js +0 -1
  121. package/dist/services/tts-runtime-config.js +0 -1
  122. package/dist/tools/calculators/desmos-provider.js +0 -1
  123. package/dist/tools/client.js +0 -1
  124. package/dist/tools/index.js +0 -1
  125. package/dist/tools/library-loader.js +0 -1
  126. package/dist/tools/registrations/accessibility-tools.js +0 -1
  127. package/dist/tools/registrations/calculator.js +0 -1
  128. package/dist/tools/registrations/interaction-tools.js +0 -1
  129. package/dist/tools/registrations/measurement-tools.js +0 -1
  130. package/dist/tools/registrations/subject-specific-tools.js +0 -1
  131. package/dist/tools/registrations/toolbar-registration-helpers.js +0 -1
  132. package/dist/tools/registrations/tts.js +0 -1
  133. package/dist/tools/response-discovery.js +0 -1
  134. package/dist/tools/tool-tag-map.js +0 -1
  135. package/dist/tools/types.js +0 -1
  136. package/dist/tools/variant-resolver.js +0 -1
  137. package/dist/utils/logger.js +0 -1
  138. package/package.json +13 -11
  139. package/dist/attempt/AssessmentSession.js.map +0 -1
  140. package/dist/attempt/TestSession.js.map +0 -1
  141. package/dist/attempt/adapters/activity-to-test-attempt-session.js.map +0 -1
  142. package/dist/components/item-toolbar-element.js.map +0 -1
  143. package/dist/components/pie-assessment-toolkit-element.js.map +0 -1
  144. package/dist/components/section-toolbar-element.js.map +0 -1
  145. package/dist/context/assessment-toolkit-context.js.map +0 -1
  146. package/dist/context/runtime-context-consumer.js.map +0 -1
  147. package/dist/index.js.map +0 -1
  148. package/dist/item-loader.js.map +0 -1
  149. package/dist/policy/core/PolicySource.js.map +0 -1
  150. package/dist/policy/core/ToolPolicyEngine.js.map +0 -1
  151. package/dist/policy/core/compose-decision.js.map +0 -1
  152. package/dist/policy/core/decision-types.js.map +0 -1
  153. package/dist/policy/core/engine-context.js.map +0 -1
  154. package/dist/policy/core/pnp-policy-inputs.js.map +0 -1
  155. package/dist/policy/core/policy-source-tag.js.map +0 -1
  156. package/dist/policy/core/provenance.js.map +0 -1
  157. package/dist/policy/engine.js.map +0 -1
  158. package/dist/policy/internal.js.map +0 -1
  159. package/dist/policy/sources/PnpPolicySource.js.map +0 -1
  160. package/dist/runtime/RuntimeRegistry.js.map +0 -1
  161. package/dist/runtime/SectionRuntimeEngine.js.map +0 -1
  162. package/dist/runtime/adapter/SectionEngineAdapter.js.map +0 -1
  163. package/dist/runtime/adapter/coordinator-bridge.js.map +0 -1
  164. package/dist/runtime/adapter/dom-event-bridge.js.map +0 -1
  165. package/dist/runtime/adapter/framework-error-bridge.js.map +0 -1
  166. package/dist/runtime/adapter/instrumentation-bridge.js.map +0 -1
  167. package/dist/runtime/adapter/subscriber-fanout.js.map +0 -1
  168. package/dist/runtime/catalog-registration.js.map +0 -1
  169. package/dist/runtime/core/SectionEngineCore.js.map +0 -1
  170. package/dist/runtime/core/cohort.js.map +0 -1
  171. package/dist/runtime/core/engine-input.js.map +0 -1
  172. package/dist/runtime/core/engine-output.js.map +0 -1
  173. package/dist/runtime/core/engine-readiness.js.map +0 -1
  174. package/dist/runtime/core/engine-resolver.js.map +0 -1
  175. package/dist/runtime/core/engine-stage-derivation.js.map +0 -1
  176. package/dist/runtime/core/engine-state.js.map +0 -1
  177. package/dist/runtime/core/engine-transition.js.map +0 -1
  178. package/dist/runtime/engine-context.js.map +0 -1
  179. package/dist/runtime/engine.js.map +0 -1
  180. package/dist/runtime/internal.js.map +0 -1
  181. package/dist/runtime/registration-events.js.map +0 -1
  182. package/dist/runtime/runtime-id.js.map +0 -1
  183. package/dist/runtime/section-runtime-engine-host-context.js.map +0 -1
  184. package/dist/runtime/session-event-emitter-policy.js.map +0 -1
  185. package/dist/runtime/stage-emit-gate.js.map +0 -1
  186. package/dist/runtime/tool-host-contract.js.map +0 -1
  187. package/dist/services/AccessibilityCatalogResolver.js.map +0 -1
  188. package/dist/services/ContextVariableStore.js.map +0 -1
  189. package/dist/services/ElementToolStateStore.js.map +0 -1
  190. package/dist/services/HighlightCoordinator.js.map +0 -1
  191. package/dist/services/I18nService.js.map +0 -1
  192. package/dist/services/RangeSerializer.js.map +0 -1
  193. package/dist/services/SSMLExtractor.js.map +0 -1
  194. package/dist/services/TTSService.js.map +0 -1
  195. package/dist/services/ThemeProvider.js.map +0 -1
  196. package/dist/services/ToolConfigResolver.js.map +0 -1
  197. package/dist/services/ToolCoordinator.js.map +0 -1
  198. package/dist/services/ToolRegistry.js.map +0 -1
  199. package/dist/services/ToolkitCoordinator.js.map +0 -1
  200. package/dist/services/create-tools-config.js.map +0 -1
  201. package/dist/services/createDefaultToolRegistry.js.map +0 -1
  202. package/dist/services/defaultPersonalNeedsProfile.js.map +0 -1
  203. package/dist/services/framework-error-bus.js.map +0 -1
  204. package/dist/services/framework-error.js.map +0 -1
  205. package/dist/services/interfaces.js.map +0 -1
  206. package/dist/services/pnp-standard-features.js.map +0 -1
  207. package/dist/services/section-controller-types.js.map +0 -1
  208. package/dist/services/tool-config-defaults.js.map +0 -1
  209. package/dist/services/tool-config-validation.js.map +0 -1
  210. package/dist/services/tool-context.js.map +0 -1
  211. package/dist/services/tool-instance-id.js.map +0 -1
  212. package/dist/services/tool-providers/DesmosToolProvider.js.map +0 -1
  213. package/dist/services/tool-providers/TTSToolProvider.js.map +0 -1
  214. package/dist/services/tool-providers/ToolProviderApi.js.map +0 -1
  215. package/dist/services/tool-providers/ToolProviderRegistry.js.map +0 -1
  216. package/dist/services/tool-providers/index.js.map +0 -1
  217. package/dist/services/toolbar-items.js.map +0 -1
  218. package/dist/services/tools-config-normalizer.js.map +0 -1
  219. package/dist/services/tts/browser-provider.js.map +0 -1
  220. package/dist/services/tts/catalog-span-alignment.js.map +0 -1
  221. package/dist/services/tts/generated-speech/assemble-plan.js.map +0 -1
  222. package/dist/services/tts/generated-speech/dom/build-dom-plan.js.map +0 -1
  223. package/dist/services/tts/generated-speech/dom/to-chunk-inputs.js.map +0 -1
  224. package/dist/services/tts/generated-speech/dom/types.js.map +0 -1
  225. package/dist/services/tts/generated-speech/index.js.map +0 -1
  226. package/dist/services/tts/generated-speech/math-speech-cache.js.map +0 -1
  227. package/dist/services/tts/generated-speech/types.js.map +0 -1
  228. package/dist/services/tts/highlight-pipeline/boundary-normalizer.js.map +0 -1
  229. package/dist/services/tts/highlight-pipeline/create-highlight-plan.js.map +0 -1
  230. package/dist/services/tts/highlight-pipeline/highlight-policy.js.map +0 -1
  231. package/dist/services/tts/highlight-pipeline/index.js.map +0 -1
  232. package/dist/services/tts/highlight-pipeline/math-semantic-resolver.js.map +0 -1
  233. package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.js.map +0 -1
  234. package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js.map +0 -1
  235. package/dist/services/tts/highlight-pipeline/readable-region.js.map +0 -1
  236. package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.js.map +0 -1
  237. package/dist/services/tts/highlight-pipeline/types.js.map +0 -1
  238. package/dist/services/tts/highlight-pipeline/visible-map-range.js.map +0 -1
  239. package/dist/services/tts/highlight-target-resolver.js.map +0 -1
  240. package/dist/services/tts/math-alignment/index.js.map +0 -1
  241. package/dist/services/tts/math-alignment/mathml-tokenizer.js.map +0 -1
  242. package/dist/services/tts/math-alignment/range-resolver.js.map +0 -1
  243. package/dist/services/tts/math-alignment/sequence-aligner.js.map +0 -1
  244. package/dist/services/tts/math-alignment/speech-tokenizer.js.map +0 -1
  245. package/dist/services/tts/math-alignment/types.js.map +0 -1
  246. package/dist/services/tts/math-aware-text-processing.js.map +0 -1
  247. package/dist/services/tts/math-speech.js.map +0 -1
  248. package/dist/services/tts/mathml-sanitization.js.map +0 -1
  249. package/dist/services/tts/ssml/spoken-text.js.map +0 -1
  250. package/dist/services/tts/text-processing.js.map +0 -1
  251. package/dist/services/tts/text-segmentation.js.map +0 -1
  252. package/dist/services/tts/visual-line-ranges.js.map +0 -1
  253. package/dist/services/tts-control-events.js.map +0 -1
  254. package/dist/services/tts-runtime-config.js.map +0 -1
  255. package/dist/tools/calculators/desmos-provider.js.map +0 -1
  256. package/dist/tools/client.js.map +0 -1
  257. package/dist/tools/index.js.map +0 -1
  258. package/dist/tools/library-loader.js.map +0 -1
  259. package/dist/tools/registrations/accessibility-tools.js.map +0 -1
  260. package/dist/tools/registrations/calculator.js.map +0 -1
  261. package/dist/tools/registrations/interaction-tools.js.map +0 -1
  262. package/dist/tools/registrations/measurement-tools.js.map +0 -1
  263. package/dist/tools/registrations/subject-specific-tools.js.map +0 -1
  264. package/dist/tools/registrations/toolbar-registration-helpers.js.map +0 -1
  265. package/dist/tools/registrations/tts.js.map +0 -1
  266. package/dist/tools/response-discovery.js.map +0 -1
  267. package/dist/tools/tool-tag-map.js.map +0 -1
  268. package/dist/tools/types.js.map +0 -1
  269. package/dist/tools/variant-resolver.js.map +0 -1
  270. package/dist/utils/logger.js.map +0 -1
@@ -35,4 +35,3 @@ export const segmentSentences = (text, options) => {
35
35
  }
36
36
  return parsed.length > 0 ? parsed : [{ text, offset: 0 }];
37
37
  };
38
- //# sourceMappingURL=text-segmentation.js.map
@@ -224,4 +224,3 @@ export function visualLineRangesForFocusInRoot(root, focus) {
224
224
  }
225
225
  return out.length > 0 ? out : [intersected.cloneRange()];
226
226
  }
227
- //# sourceMappingURL=visual-line-ranges.js.map
@@ -5,4 +5,3 @@
5
5
  * playback controls such as stop/pause/resume.
6
6
  */
7
7
  export const PIE_TTS_CONTROL_HANDOFF_EVENT = "pie-tts-control-handoff";
8
- //# sourceMappingURL=tts-control-events.js.map
@@ -352,4 +352,3 @@ export const resolveTTSHostToolbarLayout = (config) => {
352
352
  };
353
353
  }
354
354
  };
355
- //# sourceMappingURL=tts-runtime-config.js.map
@@ -391,4 +391,3 @@ class DesmosCalculator {
391
391
  }
392
392
  }
393
393
  }
394
- //# sourceMappingURL=desmos-provider.js.map
@@ -16,4 +16,3 @@ export { COMMON_LIBRARIES, LibraryLoaderImpl, libraryLoader, } from "./library-l
16
16
  export { ResponseDiscoveryServiceImpl, responseDiscovery, } from "./response-discovery.js";
17
17
  // Core types (client-safe)
18
18
  export * from "./types.js";
19
- //# sourceMappingURL=client.js.map
@@ -8,4 +8,3 @@
8
8
  export * from "./client.js";
9
9
  // Variant resolver
10
10
  export { VariantResolverImpl } from "./variant-resolver.js";
11
- //# sourceMappingURL=index.js.map
@@ -259,4 +259,3 @@ export const COMMON_LIBRARIES = {
259
259
  timeout: 5000,
260
260
  },
261
261
  };
262
- //# sourceMappingURL=library-loader.js.map
@@ -215,4 +215,3 @@ export const annotationToolbarRegistration = {
215
215
  };
216
216
  },
217
217
  };
218
- //# sourceMappingURL=accessibility-tools.js.map
@@ -226,4 +226,3 @@ export const calculatorToolRegistration = {
226
226
  };
227
227
  },
228
228
  };
229
- //# sourceMappingURL=calculator.js.map
@@ -141,4 +141,3 @@ export const highlighterToolRegistration = {
141
141
  };
142
142
  },
143
143
  };
144
- //# sourceMappingURL=interaction-tools.js.map
@@ -128,4 +128,3 @@ export const protractorToolRegistration = {
128
128
  };
129
129
  },
130
130
  };
131
- //# sourceMappingURL=measurement-tools.js.map
@@ -156,4 +156,3 @@ export const periodicTableToolRegistration = {
156
156
  };
157
157
  },
158
158
  };
159
- //# sourceMappingURL=subject-specific-tools.js.map
@@ -22,4 +22,3 @@ export function syncButtonAndOverlayVisibility(args) {
22
22
  export function applyOverlaySurface(overlay, surface) {
23
23
  overlay.setAttribute("data-pie-tool-surface", surface);
24
24
  }
25
- //# sourceMappingURL=toolbar-registration-helpers.js.map
@@ -182,4 +182,3 @@ export const ttsToolRegistration = {
182
182
  };
183
183
  },
184
184
  };
185
- //# sourceMappingURL=tts.js.map
@@ -111,4 +111,3 @@ export class ResponseDiscoveryServiceImpl {
111
111
  * Singleton instance
112
112
  */
113
113
  export const responseDiscovery = new ResponseDiscoveryServiceImpl();
114
- //# sourceMappingURL=response-discovery.js.map
@@ -34,4 +34,3 @@ export const toToolIdFromTag = (tagName, overrides) => {
34
34
  const map = { ...DEFAULT_TOOL_TAG_MAP, ...overrides?.toolTagMap };
35
35
  return Object.entries(map).find(([, tag]) => tag === validTag)?.[0];
36
36
  };
37
- //# sourceMappingURL=tool-tag-map.js.map
@@ -10,4 +10,3 @@ export var ToolCategory;
10
10
  ToolCategory["CONTENT_INTERACTIVE"] = "content-interactive";
11
11
  ToolCategory["SERVICE_DEPENDENT"] = "service-dependent";
12
12
  })(ToolCategory || (ToolCategory = {}));
13
- //# sourceMappingURL=types.js.map
@@ -205,4 +205,3 @@ export class VariantResolverImpl {
205
205
  .replace(/\b\w/g, (char) => char.toUpperCase());
206
206
  }
207
207
  }
208
- //# sourceMappingURL=variant-resolver.js.map
@@ -8,4 +8,3 @@ export function createLogger(namespace) {
8
8
  console.debug(`[${namespace}]`, ...args);
9
9
  };
10
10
  }
11
- //# sourceMappingURL=logger.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-players/pie-assessment-toolkit",
3
- "version": "0.3.61",
3
+ "version": "0.3.63",
4
4
  "type": "module",
5
5
  "description": "PIE assessment toolkit: composable services + reference implementation for assessment players and tool coordination",
6
6
  "license": "MIT",
@@ -75,15 +75,15 @@
75
75
  "test": "bun test"
76
76
  },
77
77
  "dependencies": {
78
- "@pie-players/pie-calculator": "0.3.61",
79
- "@pie-players/pie-context": "0.3.61",
80
- "@pie-players/pie-players-shared": "0.3.61",
81
- "@pie-players/pie-tts": "0.3.61",
82
- "speech-rule-engine": "^5.0.0-rc.1"
78
+ "@pie-players/pie-calculator": "0.3.63",
79
+ "@pie-players/pie-context": "0.3.63",
80
+ "@pie-players/pie-players-shared": "0.3.63",
81
+ "@pie-players/pie-tts": "0.3.63",
82
+ "speech-rule-engine": "^5.0.0-rc.4"
83
83
  },
84
84
  "peerDependencies": {
85
- "@pie-players/pie-calculator-desmos": "0.3.61",
86
- "@pie-players/tts-client-server": "0.3.61"
85
+ "@pie-players/pie-calculator-desmos": "0.3.63",
86
+ "@pie-players/tts-client-server": "0.3.63"
87
87
  },
88
88
  "peerDependenciesMeta": {
89
89
  "@pie-players/pie-calculator-desmos": {
@@ -94,9 +94,11 @@
94
94
  }
95
95
  },
96
96
  "devDependencies": {
97
- "@biomejs/biome": "^2.4.12",
98
- "@happy-dom/global-registrator": "^20.9.0",
99
- "svelte": "^5.54.0",
97
+ "@biomejs/biome": "^2.5.6",
98
+ "@happy-dom/global-registrator": "^20.11.1",
99
+ "@pie-players/pie-calculator-desmos": "0.3.63",
100
+ "@pie-players/tts-client-server": "0.3.63",
101
+ "svelte": "^5.56.8",
100
102
  "typescript": "^5.9.3"
101
103
  },
102
104
  "homepage": "https://github.com/pie-framework/pie-players/tree/master/packages/assessment-toolkit#readme",
@@ -1 +0,0 @@
1
- {"version":3,"file":"AssessmentSession.js","sourceRoot":"","sources":["../../src/attempt/AssessmentSession.ts"],"names":[],"mappings":"AAiCA,MAAM,0BAA0B,GAAG,CAAU,CAAC;AAC9C,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,SAAS,MAAM;IACd,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC7C,kCAA0C;IAE1C,OAAO,GAAG,cAAc,GAAG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wB;gBAClD,CAAC,CAAC,CAAC,wBAAwB,CAAC;gBAC5B,CAAC,CAAC,EAAE;YACL,wBAAwB,EAAE,wBAAwB;SAClD;QACD,WAAW,EAAE;YACZ,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;SAC3C;QACD,eAAe,EAAE,EAAE;KACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CACnC,OAA0B,EAC1B,IAGC;IAED,IAAI,CAAC,IAAI,CAAC,iBAAiB;QAAE,OAAO,OAAO,CAAC;IAC5C,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC;IAC3B,OAAO;QACN,GAAG,OAAO;QACV,SAAS;QACT,eAAe,EAAE;YAChB,GAAG,OAAO,CAAC,eAAe;YAC1B,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;gBACzB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;gBACzC,SAAS;gBACT,OAAO,EAAE,IAAI,CAAC,cAAc;aAC5B;SACD;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,yBAAyB,CACxC,OAA0B,EAC1B,IAGC;IAED,MAAM,OAAO,GAAG,IAAI,GAAG,CACtB,OAAO,CAAC,eAAe,CAAC,yBAAyB,IAAI,EAAE,CACvD,CAAC;IACF,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO;QACN,GAAG,OAAO;QACV,eAAe,EAAE;YAChB,GAAG,OAAO,CAAC,eAAe;YAC1B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;YAC7C,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,yBAAyB,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;SAC9C;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { SectionControllerSessionState } from \"../services/section-controller-types.js\";\nimport type { StorageLike } from \"./TestSession.js\";\n\nexport interface AssessmentSessionNavigationState {\n\tcurrentSectionIndex: number;\n\tvisitedSectionIdentifiers: string[];\n\tcurrentSectionIdentifier?: string;\n}\n\nexport interface AssessmentSessionRealization {\n\tseed: string;\n\tsectionIdentifiers: string[];\n}\n\nexport interface AssessmentSectionSessionState {\n\tsectionIdentifier: string;\n\tupdatedAt: string;\n\tsession: SectionControllerSessionState | null;\n}\n\nexport interface AssessmentSession {\n\tversion: 1;\n\tassessmentAttemptSessionIdentifier: string;\n\tassessmentId: string;\n\tstartedAt: string;\n\tupdatedAt: string;\n\tcompletedAt?: string;\n\tnavigationState: AssessmentSessionNavigationState;\n\trealization: AssessmentSessionRealization;\n\tsectionSessions: Record<string, AssessmentSectionSessionState>;\n\tcontextVariables?: Record<string, unknown>;\n}\n\nconst ASSESSMENT_SESSION_VERSION = 1 as const;\nconst STORAGE_PREFIX = \"pie:assessment-session:v1:\";\n\nfunction nowIso(): string {\n\treturn new Date().toISOString();\n}\n\nexport function getAssessmentSessionStorageKey(\n\tassessmentAttemptSessionIdentifier: string,\n): string {\n\treturn `${STORAGE_PREFIX}${assessmentAttemptSessionIdentifier}`;\n}\n\nexport function loadAssessmentSession(\n\tstorage: StorageLike,\n\tassessmentAttemptSessionIdentifier: string,\n): AssessmentSession | null {\n\tconst raw = storage.getItem(\n\t\tgetAssessmentSessionStorageKey(assessmentAttemptSessionIdentifier),\n\t);\n\tif (!raw) return null;\n\ttry {\n\t\tconst parsed = JSON.parse(raw) as AssessmentSession;\n\t\tif (!parsed || parsed.version !== ASSESSMENT_SESSION_VERSION) return null;\n\t\tif (\n\t\t\tparsed.assessmentAttemptSessionIdentifier !==\n\t\t\tassessmentAttemptSessionIdentifier\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\treturn parsed;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function saveAssessmentSession(\n\tstorage: StorageLike,\n\tsession: AssessmentSession,\n): void {\n\tconst updated: AssessmentSession = {\n\t\t...session,\n\t\tupdatedAt: nowIso(),\n\t};\n\tstorage.setItem(\n\t\tgetAssessmentSessionStorageKey(session.assessmentAttemptSessionIdentifier),\n\t\tJSON.stringify(updated),\n\t);\n}\n\nexport function createNewAssessmentSession(args: {\n\tassessmentAttemptSessionIdentifier: string;\n\tassessmentId: string;\n\tseed: string;\n\tsectionIdentifiers: string[];\n}): AssessmentSession {\n\tconst startedAt = nowIso();\n\tconst initialSectionIdentifier = args.sectionIdentifiers[0];\n\treturn {\n\t\tversion: ASSESSMENT_SESSION_VERSION,\n\t\tassessmentAttemptSessionIdentifier: args.assessmentAttemptSessionIdentifier,\n\t\tassessmentId: args.assessmentId,\n\t\tstartedAt,\n\t\tupdatedAt: startedAt,\n\t\tnavigationState: {\n\t\t\tcurrentSectionIndex: 0,\n\t\t\tvisitedSectionIdentifiers: initialSectionIdentifier\n\t\t\t\t? [initialSectionIdentifier]\n\t\t\t\t: [],\n\t\t\tcurrentSectionIdentifier: initialSectionIdentifier,\n\t\t},\n\t\trealization: {\n\t\t\tseed: args.seed,\n\t\t\tsectionIdentifiers: args.sectionIdentifiers,\n\t\t},\n\t\tsectionSessions: {},\n\t};\n}\n\nexport function upsertSectionSession(\n\tsession: AssessmentSession,\n\targs: {\n\t\tsectionIdentifier: string;\n\t\tsectionSession: SectionControllerSessionState | null;\n\t},\n): AssessmentSession {\n\tif (!args.sectionIdentifier) return session;\n\tconst updatedAt = nowIso();\n\treturn {\n\t\t...session,\n\t\tupdatedAt,\n\t\tsectionSessions: {\n\t\t\t...session.sectionSessions,\n\t\t\t[args.sectionIdentifier]: {\n\t\t\t\tsectionIdentifier: args.sectionIdentifier,\n\t\t\t\tupdatedAt,\n\t\t\t\tsession: args.sectionSession,\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport function setCurrentSectionPosition(\n\tsession: AssessmentSession,\n\targs: {\n\t\tcurrentSectionIndex: number;\n\t\tcurrentSectionIdentifier?: string;\n\t},\n): AssessmentSession {\n\tconst visited = new Set(\n\t\tsession.navigationState.visitedSectionIdentifiers || [],\n\t);\n\tif (args.currentSectionIdentifier) {\n\t\tvisited.add(args.currentSectionIdentifier);\n\t}\n\treturn {\n\t\t...session,\n\t\tnavigationState: {\n\t\t\t...session.navigationState,\n\t\t\tcurrentSectionIndex: args.currentSectionIndex,\n\t\t\tcurrentSectionIdentifier: args.currentSectionIdentifier,\n\t\t\tvisitedSectionIdentifiers: Array.from(visited),\n\t\t},\n\t};\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"TestSession.js","sourceRoot":"","sources":["../../src/attempt/TestSession.ts"],"names":[],"mappings":"AAyEA,MAAM,4BAA4B,GAAG,CAAU,CAAC;AAChD,MAAM,cAAc,GAAG,iCAAiC,CAAC;AACzD,MAAM,kBAAkB,GAAG,+BAA+B,CAAC;AAE3D,MAAM,UAAU,mBAAmB,CAClC,UAAkC,EAAE;IAEpC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/C,OAAO;QACN,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,IAAI,CAAC;QAChE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACjB,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjB,CAAC;QACD,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE;YACjB,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB;IACrC,IAAI,CAAC;QACJ,oCAAoC;QACpC,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC/C,oCAAoC;QACpC,IAAI,CAAC,M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AI,GAAG;QACrC,SAAS,EAAE,GAAG;QACd,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS;QACjE,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,QAAQ,EAAE,OAAO;KAC1C,CAAC;IAEF,OAAO;QACN,GAAG,OAAO;QACV,YAAY,EAAE;YACb,GAAG,OAAO,CAAC,YAAY;YACvB,CAAC,cAAc,CAAC,EAAE,IAAI;SACtB;KACD,CAAC;AACH,CAAC","sourcesContent":["export interface StorageLike {\n\tgetItem(key: string): string | null;\n\tsetItem(key: string, value: string): void;\n\tremoveItem(key: string): void;\n}\n\nexport interface TestAttemptSessionNavigationState {\n\tcurrentItemIndex: number;\n\tvisitedItemIdentifiers: string[];\n\tcurrentSectionIdentifier?: string;\n}\n\nexport interface TestAttemptSessionRealization {\n\t/**\n\t * Deterministic seed for shuffling/selection.\n\t * (Future: use for QTI ordering.shuffle / selection rules.)\n\t */\n\tseed: string;\n\t/**\n\t * Realized item order for this attempt (QTI item identifiers).\n\t */\n\titemIdentifiers: string[];\n}\n\nexport interface TestAttemptItemSession {\n\t/**\n\t * QTI assessmentItemRef identifier (same as questionRef.identifier).\n\t */\n\titemIdentifier: string;\n\n\t/**\n\t * PIE session id for the underlying item attempt (if/when created).\n\t */\n\tpieSessionId?: string;\n\n\tattemptCount: number;\n\tisCompleted: boolean;\n\n\tstartedAt?: string;\n\tupdatedAt?: string;\n\tcompletedAt?: string;\n\tsession?: unknown;\n}\n\nexport interface TestAttemptSession {\n\tversion: 1;\n\n\t/**\n\t * QTI-like identifier for the delivery attempt (administration).\n\t */\n\ttestAttemptSessionIdentifier: string;\n\n\tassessmentId: string;\n\n\tstartedAt: string;\n\tupdatedAt: string;\n\tcompletedAt?: string;\n\n\tnavigationState: TestAttemptSessionNavigationState;\n\trealization: TestAttemptSessionRealization;\n\n\t/**\n\t * Keyed by QTI item identifier (questionRef.identifier).\n\t */\n\titemSessions: Record<string, TestAttemptItemSession>;\n\n\t/**\n\t * QTI 3.0 context variables (global assessment-level variables).\n\t * Managed by ContextVariableStore.\n\t */\n\tcontextVariables?: Record<string, any>;\n}\n\nconst TEST_ATTEMPT_SESSION_VERSION = 1 as const;\nconst STORAGE_PREFIX = \"pieoneer:testAttemptSession:v1:\";\nconst ANON_DEVICE_ID_KEY = \"pieoneer:anonymousDeviceId:v1\";\n\nexport function createMemoryStorage(\n\tinitial: Record<string, string> = {},\n): StorageLike {\n\tconst store = new Map(Object.entries(initial));\n\treturn {\n\t\tgetItem: (k) => (store.has(k) ? (store.get(k) as string) : null),\n\t\tsetItem: (k, v) => {\n\t\t\tstore.set(k, v);\n\t\t},\n\t\tremoveItem: (k) => {\n\t\t\tstore.delete(k);\n\t\t},\n\t};\n}\n\nexport function getBrowserLocalStorage(): StorageLike | null {\n\ttry {\n\t\t// eslint-disable-next-line no-undef\n\t\tif (typeof window === \"undefined\") return null;\n\t\t// eslint-disable-next-line no-undef\n\t\tif (!window.localStorage) return null;\n\t\t// eslint-disable-next-line no-undef\n\t\treturn window.localStorage;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction nowIso(): string {\n\treturn new Date().toISOString();\n}\n\n// Lightweight, deterministic hash for IDs (no crypto dependency).\nfunction fnv1a32Hex(input: string): string {\n\tlet hash = 0x811c9dc5; // offset basis\n\tfor (let i = 0; i < input.length; i++) {\n\t\thash ^= input.charCodeAt(i);\n\t\t// hash *= 16777619 (with 32-bit overflow)\n\t\thash =\n\t\t\t(hash +\n\t\t\t\t((hash << 1) +\n\t\t\t\t\t(hash << 4) +\n\t\t\t\t\t(hash << 7) +\n\t\t\t\t\t(hash << 8) +\n\t\t\t\t\t(hash << 24))) >>>\n\t\t\t0;\n\t}\n\treturn hash.toString(16).padStart(8, \"0\");\n}\n\nfunction randomId(): string {\n\tconst cryptoAny = (globalThis as any)?.crypto;\n\tconst uuid = cryptoAny?.randomUUID?.();\n\tif (typeof uuid === \"string\" && uuid.length > 0) {\n\t\treturn uuid;\n\t}\n\treturn `anon_${Math.random().toString(16).slice(2)}_${Date.now().toString(16)}`;\n}\n\nexport function getOrCreateAnonymousDeviceId(storage: StorageLike): string {\n\tconst existing = storage.getItem(ANON_DEVICE_ID_KEY);\n\tif (existing) return existing;\n\tconst created = randomId();\n\tstorage.setItem(ANON_DEVICE_ID_KEY, created);\n\treturn created;\n}\n\nexport function createTestAttemptSessionIdentifier(args: {\n\tassessmentId: string;\n\tassignmentId?: string | null;\n\tuserId?: string | null;\n\tstorage: StorageLike;\n}): { testAttemptSessionIdentifier: string; seed: string } {\n\tconst { assessmentId, assignmentId, userId, storage } = args;\n\tif (!assessmentId) {\n\t\tthrow new Error(\n\t\t\t\"assessmentId is required to create a TestSession identifier\",\n\t\t);\n\t}\n\n\tconst subject = userId || getOrCreateAnonymousDeviceId(storage);\n\tconst source = `v1|${assessmentId}|${assignmentId || \"\"}|${subject}`;\n\tconst seed = fnv1a32Hex(source);\n\treturn { testAttemptSessionIdentifier: `tas_v1_${seed}`, seed };\n}\n\nexport function getTestAttemptSessionStorageKey(\n\ttestAttemptSessionIdentifier: string,\n): string {\n\treturn `${STORAGE_PREFIX}${testAttemptSessionIdentifier}`;\n}\n\nexport function loadTestAttemptSession(\n\tstorage: StorageLike,\n\ttestAttemptSessionIdentifier: string,\n): TestAttemptSession | null {\n\tconst raw = storage.getItem(\n\t\tgetTestAttemptSessionStorageKey(testAttemptSessionIdentifier),\n\t);\n\tif (!raw) return null;\n\ttry {\n\t\tconst parsed = JSON.parse(raw) as TestAttemptSession;\n\t\tif (!parsed || parsed.version !== TEST_ATTEMPT_SESSION_VERSION) return null;\n\t\tif (parsed.testAttemptSessionIdentifier !== testAttemptSessionIdentifier) {\n\t\t\treturn null;\n\t\t}\n\t\treturn parsed;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function saveTestAttemptSession(\n\tstorage: StorageLike,\n\tsession: TestAttemptSession,\n): void {\n\tconst updated: TestAttemptSession = {\n\t\t...session,\n\t\tupdatedAt: nowIso(),\n\t};\n\tstorage.setItem(\n\t\tgetTestAttemptSessionStorageKey(session.testAttemptSessionIdentifier),\n\t\tJSON.stringify(updated),\n\t);\n}\n\nexport function createNewTestAttemptSession(args: {\n\ttestAttemptSessionIdentifier: string;\n\tassessmentId: string;\n\tseed: string;\n\titemIdentifiers: string[];\n}): TestAttemptSession {\n\tconst startedAt = nowIso();\n\treturn {\n\t\tversion: TEST_ATTEMPT_SESSION_VERSION,\n\t\ttestAttemptSessionIdentifier: args.testAttemptSessionIdentifier,\n\t\tassessmentId: args.assessmentId,\n\t\tstartedAt,\n\t\tupdatedAt: startedAt,\n\t\tnavigationState: {\n\t\t\tcurrentItemIndex: -1,\n\t\t\tvisitedItemIdentifiers: [],\n\t\t},\n\t\trealization: {\n\t\t\tseed: args.seed,\n\t\t\titemIdentifiers: args.itemIdentifiers,\n\t\t},\n\t\titemSessions: {},\n\t};\n}\n\nexport function upsertVisitedItem(\n\tsession: TestAttemptSession,\n\titemIdentifier: string,\n): TestAttemptSession {\n\tif (!itemIdentifier) return session;\n\tconst visited = new Set(session.navigationState.visitedItemIdentifiers || []);\n\tvisited.add(itemIdentifier);\n\treturn {\n\t\t...session,\n\t\tnavigationState: {\n\t\t\t...session.navigationState,\n\t\t\tvisitedItemIdentifiers: Array.from(visited),\n\t\t},\n\t};\n}\n\nexport function setCurrentPosition(\n\tsession: TestAttemptSession,\n\targs: {\n\t\tcurrentItemIndex: number;\n\t\tcurrentSectionIdentifier?: string;\n\t},\n): TestAttemptSession {\n\treturn {\n\t\t...session,\n\t\tnavigationState: {\n\t\t\t...session.navigationState,\n\t\t\tcurrentItemIndex: args.currentItemIndex,\n\t\t\tcurrentSectionIdentifier: args.currentSectionIdentifier,\n\t\t},\n\t};\n}\n\nexport function upsertItemSessionFromPieSessionChange(\n\tsession: TestAttemptSession,\n\targs: {\n\t\titemIdentifier: string;\n\t\tpieSessionId: string;\n\t\tisCompleted?: boolean;\n\t\tsession?: unknown;\n\t},\n): TestAttemptSession {\n\tconst { itemIdentifier, pieSessionId, isCompleted } = args;\n\tif (!itemIdentifier || !pieSessionId) return session;\n\n\tconst now = nowIso();\n\tconst existing = session.itemSessions[itemIdentifier];\n\n\tconst attemptCount =\n\t\texisting && existing.pieSessionId && existing.pieSessionId !== pieSessionId\n\t\t\t? existing.attemptCount + 1\n\t\t\t: existing\n\t\t\t\t? existing.attemptCount\n\t\t\t\t: 1;\n\n\tconst completed = !!(isCompleted ?? existing?.isCompleted);\n\n\tconst next: TestAttemptItemSession = {\n\t\titemIdentifier,\n\t\tpieSessionId,\n\t\tattemptCount,\n\t\tisCompleted: completed,\n\t\tstartedAt: existing?.startedAt || now,\n\t\tupdatedAt: now,\n\t\tcompletedAt: completed ? existing?.completedAt || now : undefined,\n\t\tsession: args.session ?? existing?.session,\n\t};\n\n\treturn {\n\t\t...session,\n\t\titemSessions: {\n\t\t\t...session.itemSessions,\n\t\t\t[itemIdentifier]: next,\n\t\t},\n\t};\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"activity-to-test-attempt-session.js","sourceRoot":"","sources":["../../../src/attempt/adapters/activity-to-test-attempt-session.ts"],"names":[],"mappings":"AAsDA,SAAS,MAAM;IACd,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAkC;IAC5D,OAAO,CACN,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,EAAE,UAAU,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,IAAI,IAAI,CAC1E,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB,CAC9B,IAAyC;IAEzC,MAAM,IAAI,GACT,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,kBAAkB,EAAE,kBAAkB,IAAI,EAAE,CAAC;IACpE,MAAM,WAAW,GAAG,IAAI;SACtB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,i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,WAAW,EAAE,kBAAkB,CAAC,WAAW;YAC3C,gBAAgB,EAAE,kBAAkB,CAAC,eAAe,CAAC,gBAAgB;YACrE,wBAAwB,EACvB,kBAAkB,CAAC,eAAe,CAAC,wBAAwB;YAC5D,sBAAsB,EAAE;gBACvB,GAAG,kBAAkB,CAAC,eAAe,CAAC,sBAAsB;aAC5D;YACD,YAAY,EAAE,oBAAoB,CAAC,kBAAkB,CAAC;SACtD;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC7C,kBAAsC,EACtC,cAAsB;IAEtB,MAAM,WAAW,GAAG,kBAAkB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IACpE,OAAO;QACN,eAAe,EAAE;YAChB,EAAE,EAAE,kBAAkB,CAAC,4BAA4B;YACnD,gBAAgB,EAAE,kBAAkB,CAAC,eAAe,CAAC,gBAAgB;YACrE,wBAAwB,EACvB,kBAAkB,CAAC,eAAe,CAAC,wBAAwB;YAC5D,sBAAsB,EAAE;gBACvB,GAAG,kBAAkB,CAAC,eAAe,CAAC,sBAAsB;aAC5D;YACD,YAAY,EAAE,WAAW,EAAE,OAAO;gBACjC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE;gBAC3C,CAAC,CAAC,EAAE;SACL;KACD,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tTestAttemptItemSession,\n\tTestAttemptSession,\n} from \"../TestSession.js\";\n\nexport interface PieBackendActivityItemRef {\n\tidentifier?: string;\n\titem?: {\n\t\tid?: string;\n\t\tidentifier?: string;\n\t};\n}\n\nexport interface PieBackendActivityDefinition {\n\tid?: string;\n\tidentifier?: string;\n\tassessmentId?: string;\n\tassessmentItemRefs?: PieBackendActivityItemRef[];\n}\n\nexport interface PieBackendActivitySession {\n\tid?: string;\n\tactivitySessionId?: string;\n\tstartedAt?: string;\n\tupdatedAt?: string;\n\tcompletedAt?: string;\n\tcurrentItemIndex?: number;\n\tcurrentSectionIdentifier?: string;\n\tvisitedItemIdentifiers?: string[];\n\titemSessions?: Record<string, unknown>;\n}\n\nexport interface MapActivityToTestAttemptSessionArgs {\n\tactivityDefinition?: PieBackendActivityDefinition | null;\n\tactivitySession?: PieBackendActivitySession | null;\n\titemRefs?: PieBackendActivityItemRef[];\n\titemSessionsByItemIdentifier?: Record<string, unknown>;\n\tassessmentId?: string;\n\ttestAttemptSessionIdentifier?: string;\n}\n\nexport interface ActivitySessionPatchPayload {\n\tactivitySession: {\n\t\tid: string;\n\t\tstartedAt?: string;\n\t\tupdatedAt?: string;\n\t\tcompletedAt?: string;\n\t\tcurrentItemIndex: number;\n\t\tcurrentSectionIdentifier?: string;\n\t\tvisitedItemIdentifiers: string[];\n\t\titemSessions: Record<string, unknown>;\n\t};\n}\n\nfunction nowIso(): string {\n\treturn new Date().toISOString();\n}\n\nfunction getItemIdentifier(itemRef: PieBackendActivityItemRef): string | null {\n\treturn (\n\t\titemRef.identifier || itemRef.item?.identifier || itemRef.item?.id || null\n\t);\n}\n\nfunction resolveItemIdentifiers(\n\targs: MapActivityToTestAttemptSessionArgs,\n): string[] {\n\tconst refs =\n\t\targs.itemRefs || args.activityDefinition?.assessmentItemRefs || [];\n\tconst identifiers = refs\n\t\t.map((itemRef) => getItemIdentifier(itemRef))\n\t\t.filter((itemIdentifier): itemIdentifier is string => !!itemIdentifier);\n\treturn Array.from(new Set(identifiers));\n}\n\nfunction resolveAssessmentId(\n\targs: MapActivityToTestAttemptSessionArgs,\n): string {\n\treturn (\n\t\targs.assessmentId ||\n\t\targs.activityDefinition?.assessmentId ||\n\t\targs.activityDefinition?.identifier ||\n\t\targs.activityDefinition?.id ||\n\t\t\"unknown-assessment\"\n\t);\n}\n\nfunction resolveTestAttemptSessionIdentifier(\n\targs: MapActivityToTestAttemptSessionArgs,\n\tassessmentId: string,\n): string {\n\treturn (\n\t\targs.testAttemptSessionIdentifier ||\n\t\targs.activitySession?.activitySessionId ||\n\t\targs.activitySession?.id ||\n\t\t`tas_${assessmentId}`\n\t);\n}\n\nfunction resolveBackendItemSessions(\n\targs: MapActivityToTestAttemptSessionArgs,\n): Record<string, unknown> {\n\treturn {\n\t\t...(args.activitySession?.itemSessions || {}),\n\t\t...(args.itemSessionsByItemIdentifier || {}),\n\t};\n}\n\nfunction mapItemSessions(\n\titemIdentifiers: string[],\n\tbackendItemSessions: Record<string, unknown>,\n): Record<string, TestAttemptItemSession> {\n\treturn itemIdentifiers.reduce<Record<string, TestAttemptItemSession>>(\n\t\t(acc, itemIdentifier) => {\n\t\t\tconst rawSession = backendItemSessions[itemIdentifier] as\n\t\t\t\t| Record<string, unknown>\n\t\t\t\t| undefined;\n\t\t\tif (!rawSession) return acc;\n\n\t\t\tconst pieSessionId =\n\t\t\t\ttypeof rawSession.id === \"string\" ? rawSession.id : undefined;\n\t\t\tconst attemptCount =\n\t\t\t\ttypeof rawSession.attemptCount === \"number\" &&\n\t\t\t\trawSession.attemptCount > 0\n\t\t\t\t\t? rawSession.attemptCount\n\t\t\t\t\t: pieSessionId\n\t\t\t\t\t\t? 1\n\t\t\t\t\t\t: 0;\n\t\t\tconst isCompleted =\n\t\t\t\ttypeof rawSession.isCompleted === \"boolean\"\n\t\t\t\t\t? rawSession.isCompleted\n\t\t\t\t\t: Boolean(rawSession.complete);\n\t\t\tconst startedAt =\n\t\t\t\ttypeof rawSession.startedAt === \"string\"\n\t\t\t\t\t? rawSession.startedAt\n\t\t\t\t\t: undefined;\n\t\t\tconst updatedAt =\n\t\t\t\ttypeof rawSession.updatedAt === \"string\"\n\t\t\t\t\t? rawSession.updatedAt\n\t\t\t\t\t: undefined;\n\t\t\tconst completedAt =\n\t\t\t\ttypeof rawSession.completedAt === \"string\"\n\t\t\t\t\t? rawSession.completedAt\n\t\t\t\t\t: undefined;\n\n\t\t\tacc[itemIdentifier] = {\n\t\t\t\titemIdentifier,\n\t\t\t\tpieSessionId,\n\t\t\t\tattemptCount,\n\t\t\t\tisCompleted,\n\t\t\t\tstartedAt,\n\t\t\t\tupdatedAt,\n\t\t\t\tcompletedAt,\n\t\t\t\tsession: rawSession,\n\t\t\t};\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n}\n\nexport function mapActivityToTestAttemptSession(\n\targs: MapActivityToTestAttemptSessionArgs,\n): TestAttemptSession {\n\tconst assessmentId = resolveAssessmentId(args);\n\tconst itemIdentifiers = resolveItemIdentifiers(args);\n\tconst testAttemptSessionIdentifier = resolveTestAttemptSessionIdentifier(\n\t\targs,\n\t\tassessmentId,\n\t);\n\tconst backendItemSessions = resolveBackendItemSessions(args);\n\tconst now = nowIso();\n\tconst startedAt = args.activitySession?.startedAt || now;\n\tconst updatedAt = args.activitySession?.updatedAt || startedAt;\n\n\treturn {\n\t\tversion: 1,\n\t\ttestAttemptSessionIdentifier,\n\t\tassessmentId,\n\t\tstartedAt,\n\t\tupdatedAt,\n\t\tcompletedAt: args.activitySession?.completedAt,\n\t\tnavigationState: {\n\t\t\tcurrentItemIndex: args.activitySession?.currentItemIndex ?? -1,\n\t\t\tvisitedItemIdentifiers: [\n\t\t\t\t...(args.activitySession?.visitedItemIdentifiers || []),\n\t\t\t],\n\t\t\tcurrentSectionIdentifier: args.activitySession?.currentSectionIdentifier,\n\t\t},\n\t\trealization: {\n\t\t\tseed: testAttemptSessionIdentifier,\n\t\t\titemIdentifiers,\n\t\t},\n\t\titemSessions: mapItemSessions(itemIdentifiers, backendItemSessions),\n\t};\n}\n\nexport function toItemSessionsRecord(\n\ttestAttemptSession: TestAttemptSession,\n): Record<string, unknown> {\n\treturn Object.entries(testAttemptSession.itemSessions).reduce<\n\t\tRecord<string, unknown>\n\t>((acc, [itemIdentifier, itemSession]) => {\n\t\tif (itemSession.session) {\n\t\t\tacc[itemIdentifier] = itemSession.session;\n\t\t}\n\t\treturn acc;\n\t}, {});\n}\n\nexport function buildActivitySessionPatchFromTestAttemptSession(\n\ttestAttemptSession: TestAttemptSession,\n): ActivitySessionPatchPayload {\n\treturn {\n\t\tactivitySession: {\n\t\t\tid: testAttemptSession.testAttemptSessionIdentifier,\n\t\t\tstartedAt: testAttemptSession.startedAt,\n\t\t\tupdatedAt: testAttemptSession.updatedAt,\n\t\t\tcompletedAt: testAttemptSession.completedAt,\n\t\t\tcurrentItemIndex: testAttemptSession.navigationState.currentItemIndex,\n\t\t\tcurrentSectionIdentifier:\n\t\t\t\ttestAttemptSession.navigationState.currentSectionIdentifier,\n\t\t\tvisitedItemIdentifiers: [\n\t\t\t\t...testAttemptSession.navigationState.visitedItemIdentifiers,\n\t\t\t],\n\t\t\titemSessions: toItemSessionsRecord(testAttemptSession),\n\t\t},\n\t};\n}\n\nexport function buildActivitySessionItemUpdate(\n\ttestAttemptSession: TestAttemptSession,\n\titemIdentifier: string,\n): ActivitySessionPatchPayload {\n\tconst itemSession = testAttemptSession.itemSessions[itemIdentifier];\n\treturn {\n\t\tactivitySession: {\n\t\t\tid: testAttemptSession.testAttemptSessionIdentifier,\n\t\t\tcurrentItemIndex: testAttemptSession.navigationState.currentItemIndex,\n\t\t\tcurrentSectionIdentifier:\n\t\t\t\ttestAttemptSession.navigationState.currentSectionIdentifier,\n\t\t\tvisitedItemIdentifiers: [\n\t\t\t\t...testAttemptSession.navigationState.visitedItemIdentifiers,\n\t\t\t],\n\t\t\titemSessions: itemSession?.session\n\t\t\t\t? { [itemIdentifier]: itemSession.session }\n\t\t\t\t: {},\n\t\t},\n\t};\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"item-toolbar-element.js","sourceRoot":"","sources":["../../src/components/item-toolbar-element.ts"],"names":[],"mappings":"AAAA,OAAO,iCAAiC,CAAC","sourcesContent":["import \"./ItemToolBar.custom-element.js\";\n\nexport {};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"pie-assessment-toolkit-element.js","sourceRoot":"","sources":["../../src/components/pie-assessment-toolkit-element.ts"],"names":[],"mappings":"AAAA,OAAO,0CAA0C,CAAC","sourcesContent":["import \"./PieAssessmentToolkit.custom-element.js\";\n\nexport {};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"section-toolbar-element.js","sourceRoot":"","sources":["../../src/components/section-toolbar-element.ts"],"names":[],"mappings":"AAAA,OAAO,oCAAoC,CAAC","sourcesContent":["import \"./SectionToolBar.custom-element.js\";\n\nexport {};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"assessment-toolkit-context.js","sourceRoot":"","sources":["../../src/context/assessment-toolkit-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AA4CzD,MAAM,CAAC,MAAM,+BAA+B,GAC3C,aAAa,CACZ,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAClD,CAAC;AAOH,MAAM,CAAC,MAAM,mCAAmC,GAC/C,aAAa,CACZ,MAAM,CAAC,GAAG,CAAC,0CAA0C,CAAC,CACtD,CAAC;AAeH,MAAM,CAAC,MAAM,6BAA6B,GACzC,aAAa,CACZ,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAChD,CAAC;AAOH,MAAM,CAAC,MAAM,mCAAmC,GAC/C,aAAa,CACZ,MAAM,CAAC,GAAG,CAAC,0CAA0C,CAAC,CACtD,CAAC","sourcesContent":["import { createContext } from \"@pie-players/pie-context\";\nimport type { LoaderConfig } from \"@pie-players/pie-players-shared/loader-config\";\nimport type {\n\tAccessibilityCatalogResolverApi,\n\tElementToolStateStoreApi,\n\tHighlightCoordinatorApi,\n\tToolCoordinatorApi,\n\tToolkitCoordinatorApi,\n\tTtsServiceApi,\n} from \"../services/interfaces.js\";\nimport type { TTSHighlightTargetResolver } from \"../services/tts/highlight-target-resolver.js\";\n\nexport type ItemPlayerType = \"iife\" | \"esm\" | \"preloaded\" | \"custom\";\n\nexport interface ItemPlayerConfig {\n\ttype: ItemPlayerType;\n\ttagName: string;\n\tversion?: string;\n\tsource?: string;\n\tloaderConfig?: LoaderConfig;\n\tloaderOptions?: Record<string, unknown>;\n\tisDefault: boolean;\n}\n\nexport interface AssessmentToolkitRuntimeContext {\n\ttoolkitCoordinator: ToolkitCoordinatorApi;\n\ttoolCoordinator: ToolCoordinatorApi;\n\tttsService: TtsServiceApi;\n\thighlightCoordinator: HighlightCoordinatorApi;\n\tcatalogResolver: AccessibilityCatalogResolverApi;\n\telementToolStateStore: ElementToolStateStoreApi;\n\tassessmentId: string;\n\tsectionId: string;\n\titemPlayer: ItemPlayerConfig;\n\t/**\n\t * Opt-in flag: context consumers render the vendored `<nds-icon-button>`\n\t * only when this is `true`; otherwise (unset/`false`, the default) they\n\t * render plain `<button>` controls. Sourced from the host's\n\t * `runtime.ndsIcons` (or the `nds-icons` attribute on the toolkit).\n\t */\n\tndsIcons?: boolean;\n\treportSessionChanged?: (itemId: string, detail: unknown) => void;\n}\n\nexport const assessmentToolkitRuntimeContext =\n\tcreateContext<AssessmentToolkitRuntimeContext>(\n\t\tSymbol.for(\"pie.assessmentToolkit.runtimeContext\"),\n\t);\n\nexport interface AssessmentToolkitHostRuntimeContext {\n\truntimeId: string;\n\tcoordinator: ToolkitCoordinatorApi;\n}\n\nexport const assessmentToolkitHostRuntimeContext =\n\tcreateContext<AssessmentToolkitHostRuntimeContext>(\n\t\tSymbol.for(\"pie.assessmentToolkit.hostRuntimeContext\"),\n\t);\n\nexport type ShellContextKind = \"item\" | \"passage\";\n\nexport interface AssessmentToolkitShellContext {\n\tkind: ShellContextKind;\n\titemId: string;\n\tcanonicalItemId: string;\n\tcontentKind: string;\n\tregionPolicy: string;\n\tscopeElement: HTMLElement | null;\n\titem: unknown;\n\tcontextVersion: number;\n}\n\nexport const assessmentToolkitShellContext =\n\tcreateContext<AssessmentToolkitShellContext>(\n\t\tSymbol.for(\"pie.assessmentToolkit.shellContext\"),\n\t);\n\nexport interface AssessmentToolkitRegionScopeContext {\n\tscopeElement: HTMLElement | null;\n\tttsHighlightTargetResolver?: TTSHighlightTargetResolver | null;\n}\n\nexport const assessmentToolkitRegionScopeContext =\n\tcreateContext<AssessmentToolkitRegionScopeContext>(\n\t\tSymbol.for(\"pie.assessmentToolkit.regionScopeContext\"),\n\t);\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime-context-consumer.js","sourceRoot":"","sources":["../../src/context/runtime-context-consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EACN,mCAAmC,EACnC,mCAAmC,EACnC,6BAA6B,EAC7B,+BAA+B,GAK/B,MAAM,iCAAiC,CAAC;AAmBzC,SAAS,gCAAgC,CACxC,IAAiB,EACjB,OAAU,EACV,OAAiC;IAEjC,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,IAAI,EAAE;QAC1C,OAAO;QACP,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,QAAQ,GAAG,IAAI,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;KACD,CAAC,CAAC;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC;IAEnB,MAAM,iBAAiB,GAAG,CAAC,KAA+B,EAAE,EAAE;QAC7D,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO;YAAE,OAAO;QACtC,QAAQ,CAAC,YAAY,EAAE,CAAC;IACzB,CAAC,CAAC;IACF,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;IAE7D,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,MAAM,WAAW,GAAG,GAAG,CAAC;IACxB,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE;QAC9C,IAAI,QAAQ,IAAI,QAAQ,IAAI,WAAW,EAAE,CAAC;YACzC,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACrC,OAAO;QACR,CAAC;QACD,QAAQ,IAAI,CAAC,CAAC;QACd,QAAQ,CAAC,YAAY,EAAE,CAAC;IACzB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,GAAG,EAAE;QACX,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;QAChE,QAAQ,CAAC,UAAU,EAAE,CAAC;IACvB,CAAC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sCAAsC,CACrD,IAAiB,EACjB,OAA+B;IAE/B,OAAO,gCAAgC,CACtC,IAAI,EACJ,+BAA+B,EAC/B,OAAmC,CACnC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,0CAA0C,CACzD,IAAiB,EACjB,OAAmC;IAEnC,OAAO,gCAAgC,CACtC,IAAI,EACJ,mCAAmC,EACnC,OAAmC,CACnC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oCAAoC,CACnD,IAAiB,EACjB,OAA6B;IAE7B,OAAO,gCAAgC,CACtC,IAAI,EACJ,6BAA6B,EAC7B,OAAmC,CACnC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,0CAA0C,CACzD,IAAiB,EACjB,OAAmC;IAEnC,OAAO,gCAAgC,CACtC,IAAI,EACJ,mCAAmC,EACnC,OAAmC,CACnC,CAAC;AACH,CAAC","sourcesContent":["import { ContextConsumer } from \"@pie-players/pie-context\";\nimport type { UnknownContext } from \"@pie-players/pie-context\";\nimport {\n\tassessmentToolkitHostRuntimeContext,\n\tassessmentToolkitRegionScopeContext,\n\tassessmentToolkitShellContext,\n\tassessmentToolkitRuntimeContext,\n\ttype AssessmentToolkitHostRuntimeContext,\n\ttype AssessmentToolkitRegionScopeContext,\n\ttype AssessmentToolkitShellContext,\n\ttype AssessmentToolkitRuntimeContext,\n} from \"./assessment-toolkit-context.js\";\n\nexport type RuntimeContextListener = (\n\tvalue: AssessmentToolkitRuntimeContext,\n) => void;\nexport type HostRuntimeContextListener = (\n\tvalue: AssessmentToolkitHostRuntimeContext,\n) => void;\nexport type ShellContextListener = (\n\tvalue: AssessmentToolkitShellContext,\n) => void;\nexport type RegionScopeContextListener = (\n\tvalue: AssessmentToolkitRegionScopeContext,\n) => void;\n\ntype ContextProviderLikeEvent = Event & {\n\tcontext?: unknown;\n};\n\nfunction connectConsumerWithProviderRetry<T extends UnknownContext>(\n\thost: HTMLElement,\n\tcontext: T,\n\tonValue: (value: unknown) => void,\n): () => void {\n\tlet hasValue = false;\n\tconst consumer = new ContextConsumer(host, {\n\t\tcontext,\n\t\tsubscribe: true,\n\t\tonValue: (value) => {\n\t\t\thasValue = true;\n\t\t\tonValue(value);\n\t\t},\n\t});\n\tconsumer.connect();\n\n\tconst onContextProvider = (event: ContextProviderLikeEvent) => {\n\t\tif (event.context !== context) return;\n\t\tconsumer.requestValue();\n\t};\n\thost.addEventListener(\"context-provider\", onContextProvider);\n\n\tlet attempts = 0;\n\tconst maxAttempts = 200;\n\tconst retryTimer = globalThis.setInterval(() => {\n\t\tif (hasValue || attempts >= maxAttempts) {\n\t\t\tglobalThis.clearInterval(retryTimer);\n\t\t\treturn;\n\t\t}\n\t\tattempts += 1;\n\t\tconsumer.requestValue();\n\t}, 50);\n\n\treturn () => {\n\t\tglobalThis.clearInterval(retryTimer);\n\t\thost.removeEventListener(\"context-provider\", onContextProvider);\n\t\tconsumer.disconnect();\n\t};\n}\n\n/**\n * Connect a DOM host element to the shared assessment toolkit runtime context.\n * Returns a cleanup function that disconnects the underlying consumer.\n */\nexport function connectAssessmentToolkitRuntimeContext(\n\thost: HTMLElement,\n\tonValue: RuntimeContextListener,\n): () => void {\n\treturn connectConsumerWithProviderRetry(\n\t\thost,\n\t\tassessmentToolkitRuntimeContext,\n\t\tonValue as (value: unknown) => void,\n\t);\n}\n\nexport function connectAssessmentToolkitHostRuntimeContext(\n\thost: HTMLElement,\n\tonValue: HostRuntimeContextListener,\n): () => void {\n\treturn connectConsumerWithProviderRetry(\n\t\thost,\n\t\tassessmentToolkitHostRuntimeContext,\n\t\tonValue as (value: unknown) => void,\n\t);\n}\n\nexport function connectAssessmentToolkitShellContext(\n\thost: HTMLElement,\n\tonValue: ShellContextListener,\n): () => void {\n\treturn connectConsumerWithProviderRetry(\n\t\thost,\n\t\tassessmentToolkitShellContext,\n\t\tonValue as (value: unknown) => void,\n\t);\n}\n\nexport function connectAssessmentToolkitRegionScopeContext(\n\thost: HTMLElement,\n\tonValue: RegionScopeContextListener,\n): () => void {\n\treturn connectConsumerWithProviderRetry(\n\t\thost,\n\t\tassessmentToolkitRegionScopeContext,\n\t\tonValue as (value: unknown) => void,\n\t);\n}\n"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqBH,OAAO,EACN,mCAAmC,EACnC,mCAAmC,EACnC,+BAA+B,EAC/B,6BAA6B,GAC7B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,0CAA0C,EAC1C,0CAA0C,EAC1C,sCAAsC,EACtC,oCAAoC,GACpC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,iCAAiC,EACjC,uCAAuC,EACvC,oCAAoC,EACpC,8BAA8B,EAC9B,kBAAkB,EAClB,oBAAoB,GAOpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,GACrB,MAAM,iCAAiC,CAAC;AAgCzC,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC1F,wDAAwD;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,gEAAgE;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAG5E,OAAO,EACN,cAAc,EACd,oBAAoB,EACpB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAAE,eAAe,EAAE,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kB,EAClB,iBAAiB,EACjB,aAAa,GACb,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,sCAAsC,EACtC,+BAA+B,GAC/B,MAAM,sCAAsC,CAAC;AAK9C,OAAO,EACN,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,GACf,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EACN,6BAA6B,GAE7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAUxE,OAAO,EACN,yBAAyB,EACzB,2BAA2B,EAC3B,sBAAsB,EACtB,+BAA+B,EAC/B,8BAA8B,EAC9B,wBAAwB,EACxB,4BAA4B,EAC5B,2BAA2B,EAC3B,oBAAoB,EACpB,yBAAyB,GACzB,MAAM,kCAAkC,CAAC;AAmB1C,OAAO,EACN,qBAAqB,EACrB,cAAc,EACd,aAAa,GACb,MAAM,kBAAkB,CAAC;AAa1B,OAAO,EACN,mBAAmB,EACnB,kCAAkC,EAClC,2BAA2B,EAC3B,sBAAsB,EACtB,4BAA4B,EAC5B,+BAA+B,EAC/B,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,qCAAqC,EACrC,iBAAiB,GACjB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AAQxC,OAAO,EACN,8BAA8B,EAC9B,+CAA+C,EAC/C,+BAA+B,EAC/B,oBAAoB,GACpB,MAAM,wDAAwD,CAAC;AAEhE,qEAAqE;AAErE,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,4FAA4F;AAC5F,8FAA8F;AAC9F,qGAAqG","sourcesContent":["/**\n * PIE Assessment Toolkit\n *\n * Independent, composable services for coordinating tools, accommodations,\n * and item players in assessment applications.\n *\n * @packageDocumentation\n */\n\n// ============================================================================\n// Core Infrastructure\n// ============================================================================\n\nexport type {\n\tAssessmentToolkitHostRuntimeContext,\n\tAssessmentToolkitRegionScopeContext,\n\tAssessmentToolkitRuntimeContext,\n\tAssessmentToolkitShellContext,\n\tItemPlayerConfig,\n\tItemPlayerType,\n\tShellContextKind,\n} from \"./context/assessment-toolkit-context.js\";\nexport type {\n\tTTSHighlightContext,\n\tTTSHighlightTargetResolver,\n\tTTSHighlightTargetResolverProvider,\n\tTTSHighlightTargetResolverRuntime,\n} from \"./services/tts/highlight-target-resolver.js\";\nexport {\n\tassessmentToolkitHostRuntimeContext,\n\tassessmentToolkitRegionScopeContext,\n\tassessmentToolkitRuntimeContext,\n\tassessmentToolkitShellContext,\n} from \"./context/assessment-toolkit-context.js\";\nexport {\n\tconnectAssessmentToolkitHostRuntimeContext,\n\tconnectAssessmentToolkitRegionScopeContext,\n\tconnectAssessmentToolkitRuntimeContext,\n\tconnectAssessmentToolkitShellContext,\n} from \"./context/runtime-context-consumer.js\";\nexport {\n\tPIE_INTERNAL_CONTENT_LOADED_EVENT,\n\tPIE_INTERNAL_ITEM_SESSION_CHANGED_EVENT,\n\tPIE_INTERNAL_ITEM_PLAYER_ERROR_EVENT,\n\tPIE_ITEM_SESSION_CHANGED_EVENT,\n\tPIE_REGISTER_EVENT,\n\tPIE_UNREGISTER_EVENT,\n\ttype InternalContentLoadedDetail,\n\ttype InternalItemSessionChangedDetail,\n\ttype InternalItemPlayerErrorDetail,\n\ttype ItemSessionChangedDetail,\n\ttype RuntimeRegistrationDetail,\n\ttype RuntimeRegistrationKind,\n} from \"./runtime/registration-events.js\";\nexport {\n\tconnectToolRegionScopeContext,\n\tconnectToolRuntimeContext,\n\tconnectToolShellContext,\n\tcreateCrossBoundaryEvent,\n\tdispatchCrossBoundaryEvent,\n\tisContextValueDefined,\n} from \"./runtime/tool-host-contract.js\";\n\n// ============================================================================\n// Service Interfaces\n// ============================================================================\n\nexport type {\n\tAccessibilityCatalogResolverApi,\n\tElementToolStateStoreApi,\n\tHighlightCoordinatorApi,\n\tI18nServiceApi,\n\tThemeProviderApi,\n\tToolCoordinatorApi,\n\tToolkitCoordinatorApi,\n\tTtsServiceApi,\n\tToolState,\n} from \"./services/interfaces.js\";\n\n// ============================================================================\n// Toolkit Services\n// ============================================================================\n\n// Accessibility Catalog Resolver (QTI 3.0 Accessibility Catalogs)\nexport type {\n\tCatalogLookupContext,\n\tCatalogLookupOptions,\n\tCatalogOwnerContext,\n\tCatalogOwnerKind,\n\tCatalogStatistics,\n\tCatalogType,\n\tResolvedCatalog,\n} from \"./services/AccessibilityCatalogResolver.js\";\nexport { AccessibilityCatalogResolver } from \"./services/AccessibilityCatalogResolver.js\";\n// Context Variable Store (QTI 3.0 Context Declarations)\nexport { ContextVariableStore } from \"./services/ContextVariableStore.js\";\n// Element Tool State Store (Element-level ephemeral tool state)\nexport { ElementToolStateStore } from \"./services/ElementToolStateStore.js\";\n// Highlight Coordinator\nexport type { Annotation } from \"./services/HighlightCoordinator.js\";\nexport {\n\tHighlightColor,\n\tHighlightCoordinator,\n\tHighlightType,\n} from \"./services/HighlightCoordinator.js\";\n// Range Serializer (for annotation persistence)\nexport type { SerializedRange } from \"./services/RangeSerializer.js\";\nexport { RangeSerializer } from \"./services/RangeSerializer.js\";\n// I18n Service\nexport type {\n\tI18nConfig,\n\tPluralTranslation,\n\tTranslationBundle,\n} from \"./services/I18nService.js\";\nexport { I18nService } from \"./services/I18nService.js\";\n// Tool Registry (Registry-based tool system)\nexport type {\n\tResolvedToolContext,\n\tToolbarContext,\n\tToolContextResolver,\n\tToolContextResolverContext,\n\tToolContextResolverMap,\n\tToolContextResolverResult,\n\tToolModuleLoader,\n\tToolToolbarButtonDefinition,\n\tToolToolbarRenderResult,\n\tToolWindowShellAction,\n\tToolWindowShellAlign,\n\tToolWindowShellConfig,\n\tToolWindowShellContentConfig,\n\tToolRegistration,\n} from \"./services/ToolRegistry.js\";\nexport { ToolRegistry } from \"./services/ToolRegistry.js\";\nexport type {\n\tAssessmentToolContext,\n\tBaseToolContext,\n\tElementToolContext,\n\tItemToolContext,\n\tPassageToolContext,\n\tRubricToolContext,\n\tSectionToolContext,\n\tToolContext,\n\tToolLevel,\n} from \"./services/tool-context.js\";\nexport {\n\textractTextContent,\n\thasChoiceInteraction,\n\thasMathContent,\n\thasReadableText,\n\tisAssessmentContext,\n\tisElementContext,\n\tisItemContext,\n\tisPassageContext,\n\tisRubricContext,\n\tisSectionContext,\n} from \"./services/tool-context.js\";\nexport {\n\tDEFAULT_TOOL_PLACEMENT,\n\tDEFAULT_TOOL_ORDER,\n\tcreatePackagedToolRegistry,\n\tPACKAGED_TOOL_PLACEMENT,\n\tregisterPackagedTools,\n\tSECTION_PLAYER_PREFERRED_TOOL_PLACEMENT,\n} from \"./services/createDefaultToolRegistry.js\";\nexport type { CreateToolsConfigArgs } from \"./services/create-tools-config.js\";\nexport { createToolsConfig } from \"./services/create-tools-config.js\";\nexport {\n\tDEFAULT_PERSONAL_NEEDS_PROFILE,\n\tcreateDefaultPersonalNeedsProfile,\n} from \"./services/defaultPersonalNeedsProfile.js\";\nexport type {\n\tToolComponentFactory,\n\tToolComponentFactoryMap,\n\tToolComponentOverrides,\n\tToolTagMap,\n} from \"./tools/tool-tag-map.js\";\nexport {\n\tcreateToolElement,\n\tDEFAULT_TOOL_TAG_MAP,\n\tresolveToolTag,\n\ttoToolIdFromTag,\n} from \"./tools/tool-tag-map.js\";\n// QTI 3.0 Standard Access Features\nexport {\n\tALL_STANDARD_ACCESS_FEATURES,\n\tEXAMPLE_PNP_CONFIGURATIONS,\n\tgetFeatureCategory,\n\tgetFeaturesInCategory,\n\tisStandardAccessFeature,\n\tQTI_STANDARD_ACCESS_FEATURES,\n} from \"./services/pnp-standard-features.js\";\n// SSML Extractor (Auto-generates catalogs from embedded SSML)\nexport type { ExtractionResult } from \"./services/SSMLExtractor.js\";\nexport { SSMLExtractor } from \"./services/SSMLExtractor.js\";\n// Theme Provider\nexport type { FontSize, ThemeConfig } from \"./services/ThemeProvider.js\";\nexport { ThemeProvider } from \"./services/ThemeProvider.js\";\n// Tool Coordinator\nexport { ToolCoordinator, ZIndexLayer } from \"./services/ToolCoordinator.js\";\n// Toolkit Coordinator (Centralized service management)\nexport type {\n\tAnswerEliminatorToolConfig,\n\tProviderLifecycleContext,\n\tSectionControllerContext,\n\tSectionControllerEvent,\n\tSectionControllerEventType,\n\tSectionItemEvent,\n\tSectionItemEventType,\n\tSectionControllerFactoryDefaults,\n\tSectionControllerHandle,\n\tSectionControllerKey,\n\tSectionScopedEvent,\n\tSectionScopedEventType,\n\tSectionSessionPersistenceConfig,\n\tSectionItemEventSubscriptionArgs,\n\tSectionScopedEventSubscriptionArgs,\n\tSectionEventSubscriptionArgs,\n\tSectionSessionPersistenceStrategy,\n\tSectionControllerLoadedRenderable,\n\tSectionControllerRuntimeState,\n\tSectionControllerSessionState,\n\tSectionPersistenceFactoryDefaults,\n\tToolConfig,\n\tToolkitCoordinatorConfig,\n\tToolkitCoordinatorHooks,\n\tToolkitErrorContext,\n\tToolkitInitStatus,\n\tToolkitServiceBundle,\n\tToolkitToolsConfig,\n\tTTSToolConfig,\n} from \"./services/ToolkitCoordinator.js\";\nexport { ToolkitCoordinator } from \"./services/ToolkitCoordinator.js\";\nexport type {\n\tCanonicalToolsConfig,\n\tToolPlacementConfig,\n\tToolPlacementLevel,\n\tToolPolicyConfig,\n\tToolProvidersConfig,\n} from \"./services/tools-config-normalizer.js\";\nexport type {\n\tFrameworkErrorKind,\n\tFrameworkErrorModel,\n\tFrameworkErrorSeverity,\n} from \"./services/framework-error.js\";\nexport {\n\tformatFrameworkErrorForConsole,\n\tframeworkErrorFromToolConfigDiagnostics,\n\tframeworkErrorFromUnknown,\n\ttoFrameworkErrorModel,\n} from \"./services/framework-error.js\";\nexport type { FrameworkErrorListener } from \"./services/framework-error-bus.js\";\nexport type {\n\tToolConfigDiagnostic,\n\tToolConfigDiagnosticSeverity,\n\tToolConfigStrictness,\n\tToolConfigValidationOptions,\n\tToolConfigValidationResult,\n} from \"./services/tool-config-validation.js\";\nexport type {\n\tToolbarButtonItem,\n\tToolbarItem,\n\tToolbarItemBase,\n\tToolbarLinkItem,\n} from \"./services/toolbar-items.js\";\nexport {\n\tisExternalIconUrl,\n\tisInlineSvgIcon,\n\tisToolbarLinkItem,\n\tisValidToolbarItemShape,\n} from \"./services/toolbar-items.js\";\nexport {\n\tnormalizeToolsConfig,\n\tnormalizeToolAlias,\n\tnormalizeToolList,\n\tparseToolList,\n} from \"./services/tools-config-normalizer.js\";\nexport {\n\tframeworkErrorFromToolConfigValidation,\n\tnormalizeAndValidateToolsConfig,\n} from \"./services/tool-config-validation.js\";\nexport type {\n\tParsedToolInstanceId,\n\tToolScopeLevel,\n} from \"./services/tool-instance-id.js\";\nexport {\n\tcreateScopedToolId,\n\tparseScopedToolId,\n\ttoOverlayToolId,\n} from \"./services/tool-instance-id.js\";\n// Text-to-Speech Service\nexport type { TTSConfig } from \"./services/TTSService.js\";\nexport { PlaybackState, TTSService } from \"./services/TTSService.js\";\nexport {\n\tPIE_TTS_CONTROL_HANDOFF_EVENT,\n\ttype TTSControlHandoffDetail,\n} from \"./services/tts-control-events.js\";\nexport { BrowserTTSProvider } from \"./services/tts/browser-provider.js\";\nexport type { SREMathSpeechOptions } from \"./services/tts/math-speech.js\";\nexport type {\n\tNormalizedTTSSpeedOption,\n\tTTSHostToolbarLayout,\n\tTTSLayoutMode,\n\tTTSRuntimeSettings,\n\tTTSSpeedOption,\n\tTTSSpeedOptionConfig,\n} from \"./services/tts-runtime-config.js\";\nexport {\n\tDEFAULT_TTS_SPEED_OPTIONS,\n\tformatTTSSpeedOptionsAsText,\n\tnormalizeTTSLayoutMode,\n\tnormalizeTTSSpeedControlOptions,\n\tnormalizeTTSSpeedOptionConfigs,\n\tnormalizeTTSSpeedOptions,\n\tparseTTSSpeedOptionsFromText,\n\tresolveTTSHostToolbarLayout,\n\tresolveTTSLayoutMode,\n\tresolveTTSRuntimeSettings,\n} from \"./services/tts-runtime-config.js\";\n// TTS Provider System\nexport type {\n\tITTSProvider,\n\tITTSProviderImplementation,\n\tTTSSpeechSegment,\n\tTTSFeature,\n\tTTSProviderCapabilities,\n} from \"@pie-players/pie-tts\";\n\n// ============================================================================\n// Item loading (client-resolvable default; optional backend hook)\n// ============================================================================\n\nexport type {\n\tCreateLoadItemOptions,\n\tLoadItem,\n\tLoadItemOptions,\n} from \"./item-loader.js\";\nexport {\n\tcreateFetchItemLoader,\n\tcreateLoadItem,\n\tItemLoadError,\n} from \"./item-loader.js\";\n\n// ============================================================================\n// Attempt Session\n// ============================================================================\n\nexport type {\n\tStorageLike,\n\tTestAttemptItemSession,\n\tTestAttemptSession,\n\tTestAttemptSessionNavigationState,\n\tTestAttemptSessionRealization,\n} from \"./attempt/TestSession.js\";\nexport {\n\tcreateMemoryStorage,\n\tcreateTestAttemptSessionIdentifier,\n\tcreateNewTestAttemptSession,\n\tgetBrowserLocalStorage,\n\tgetOrCreateAnonymousDeviceId,\n\tgetTestAttemptSessionStorageKey,\n\tloadTestAttemptSession,\n\tsaveTestAttemptSession,\n\tsetCurrentPosition,\n\tupsertItemSessionFromPieSessionChange,\n\tupsertVisitedItem,\n} from \"./attempt/TestSession.js\";\nexport type {\n\tAssessmentSession,\n\tAssessmentSectionSessionState,\n\tAssessmentSessionNavigationState,\n\tAssessmentSessionRealization,\n} from \"./attempt/AssessmentSession.js\";\nexport {\n\tcreateNewAssessmentSession,\n\tgetAssessmentSessionStorageKey,\n\tloadAssessmentSession,\n\tsaveAssessmentSession,\n\tsetCurrentSectionPosition,\n\tupsertSectionSession,\n} from \"./attempt/AssessmentSession.js\";\nexport type {\n\tActivitySessionPatchPayload,\n\tMapActivityToTestAttemptSessionArgs,\n\tPieBackendActivityDefinition,\n\tPieBackendActivityItemRef,\n\tPieBackendActivitySession,\n} from \"./attempt/adapters/activity-to-test-attempt-session.js\";\nexport {\n\tbuildActivitySessionItemUpdate,\n\tbuildActivitySessionPatchFromTestAttemptSession,\n\tmapActivityToTestAttemptSession,\n\ttoItemSessionsRecord,\n} from \"./attempt/adapters/activity-to-test-attempt-session.js\";\n\n// Section Player - Use @pie-players/pie-section-player web component\n\n// ============================================================================\n// Shared Components\n// ============================================================================\n\n// ItemToolBar custom element registration helper is exported via package.json exports field\n// Import using: import '@pie-players/pie-assessment-toolkit/components/item-toolbar-element';\n// PieAssessmentToolkit custom element registration helper is exported via package.json exports field\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"item-loader.js","sourceRoot":"","sources":["../src/item-loader.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC9B,IAAI,CAIK;IAElB,YAAY,IAA2B,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AA8BD,SAAS,mBAAmB,CAAC,OAAe,EAAE,IAAsB;IACnE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,aAAa,OAAO,EAAE,EAAE,6BAA6B,CAAC,CAAC;IAC3E,IAAI,IAAI,EAAE,cAAc;QACvB,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IAC7D,OAAO,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAIrC;IACA,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC;IACrD,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,MAAM,IAAI,aAAa,CACtB,qBAAqB,EACrB,uDAAuD,CACvD,CAAC;IACH,CAAC;IAED,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;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AClC,IAAI,QAAQ,EAAE,CAAC,OAAO,CAAC;YAAE,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC;QAElD,IAAI,WAAW;YAAE,OAAO,MAAM,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAE7D,IAAI,YAAY,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;YACrD,MAAM,IAAI,aAAa,CACtB,qBAAqB,EACrB,iEAAiE,CACjE,CAAC;QACH,CAAC;QAED,MAAM,IAAI,aAAa,CACtB,8BAA8B,EAC9B,mEAAmE,CACnE,CAAC;IACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { ItemEntity } from \"@pie-players/pie-players-shared\";\n\nexport type LoadItemOptions = {\n\torganizationId?: string | null;\n};\n\nexport type LoadItem = (\n\titemVId: string,\n\topts?: LoadItemOptions,\n) => Promise<ItemEntity>;\n\nexport class ItemLoadError extends Error {\n\treadonly code:\n\t\t| \"ITEM_NOT_FOUND\"\n\t\t| \"NO_ITEM_BANK_OR_FETCH_CONFIG\"\n\t\t| \"FETCH_NOT_AVAILABLE\"\n\t\t| \"FETCH_FAILED\";\n\n\tconstructor(code: ItemLoadError[\"code\"], message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ItemLoadError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport type CreateLoadItemOptions = {\n\t/**\n\t * Optional in-memory item bank. Keys are itemVId.\n\t * This enables a no-backend default for demos/tests.\n\t */\n\titemBank?: Record<string, ItemEntity>;\n\n\t/**\n\t * Optional base URL for an item API. If set, `createLoadItem` will fetch when\n\t * an item is not present in `itemBank`.\n\t *\n\t * Example: `https://host.example.com`\n\t */\n\tfetchBaseUrl?: string;\n\n\t/**\n\t * Optional endpoint builder.\n\t * Defaults to `/api/item/:itemVId` (and appends `?organizationId=...` if provided).\n\t */\n\titemEndpoint?: string | ((itemVId: string, opts?: LoadItemOptions) => string);\n\n\t/**\n\t * Custom fetch implementation (useful for tests or hosts).\n\t * Defaults to `globalThis.fetch`.\n\t */\n\tfetchImpl?: typeof fetch;\n};\n\nfunction defaultItemEndpoint(itemVId: string, opts?: LoadItemOptions) {\n\tconst url = new URL(`/api/item/${itemVId}`, \"https://placeholder.invalid\");\n\tif (opts?.organizationId)\n\t\turl.searchParams.set(\"organizationId\", opts.organizationId);\n\treturn url.pathname + url.search;\n}\n\nexport function createFetchItemLoader(opts: {\n\tbaseUrl: string;\n\titemEndpoint?: CreateLoadItemOptions[\"itemEndpoint\"];\n\tfetchImpl?: typeof fetch;\n}): LoadItem {\n\tconst fetchImpl = opts.fetchImpl ?? globalThis.fetch;\n\tif (!fetchImpl) {\n\t\tthrow new ItemLoadError(\n\t\t\t\"FETCH_NOT_AVAILABLE\",\n\t\t\t\"globalThis.fetch is not available in this environment\",\n\t\t);\n\t}\n\n\treturn async (itemVId, loadOpts) => {\n\t\tconst endpointBuilder =\n\t\t\ttypeof opts.itemEndpoint === \"function\"\n\t\t\t\t? opts.itemEndpoint\n\t\t\t\t: typeof opts.itemEndpoint === \"string\"\n\t\t\t\t\t? () => opts.itemEndpoint as string\n\t\t\t\t\t: defaultItemEndpoint;\n\n\t\tconst endpoint = endpointBuilder(itemVId, loadOpts);\n\t\tconst url = new URL(endpoint, opts.baseUrl);\n\n\t\tconst res = await fetchImpl(url.toString());\n\t\tif (!res.ok) {\n\t\t\tthrow new ItemLoadError(\n\t\t\t\t\"FETCH_FAILED\",\n\t\t\t\t`Failed to load item ${itemVId}: ${res.status} ${res.statusText}`,\n\t\t\t);\n\t\t}\n\t\treturn (await res.json()) as ItemEntity;\n\t};\n}\n\n/**\n * Client-resolvable default loader:\n * - resolve from `itemBank` first (no backend required)\n * - optionally fallback to fetch (encouraged backend hook)\n */\nexport function createLoadItem(opts: CreateLoadItemOptions): LoadItem {\n\tconst itemBank = opts.itemBank;\n\tconst fetchBaseUrl = opts.fetchBaseUrl;\n\n\tconst fetchImpl =\n\t\topts.fetchImpl ?? (globalThis.fetch as typeof fetch | undefined);\n\tconst fetchLoader =\n\t\tfetchBaseUrl && typeof fetchImpl === \"function\"\n\t\t\t? createFetchItemLoader({\n\t\t\t\t\tbaseUrl: fetchBaseUrl,\n\t\t\t\t\titemEndpoint: opts.itemEndpoint,\n\t\t\t\t\tfetchImpl,\n\t\t\t\t})\n\t\t\t: null;\n\n\treturn async (itemVId, loadOpts) => {\n\t\tif (itemBank?.[itemVId]) return itemBank[itemVId];\n\n\t\tif (fetchLoader) return await fetchLoader(itemVId, loadOpts);\n\n\t\tif (fetchBaseUrl && typeof fetchImpl !== \"function\") {\n\t\t\tthrow new ItemLoadError(\n\t\t\t\t\"FETCH_NOT_AVAILABLE\",\n\t\t\t\t\"fetchBaseUrl was provided but globalThis.fetch is not available\",\n\t\t\t);\n\t\t}\n\n\t\tthrow new ItemLoadError(\n\t\t\t\"NO_ITEM_BANK_OR_FETCH_CONFIG\",\n\t\t\t\"No itemBank entry and no fetchBaseUrl configured for item loading\",\n\t\t);\n\t};\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PolicySource.js","sourceRoot":"","sources":["../../../src/policy/core/PolicySource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/**\n * Custom `PolicySource` extension point (M8 — see\n * `.cursor/plans/m8-design.md` § 5).\n *\n * Custom sources run in step 6 of the composition pipeline — *after*\n * placement membership, provider veto, host policy, and PNP/profile gates.\n * That ordering is deliberate: custom rules can only further *narrow*\n * the candidate set or add advisory provenance entries; they cannot\n * promote a tool that the host already removed.\n *\n * Sources MUST be pure with respect to `decide(...)`: given the same\n * `(candidates, context)` input they should produce the same\n * `(refinedCandidates, decisions)` output. Side-effects are reserved\n * for the engine's own subscription bus (`onPolicyChange`).\n */\n\nimport type { ToolPolicyDecisionRequest } from \"./decision-types.js\";\nimport type {\n\tToolPolicyDecisionRule,\n\tToolPolicyResolutionDecision,\n\tToolPolicySourceType,\n} from \"./provenance.js\";\n\nexport interface PolicySourceDecisionContext {\n\trequest: ToolPolicyDecisionRequest;\n\t/**\n\t * Snapshot of the candidate set as it enters this source. Sources\n\t * SHOULD treat this as read-only and return a fresh array via\n\t * `result.refinedCandidates`. Mutating `candidates` in place is\n\t * not supported and will be flagged in tests.\n\t */\n\tcandidates: readonly string[];\n}\n\nexport interface PolicySourceProvenanceEntry {\n\trule: ToolPolicyDecisionRule;\n\tfeatureId: string;\n\taction: ToolPolicyResolutionDecision[\"action\"];\n\tsourceType: ToolPolicySourceType;\n\treason: string;\n\tvalue?: unknown;\n\t/**\n\t * Custom precedence value used for the decision log. Defaults to\n\t * `100 + sourceIndex` (engine-assigned) when `undefined`. Sources\n\t * MAY override only if they know what they are doing — overriding\n\t * to a value `<= 6` lets the source masquerade as a PNP/profile rule and\n\t * is generally a bug.\n\t */\n\tprecedence?: number;\n}\n\nexport interface PolicySourceResult {\n\t/**\n\t * Refined candidate set. MUST be a subset of `context.candidates`.\n\t * Returning a superset is unsupported and will be normalized away\n\t * by the engine (with an `tool-policy.placementMissing` diagnostic\n\t * for any added IDs).\n\t */\n\trefinedCandidates: string[];\n\t/**\n\t * Provenance entries to append to the decision log. Each entry is\n\t * recorded under `featureId` whether or not it survives — sources\n\t * MAY emit advisory entries for blocked tools to document why.\n\t */\n\tdecisions?: PolicySourceProvenanceEntry[];\n}\n\nexport interface PolicySource {\n\t/** Stable identifier — used for `custom.${id}` source tags. */\n\treadonly id: string;\n\n\trefine(context: PolicySourceDecisionContext): PolicySourceResult;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ToolPolicyEngine.js","sourceRoot":"","sources":["../../../src/policy/core/ToolPolicyEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAQjF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,eAAe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AClB,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE;SAC7B,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,CAAC;IAEO,cAAc;QACrB,OAAO,MAAM,CAAC,MAAM,CAAC;YACpB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,cAAc,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,KAA4B;QACxC,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC;gBACJ,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACR,0DAA0D;gBAC1D,mDAAmD;YACpD,CAAC;QACF,CAAC;IACF,CAAC;IAEO,iBAAiB;QACxB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC;CACD","sourcesContent":["/**\n * Tool Policy Engine — facade class (M8 — see\n * `.cursor/plans/m8-design.md` § 2).\n *\n * Wraps `composeDecision(...)` with engine-instance state:\n * - bound inputs (`tools`, `assessment`, `currentItemRef`, ...)\n * - registered custom `PolicySource`s\n * - `onPolicyChange` subscriber bus\n * - `dispose()` clean-up\n *\n * The class has no DOM dependency and no Svelte runes. It is safe to\n * instantiate inside a worker, in a Node test, or inside a CE\n * connectedCallback. The Svelte context glue (`TOOL_POLICY_ENGINE_KEY`)\n * lives in `engine-context.ts`.\n *\n * PR 1 ships the engine *without callers*. PR 2 wires it into\n * `ToolkitCoordinator`. PR 3 switches `<pie-item-toolbar>` over.\n */\n\nimport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\n\nimport type {\n\tCanonicalToolsConfig,\n\tToolPlacementLevel,\n} from \"../../services/tools-config-normalizer.js\";\nimport { normalizeToolsConfig } from \"../../services/tools-config-normalizer.js\";\nimport type { ToolRegistry } from \"../../services/ToolRegistry.js\";\n\nimport type {\n\tToolPolicyDecision,\n\tToolPolicyDecisionRequest,\n} from \"./decision-types.js\";\nimport type { PolicySource } from \"./PolicySource.js\";\nimport { composeDecision } from \"./compose-decision.js\";\nimport { resolveDefaultPnpEnforcement } from \"./pnp-policy-inputs.js\";\nimport { PnpPolicySource } from \"../sources/PnpPolicySource.js\";\n\nexport type PnpEnforcementMode = \"on\" | \"off\";\n\nexport interface ToolPolicyEngineInputs {\n\ttools?: CanonicalToolsConfig | null;\n\tassessment?: AssessmentEntity | null;\n\tcurrentItemRef?: AssessmentItemRef | null;\n\t/**\n\t * Explicit PNP/profile override. When omitted (or `undefined`), the engine\n\t * defaults to {@link resolveDefaultPnpEnforcement} over the bound\n\t * `assessment` and `currentItemRef`: `\"on\"` if they carry any\n\t * PNP/profile policy material (PNP, district policy, test\n\t * administration, item-level required/restricted/parameters),\n\t * `\"off\"` otherwise. See `.cursor/plans/m8-design.md` F2.\n\t *\n\t * Hosts that want to force a mode pass `\"on\"` or `\"off\"`\n\t * explicitly. Embedded under `<pie-section-player-*>` the preferred\n\t * override flows through `runtime.tools.pnpEnforcement`.\n\t */\n\tpnpEnforcement?: PnpEnforcementMode;\n}\n\nexport interface ToolPolicyEngineArgs {\n\ttoolRegistry: ToolRegistry;\n\tinputs?: ToolPolicyEngineInputs;\n\tcustomSources?: readonly PolicySource[];\n\t/** Stable context label used in provenance trails. Defaults to \"tool-policy\". */\n\tcontextId?: string;\n}\n\nexport interface ToolPolicyChangeEvent {\n\t/** What changed in this update. */\n\treason:\n\t\t| \"inputs\"\n\t\t| \"policy-source-added\"\n\t\t| \"policy-source-removed\"\n\t\t| \"pnp-enforcement\"\n\t\t| \"disposed\";\n\t/** Snapshot of the engine's inputs after the change. */\n\tinputs: Readonly<ResolvedEngineInputs>;\n}\n\nexport interface ResolvedEngineInputs {\n\ttools: CanonicalToolsConfig;\n\tassessment: AssessmentEntity | null;\n\tcurrentItemRef: AssessmentItemRef | null;\n\tpnpEnforcement: PnpEnforcementMode;\n}\n\nexport type ToolPolicyChangeListener = (event: ToolPolicyChangeEvent) => void;\n\nconst DEFAULT_TOOLS: CanonicalToolsConfig = normalizeToolsConfig({\n\tpolicy: { allowed: [], blocked: [] },\n\tplacement: { section: [], item: [], passage: [] },\n\tproviders: {},\n});\n\nexport class ToolPolicyEngine {\n\tprivate readonly toolRegistry: ToolRegistry;\n\tprivate readonly contextId: string;\n\tprivate readonly pnpPolicySource: PnpPolicySource;\n\tprivate readonly customSources: PolicySource[];\n\tprivate readonly listeners = new Set<ToolPolicyChangeListener>();\n\n\tprivate tools: CanonicalToolsConfig;\n\tprivate assessment: AssessmentEntity | null;\n\tprivate currentItemRef: AssessmentItemRef | null;\n\tprivate pnpEnforcement: PnpEnforcementMode;\n\tprivate disposed = false;\n\n\tconstructor(args: ToolPolicyEngineArgs) {\n\t\tthis.toolRegistry = args.toolRegistry;\n\t\tthis.contextId = args.contextId ?? \"tool-policy\";\n\t\tthis.pnpPolicySource = new PnpPolicySource(this.toolRegistry);\n\t\tthis.customSources = args.customSources ? [...args.customSources] : [];\n\n\t\tconst inputs = args.inputs ?? {};\n\t\tthis.tools = inputs.tools ?? DEFAULT_TOOLS;\n\t\tthis.assessment = inputs.assessment ?? null;\n\t\tthis.currentItemRef = inputs.currentItemRef ?? null;\n\t\tthis.pnpEnforcement =\n\t\t\tinputs.pnpEnforcement ??\n\t\t\tresolveDefaultPnpEnforcement({\n\t\t\t\tassessment: this.assessment,\n\t\t\t\tcurrentItemRef: this.currentItemRef,\n\t\t\t});\n\t}\n\n\t/**\n\t * Resolve the visible tool set for a given placement level and\n\t * scope.\n\t *\n\t * `visibleTools` and `diagnostics` are deterministic with respect\n\t * to the engine's currently-bound inputs — calling `decide(...)`\n\t * twice with identical inputs returns structurally equal\n\t * `visibleTools` and `diagnostics`. The returned `provenance`\n\t * carries call-time `evaluatedAt` timestamps generated by\n\t * `ToolPolicyProvenanceBuilder` (one per `decide(...)`); two\n\t * back-to-back calls therefore produce different `evaluatedAt`\n\t * values even though the policy decision itself is identical.\n\t * Hosts that want timestamp-stable provenance should reuse a\n\t * cached `ToolPolicyDecision` rather than re-call `decide(...)`.\n\t */\n\tdecide(request: ToolPolicyDecisionRequest): ToolPolicyDecision {\n\t\tthis.assertNotDisposed();\n\t\tconst requestContextId = request.scope.scopeId\n\t\t\t? `${this.contextId}:${request.level}:${request.scope.scopeId}`\n\t\t\t: `${this.contextId}:${request.level}`;\n\t\treturn composeDecision({\n\t\t\trequest,\n\t\t\ttools: this.tools,\n\t\t\tpnpPolicy: {\n\t\t\t\tsource: this.pnpPolicySource,\n\t\t\t\tassessment: this.assessment ?? undefined,\n\t\t\t\tcurrentItemRef: this.currentItemRef ?? undefined,\n\t\t\t\tenforcement: this.pnpEnforcement,\n\t\t\t},\n\t\t\tcustomSources: this.customSources,\n\t\t\tcontextId: requestContextId,\n\t\t});\n\t}\n\n\t/**\n\t * Convenience wrapper for hosts that just want the visible tool\n\t * IDs. Equivalent to `decide(...).visibleTools.map(e => e.toolId)`.\n\t */\n\tgetVisibleToolIds(level: ToolPlacementLevel, scopeId: string): string[] {\n\t\treturn this.decide({\n\t\t\tlevel,\n\t\t\tscope: { level, scopeId },\n\t\t}).visibleTools.map((entry) => entry.toolId);\n\t}\n\n\t/**\n\t * Apply a partial input update.\n\t *\n\t * Each key is value-diffed via `Object.is` before storing, so callers\n\t * may safely re-push the same reference (e.g. on Svelte effect\n\t * re-runs caused by unrelated tracked reads): no-op patches do not\n\t * fire `onPolicyChange` listeners. This contract is relied on by\n\t * `PieAssessmentToolkit.svelte`'s prop-forwarding effect and by the\n\t * coordinator's `decideToolPolicy()` tests.\n\t *\n\t * `pnpEnforcement` is stored on its own field and always emits with\n\t * a distinct `\"pnp-enforcement\"` reason when no other key changed,\n\t * so PR 4's auto-on flip can target that reason without a separate\n\t * event channel.\n\t */\n\tupdateInputs(patch: Partial<ToolPolicyEngineInputs>): void {\n\t\tthis.assertNotDisposed();\n\t\tlet changed = false;\n\t\tlet pnpChanged = false;\n\t\tif (\"tools\" in patch) {\n\t\t\tconst next = patch.tools ?? DEFAULT_TOOLS;\n\t\t\tif (!Object.is(this.tools, next)) {\n\t\t\t\tthis.tools = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"assessment\" in patch) {\n\t\t\tconst next = patch.assessment ?? null;\n\t\t\tif (!Object.is(this.assessment, next)) {\n\t\t\t\tthis.assessment = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"currentItemRef\" in patch) {\n\t\t\tconst next = patch.currentItemRef ?? null;\n\t\t\tif (!Object.is(this.currentItemRef, next)) {\n\t\t\t\tthis.currentItemRef = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"pnpEnforcement\" in patch && patch.pnpEnforcement) {\n\t\t\tif (this.pnpEnforcement !== patch.pnpEnforcement) {\n\t\t\t\tthis.pnpEnforcement = patch.pnpEnforcement;\n\t\t\t\tpnpChanged = true;\n\t\t\t}\n\t\t}\n\t\tif (changed || pnpChanged) {\n\t\t\tthis.emit({\n\t\t\t\treason: pnpChanged && !changed ? \"pnp-enforcement\" : \"inputs\",\n\t\t\t\tinputs: this.snapshotInputs(),\n\t\t\t});\n\t\t}\n\t}\n\n\tregisterPolicySource(source: PolicySource): () => void {\n\t\tthis.assertNotDisposed();\n\t\tthis.customSources.push(source);\n\t\tthis.emit({\n\t\t\treason: \"policy-source-added\",\n\t\t\tinputs: this.snapshotInputs(),\n\t\t});\n\t\treturn () => {\n\t\t\tconst idx = this.customSources.indexOf(source);\n\t\t\tif (idx !== -1) {\n\t\t\t\tthis.customSources.splice(idx, 1);\n\t\t\t\tif (!this.disposed) {\n\t\t\t\t\tthis.emit({\n\t\t\t\t\t\treason: \"policy-source-removed\",\n\t\t\t\t\t\tinputs: this.snapshotInputs(),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tonPolicyChange(listener: ToolPolicyChangeListener): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\tgetInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn this.snapshotInputs();\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.emit({\n\t\t\treason: \"disposed\",\n\t\t\tinputs: this.snapshotInputs(),\n\t\t});\n\t\tthis.listeners.clear();\n\t\tthis.customSources.length = 0;\n\t}\n\n\tprivate snapshotInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn Object.freeze({\n\t\t\ttools: this.tools,\n\t\t\tassessment: this.assessment,\n\t\t\tcurrentItemRef: this.currentItemRef,\n\t\t\tpnpEnforcement: this.pnpEnforcement,\n\t\t});\n\t}\n\n\tprivate emit(event: ToolPolicyChangeEvent): void {\n\t\tfor (const listener of Array.from(this.listeners)) {\n\t\t\ttry {\n\t\t\t\tlistener(event);\n\t\t\t} catch {\n\t\t\t\t// Subscriber errors must not break the engine. Hosts that\n\t\t\t\t// want error telemetry should wrap their listener.\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new Error(\"ToolPolicyEngine has been disposed.\");\n\t\t}\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"compose-decision.js","sourceRoot":"","sources":["../../../src/policy/core/compose-decision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,EAEN,iBAAiB,GACjB,MAAM,2CAA2C,CAAC;AAWnD,OAAO,EAAE,2BAA2B,EAAE,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AO,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAE3C,OAAO;QACN,YAAY;QACZ,WAAW;QACX,UAAU,EAAE,OAAO,CAAC,KAAK,EAAE;KAC3B,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,qBAAqB,CAC7B,MAAc,EACd,IAKC;IAED,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IACrE,CAAC;IACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,KAAK,EAAE,CAAC;QACjD,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC5D,CAAC;IACD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/D,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IAChE,CAAC;IACD,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO;YACN,QAAQ,EAAE,cAAc;YACxB,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;SACnC,CAAC;IACH,CAAC;IACD,mEAAmE;IACnE,mEAAmE;IACnE,8DAA8D;IAC9D,kEAAkE;IAClE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Compose-decision pipeline (M8 — see `.cursor/plans/m8-design.md` § 3).\n *\n * Pure function: given a decision request, the host's tools config,\n * an optional PNP policy source, and the registered custom sources, returns\n * a `ToolPolicyDecision`. The function performs no I/O, holds no\n * mutable state, and never reaches into Svelte / DOM — that is the\n * `ToolPolicyEngine` class's job.\n *\n * The six steps below mirror the design doc exactly. The tests in\n * `tests/policy/compose-decision.test.ts` lock the orchestration in.\n */\n\nimport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\n\nimport {\n\ttype CanonicalToolsConfig,\n\tnormalizeToolList,\n} from \"../../services/tools-config-normalizer.js\";\nimport type {\n\tRequiredToolBlockedDetails,\n\tToolPolicyDecision,\n\tToolPolicyDecisionRequest,\n\tToolPolicyDiagnostic,\n\tToolPolicyEntry,\n\tToolPolicyHostGate,\n} from \"./decision-types.js\";\nimport type { PolicySource } from \"./PolicySource.js\";\nimport type { PolicySourceTag } from \"./policy-source-tag.js\";\nimport { ToolPolicyProvenanceBuilder } from \"./provenance.js\";\nimport type { PnpPolicySource } from \"../sources/PnpPolicySource.js\";\n\nexport interface ComposeDecisionInputs {\n\trequest: ToolPolicyDecisionRequest;\n\ttools: CanonicalToolsConfig;\n\tpnpPolicy: {\n\t\tsource: PnpPolicySource | null;\n\t\tassessment?: AssessmentEntity;\n\t\tcurrentItemRef?: AssessmentItemRef;\n\t\t/**\n\t\t * \"on\" applies the PNP/profile precedence rules; \"off\" skips step 5\n\t\t * entirely. Defaults to \"on\" when an assessment is present\n\t\t * and the source is non-null (see M8 design Q5).\n\t\t */\n\t\tenforcement: \"on\" | \"off\";\n\t};\n\tcustomSources: readonly PolicySource[];\n\t/** Stable identifier used as the provenance `contextId`. */\n\tcontextId: string;\n}\n\nexport function composeDecision(\n\tinputs: ComposeDecisionInputs,\n): ToolPolicyDecision {\n\tconst { request, tools, pnpPolicy, customSources, contextId } = inputs;\n\tconst builder = new ToolPolicyProvenanceBuilder(contextId);\n\n\tbuilder.addSource(\"host\", {\n\t\tid: request.scope.scopeId,\n\t\tname: `${request.level}:${request.scope.scopeId}`,\n\t\tconfig: {\n\t\t\tplacement: tools.placement,\n\t\t\tpolicy: tools.policy,\n\t\t},\n\t});\n\n\tconst placement = normalizeToolList(tools.placement[request.level]);\n\tconst allowed = normalizeToolList(tools.policy.allowed);\n\tconst blocked = new Set(normalizeToolList(tools.policy.blocked));\n\n\t// Step 1 — Membership filter.\n\t//\n\t// Logged with `action: \"skip\"` rather than `\"enable\"` because a\n\t// placement-membership entry is the pipeline's starting point, not\n\t// a winning decision. Subsequent steps may block the tool at the\n\t// same precedence (0); the builder's `decision.precedence <\n\t// winning.precedence` rule would otherwise let the placement entry\n\t// win equality and mask later blocks. Surviving tools are flipped\n\t// to `enabled` by `builder.reconcileFinalStates(...)` at the end of\n\t// the pipeline once the final candidate set is known.\n\tlet candidates: string[] = [];\n\tfor (const toolId of placement) {\n\t\tcandidates.push(toolId);\n\t\tbuilder.addDecision({\n\t\t\tprecedence: 0,\n\t\t\trule: \"placement-membership\",\n\t\t\tfeatureId: toolId,\n\t\t\taction: \"skip\",\n\t\t\tsourceType: \"host\",\n\t\t\treason: `Listed in tools.placement.${request.level}`,\n\t\t});\n\t}\n\n\t// Step 2 — Provider veto.\n\tcandidates = candidates.filter((toolId) => {\n\t\tconst providerEnabled = tools.providers?.[toolId]?.enabled;\n\t\tif (providerEnabled === false) {\n\t\t\tbuilder.addDecision({\n\t\t\t\tprecedence: 0,\n\t\t\t\trule: \"provider-disabled\",\n\t\t\t\tfeatureId: toolId,\n\t\t\t\taction: \"block\",\n\t\t\t\tsourceType: \"host\",\n\t\t\t\treason: `tools.providers.${toolId}.enabled === false`,\n\t\t\t\tvalue: false,\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Step 3 — Host whitelist (only when non-empty).\n\tif (allowed.length > 0) {\n\t\tconst allowedSet = new Set(allowed);\n\t\tcandidates = candidates.filter((toolId) => {\n\t\t\tif (!allowedSet.has(toolId)) {\n\t\t\t\tbuilder.addDecision({\n\t\t\t\t\tprecedence: 0,\n\t\t\t\t\trule: \"host-allowlist\",\n\t\t\t\t\tfeatureId: toolId,\n\t\t\t\t\taction: \"block\",\n\t\t\t\t\tsourceType: \"host\",\n\t\t\t\t\treason: \"Not present in tools.policy.allowed\",\n\t\t\t\t\tvalue: allowed,\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t}\n\n\t// Step 4 — Host blocklist (absolute).\n\tcandidates = candidates.filter((toolId) => {\n\t\tif (blocked.has(toolId)) {\n\t\t\tbuilder.addDecision({\n\t\t\t\tprecedence: 0,\n\t\t\t\trule: \"host-blocked\",\n\t\t\t\tfeatureId: toolId,\n\t\t\t\taction: \"block\",\n\t\t\t\tsourceType: \"host\",\n\t\t\t\treason: \"Listed in tools.policy.blocked\",\n\t\t\t\tvalue: tools.policy.blocked,\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Step 5 — PNP/profile policy gates.\n\tconst diagnostics: ToolPolicyDiagnostic[] = [];\n\tconst sourcesByTool = new Map<string, PolicySourceTag[]>();\n\tfor (const toolId of candidates) {\n\t\tsourcesByTool.set(toolId, [\"placement\"]);\n\t}\n\n\t// Snapshot the post-host candidate set so step 5b can distinguish\n\t// \"host removed a required tool\" (requiredToolBlocked fires)\n\t// from \"profile policy's own precedence removed a required tool\" (fix\n\t// per M8 PR 1 R1 S1 — multi-rule conflict on the same tool must\n\t// not blame the host).\n\tconst postHostCandidates = new Set(candidates);\n\n\tlet pnpPolicyResult: ReturnType<PnpPolicySource[\"apply\"]> | null = null;\n\tif (\n\t\tpnpPolicy.enforcement === \"on\" &&\n\t\tpnpPolicy.source &&\n\t\t(pnpPolicy.assessment || pnpPolicy.currentItemRef)\n\t) {\n\t\tpnpPolicyResult = pnpPolicy.source.apply({\n\t\t\tassessment: pnpPolicy.assessment,\n\t\t\tcurrentItemRef: pnpPolicy.currentItemRef,\n\t\t});\n\n\t\tif (pnpPolicyResult.sources.assessment) {\n\t\t\tbuilder.addSource(\"assessment\", pnpPolicyResult.sources.assessment);\n\t\t}\n\t\tif (pnpPolicyResult.sources.student) {\n\t\t\tbuilder.addSource(\"student\", pnpPolicyResult.sources.student);\n\t\t}\n\t\tif (pnpPolicyResult.sources.item) {\n\t\t\tbuilder.addSource(\"item\", pnpPolicyResult.sources.item);\n\t\t}\n\n\t\tfor (const decision of pnpPolicyResult.decisions) {\n\t\t\tbuilder.addDecision({\n\t\t\t\tprecedence: decision.precedence,\n\t\t\t\trule: decision.rule,\n\t\t\t\tfeatureId: decision.featureId,\n\t\t\t\taction: decision.action,\n\t\t\t\tsourceType: decision.sourceType,\n\t\t\t\treason: decision.reason,\n\t\t\t\tvalue: decision.value,\n\t\t\t});\n\t\t}\n\n\t\t// 5a — remove PNP/profile-blocked tools from the candidate set.\n\t\tcandidates = candidates.filter((toolId) => {\n\t\t\treturn !pnpPolicyResult!.blockedToolIds.has(toolId);\n\t\t});\n\t\tfor (const toolId of Array.from(sourcesByTool.keys())) {\n\t\t\tif (pnpPolicyResult.blockedToolIds.has(toolId)) {\n\t\t\t\tsourcesByTool.delete(toolId);\n\t\t\t}\n\t\t}\n\n\t\t// 5b — surface requiredToolBlocked diagnostics ONLY for\n\t\t// PNP/profile-mandated tools that the host removed (i.e., the tool was\n\t\t// NOT in `postHostCandidates`). Mandated tools removed by\n\t\t// profile policy's own higher-precedence rule (e.g. `restrictedTools`\n\t\t// blocking a `requiredTools` mandate) are an internal policy\n\t\t// resolution and must not be reported as a host conflict — the\n\t\t// loser's `block` decision is already in the trail with full\n\t\t// provenance.\n\t\t//\n\t\t// `details` carries `{ rule, hostRule, hostValue }` so consumers\n\t\t// can render the conflict as a single sentence without\n\t\t// re-deriving the host gate from `provenance.features`. See\n\t\t// `RequiredToolBlockedDetails` for the typed shape.\n\t\tfor (const mandatedToolId of pnpPolicyResult.mandatedToolIds) {\n\t\t\tconst removedByHost = !postHostCandidates.has(mandatedToolId);\n\t\t\tif (!removedByHost) continue;\n\t\t\tconst flag = pnpPolicyResult.perToolFlags.get(mandatedToolId);\n\t\t\tconst ruleName = flag?.rule ?? \"required-tool\";\n\t\t\tconst hostGate = detectHostRemovalGate(mandatedToolId, {\n\t\t\t\tplacement,\n\t\t\t\tallowed,\n\t\t\t\tblocked,\n\t\t\t\tproviders: tools.providers,\n\t\t\t});\n\t\t\tconst details: RequiredToolBlockedDetails = {\n\t\t\t\trule: ruleName,\n\t\t\t\thostRule: hostGate.hostRule,\n\t\t\t\thostValue: hostGate.hostValue,\n\t\t\t};\n\t\t\tdiagnostics.push({\n\t\t\t\tcode: \"tool-policy.requiredToolBlocked\",\n\t\t\t\tlevel: request.level,\n\t\t\t\ttoolId: mandatedToolId,\n\t\t\t\tmessage: `Profile policy mandates \"${mandatedToolId}\" (${ruleName}) but host policy removed it from level \"${request.level}\" via ${hostGate.hostRule}.`,\n\t\t\t\tdetails,\n\t\t\t});\n\t\t\tbuilder.addDecision({\n\t\t\t\tprecedence: 0,\n\t\t\t\trule: \"required-tool-blocked\",\n\t\t\t\tfeatureId: mandatedToolId,\n\t\t\t\taction: \"advisory\",\n\t\t\t\tsourceType: \"host\",\n\t\t\t\treason: `Host removed required tool \"${mandatedToolId}\" via ${hostGate.hostRule}`,\n\t\t\t\tvalue: details,\n\t\t\t});\n\t\t}\n\n\t\t// 5c — attach PNP policy source tags to surviving entries.\n\t\tfor (const toolId of candidates) {\n\t\t\tconst flag = pnpPolicyResult.perToolFlags.get(toolId);\n\t\t\tif (flag) {\n\t\t\t\tconst tags = sourcesByTool.get(toolId) ?? [];\n\t\t\t\ttags.push(`pnp.${flag.rule}` satisfies PolicySourceTag);\n\t\t\t\tsourcesByTool.set(toolId, tags);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Step 6 — Custom PolicySources.\n\tfor (let i = 0; i < customSources.length; i++) {\n\t\tconst source = customSources[i];\n\t\tconst before = candidates.slice();\n\t\tconst result = source.refine({\n\t\t\trequest,\n\t\t\tcandidates: before,\n\t\t});\n\t\tconst refinedSet = new Set(result.refinedCandidates);\n\t\t// Reject any superset additions (custom sources can only narrow).\n\t\tfor (const toolId of result.refinedCandidates) {\n\t\t\tif (!before.includes(toolId)) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\tcode: \"tool-policy.placementMissing\",\n\t\t\t\t\tlevel: request.level,\n\t\t\t\t\ttoolId,\n\t\t\t\t\tmessage: `Custom source \"${source.id}\" tried to add tool \"${toolId}\" that was not in candidates; ignored.`,\n\t\t\t\t\tsource: `custom.${source.id}` satisfies PolicySourceTag,\n\t\t\t\t});\n\t\t\t\trefinedSet.delete(toolId);\n\t\t\t}\n\t\t}\n\t\tcandidates = before.filter((id) => refinedSet.has(id));\n\n\t\t// Index the source's emitted block decisions by featureId so we\n\t\t// can detect \"silent removals\" — tools the source dropped from\n\t\t// the candidate set without logging an explicit block. Without\n\t\t// this auto-log, the provenance trail for a silently-removed\n\t\t// tool would show only the prior `enable` decisions and the\n\t\t// final-state reconciliation would have no evidence to mark it\n\t\t// `blocked` (M8 PR 1 R2 S1 / M1 case B).\n\t\tconst explicitBlocks = new Set<string>();\n\t\tif (result.decisions) {\n\t\t\tfor (const event of result.decisions) {\n\t\t\t\tbuilder.addDecision({\n\t\t\t\t\tprecedence: event.precedence ?? 100 + i,\n\t\t\t\t\trule: event.rule,\n\t\t\t\t\tfeatureId: event.featureId,\n\t\t\t\t\taction: event.action,\n\t\t\t\t\tsourceType: event.sourceType,\n\t\t\t\t\treason: event.reason,\n\t\t\t\t\tvalue: event.value,\n\t\t\t\t});\n\t\t\t\tif (event.action === \"block\") {\n\t\t\t\t\texplicitBlocks.add(event.featureId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Auto-log a `custom-source / block` decision for silent removals.\n\t\tfor (const toolId of before) {\n\t\t\tif (refinedSet.has(toolId)) continue;\n\t\t\tif (explicitBlocks.has(toolId)) continue;\n\t\t\tbuilder.addDecision({\n\t\t\t\tprecedence: 100 + i,\n\t\t\t\trule: \"custom-source\",\n\t\t\t\tfeatureId: toolId,\n\t\t\t\taction: \"block\",\n\t\t\t\tsourceType: \"custom\",\n\t\t\t\treason: `Custom policy source \"${source.id}\" removed tool \"${toolId}\" from candidates without emitting a decision; auto-logged for trail completeness.`,\n\t\t\t\tvalue: { customSourceId: source.id },\n\t\t\t});\n\t\t}\n\n\t\t// Annotate surviving entries with `custom.<id>` so hosts can see\n\t\t// which custom source kept them in.\n\t\tfor (const toolId of candidates) {\n\t\t\tconst tags = sourcesByTool.get(toolId) ?? [\"placement\"];\n\t\t\ttags.push(`custom.${source.id}` satisfies PolicySourceTag);\n\t\t\tsourcesByTool.set(toolId, tags);\n\t\t}\n\t\t// And drop attribution for IDs the source removed.\n\t\tfor (const toolId of before) {\n\t\t\tif (!refinedSet.has(toolId)) {\n\t\t\t\tsourcesByTool.delete(toolId);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst survivingIds = new Set(candidates);\n\tconst visibleTools: ToolPolicyEntry[] = candidates.map((toolId) => {\n\t\tconst flag = pnpPolicyResult?.perToolFlags.get(toolId);\n\t\treturn {\n\t\t\ttoolId,\n\t\t\trequired: flag?.required ?? false,\n\t\t\talwaysAvailable: flag?.alwaysAvailable ?? false,\n\t\t\tsettings: flag?.settings,\n\t\t\tsources: sourcesByTool.get(toolId) ?? [\"placement\"],\n\t\t};\n\t});\n\n\tbuilder.reconcileFinalStates(survivingIds);\n\n\treturn {\n\t\tvisibleTools,\n\t\tdiagnostics,\n\t\tprovenance: builder.build(),\n\t};\n}\n\n/**\n * Identify which step-1-through-4 host gate removed a tool. Used by\n * step 5b to enrich `tool-policy.requiredToolBlocked` diagnostics. The\n * checks mirror the pipeline order — step 1 (placement) first, step 4\n * (blocklist) last — so the FIRST gate that would have matched wins,\n * which is the gate the pipeline actually invoked. Subsequent gates\n * never get to evaluate a tool that an earlier step already removed.\n */\nfunction detectHostRemovalGate(\n\ttoolId: string,\n\targs: {\n\t\tplacement: string[];\n\t\tallowed: string[];\n\t\tblocked: Set<string>;\n\t\tproviders: CanonicalToolsConfig[\"providers\"];\n\t},\n): { hostRule: ToolPolicyHostGate; hostValue: unknown } {\n\tif (!args.placement.includes(toolId)) {\n\t\treturn { hostRule: \"placement-missing\", hostValue: args.placement };\n\t}\n\tif (args.providers?.[toolId]?.enabled === false) {\n\t\treturn { hostRule: \"provider-disabled\", hostValue: false };\n\t}\n\tif (args.allowed.length > 0 && !args.allowed.includes(toolId)) {\n\t\treturn { hostRule: \"host-allowlist\", hostValue: args.allowed };\n\t}\n\tif (args.blocked.has(toolId)) {\n\t\treturn {\n\t\t\thostRule: \"host-blocked\",\n\t\t\thostValue: Array.from(args.blocked),\n\t\t};\n\t}\n\t// Defensive: `removedByHost` is true at the call site (the tool is\n\t// in `mandatedToolIds` but not in `postHostCandidates`), so one of\n\t// the four gates above MUST have fired. If none did, the host\n\t// pipeline has a bug; surface a best-effort rather than throwing.\n\treturn { hostRule: \"placement-missing\", hostValue: args.placement };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"decision-types.js","sourceRoot":"","sources":["../../../src/policy/core/decision-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG","sourcesContent":["/**\n * Tool Policy Engine — decision input/output types.\n *\n * These types describe the *request/response* contract for\n * `ToolPolicyEngine.decide(...)`. The engine itself, plus the\n * composition pipeline that produces the response, lives in sibling\n * modules.\n *\n * See `.cursor/plans/m8-design.md` § 2 for the engine shape, § 3 for\n * the composition rule, and § 4 for the provenance contract.\n */\n\nimport type { ToolPlacementLevel } from \"../../services/tools-config-normalizer.js\";\nimport type { ToolContext, ToolLevel } from \"../../services/tool-context.js\";\nimport type { PolicySourceTag } from \"./policy-source-tag.js\";\nimport type { ToolPolicyProvenance } from \"./provenance.js\";\n\n/**\n * Scope identifier for a `decide(...)` request. The engine uses\n * `level` to pick which placement bucket to read; `scopeId` is opaque\n * to the engine (it is round-tripped into provenance for human-readable\n * trails) and is typically the section-id, item-id, or passage-id of\n * the surface asking the question. `contentKind` mirrors the\n * `ToolbarContext.scope.contentKind` field already in use by\n * `<pie-item-toolbar>` Pass-2 visibility.\n */\nexport interface ToolScope {\n\tlevel: ToolLevel;\n\tscopeId: string;\n\tassessmentId?: string;\n\tsectionId?: string;\n\titemId?: string;\n\tcanonicalItemId?: string;\n\tcontentKind?: string;\n}\n\nexport interface ToolPolicyDecisionRequest {\n\t/**\n\t * Placement bucket the engine reads from\n\t * (`tools.placement[level]`). Stays narrow (`section | item |\n\t * passage`) — broader `ToolLevel` values from `tool-context.ts`\n\t * are surfaced through `scope.level` only.\n\t */\n\tlevel: ToolPlacementLevel;\n\tscope: ToolScope;\n\t/**\n\t * Optional Pass-2 context. The engine itself does NOT call\n\t * `isVisibleInContext(...)`; that gate is intentionally applied\n\t * at the toolbar boundary (Pass-2 = relevance, Pass-1 = the\n\t * engine's job). The context is forwarded to custom\n\t * `PolicySource` instances so they can refine the candidate set\n\t * if they need to.\n\t */\n\tcontext?: ToolContext;\n}\n\n/**\n * Diagnostic codes the engine may emit alongside a decision. The\n * canonical case in M8 is `tool-policy.requiredToolBlocked` — fired\n * when a host policy gate (`policy.blocked`, missing-from-`placement`,\n * provider veto) removed a tool that profile policy `requiredTools` /\n * `district.requiredTools` mandates.\n *\n * `tool-policy.placementMissing` fires when a custom `PolicySource`\n * references a tool ID that is not present in `tools.placement[level]`\n * for the resolved level. The host-side `ToolConfigDiagnostic` channel\n * (already used by `tool-config-validation.ts`) covers config-time\n * misconfiguration; this channel covers per-decision conflicts.\n */\nexport type ToolPolicyDiagnosticCode =\n\t| \"tool-policy.requiredToolBlocked\"\n\t| \"tool-policy.placementMissing\";\n\n/**\n * Which host gate removed a profile-mandated tool. Surfaced inside\n * `ToolPolicyDiagnostic.details` for `tool-policy.requiredToolBlocked`\n * so consumers can render a single human-readable explanation\n * (\"the proctor blocked the calculator that this student's IEP\n * requires\") without re-deriving the host gate from\n * `provenance.features[toolId].allDecisions`.\n *\n * The four values mirror steps 1–4 of `composeDecision`:\n * - `placement-missing` — tool is not in `tools.placement[level]`\n * - `provider-disabled` — `tools.providers[id].enabled === false`\n * - `host-allowlist` — non-empty `tools.policy.allowed` excludes the id\n * - `host-blocked` — `tools.policy.blocked` lists the id\n */\nexport type ToolPolicyHostGate =\n\t| \"placement-missing\"\n\t| \"provider-disabled\"\n\t| \"host-allowlist\"\n\t| \"host-blocked\";\n\n/**\n * Strongly-typed payload for `tool-policy.requiredToolBlocked`\n * diagnostics. The diagnostic's `details` field still types as\n * `Record<string, unknown>` for forward compatibility, but engines\n * always populate this exact shape today and consumers can safely\n * cast.\n */\nexport interface RequiredToolBlockedDetails extends Record<string, unknown> {\n\t/** The profile policy rule that mandated the tool (e.g. `district-requirement`). */\n\trule: string;\n\t/** Which host gate removed the tool. */\n\thostRule: ToolPolicyHostGate;\n\t/** The host configuration value that triggered the gate (best-effort, may be omitted). */\n\thostValue?: unknown;\n}\n\nexport interface ToolPolicyDiagnostic {\n\tcode: ToolPolicyDiagnosticCode;\n\tlevel: ToolPlacementLevel;\n\ttoolId: string;\n\tmessage: string;\n\tsource?: PolicySourceTag;\n\tdetails?: Record<string, unknown>;\n}\n\nexport interface ToolPolicyEntry {\n\ttoolId: string;\n\t/**\n\t * `true` when PNP/profile policy mandates this tool (item or district\n\t * `requiredTools`, or PNP support without prohibition). Advisory\n\t * mandates that the host blocked do *not* surface here — they\n\t * appear in `diagnostics` instead. Hosts that need to know about\n\t * those should listen on the diagnostic channel.\n\t */\n\trequired: boolean;\n\t/**\n\t * `true` for PNP `supports` — UI-level signal that the host\n\t * cannot toggle this tool off in user preferences. Does NOT\n\t * override host blocks (they would have removed the entry\n\t * before this flag is read).\n\t */\n\talwaysAvailable: boolean;\n\t/**\n\t * Tool-specific settings resolved from the assessment / item\n\t * settings via the PNP policy source. Hosts that want to read these\n\t * directly should use `entry.settings` rather than peeking into\n\t * the assessment entity from above the engine.\n\t */\n\tsettings?: unknown;\n\t/**\n\t * Every contributor that helped this entry survive the\n\t * composition pipeline. Always non-empty — at minimum\n\t * `[\"placement\"]` for any entry that came from\n\t * `tools.placement[level]`.\n\t */\n\tsources: PolicySourceTag[];\n}\n\nexport interface ToolPolicyDecision {\n\tvisibleTools: ToolPolicyEntry[];\n\tdiagnostics: ToolPolicyDiagnostic[];\n\tprovenance: ToolPolicyProvenance;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"engine-context.js","sourceRoot":"","sources":["../../../src/policy/core/engine-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,MAAM,CAAC,MAAM,sBAAsB,GAAkB,MAAM,CAC1D,iCAAiC,CACjC,CAAC","sourcesContent":["/**\n * Svelte context key for the tool policy engine (M8 PR 1).\n *\n * Components inside an assessment toolkit subtree consume the engine\n * through Svelte's native `getContext(TOOL_POLICY_ENGINE_KEY)`. The\n * canonical provider is the `ToolkitCoordinator` wiring (M8 PR 2):\n * the toolkit CE constructs a `ToolPolicyEngine`, attaches it to the\n * coordinator, and exposes it to descendants via\n * `setContext(TOOL_POLICY_ENGINE_KEY, engine)`.\n *\n * Mirrors the M7 `SECTION_RUNTIME_ENGINE_KEY` pattern. As with the\n * runtime engine, the key is a `Symbol` so it cannot collide with\n * userland context keys and so descendants are forced to import this\n * module rather than guess a string id.\n *\n * **No cross-CE bridge.** Unlike the runtime engine, there is no\n * `connectToolPolicyEngineHostContext` helper — see M8 design Q8.\n * Every CE in the tree gets its engine from its own coordinator\n * (the toolkit element). This avoids subscription-bridge overhead\n * for a function-style engine that hosts can simply re-call after\n * an input swap.\n *\n * **Stability.** This export is part of the stable `policy/engine`\n * surface; renaming or replacing the symbol is a major breaking\n * change.\n */\n\nimport type { ToolPolicyEngine } from \"./ToolPolicyEngine.js\";\n\nexport const TOOL_POLICY_ENGINE_KEY: unique symbol = Symbol(\n\t\"@pie-players/tool-policy-engine\",\n);\n\nexport type ToolPolicyEngineContext = ToolPolicyEngine;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"pnp-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CAAC;IACD,IACC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QACvC,QAAQ,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAClC,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IACC,QAAQ,CAAC,cAAc;QACvB,OAAO,QAAQ,CAAC,cAAc,KAAK,QAAQ;QAC3C,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAC9C,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAG5C;IACA,IAAI,4BAA4B,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,IAAI,yBAAyB,CAAC,IAAI,CAAC,cAAc,CAAC;QAAE,OAAO,IAAI,CAAC;IAChE,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/**\n * PNP/profile policy input detection (M8 PR 4 — see `.cursor/plans/m8-design.md` F2 and\n * `.cursor/plans/m8-implementation-plan.md` § PR 4).\n *\n * Pure helpers that decide whether the inputs the engine has been given\n * actually carry PNP/profile policy material. Used by:\n *\n * - {@link ToolPolicyEngine}'s constructor as the auto-default for\n * `pnpEnforcement` when the host did not pass an explicit `\"on\"` /\n * `\"off\"`.\n * - {@link ToolkitCoordinator.resolveEffectivePnpEnforcement} as the\n * auto-mode rule. PR 2 used a coarse \"any non-null assessment → on\"\n * placeholder; PR 4 narrows it to \"assessment OR currentItemRef\n * carries profile policy material.\"\n *\n * The rule is intentionally narrow. Hosts that bind a bare assessment\n * record (only `id` / `name`, no PNP and no settings) do not engage\n * PNP/profile gates. The flip happens the moment the assessment carries any of:\n *\n * - `personalNeedsProfile` (any `supports`, `prohibitedSupports`, or\n * `activateAtInit`),\n * - `settings.districtPolicy` (any `blockedTools`, `requiredTools`,\n * or `policies`),\n * - `settings.testAdministration` (any populated key — `mode`,\n * `toolOverrides`, etc.),\n * - or the bound `currentItemRef.settings` carries\n * `requiredTools` / `restrictedTools` / `toolParameters`.\n *\n * Hosts opt out of the auto-on behavior by passing\n * `pnpEnforcement: \"off\"` explicitly (engine input or\n * `ToolkitCoordinator.setPnpEnforcement(\"off\")`).\n */\n\nimport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\n\n/**\n * Return `true` when the assessment carries any PNP/profile policy\n * material that the engine's `PnpPolicySource` would consume.\n *\n * The check is structural — the presence of a non-empty PNP, district\n * policy, or test administration block is enough; the content does not\n * have to validate against any specific rule.\n */\nexport function assessmentHasPnpPolicyInputs(\n\tassessment: AssessmentEntity | null | undefined,\n): boolean {\n\tif (!assessment) return false;\n\tconst pnp = assessment.personalNeedsProfile;\n\tif (pnp) {\n\t\tif (Array.isArray(pnp.supports) && pnp.supports.length > 0) return true;\n\t\tif (\n\t\t\tArray.isArray(pnp.prohibitedSupports) &&\n\t\t\tpnp.prohibitedSupports.length > 0\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (Array.isArray(pnp.activateAtInit) && pnp.activateAtInit.length > 0) {\n\t\t\treturn true;\n\t\t}\n\t}\n\tconst settings = assessment.settings;\n\tif (settings) {\n\t\tconst district = settings.districtPolicy;\n\t\tif (district) {\n\t\t\tif (\n\t\t\t\tArray.isArray(district.blockedTools) &&\n\t\t\t\tdistrict.blockedTools.length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tArray.isArray(district.requiredTools) &&\n\t\t\t\tdistrict.requiredTools.length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tdistrict.policies &&\n\t\t\t\ttypeof district.policies === \"object\" &&\n\t\t\t\tObject.keys(district.policies).length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tconst admin = settings.testAdministration;\n\t\tif (admin && typeof admin === \"object\") {\n\t\t\tfor (const key of Object.keys(admin)) {\n\t\t\t\tconst value = (admin as Record<string, unknown>)[key];\n\t\t\t\tif (value === undefined || value === null) continue;\n\t\t\t\tif (Array.isArray(value) && value.length === 0) continue;\n\t\t\t\tif (\n\t\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t\t!Array.isArray(value) &&\n\t\t\t\t\tObject.keys(value as Record<string, unknown>).length === 0\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Return `true` when the bound item reference carries item-level profile policy\n * material (`requiredTools`, `restrictedTools`, or `toolParameters`).\n *\n * Used in addition to {@link assessmentHasPnpPolicyInputs} so a host that\n * navigates to an item with profile-relevant settings — without a parent\n * assessment carrying its own PNP/district/test-admin block — still\n * gets PNP/profile gates engaged for that item.\n */\nexport function itemRefHasPnpPolicyInputs(\n\titemRef: AssessmentItemRef | null | undefined,\n): boolean {\n\tconst settings = itemRef?.settings;\n\tif (!settings) return false;\n\tif (\n\t\tArray.isArray(settings.requiredTools) &&\n\t\tsettings.requiredTools.length > 0\n\t) {\n\t\treturn true;\n\t}\n\tif (\n\t\tArray.isArray(settings.restrictedTools) &&\n\t\tsettings.restrictedTools.length > 0\n\t) {\n\t\treturn true;\n\t}\n\tif (\n\t\tsettings.toolParameters &&\n\t\ttypeof settings.toolParameters === \"object\" &&\n\t\tObject.keys(settings.toolParameters).length > 0\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Resolve the default `pnpEnforcement` mode given the bound inputs.\n *\n * Returns `\"on\"` when {@link assessmentHasPnpPolicyInputs} or\n * {@link itemRefHasPnpPolicyInputs} reports any profile policy material; otherwise\n * `\"off\"`. Hosts override the default by passing an explicit\n * `pnpEnforcement` value (engine input) or by calling\n * `ToolkitCoordinator.setPnpEnforcement(\"on\" | \"off\")`.\n */\nexport function resolveDefaultPnpEnforcement(args: {\n\tassessment?: AssessmentEntity | null;\n\tcurrentItemRef?: AssessmentItemRef | null;\n}): \"on\" | \"off\" {\n\tif (assessmentHasPnpPolicyInputs(args.assessment)) return \"on\";\n\tif (itemRefHasPnpPolicyInputs(args.currentItemRef)) return \"on\";\n\treturn \"off\";\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy-source-tag.js","sourceRoot":"","sources":["../../../src/policy/core/policy-source-tag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG","sourcesContent":["/**\n * Policy source tag — attribution for `ToolPolicyEntry.sources`.\n *\n * The engine attaches a `PolicySourceTag` to every `ToolPolicyEntry` it\n * emits, capturing every step from `compose-decision.ts` that contributed\n * to the entry being kept (or, in the case of `required-tool-blocked`,\n * the step that surfaced the conflict).\n *\n * Tag vocabulary maps onto the six composition steps in\n * `m8-design.md` § 3:\n *\n * 1. Membership filter → `\"placement\"`\n * 2. Provider veto → `\"provider\"` (negative; only present when\n * the entry survived a\n * non-`enabled: false` check)\n * 3. Host whitelist → `\"policy\"`\n * 4. Host blocklist → `\"policy\"` (negative)\n * 5. PNP/profile gates → `\"pnp.${rule}\"` (e.g. `\"pnp.pnp-support\"`,\n * `\"pnp.item-requirement\"`)\n * 6. Custom PolicySources → `\"custom.${source.id}\"`\n *\n * Negative tags do not appear on surviving entries — they are reflected\n * only in `ToolPolicyProvenance` decisions. The tag union therefore\n * tracks contributors that *kept* a tool, not contributors that\n * *removed* one. Diagnostic surfacing of removals is the\n * provenance/diagnostic channel's job.\n */\n\nexport type PnpPolicySourceRule =\n\t| \"district-block\"\n\t| \"test-admin-override\"\n\t| \"item-restriction\"\n\t| \"item-requirement\"\n\t| \"district-requirement\"\n\t| \"pnp-support\"\n\t| \"pnp-prohibited\";\n\nexport type PnpPolicySourceTag = `pnp.${PnpPolicySourceRule}`;\n\nexport type CustomPolicySourceTag = `custom.${string}`;\n\nexport type PolicySourceTag =\n\t| \"placement\"\n\t| \"policy\"\n\t| \"provider\"\n\t| PnpPolicySourceTag\n\t| CustomPolicySourceTag;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"provenance.js","sourceRoot":"","sources":["../../../src/policy/core/provenance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwGH;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAC/B,UAAU,CAAuB;IACjC,WAAW,GAAG,CAAC,CAAC;IAExB,YAAY,SAAiB;QAC5B,IAAI,CAAC,UAAU,GAAG;YACjB,SAAS;YACT,UAAU,EAAE,IAAI,IAAI,EAAE;YACtB,OAAO,EAAE,EAAE;YACX,QAAQ,EAAE,IAAI,GAAG,EAAE;YACnB,WAAW,EAAE,EAAE;YACf,OAAO,EAAE;gBACR,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC;gBACV,aAAa,EAAE,CAAC;gBAChB,QAAQ,EAAE,EAAE;gBACZ,MAAM,EAAE,EAAE;aACV;SACD,CAAC;IACH,CAAC;IAED,SAAS,CACR,IAA2C,EAC3C,IAAqD;QAErD,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QACzD,QAAQ,IAAI,EAAE,CAAC;YACd,KAAK,cAAc;gBAClB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,GAAG;oBACtC,GAAG,IAAI;oBACP,WAAW,EAAE,IAAI,CAAC,MAAM;iBACxB,CAAC;gBACF,MAAM;YACP,KAAK,YAAY;gBAChB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,GAAG;oBACpC,GAAG,IAAI;oBACP,QAAQ,EAAE,IAAI,CAAC,MAAM;iBACrB,CAAC;gBACF,MAAM;YACP,KAAK,SAAS;gBACb,IAAI,CAAC,UAAU,CAAC,OA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C","sourcesContent":["/**\n * Tool Policy Provenance (M8 — see `.cursor/plans/m8-design.md` § 4).\n *\n * Tracks decisions from every Pass-1 contributor: host placement, host policy,\n * provider veto, PNP/profile gates, and custom policy sources.\n */\n\n/**\n * Rule vocabulary for tool policy decisions.\n */\nexport type ToolPolicyDecisionRule =\n\t| \"district-block\"\n\t| \"test-admin-override\"\n\t| \"item-restriction\"\n\t| \"item-requirement\"\n\t| \"district-requirement\"\n\t| \"pnp-support\"\n\t| \"pnp-prohibited\"\n\t| \"placement-membership\"\n\t| \"provider-disabled\"\n\t| \"host-allowlist\"\n\t| \"host-blocked\"\n\t| \"required-tool-blocked\"\n\t| \"custom-source\"\n\t| \"system-default\";\n\nexport type ToolPolicySourceType =\n\t| \"organization\"\n\t| \"assessment\"\n\t| \"section\"\n\t| \"item\"\n\t| \"student\"\n\t| \"system\"\n\t| \"host\"\n\t| \"custom\";\n\nexport interface ToolPolicyResolutionDecision {\n\t/** Monotonic step index across the entire decision log. */\n\tstep: number;\n\n\t/**\n\t * Precedence level. PNP/profile rules use `1`–`6`; non-profile rules use `0`\n\t * for host-side gates or `7+` for custom sources that run after PNP/profile policy.\n\t */\n\tprecedence: number;\n\n\trule: ToolPolicyDecisionRule;\n\n\t/** Tool ID being resolved (post-PNP-support-mapping where applicable). */\n\tfeatureId: string;\n\n\taction: \"block\" | \"enable\" | \"skip\" | \"advisory\";\n\n\tsource: {\n\t\ttype: ToolPolicySourceType;\n\t\tid?: string;\n\t\tname?: string;\n\t};\n\n\treason: string;\n\n\tvalue?: unknown;\n\n\ttimestamp: Date;\n}\n\nexport interface ToolPolicyFeatureTrail {\n\tfeatureId: string;\n\tfinalState: \"enabled\" | \"blocked\" | \"not-configured\" | \"advisory-only\";\n\twinningDecision?: ToolPolicyResolutionDecision;\n\tallDecisions: ToolPolicyResolutionDecision[];\n\texplanation: string;\n}\n\nexport interface ToolPolicyProvenance {\n\tcontextId: string;\n\tresolvedAt: Date;\n\tsources: {\n\t\torganization?: { id: string; name: string; pnpDefaults?: unknown };\n\t\tassessment?: { id: string; name: string; settings?: unknown };\n\t\tsection?: { id: string; title?: string; settings?: unknown };\n\t\titem?: { id: string; name?: string; settings?: unknown };\n\t\tstudent?: { id: string; pnpProfile?: unknown };\n\t\thost?: { id: string; config?: unknown };\n\t};\n\tfeatures: Map<string, ToolPolicyFeatureTrail>;\n\tdecisionLog: ToolPolicyResolutionDecision[];\n\tsummary: {\n\t\ttotalFeatures: number;\n\t\tenabled: number;\n\t\tblocked: number;\n\t\tnotConfigured: number;\n\t\tbySource: Record<string, number>;\n\t\tbyRule: Record<string, number>;\n\t};\n}\n\ninterface AddDecisionParams {\n\tprecedence: number;\n\trule: ToolPolicyDecisionRule;\n\tfeatureId: string;\n\taction: ToolPolicyResolutionDecision[\"action\"];\n\tsourceType: ToolPolicySourceType;\n\tsourceId?: string;\n\tsourceName?: string;\n\treason: string;\n\tvalue?: unknown;\n}\n\n/**\n * Builder for `ToolPolicyProvenance`.\n */\nexport class ToolPolicyProvenanceBuilder {\n\tprivate provenance: ToolPolicyProvenance;\n\tprivate stepCounter = 0;\n\n\tconstructor(contextId: string) {\n\t\tthis.provenance = {\n\t\t\tcontextId,\n\t\t\tresolvedAt: new Date(),\n\t\t\tsources: {},\n\t\t\tfeatures: new Map(),\n\t\t\tdecisionLog: [],\n\t\t\tsummary: {\n\t\t\t\ttotalFeatures: 0,\n\t\t\t\tenabled: 0,\n\t\t\t\tblocked: 0,\n\t\t\t\tnotConfigured: 0,\n\t\t\t\tbySource: {},\n\t\t\t\tbyRule: {},\n\t\t\t},\n\t\t};\n\t}\n\n\taddSource(\n\t\ttype: keyof ToolPolicyProvenance[\"sources\"],\n\t\tdata: { id: string; name?: string; config?: unknown },\n\t): this {\n\t\tconst base = { id: data.id, name: data.name ?? data.id };\n\t\tswitch (type) {\n\t\t\tcase \"organization\":\n\t\t\t\tthis.provenance.sources.organization = {\n\t\t\t\t\t...base,\n\t\t\t\t\tpnpDefaults: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"assessment\":\n\t\t\t\tthis.provenance.sources.assessment = {\n\t\t\t\t\t...base,\n\t\t\t\t\tsettings: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"section\":\n\t\t\t\tthis.provenance.sources.section = { ...base, settings: data.config };\n\t\t\t\tbreak;\n\t\t\tcase \"item\":\n\t\t\t\tthis.provenance.sources.item = { ...base, settings: data.config };\n\t\t\t\tbreak;\n\t\t\tcase \"student\":\n\t\t\t\tthis.provenance.sources.student = {\n\t\t\t\t\tid: data.id,\n\t\t\t\t\tpnpProfile: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"host\":\n\t\t\t\tthis.provenance.sources.host = { id: data.id, config: data.config };\n\t\t\t\tbreak;\n\t\t}\n\t\treturn this;\n\t}\n\n\taddDecision(params: AddDecisionParams): this {\n\t\tconst decision: ToolPolicyResolutionDecision = {\n\t\t\tstep: ++this.stepCounter,\n\t\t\tprecedence: params.precedence,\n\t\t\trule: params.rule,\n\t\t\tfeatureId: params.featureId,\n\t\t\taction: params.action,\n\t\t\tsource: {\n\t\t\t\ttype: params.sourceType,\n\t\t\t\tid: params.sourceId,\n\t\t\t\tname: params.sourceName,\n\t\t\t},\n\t\t\treason: params.reason,\n\t\t\tvalue: params.value,\n\t\t\ttimestamp: new Date(),\n\t\t};\n\n\t\tthis.provenance.decisionLog.push(decision);\n\n\t\tlet trail = this.provenance.features.get(params.featureId);\n\t\tif (!trail) {\n\t\t\ttrail = {\n\t\t\t\tfeatureId: params.featureId,\n\t\t\t\tfinalState: \"not-configured\",\n\t\t\t\tallDecisions: [],\n\t\t\t\texplanation: \"\",\n\t\t\t};\n\t\t\tthis.provenance.features.set(params.featureId, trail);\n\t\t}\n\t\ttrail.allDecisions.push(decision);\n\n\t\t// \"advisory\" doesn't change finalState — it preserves the existing\n\t\t// blocked/enabled state and only flags a documented conflict.\n\t\tif (params.action === \"advisory\") {\n\t\t\tif (trail.finalState === \"not-configured\") {\n\t\t\t\ttrail.finalState = \"advisory-only\";\n\t\t\t}\n\t\t} else if (params.action !== \"skip\") {\n\t\t\tconst isWinning =\n\t\t\t\t!trail.winningDecision ||\n\t\t\t\tdecision.precedence < trail.winningDecision.precedence;\n\t\t\tif (isWinning) {\n\t\t\t\ttrail.winningDecision = decision;\n\t\t\t\ttrail.finalState = decision.action === \"enable\" ? \"enabled\" : \"blocked\";\n\t\t\t}\n\t\t}\n\n\t\tthis.provenance.summary.bySource[params.sourceType] =\n\t\t\t(this.provenance.summary.bySource[params.sourceType] || 0) + 1;\n\t\tthis.provenance.summary.byRule[params.rule] =\n\t\t\t(this.provenance.summary.byRule[params.rule] || 0) + 1;\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Reconcile every feature's `finalState` against the post-pipeline\n\t * candidate set.\n\t *\n\t * The eager `finalState` updates inside `addDecision` track the\n\t * highest-precedence non-skip decision per feature, but a tool's\n\t * *actual* visibility is only known after step 6 of the\n\t * composition pipeline — earlier decisions can be reversed by\n\t * later host gates, PNP/profile gates, or custom sources. This method\n\t * walks every feature trail and rewrites `finalState` from the\n\t * final candidate set so callers can rely on\n\t * `provenance.features.get(toolId)?.finalState` as the canonical\n\t * \"is this tool visible right now?\" answer (M8 design § 4 + § 12).\n\t *\n\t * Semantics applied per feature:\n\t * - In `survivingIds` → \"enabled\"\n\t * - Not in `survivingIds`, has any non-skip decision → \"blocked\"\n\t * - Not in `survivingIds`, only advisory decisions → \"advisory-only\"\n\t * - Otherwise → \"not-configured\"\n\t *\n\t * Surviving features without any logged decisions get a synthetic\n\t * \"enabled\" trail so the provenance is dense enough for hosts that\n\t * iterate `provenance.features` to find the visible set.\n\t */\n\treconcileFinalStates(survivingIds: ReadonlySet<string>): this {\n\t\tfor (const featureId of survivingIds) {\n\t\t\tlet trail = this.provenance.features.get(featureId);\n\t\t\tif (!trail) {\n\t\t\t\ttrail = {\n\t\t\t\t\tfeatureId,\n\t\t\t\t\tfinalState: \"enabled\",\n\t\t\t\t\tallDecisions: [],\n\t\t\t\t\texplanation: \"\",\n\t\t\t\t};\n\t\t\t\tthis.provenance.features.set(featureId, trail);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttrail.finalState = \"enabled\";\n\t\t}\n\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\tif (survivingIds.has(trail.featureId)) continue;\n\t\t\tconst hasNonSkip = trail.allDecisions.some(\n\t\t\t\t(d) => d.action !== \"skip\" && d.action !== \"advisory\",\n\t\t\t);\n\t\t\tconst hasAdvisory = trail.allDecisions.some(\n\t\t\t\t(d) => d.action === \"advisory\",\n\t\t\t);\n\t\t\tif (hasNonSkip) {\n\t\t\t\ttrail.finalState = \"blocked\";\n\t\t\t} else if (hasAdvisory) {\n\t\t\t\ttrail.finalState = \"advisory-only\";\n\t\t\t} else {\n\t\t\t\ttrail.finalState = \"not-configured\";\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\tbuild(): ToolPolicyProvenance {\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\ttrail.explanation = generateExplanation(trail);\n\t\t}\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\tthis.provenance.summary.totalFeatures++;\n\t\t\tif (trail.finalState === \"enabled\") {\n\t\t\t\tthis.provenance.summary.enabled++;\n\t\t\t} else if (trail.finalState === \"blocked\") {\n\t\t\t\tthis.provenance.summary.blocked++;\n\t\t\t} else {\n\t\t\t\tthis.provenance.summary.notConfigured++;\n\t\t\t}\n\t\t}\n\t\treturn this.provenance;\n\t}\n}\n\nfunction generateExplanation(trail: ToolPolicyFeatureTrail): string {\n\tif (!trail.winningDecision) {\n\t\tif (trail.finalState === \"advisory-only\") {\n\t\t\tconst advisory = trail.allDecisions.find((d) => d.action === \"advisory\");\n\t\t\treturn advisory\n\t\t\t\t? `Feature \"${trail.featureId}\" was kept in its host-decided state; ${advisory.reason}`\n\t\t\t\t: `Feature \"${trail.featureId}\" carries an advisory note.`;\n\t\t}\n\t\treturn `Feature \"${trail.featureId}\" was not configured at any level.`;\n\t}\n\n\tconst decision = trail.winningDecision;\n\tconst sourceName = decision.source.name || decision.source.type;\n\tlet explanation = `Feature \"${trail.featureId}\" is ${trail.finalState}.\\n\\n`;\n\texplanation += `**Primary Reason** (${decision.rule}):\\n`;\n\texplanation += `${decision.reason}\\n`;\n\texplanation += `Source: ${sourceName} (${decision.source.type})\\n`;\n\tconst overridden = trail.allDecisions.filter(\n\t\t(d) =>\n\t\t\td.step !== decision.step &&\n\t\t\td.action !== \"skip\" &&\n\t\t\td.action !== \"advisory\" &&\n\t\t\td.precedence > decision.precedence,\n\t);\n\tif (overridden.length > 0) {\n\t\texplanation += `\\n**Overridden Rules**:\\n`;\n\t\tfor (const d of overridden) {\n\t\t\texplanation += `- ${d.rule}: ${d.reason}\\n`;\n\t\t}\n\t}\n\treturn explanation;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/policy/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACN,gBAAgB,GAOhB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACN,sBAAsB,GAEtB,MAAM,0BAA0B,CAAC","sourcesContent":["/**\n * Tool policy engine — facade entry point (M8 PR 1).\n *\n * Narrow, stable public surface for hosts that want to instantiate or\n * consume a `ToolPolicyEngine`. Re-exports the engine class, its\n * decision request/response types, the Svelte context key, and the\n * minimal `PolicySource` extension contract.\n *\n * **Pairing.** This module is the stable counterpart to\n * `./policy/internal`, which exposes the wider, evolving surface\n * (composition pipeline, provenance builder, PNP policy source). Consumers\n * that only need to drive an engine and read its decisions should\n * import from here. Consumers that need to reach past the facade\n * (e.g. test the composition pipeline directly, build a custom PNP policy\n * source variant, instrument provenance generation) should import\n * from `./policy/internal` and accept the documented stability\n * disclaimer there.\n *\n * Mirrors the M7 `runtime/engine` / `runtime/internal` split — see\n * the same rationale in `src/runtime/engine.ts`.\n */\n\nexport {\n\tToolPolicyEngine,\n\ttype PnpEnforcementMode,\n\ttype ResolvedEngineInputs,\n\ttype ToolPolicyChangeEvent,\n\ttype ToolPolicyChangeListener,\n\ttype ToolPolicyEngineArgs,\n\ttype ToolPolicyEngineInputs,\n} from \"./core/ToolPolicyEngine.js\";\n\nexport {\n\tTOOL_POLICY_ENGINE_KEY,\n\ttype ToolPolicyEngineContext,\n} from \"./core/engine-context.js\";\n\nexport type {\n\tRequiredToolBlockedDetails,\n\tToolPolicyDecision,\n\tToolPolicyDecisionRequest,\n\tToolPolicyDiagnostic,\n\tToolPolicyDiagnosticCode,\n\tToolPolicyEntry,\n\tToolPolicyHostGate,\n\tToolScope,\n} from \"./core/decision-types.js\";\n\nexport type {\n\tPolicySource,\n\tPolicySourceDecisionContext,\n\tPolicySourceProvenanceEntry,\n\tPolicySourceResult,\n} from \"./core/PolicySource.js\";\n\nexport type {\n\tPolicySourceTag,\n\tPnpPolicySourceRule,\n\tPnpPolicySourceTag,\n\tCustomPolicySourceTag,\n} from \"./core/policy-source-tag.js\";\n\nexport type {\n\tToolPolicyDecisionRule,\n\tToolPolicyFeatureTrail,\n\tToolPolicyProvenance,\n\tToolPolicyResolutionDecision,\n\tToolPolicySourceType,\n} from \"./core/provenance.js\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/policy/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACN,eAAe,GAEf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACN,eAAe,GAKf,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EACN,4BAA4B,EAC5B,yBAAyB,EACzB,4BAA4B,GAC5B,MAAM,6BAA6B,CAAC","sourcesContent":["/**\n * Tool policy engine — **internal** entry point (M8 PR 1).\n *\n * Re-exports the composition pipeline, the PNP policy source, and the\n * provenance builder for advanced hosts that want to drive the engine\n * components directly, and for the engine's own tests.\n *\n * **Stability posture.** This module is **not** part of the stable\n * public API. Symbols here are subject to change between minor\n * versions with only a changeset note. Hosts that need long-term\n * stability should depend on the facade (`ToolPolicyEngine` exported\n * from `./policy/engine`) instead.\n *\n * The split is intentional:\n * - `./policy/engine` — narrow, stable facade for common host\n * wiring and Svelte context.\n * - `./policy/internal` — wide, evolving surface for the\n * composition pipeline, PNP policy source, and\n * any host that wants to reach past the\n * facade.\n */\n\nexport {\n\tcomposeDecision,\n\ttype ComposeDecisionInputs,\n} from \"./core/compose-decision.js\";\n\nexport {\n\tPnpPolicySource,\n\ttype PnpPolicyApplyArgs,\n\ttype PnpPolicyDecisionEvent,\n\ttype PnpPolicyResult,\n\ttype PnpPolicyToolFlags,\n} from \"./sources/PnpPolicySource.js\";\n\nexport { ToolPolicyProvenanceBuilder } from \"./core/provenance.js\";\n\nexport {\n\tassessmentHasPnpPolicyInputs,\n\titemRefHasPnpPolicyInputs,\n\tresolveDefaultPnpEnforcement,\n} from \"./core/pnp-policy-inputs.js\";\n"]}