@pie-players/pie-assessment-toolkit 0.3.49 → 0.3.51

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ToolkitCoordinator.js","sourceRoot":"","sources":["../../src/services/ToolkitCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,EAON,oBAAoB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,+BAA+B,EAC/B,6BAA6B,GAE7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EACN,oCAAoC,GAEpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,iBAAiB,GAEjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAqC,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EACN,qBAAqB,EACrB,iBAAiB,EACjB,yBAAyB,GAEzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAS5E,OAAO,EACN,gBAAgB,GAOhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAiFrE,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE,CAC1E,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAA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CACD","sourcesContent":["/**\n * ToolkitCoordinator - Centralized Assessment Toolkit Service Management\n *\n * Orchestrates all toolkit services (TTS, tools, accessibility, state management) from a single entry point.\n * Provides centralized configuration for tool availability and settings.\n *\n * Key features:\n * - Owns all toolkit services (TTSService, ToolCoordinator, HighlightCoordinator, ElementToolStateStore, AccessibilityCatalogResolver)\n * - Single configuration point for tool availability and settings\n * - Sensible defaults for standalone usage\n * - Direct access for settings widgets (no player dependency)\n * - Clean separation: toolkit concerns only (NOT assessment state like navigation, timing, progress)\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type {\n\tAccessibilityCatalog,\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\nimport {\n\ttype CanonicalToolsConfig,\n\ttype ToolPlacementConfig,\n\ttype ToolPlacementLevel,\n\ttype ToolPolicyConfig,\n\ttype ToolProviderConfig,\n\ttype ToolProvidersConfig,\n\tnormalizeToolsConfig,\n} from \"./tools-config-normalizer.js\";\nimport {\n\tnormalizeAndValidateToolsConfig,\n\tnormalizeToolConfigStrictness,\n\ttype ToolConfigStrictness,\n} from \"./tool-config-validation.js\";\nimport { AccessibilityCatalogResolver } from \"./AccessibilityCatalogResolver.js\";\nimport { ElementToolStateStore } from \"./ElementToolStateStore.js\";\nimport {\n\tframeworkErrorFromCoordinatorContext,\n\ttype FrameworkErrorModel,\n} from \"./framework-error.js\";\nimport {\n\tFrameworkErrorBus,\n\ttype FrameworkErrorListener,\n} from \"./framework-error-bus.js\";\nimport { HighlightCoordinator } from \"./HighlightCoordinator.js\";\nimport { ToolCoordinator } from \"./ToolCoordinator.js\";\nimport { TTSService, type ITTSProvider, type TTSConfig } from \"./TTSService.js\";\nimport { BrowserTTSProvider } from \"./tts/browser-provider.js\";\nimport {\n\tbuildRuntimeTTSConfig,\n\tresolveTTSBackend,\n\tresolveTTSRuntimeSettings,\n\ttype TTSLayoutMode,\n} from \"./tts-runtime-config.js\";\nimport type { SREMathSpeechOptions } from \"./tts/math-speech.js\";\nimport { ToolProviderRegistry } from \"./tool-providers/index.js\";\nimport type { ToolProviderApi } from \"./tool-providers/ToolProviderApi.js\";\nimport type { TTSToolProviderConfig } from \"./tool-providers/index.js\";\nimport { createPackagedToolRegistry } from \"./createDefaultToolRegistry.js\";\nimport type {\n\tResolvedToolContext,\n\tToolContextResolver,\n\tToolContextResolverContext,\n\tToolContextResolverMap,\n\tToolRegistration,\n\tToolRegistry,\n} from \"./ToolRegistry.js\";\nimport {\n\tToolPolicyEngine,\n\ttype PnpEnforcementMode,\n\ttype PolicySource,\n\ttype ResolvedEngineInputs,\n\ttype ToolPolicyChangeListener,\n\ttype ToolPolicyDecision,\n\ttype ToolPolicyDecisionRequest,\n} from \"../policy/engine.js\";\nimport { resolveDefaultPnpEnforcement } from \"../policy/internal.js\";\nimport type {\n\tSectionControllerContext,\n\tSectionControllerEvent,\n\tSectionControllerEventType,\n\tSectionControllerFactoryDefaults,\n\tSectionControllerHandle,\n\tSectionControllerKey,\n\tSectionSessionPersistenceStrategy,\n\tSectionPersistenceFactoryDefaults,\n} from \"./section-controller-types.js\";\nexport type {\n\tSectionControllerContext,\n\tSectionControllerEvent,\n\tSectionControllerEventType,\n\tSectionControllerFactoryDefaults,\n\tSectionControllerHandle,\n\tSectionControllerKey,\n\tSectionControllerLoadedRenderable,\n\tSectionSessionPersistenceConfig,\n\tSectionSessionPersistenceStrategy,\n\tSectionControllerRuntimeState,\n\tSectionControllerSessionState,\n\tSectionPersistenceFactoryDefaults,\n} from \"./section-controller-types.js\";\nexport type {\n\tPnpEnforcementMode,\n\tResolvedEngineInputs,\n\tToolPolicyChangeListener,\n\tToolPolicyDecision,\n\tToolPolicyDecisionRequest,\n} from \"../policy/engine.js\";\n\n/**\n * Generic tool configuration\n */\nexport interface ToolConfig {\n\tenabled?: boolean;\n\tprovider?: unknown;\n\tsettings?: Record<string, unknown>;\n\t[key: string]: unknown;\n}\n\n/**\n * TTS tool configuration\n */\nexport interface TTSToolConfig extends ToolConfig {\n\tbackend?: \"browser\" | \"polly\" | \"google\" | \"server\";\n\tprovider?: \"polly\" | \"google\" | \"custom\";\n\tserverProvider?: \"polly\" | \"google\" | \"custom\";\n\tengine?: \"standard\" | \"neural\";\n\tsampleRate?: number;\n\tformat?: \"mp3\" | \"ogg\" | \"pcm\";\n\tspeechMarksMode?: \"word\" | \"word+sentence\";\n\tdefaultVoice?: string;\n\trate?: number;\n\tpitch?: number;\n\tapiEndpoint?: string;\n\tlanguage?: string;\n\ttransportMode?: \"pie\" | \"custom\";\n\tendpointMode?: \"synthesizePath\" | \"rootPost\";\n\tendpointValidationMode?: \"voices\" | \"endpoint\" | \"none\";\n\tincludeAuthOnAssetFetch?: boolean;\n\tvalidateEndpoint?: boolean;\n\tcache?: boolean;\n\tspeedRate?: \"slow\" | \"medium\" | \"fast\";\n\tlang_id?: string;\n\t/**\n\t * Optional inline TTS speed buttons.\n\t * - Omitted/non-array: default speed buttons are shown.\n\t * - Empty array: hide speed buttons.\n\t * - Arrays that sanitize to no valid values: default speed buttons are shown.\n\t */\n\tspeedOptions?: number[];\n\tlayoutMode?: TTSLayoutMode;\n\t/** Speech Rule Engine options for generated MathML speech. */\n\tmathSpeech?: SREMathSpeechOptions;\n\tsettings?: Record<string, unknown> & { mathSpeech?: SREMathSpeechOptions };\n\tauthFetcher?: () => Promise<Partial<TTSToolProviderConfig>>;\n}\n\nconst isPlainRecord = (value: unknown): value is Record<string, unknown> =>\n\t!!value && typeof value === \"object\" && !Array.isArray(value);\n\nconst mergeToolConfigUpdate = (\n\ttoolId: string,\n\tcurrent: ToolConfig,\n\tupdates: Partial<ToolProviderConfig> | Partial<TTSToolConfig>,\n): ToolConfig => {\n\tconst next = { ...current, ...updates };\n\tif (\n\t\ttoolId === \"textToSpeech\" &&\n\t\tisPlainRecord(current.settings) &&\n\t\tisPlainRecord(updates.settings)\n\t) {\n\t\tnext.settings = { ...current.settings, ...updates.settings };\n\t\tif (\n\t\t\tisPlainRecord(current.settings.mathSpeech) &&\n\t\t\tisPlainRecord(updates.settings.mathSpeech)\n\t\t) {\n\t\t\tnext.settings.mathSpeech = {\n\t\t\t\t...current.settings.mathSpeech,\n\t\t\t\t...updates.settings.mathSpeech,\n\t\t\t};\n\t\t}\n\t}\n\treturn next;\n};\n\n/**\n * Answer eliminator tool configuration\n */\nexport interface AnswerEliminatorToolConfig extends ToolConfig {\n\tstrategy?: \"strikethrough\" | \"hide\";\n}\n\nexport interface ToolkitToolsConfig extends CanonicalToolsConfig {\n\tpolicy: ToolPolicyConfig;\n\tplacement: Required<ToolPlacementConfig>;\n\tproviders: ToolProvidersConfig;\n}\n\n/**\n * Configuration for ToolkitCoordinator\n */\nexport interface ToolkitCoordinatorConfig {\n\t/**\n\t * Unique identifier for the assessment content.\n\t * Used for scoping tool state across sections.\n\t */\n\tassessmentId: string;\n\n\t/**\n\t * Tool availability and configuration.\n\t * Defaults: all tools enabled with default settings.\n\t */\n\ttools?: Partial<CanonicalToolsConfig>;\n\n\t/**\n\t * Validation strictness for tool config contracts.\n\t * - off: keep diagnostics internal (no warnings or throws)\n\t * - warn: log diagnostics and continue\n\t * - error: throw on diagnostics\n\t *\n\t * @default \"error\"\n\t */\n\ttoolConfigStrictness?: ToolConfigStrictness;\n\n\t/**\n\t * Optional registry used for tool-config validation and provider descriptor resolution.\n\t * Defaults to packaged PIE tools when omitted.\n\t */\n\ttoolRegistry?: ToolRegistry | null;\n\n\t/**\n\t * Host-owned per-tool render-context resolvers. These run after\n\t * framework policy gates (placement, provider config, host policy,\n\t * PNP/profile rules, and custom policy sources) and can hide a\n\t * surviving tool or attach render params for the tool registration.\n\t * They cannot re-enable a tool removed by policy.\n\t */\n\ttoolContextResolvers?: ToolContextResolverMap;\n\n\t/**\n\t * Accessibility configuration.\n\t * Includes QTI 3.0 accessibility catalogs and language settings.\n\t */\n\taccessibility?: {\n\t\tcatalogs?: AccessibilityCatalog[];\n\t\tlanguage?: string;\n\t};\n\n\t/**\n\t * Optional lifecycle and extension hooks for runtime customization.\n\t */\n\thooks?: ToolkitCoordinatorHooks;\n\n\t/**\n\t * Lazy initialization mode.\n\t * When true, async service/provider initialization is deferred until ensure methods are called.\n\t *\n\t * @default false\n\t */\n\tlazyInit?: boolean;\n\n\t/**\n\t * Internal bootstrap escape hatch used by framework-owned hosts.\n\t * When true, constructor skips throwing validation and expects caller\n\t * to pass a pre-validated tools config.\n\t *\n\t * @internal\n\t */\n\tdeferToolConfigValidation?: boolean;\n\n\t/**\n\t * Optional pre-constructed framework-error bus.\n\t *\n\t * Pass a bus owned by the embedding host (typically\n\t * `<pie-assessment-toolkit>`) when the host wants pre-coordinator\n\t * failures (e.g. `coordinator-init` itself) to flow through the same\n\t * fan-out as post-coordinator failures. When omitted, the coordinator\n\t * constructs its own private bus, which is what standalone embeds get.\n\t *\n\t * @internal\n\t */\n\tframeworkErrorBus?: FrameworkErrorBus;\n}\n\nexport interface ToolkitErrorContext {\n\tphase:\n\t\t| \"coordinator-ready\"\n\t\t| \"state-load\"\n\t\t| \"state-save\"\n\t\t| \"provider-register\"\n\t\t| \"provider-init\"\n\t\t| \"tts-init\"\n\t\t| \"section-controller-init\"\n\t\t| \"section-controller-dispose\";\n\tproviderId?: string;\n\tdetails?: Record<string, unknown>;\n}\n\nexport interface ProviderLifecycleContext {\n\tproviderId: string;\n\tproviderName?: string;\n}\n\nexport interface ToolkitInitStatus {\n\ttts: boolean;\n\tstateLoaded: boolean;\n\tcoordinator: boolean;\n\tproviders: Record<string, boolean>;\n}\n\nexport interface SectionControllerLifecycleEvent {\n\ttype: \"ready\" | \"disposed\";\n\tkey: SectionControllerKey;\n\tcontroller?: SectionControllerHandle;\n}\n\n/**\n * Subscribe-time arguments for {@link ToolkitCoordinator.subscribeSectionEvents}.\n *\n * Phase D contract: subscriptions follow the toolkit's *active section\n * cohort* automatically. The listener is bound to whatever section\n * controller is active at subscribe time and is migrated, with snapshot\n * replay, on every cohort transition. There is no per-subscription\n * `(sectionId, attemptId)` binding.\n */\nexport interface SectionEventSubscriptionArgs {\n\tlistener: (event: SectionControllerEvent) => void;\n\teventTypes?: readonly SectionControllerEventType[];\n\titemIds?: readonly string[];\n}\n\n/**\n * Internal Phase D subscription record. Holds a listener's filter args\n * and the disposer for whichever section controller it is currently\n * bound to. Detached and re-attached by the coordinator on every cohort\n * transition.\n *\n * @internal\n */\ninterface ActiveSectionSubscription {\n\tlistener: (event: SectionControllerEvent) => void;\n\teventTypes?: readonly SectionControllerEventType[];\n\titemIds?: readonly string[];\n\t/**\n\t * Disposer for the controller `subscribe(...)` call backing this\n\t * subscription, or `null` when no cohort is currently active. Cleared\n\t * on every detach so subsequent re-binds start from a clean slate.\n\t */\n\tunsubscribeCurrent: (() => void) | null;\n}\n\nexport type SectionItemEventType = Exclude<\n\tSectionControllerEventType,\n\t| \"section-navigation-change\"\n\t| \"section-session-applied\"\n\t| \"section-loading-complete\"\n\t| \"section-items-complete-changed\"\n\t| \"section-error\"\n>;\n\nexport type SectionScopedEventType = Extract<\n\tSectionControllerEventType,\n\t| \"section-navigation-change\"\n\t| \"section-session-applied\"\n\t| \"section-loading-complete\"\n\t| \"section-items-complete-changed\"\n\t| \"section-error\"\n>;\n\nexport type SectionItemEvent = Extract<\n\tSectionControllerEvent,\n\t{ type: SectionItemEventType }\n>;\n\nexport type SectionScopedEvent = Extract<\n\tSectionControllerEvent,\n\t{ type: SectionScopedEventType }\n>;\n\n/**\n * Subscribe-time arguments for {@link ToolkitCoordinator.subscribeItemEvents}.\n *\n * See {@link SectionEventSubscriptionArgs} for the Phase D active-cohort\n * binding contract.\n */\nexport interface SectionItemEventSubscriptionArgs {\n\tlistener: (event: SectionItemEvent) => void;\n\teventTypes?: readonly SectionItemEventType[];\n\titemIds?: readonly string[];\n}\n\n/**\n * Subscribe-time arguments for\n * {@link ToolkitCoordinator.subscribeSectionLifecycleEvents}.\n *\n * See {@link SectionEventSubscriptionArgs} for the Phase D active-cohort\n * binding contract.\n */\nexport interface SectionScopedEventSubscriptionArgs {\n\tlistener: (event: SectionScopedEvent) => void;\n\teventTypes?: readonly SectionScopedEventType[];\n}\n\nconst SECTION_ITEM_EVENT_TYPES: readonly SectionItemEventType[] = [\n\t\"item-selected\",\n\t\"item-session-data-changed\",\n\t\"item-session-meta-changed\",\n\t\"item-complete-changed\",\n\t\"content-loaded\",\n\t\"item-player-error\",\n];\n\nconst SECTION_SCOPED_EVENT_TYPES: readonly SectionScopedEventType[] = [\n\t\"section-navigation-change\",\n\t\"section-session-applied\",\n\t\"section-loading-complete\",\n\t\"section-items-complete-changed\",\n\t\"section-error\",\n];\n\nexport interface ToolkitCoordinatorHooks {\n\t/**\n\t * Canonical framework-error hook.\n\t *\n\t * Called once per framework-level failure (tool-config validation,\n\t * provider register / init, TTS bring-up, state load / save, section\n\t * controller init / dispose, coordinator init). The model carries the\n\t * canonical {@link FrameworkErrorModel} shape — `kind`, `severity`,\n\t * `source`, `message`, `details`, `recoverable`, and the original\n\t * thrown value as `cause`.\n\t *\n\t * Listeners should return synchronously and avoid throwing; a thrown\n\t * hook is caught and logged but does not stop fan-out to the other\n\t * subscribers (DOM event, prop callback, `subscribeFrameworkErrors`\n\t * listeners).\n\t */\n\tonFrameworkError?: (model: FrameworkErrorModel) => void;\n\n\tonBeforeTTSInit?: (context: ToolkitErrorContext) => void | Promise<void>;\n\tonTTSReady?: () => void | Promise<void>;\n\tonCoordinatorReady?: (\n\t\tcoordinator: ToolkitCoordinator,\n\t) => void | Promise<void>;\n\n\tonProviderRegistered?: (\n\t\tproviderId: string,\n\t\tmeta: ProviderLifecycleContext,\n\t) => void | Promise<void>;\n\tonProviderInitStart?: (\n\t\tproviderId: string,\n\t\tmeta: ProviderLifecycleContext,\n\t) => void | Promise<void>;\n\tonProviderReady?: (\n\t\tproviderId: string,\n\t\tmeta: ProviderLifecycleContext,\n\t) => void | Promise<void>;\n\n\tonTelemetry?: (\n\t\teventName: string,\n\t\tpayload?: Record<string, unknown>,\n\t) => void | Promise<void>;\n\n\tloadToolState?: () =>\n\t\t| Record<string, Record<string, unknown>>\n\t\t| Promise<Record<string, Record<string, unknown>> | null | undefined>\n\t\t| null\n\t\t| undefined;\n\tsaveToolState?: (\n\t\tstate: Record<string, Record<string, unknown>>,\n\t) => void | Promise<void>;\n\n\t/**\n\t * Provide section-level controller overrides only.\n\t * Avoid instantiating per-item controller graphs here unless item lifecycle\n\t * requirements explicitly demand it.\n\t */\n\tcreateSectionController?: (\n\t\tcontext: SectionControllerContext,\n\t\tdefaults: SectionControllerFactoryDefaults,\n\t) => SectionControllerHandle | Promise<SectionControllerHandle>;\n\n\tcreateSectionSessionPersistence?: (\n\t\tcontext: SectionControllerContext,\n\t\tdefaults: SectionPersistenceFactoryDefaults,\n\t) =>\n\t\t| SectionSessionPersistenceStrategy\n\t\t| Promise<SectionSessionPersistenceStrategy>;\n\n\tonSectionControllerReady?: (\n\t\tcontext: SectionControllerContext,\n\t\tcontroller: SectionControllerHandle,\n\t) => void | Promise<void>;\n\n\tonSectionControllerDispose?: (\n\t\tcontext: SectionControllerContext,\n\t\tcontroller: SectionControllerHandle,\n\t) => void | Promise<void>;\n}\n\nexport type ToolkitTelemetryListener = (args: {\n\teventName: string;\n\tpayload?: Record<string, unknown>;\n}) => void;\n\n/**\n * Service bundle returned by getServiceBundle()\n */\nexport interface ToolkitServiceBundle {\n\tttsService: TTSService;\n\ttoolCoordinator: ToolCoordinator;\n\thighlightCoordinator: HighlightCoordinator;\n\telementToolStateStore: ElementToolStateStore;\n\tcatalogResolver: AccessibilityCatalogResolver;\n\ttoolProviderRegistry: ToolProviderRegistry;\n}\n\n/**\n * ToolkitCoordinator - Orchestrates all assessment toolkit services\n *\n * @example\n * ```typescript\n * // Create coordinator with configuration\n * const coordinator = new ToolkitCoordinator({\n * assessmentId: 'demo-three-questions',\n * tools: {\n * providers: {\n * textToSpeech: { enabled: true, defaultVoice: 'en-US' },\n * answerEliminator: { enabled: true, strategy: 'strikethrough' }\n * },\n * placement: {\n * item: ['textToSpeech', 'answerEliminator']\n * }\n * }\n * });\n *\n * // Pass to section player\n * player.toolkitCoordinator = coordinator;\n *\n * // Access services directly\n * const ttsService = coordinator.ttsService;\n * const toolState = coordinator.elementToolStateStore.getAllState();\n * ```\n */\nexport class ToolkitCoordinator {\n\t/** Assessment identifier (for scoping tool state) */\n\treadonly assessmentId: string;\n\n\t/** Configuration */\n\treadonly config: ToolkitCoordinatorConfig;\n\n\t/** Managed services (public for direct access) */\n\treadonly ttsService: TTSService;\n\treadonly toolCoordinator: ToolCoordinator;\n\treadonly highlightCoordinator: HighlightCoordinator;\n\treadonly elementToolStateStore: ElementToolStateStore;\n\treadonly catalogResolver: AccessibilityCatalogResolver;\n\treadonly toolProviderRegistry: ToolProviderRegistry;\n\treadonly hooks: ToolkitCoordinatorHooks;\n\treadonly lazyInit: boolean;\n\n\t/** Track TTS initialization state */\n\tprivate ttsInitialized = false;\n\tprivate ttsInitPromise?: Promise<void>;\n\tprivate ttsReconfigurePromise?: Promise<void>;\n\tprivate stateLoaded = false;\n\tprivate stateLoadPromise?: Promise<void>;\n\tprivate coordinatorReadyPromise?: Promise<void>;\n\tprivate coordinatorReadyNotified = false;\n\tprivate readonly providerInitPromises = new Map<\n\t\tstring,\n\t\tPromise<ToolProviderApi>\n\t>();\n\tprivate readonly toolRegistry: ToolRegistry;\n\tprivate readonly toolContextResolvers = new Map<\n\t\tstring,\n\t\tToolContextResolver\n\t>();\n\tprivate readonly toolContextResolverChangeListeners = new Set<() => void>();\n\tprivate readonly sectionControllers = new Map<\n\t\tstring,\n\t\tSectionControllerHandle\n\t>();\n\tprivate readonly sectionControllerKeys = new Map<\n\t\tstring,\n\t\tSectionControllerKey\n\t>();\n\tprivate readonly sectionControllerInitPromises = new Map<\n\t\tstring,\n\t\tPromise<SectionControllerHandle>\n\t>();\n\tprivate readonly sectionPersistenceStrategies = new Map<\n\t\tstring,\n\t\tSectionSessionPersistenceStrategy\n\t>();\n\tprivate readonly sectionControllerLifecycleListeners = new Set<\n\t\t(event: SectionControllerLifecycleEvent) => void\n\t>();\n\t/**\n\t * Phase D: every active section-event subscription, indexed by\n\t * listener identity. The listener follows the toolkit's active\n\t * section cohort across transitions; this map is the registry the\n\t * coordinator iterates on every cohort change to detach the listener\n\t * from the outgoing controller, attach it to the new one, and replay\n\t * the snapshot (content-loaded × N then section-loading-complete) in\n\t * canonical order.\n\t *\n\t * Dedup is by listener identity: subscribing the same listener\n\t * function twice replaces the prior subscription's filter args.\n\t */\n\tprivate readonly activeSubscriptions = new Map<\n\t\t(event: SectionControllerEvent) => void,\n\t\tActiveSectionSubscription\n\t>();\n\t/**\n\t * Phase D: map key of the section controller currently treated as\n\t * the *active cohort*. Set by `getOrCreateSectionController` (both\n\t * the create-new and resolve-existing paths) and cleared when the\n\t * matching controller is disposed. `null` while no cohort exists,\n\t * which is the only state where `subscribeSectionEvents` throws.\n\t */\n\tprivate activeCohortMapKey: string | null = null;\n\t/**\n\t * Latest requested active cohort. Async controller initialization can\n\t * resolve out of order; only the most recent request may migrate active\n\t * subscriptions. Older completions still populate the controller cache.\n\t */\n\tprivate latestRequestedActiveCohortMapKey: string | null = null;\n\tprivate readonly telemetryListeners = new Set<ToolkitTelemetryListener>();\n\tprivate readonly frameworkErrorBus: FrameworkErrorBus;\n\tprivate readonly ownsFrameworkErrorBus: boolean;\n\n\t/**\n\t * Unified Tool Policy Engine. Owned by the coordinator and lives\n\t * for the lifetime of the coordinator instance — there is no\n\t * explicit teardown path today; the engine and its listener set\n\t * are reclaimed by GC when the coordinator becomes unreachable.\n\t * Subscribers attached via {@link onPolicyChange} must therefore\n\t * detach via the unsubscribe function the engine returns; do not\n\t * rely on a `disposed` event being emitted on coordinator teardown.\n\t *\n\t * Hosts read decisions via {@link decideToolPolicy} or subscribe\n\t * to changes via {@link onPolicyChange}.\n\t */\n\tprivate readonly policyEngine: ToolPolicyEngine;\n\n\t/**\n\t * Host-set override for PNP/profile enforcement. `null` (the default) means\n\t * \"auto\" — the coordinator infers the effective mode from the\n\t * PNP/profile policy inputs the bound `AssessmentEntity` and `AssessmentItemRef`\n\t * actually carry (see {@link resolveEffectivePnpEnforcement}).\n\t * `\"on\"` / `\"off\"` are explicit host opt-in / opt-out and stick\n\t * across subsequent assessment / item swaps until the host clears\n\t * the override by calling `setPnpEnforcement(null)`.\n\t */\n\tprivate pnpEnforcementOverride: PnpEnforcementMode | null = null;\n\n\t/**\n\t * Last assessment passed to {@link updateAssessment}. Read by\n\t * {@link resolveEffectivePnpEnforcement} to compute auto-mode.\n\t * The engine's own copy is the canonical record for decisions;\n\t * this mirror exists only so the auto-mode helper does not need\n\t * to round-trip through {@link policyEngine}'s frozen snapshot.\n\t */\n\tprivate boundAssessment: AssessmentEntity | null = null;\n\n\t/**\n\t * Last item reference passed to {@link updateCurrentItemRef}.\n\t * Mirrored alongside {@link boundAssessment} so\n\t * {@link resolveEffectivePnpEnforcement} can detect item-level\n\t * profile policy inputs (`requiredTools` / `restrictedTools` /\n\t * `toolParameters`) without round-tripping through the engine's\n\t * frozen snapshot.\n\t */\n\tprivate boundCurrentItemRef: AssessmentItemRef | null = null;\n\n\tprivate static resolveConfig(\n\t\tconfig: ToolkitCoordinatorConfig,\n\t): ToolkitCoordinatorConfig {\n\t\tconst strictness = normalizeToolConfigStrictness(\n\t\t\tconfig.toolConfigStrictness,\n\t\t);\n\t\tconst toolRegistry = config.toolRegistry ?? createPackagedToolRegistry();\n\t\tconst normalized =\n\t\t\tconfig.deferToolConfigValidation === true\n\t\t\t\t? normalizeToolsConfig(config.tools as any)\n\t\t\t\t: normalizeAndValidateToolsConfig(config.tools as any, {\n\t\t\t\t\t\tstrictness,\n\t\t\t\t\t\tsource: \"ToolkitCoordinator.init\",\n\t\t\t\t\t\ttoolRegistry,\n\t\t\t\t\t}).config;\n\t\tconst defaultProviders: ToolkitToolsConfig[\"providers\"] = {\n\t\t\ttextToSpeech: {\n\t\t\t\tenabled: true,\n\t\t\t\tbackend: \"browser\",\n\t\t\t},\n\t\t\tannotationToolbar: {\n\t\t\t\tenabled: true,\n\t\t\t},\n\t\t};\n\n\t\treturn {\n\t\t\t...config,\n\t\t\ttoolConfigStrictness: strictness,\n\t\t\ttoolRegistry,\n\t\t\ttools: {\n\t\t\t\t...normalized,\n\t\t\t\tproviders: {\n\t\t\t\t\t...defaultProviders,\n\t\t\t\t\t...normalized.providers,\n\t\t\t\t},\n\t\t\t},\n\t\t\taccessibility: {\n\t\t\t\tlanguage: \"en-US\",\n\t\t\t\t...(config.accessibility ?? {}),\n\t\t\t\tcatalogs: config.accessibility?.catalogs ?? [],\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor(config: ToolkitCoordinatorConfig) {\n\t\tif (!config.assessmentId) {\n\t\t\tthrow new Error(\"ToolkitCoordinator requires assessmentId in config\");\n\t\t}\n\n\t\tconst resolvedConfig = ToolkitCoordinator.resolveConfig(config);\n\n\t\tthis.assessmentId = resolvedConfig.assessmentId;\n\t\tthis.config = resolvedConfig;\n\t\tthis.toolRegistry =\n\t\t\tresolvedConfig.toolRegistry ?? createPackagedToolRegistry();\n\t\tthis.installToolContextResolvers(resolvedConfig.toolContextResolvers);\n\t\tthis.hooks = resolvedConfig.hooks ?? {};\n\t\tthis.lazyInit = config.lazyInit === true;\n\t\tthis.pnpEnforcementOverride = this.resolveConfiguredPnpEnforcement();\n\n\t\t// Use the host-provided framework-error bus if one was passed\n\t\t// (typical when embedded inside <pie-assessment-toolkit>, so\n\t\t// pre-coordinator failures from the CE flow through the same\n\t\t// fan-out as coordinator failures). Otherwise own a private one.\n\t\tthis.frameworkErrorBus =\n\t\t\tconfig.frameworkErrorBus ?? new FrameworkErrorBus();\n\t\tthis.ownsFrameworkErrorBus = !config.frameworkErrorBus;\n\t\tthis.subscribeFrameworkErrorHookAdapters();\n\n\t\t// Initialize all services\n\t\tthis.toolCoordinator = new ToolCoordinator();\n\t\tthis.highlightCoordinator = new HighlightCoordinator();\n\t\tthis.elementToolStateStore = new ElementToolStateStore();\n\t\tthis.catalogResolver = new AccessibilityCatalogResolver(\n\t\t\tresolvedConfig.accessibility?.catalogs || [],\n\t\t\tresolvedConfig.accessibility?.language || \"en-US\",\n\t\t);\n\n\t\t// Initialize tool provider registry\n\t\tthis.toolProviderRegistry = new ToolProviderRegistry();\n\t\tthis._registerToolProviders();\n\n\t\t// Initialize TTS service based on config\n\t\tthis.ttsService = new TTSService();\n\t\tthis.setupStatePersistenceHooks();\n\n\t\t// M8 PR 2 — construct the unified ToolPolicyEngine seeded with\n\t\t// the validated tools config. PNP/profile inputs (`assessment`,\n\t\t// `currentItemRef`) start `null`; `pnpEnforcement` is resolved\n\t\t// through {@link resolveEffectivePnpEnforcement}, which flips\n\t\t// to `\"on\"` only once the bound assessment or item carries\n\t\t// actual profile material. Hosts that only consume the\n\t\t// engine for placement/policy gating get the pre-PR-2 behavior\n\t\t// bit-for-bit.\n\t\tthis.policyEngine = new ToolPolicyEngine({\n\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\tcontextId: `toolkit-coordinator:${this.assessmentId}`,\n\t\t\tinputs: {\n\t\t\t\ttools: this.config.tools as CanonicalToolsConfig,\n\t\t\t\tassessment: null,\n\t\t\t\tcurrentItemRef: null,\n\t\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t\t},\n\t\t});\n\n\t\tif (!this.lazyInit) {\n\t\t\tvoid this.waitUntilReady().catch((err) => {\n\t\t\t\tconsole.error(\"[ToolkitCoordinator] Failed eager initialization:\", err);\n\t\t\t\tthis.handleError(err, { phase: \"coordinator-ready\" });\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Subscribe the canonical `onFrameworkError` hook adapter to the\n\t * framework-error bus.\n\t *\n\t * Called once from the constructor. The adapter inspects the live\n\t * `this.hooks` reference, so a hook added later via {@link setHooks}\n\t * is picked up automatically without re-subscribing.\n\t */\n\tprivate subscribeFrameworkErrorHookAdapters(): void {\n\t\tthis.frameworkErrorBus.subscribeFrameworkErrors((model) => {\n\t\t\tconst hook = this.hooks.onFrameworkError;\n\t\t\tif (!hook) return;\n\t\t\ttry {\n\t\t\t\thook(model);\n\t\t\t} catch (hookError) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] onFrameworkError hook failed:\",\n\t\t\t\t\thookError,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Emit a telemetry event to `onTelemetry` hook + all `subscribeTelemetry`\n\t * listeners.\n\t *\n\t * **Naming convention.** Event names MUST be prefixed at the call site,\n\t * not auto-decorated here. The convention is:\n\t *\n\t * - `pie-toolkit-*` for toolkit lifecycle (state load, providers,\n\t * coordinator readiness, section-controller register/dispose, TTS\n\t * bring-up, tool-config updates, etc.).\n\t * - `pie-tool-*` for individual tool events (provider init lifecycle,\n\t * provider backend calls, tool-specific telemetry forwarded from\n\t * `__pieTelemetry`).\n\t * - `pie-section-*` is reserved for section-player layout events\n\t * surfaced via `attachInstrumentationEventBridge` and is not emitted\n\t * from this method directly.\n\t *\n\t * Anything that does not fit a documented prefix is a deliberate decision\n\t * to be raised in code review, not a fallback. There is no \"auto prefix\"\n\t * here on purpose: it keeps every emit-site honest about which namespace\n\t * it owns, and lets `subscribeTelemetry` consumers compare against\n\t * documented strings without per-consumer normalization.\n\t */\n\tprivate async emitTelemetry(\n\t\teventName: string,\n\t\tpayload?: Record<string, unknown>,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait this.hooks.onTelemetry?.(eventName, payload);\n\t\t} catch (err) {\n\t\t\tconsole.warn(\"[ToolkitCoordinator] telemetry hook failed:\", err);\n\t\t}\n\t\tconst nextPayload = payload ? { ...payload } : undefined;\n\t\tfor (const listener of this.telemetryListeners) {\n\t\t\ttry {\n\t\t\t\tlistener({\n\t\t\t\t\teventName,\n\t\t\t\t\tpayload: nextPayload ? { ...nextPayload } : undefined,\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\tconsole.warn(\"[ToolkitCoordinator] telemetry listener failed:\", err);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate emitSectionControllerLifecycle(\n\t\tevent: SectionControllerLifecycleEvent,\n\t): void {\n\t\tfor (const listener of this.sectionControllerLifecycleListeners) {\n\t\t\ttry {\n\t\t\t\tlistener(event);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] section controller lifecycle listener failed:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleError(error: unknown, context: ToolkitErrorContext): void {\n\t\tconst model = frameworkErrorFromCoordinatorContext({\n\t\t\terror,\n\t\t\tcontext,\n\t\t});\n\t\tthis.frameworkErrorBus.reportFrameworkError(model);\n\t}\n\n\t/**\n\t * Subscribe to framework-error events emitted by this coordinator.\n\t *\n\t * See `ToolkitCoordinatorApi.subscribeFrameworkErrors` for the\n\t * contract. The bus is shared with the canonical\n\t * `onFrameworkError` lifecycle hook, so a listener registered here\n\t * sees the same fan-out the hook sees.\n\t */\n\tpublic subscribeFrameworkErrors(\n\t\tlistener: FrameworkErrorListener,\n\t): () => void {\n\t\treturn this.frameworkErrorBus.subscribeFrameworkErrors(listener);\n\t}\n\n\t/**\n\t * Report a framework-error model directly into this coordinator's bus.\n\t *\n\t * Used by embedding hosts (e.g. `<pie-assessment-toolkit>`) that\n\t * pre-construct their own framework-error model in a path that does\n\t * not go through `handleError` — for example, `runtime-init` failures\n\t * raised before any coordinator phase, or `tool-config` failures\n\t * synthesized from validation diagnostics.\n\t *\n\t * Hosts that already share their bus via the constructor's\n\t * `frameworkErrorBus` config field do not need to call this; their\n\t * own `bus.reportFrameworkError(model)` is observed here.\n\t *\n\t * @internal\n\t */\n\tpublic reportFrameworkError(model: FrameworkErrorModel): void {\n\t\tthis.frameworkErrorBus.reportFrameworkError(model);\n\t}\n\n\tprivate getSectionControllerMapKey(key: SectionControllerKey): string {\n\t\treturn `${key.assessmentId}::${key.sectionId}::${key.attemptId || \"\"}`;\n\t}\n\n\tprivate createDefaultSectionPersistence(): SectionSessionPersistenceStrategy {\n\t\tconst storage = (() => {\n\t\t\ttry {\n\t\t\t\tif (typeof window === \"undefined\") return null;\n\t\t\t\treturn window.localStorage;\n\t\t\t} catch {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t})();\n\t\tconst getStorageKey = (context: SectionControllerContext): string => {\n\t\t\tconst { assessmentId, sectionId, attemptId } = context.key;\n\t\t\treturn `pie:section-controller:v1:${assessmentId}:${sectionId}:${attemptId || \"default\"}`;\n\t\t};\n\t\treturn {\n\t\t\tasync loadSession(context) {\n\t\t\t\tif (!storage) return null;\n\t\t\t\tconst value = storage.getItem(getStorageKey(context));\n\t\t\t\tif (!value) return null;\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(value);\n\t\t\t\t} catch {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync saveSession(context, session) {\n\t\t\t\tif (!storage) return;\n\t\t\t\tstorage.setItem(getStorageKey(context), JSON.stringify(session));\n\t\t\t},\n\t\t\tasync clearSession(context) {\n\t\t\t\tif (!storage) return;\n\t\t\t\tstorage.removeItem(getStorageKey(context));\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async resolveSectionPersistence(\n\t\tcontext: SectionControllerContext,\n\t): Promise<SectionSessionPersistenceStrategy> {\n\t\tconst cacheKey = this.getSectionControllerMapKey(context.key);\n\t\tconst existing = this.sectionPersistenceStrategies.get(cacheKey);\n\t\tif (existing) return existing;\n\n\t\tconst defaults: SectionPersistenceFactoryDefaults = {\n\t\t\tcreateDefaultPersistence: () => this.createDefaultSectionPersistence(),\n\t\t};\n\t\tconst strategy =\n\t\t\t(await this.hooks.createSectionSessionPersistence?.(context, defaults)) ??\n\t\t\t(await defaults.createDefaultPersistence());\n\t\tthis.sectionPersistenceStrategies.set(cacheKey, strategy);\n\t\treturn strategy;\n\t}\n\n\tprivate setupStatePersistenceHooks(): void {\n\t\tthis.elementToolStateStore.setOnStateChange((state) => {\n\t\t\tif (!this.hooks.saveToolState) return;\n\t\t\tvoid Promise.resolve(this.hooks.saveToolState(state)).catch((err) => {\n\t\t\t\tthis.handleError(err, { phase: \"state-save\" });\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate async ensureStateLoaded(): Promise<void> {\n\t\tif (this.stateLoaded) return;\n\t\tif (this.stateLoadPromise) return this.stateLoadPromise;\n\t\tthis.stateLoadPromise = (async () => {\n\t\t\tconst loader = this.hooks.loadToolState;\n\t\t\tif (!loader) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst state = await loader();\n\t\t\t\tif (state && typeof state === \"object\") {\n\t\t\t\t\tthis.elementToolStateStore.loadState(state);\n\t\t\t\t}\n\t\t\t\tthis.stateLoaded = true;\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-tool-state-loaded\", {\n\t\t\t\t\thasState: Boolean(state),\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\tthis.handleError(err, { phase: \"state-load\" });\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tthis.stateLoadPromise = undefined;\n\t\t});\n\t\treturn this.stateLoadPromise;\n\t}\n\n\t/**\n\t * Register tool providers in the registry\n\t */\n\tprivate _registerToolProviders(): void {\n\t\tconst descriptorTools = this.getProviderDescriptorTools();\n\t\tfor (const tool of descriptorTools) {\n\t\t\tvoid this.registerProviderFromTool(tool);\n\t\t}\n\t}\n\n\tprivate getProviderDescriptorTools(): ToolRegistration[] {\n\t\treturn this.toolRegistry.getAllTools().filter((tool) => !!tool.provider);\n\t}\n\n\tprivate async registerProviderFromTool(\n\t\ttool: ToolRegistration,\n\t): Promise<void> {\n\t\tconst descriptor = tool.provider;\n\t\tif (!descriptor) return;\n\t\tconst toolConfig = this.getToolConfig(tool.toolId) || undefined;\n\t\tif (toolConfig?.enabled === false) return;\n\t\tconst providerId =\n\t\t\tdescriptor.getProviderId?.(toolConfig) ??\n\t\t\ttoolConfig?.provider?.id ??\n\t\t\ttool.toolId;\n\t\tif (this.toolProviderRegistry.has(providerId)) return;\n\t\tconst provider = descriptor.createProvider(toolConfig);\n\t\tconst initConfig =\n\t\t\tdescriptor.getInitConfig?.(toolConfig) ??\n\t\t\ttoolConfig?.provider?.init ??\n\t\t\t{};\n\t\tconst initConfigWithTelemetry = this.addToolTelemetryReporter({\n\t\t\ttoolId: tool.toolId,\n\t\t\tproviderId,\n\t\t\tinitConfig,\n\t\t});\n\t\tconst registryTelemetry = this.createToolTelemetryForwarder({\n\t\t\ttoolId: tool.toolId,\n\t\t\tproviderId,\n\t\t});\n\t\tconst authFetcher =\n\t\t\tdescriptor.getAuthFetcher?.(toolConfig) ??\n\t\t\ttoolConfig?.provider?.runtime?.authFetcher;\n\t\tawait this.registerProvider(providerId, {\n\t\t\tprovider,\n\t\t\tconfig: initConfigWithTelemetry,\n\t\t\tlazy: descriptor.lazy ?? true,\n\t\t\tauthFetcher,\n\t\t\tonTelemetry: registryTelemetry,\n\t\t});\n\t}\n\n\tprivate createToolTelemetryForwarder(args: {\n\t\ttoolId: string;\n\t\tproviderId: string;\n\t}): (eventName: string, payload?: Record<string, unknown>) => Promise<void> {\n\t\treturn async (eventName: string, payload?: Record<string, unknown>) => {\n\t\t\tawait this.emitTelemetry(eventName, {\n\t\t\t\t...(payload || {}),\n\t\t\t\ttoolId: args.toolId,\n\t\t\t\tproviderId: args.providerId,\n\t\t\t});\n\t\t};\n\t}\n\n\tprivate addToolTelemetryReporter(args: {\n\t\ttoolId: string;\n\t\tproviderId: string;\n\t\tinitConfig: unknown;\n\t}): Record<string, unknown> {\n\t\tconst configObject =\n\t\t\targs.initConfig && typeof args.initConfig === \"object\"\n\t\t\t\t? { ...(args.initConfig as Record<string, unknown>) }\n\t\t\t\t: {};\n\t\tconst existingReporter =\n\t\t\ttypeof configObject.onTelemetry === \"function\"\n\t\t\t\t? (configObject.onTelemetry as (\n\t\t\t\t\t\teventName: string,\n\t\t\t\t\t\tpayload?: Record<string, unknown>,\n\t\t\t\t\t) => void | Promise<void>)\n\t\t\t\t: null;\n\t\tconst forwardTelemetry = this.createToolTelemetryForwarder({\n\t\t\ttoolId: args.toolId,\n\t\t\tproviderId: args.providerId,\n\t\t});\n\t\tconfigObject.onTelemetry = async (\n\t\t\teventName: string,\n\t\t\tpayload?: Record<string, unknown>,\n\t\t) => {\n\t\t\tif (existingReporter) {\n\t\t\t\tawait existingReporter(eventName, payload);\n\t\t\t}\n\t\t\tawait forwardTelemetry(eventName, payload);\n\t\t};\n\t\treturn configObject;\n\t}\n\n\tprivate async registerProvider(\n\t\tproviderId: string,\n\t\tconfig: Parameters<ToolProviderRegistry[\"register\"]>[1],\n\t): Promise<void> {\n\t\ttry {\n\t\t\tthis.toolProviderRegistry.register(providerId, config);\n\t\t\tconst meta: ProviderLifecycleContext = {\n\t\t\t\tproviderId,\n\t\t\t\tproviderName: config.provider.providerName,\n\t\t\t};\n\t\t\tawait this.hooks.onProviderRegistered?.(providerId, meta);\n\t\t\tawait this.emitTelemetry(\"pie-toolkit-provider-registered\", {\n\t\t\t\tproviderId,\n\t\t\t\tproviderName: config.provider.providerName,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tconsole.warn(\n\t\t\t\t`[ToolkitCoordinator] Failed to register provider \"${providerId}\":`,\n\t\t\t\terr,\n\t\t\t);\n\t\t\tthis.handleError(err, { phase: \"provider-register\", providerId });\n\t\t}\n\t}\n\n\tpublic async ensureProviderReady(\n\t\tproviderId: string,\n\t): Promise<ToolProviderApi> {\n\t\tconst existing = this.providerInitPromises.get(providerId);\n\t\tif (existing) return existing;\n\t\tconst promise = (async () => {\n\t\t\tconst provider = await this.toolProviderRegistry.getProvider(\n\t\t\t\tproviderId,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tconst meta: ProviderLifecycleContext = {\n\t\t\t\tproviderId,\n\t\t\t\tproviderName: provider.providerName,\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tawait this.hooks.onProviderInitStart?.(providerId, meta);\n\t\t\t\tawait this.toolProviderRegistry.initialize(providerId);\n\t\t\t\tawait this.hooks.onProviderReady?.(providerId, meta);\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-provider-ready\", { providerId });\n\t\t\t\treturn provider;\n\t\t\t} catch (err) {\n\t\t\t\tconst error = err instanceof Error ? err : new Error(String(err));\n\t\t\t\tthis.handleError(error, { phase: \"provider-init\", providerId });\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tthis.providerInitPromises.delete(providerId);\n\t\t});\n\t\tthis.providerInitPromises.set(providerId, promise);\n\t\treturn promise;\n\t}\n\n\tpublic setHooks(hooks: ToolkitCoordinatorHooks): void {\n\t\tObject.assign(this.hooks, hooks);\n\t\tthis.setupStatePersistenceHooks();\n\n\t\tif (hooks.onCoordinatorReady && this.isReady()) {\n\t\t\tvoid Promise.resolve(hooks.onCoordinatorReady(this)).catch((err) => {\n\t\t\t\tthis.handleError(err, { phase: \"coordinator-ready\" });\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic subscribeTelemetry(listener: ToolkitTelemetryListener): () => void {\n\t\tthis.telemetryListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.telemetryListeners.delete(listener);\n\t\t};\n\t}\n\n\tpublic getSectionController(args: {\n\t\tsectionId: string;\n\t\tattemptId?: string;\n\t}): SectionControllerHandle | undefined {\n\t\tconst key: SectionControllerKey = {\n\t\t\tassessmentId: this.assessmentId,\n\t\t\tsectionId: args.sectionId,\n\t\t\tattemptId: args.attemptId,\n\t\t};\n\t\treturn this.sectionControllers.get(this.getSectionControllerMapKey(key));\n\t}\n\n\tpublic subscribeSectionEvents(\n\t\targs: SectionEventSubscriptionArgs,\n\t): () => void {\n\t\t// Phase D: subscriptions follow the toolkit's *active section\n\t\t// cohort* automatically. We bind the listener to whichever\n\t\t// controller is currently active and re-bind it on every\n\t\t// `getOrCreateSectionController` / `disposeSectionController`\n\t\t// transition, with snapshot replay on each migration.\n\t\tif (this.activeCohortMapKey === null) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[ToolkitCoordinator] subscribeSectionEvents requires an active section cohort; call getOrCreateSectionController first.\",\n\t\t\t);\n\t\t}\n\t\tconst previous = this.activeSubscriptions.get(args.listener);\n\t\tif (previous) {\n\t\t\tprevious.unsubscribeCurrent?.();\n\t\t\tprevious.unsubscribeCurrent = null;\n\t\t}\n\t\tconst sub: ActiveSectionSubscription = {\n\t\t\tlistener: args.listener,\n\t\t\teventTypes: args.eventTypes,\n\t\t\titemIds: args.itemIds,\n\t\t\tunsubscribeCurrent: null,\n\t\t};\n\t\tthis.activeSubscriptions.set(args.listener, sub);\n\n\t\tconst controller = this.sectionControllers.get(this.activeCohortMapKey);\n\t\tif (controller) {\n\t\t\tthis.bindSubscriptionToController(sub, controller);\n\t\t}\n\n\t\tlet detached = false;\n\t\treturn () => {\n\t\t\tif (detached) return;\n\t\t\tdetached = true;\n\t\t\tsub.unsubscribeCurrent?.();\n\t\t\tsub.unsubscribeCurrent = null;\n\t\t\t// Only delete if the registry still points at *this* sub. A\n\t\t\t// re-subscribe with the same listener replaces the entry; an\n\t\t\t// old disposer must not stomp the new one.\n\t\t\tif (this.activeSubscriptions.get(args.listener) === sub) {\n\t\t\t\tthis.activeSubscriptions.delete(args.listener);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Bind a Phase D subscription to a section controller. Detaches any\n\t * prior controller binding the subscription was holding, attaches a\n\t * fresh `controller.subscribe(...)` callback, and replays the\n\t * canonical late-subscribe sequence (content-loaded × N then\n\t * section-loading-complete) so the listener observes the same\n\t * ordering a fresh subscriber would have seen.\n\t *\n\t * Listener throws are caught and `console.warn`-logged; the throw\n\t * does not interrupt fan-out to the remaining listeners (matches\n\t * the {@link FrameworkErrorBus} isolation pattern).\n\t */\n\tprivate bindSubscriptionToController(\n\t\tsub: ActiveSectionSubscription,\n\t\tcontroller: SectionControllerHandle,\n\t): void {\n\t\tsub.unsubscribeCurrent?.();\n\t\tsub.unsubscribeCurrent = null;\n\n\t\tconst subscribe = controller.subscribe;\n\t\tif (typeof subscribe !== \"function\") return;\n\n\t\tconst predicate = this.buildSectionEventPredicate(sub);\n\n\t\tsub.unsubscribeCurrent = subscribe.call(controller, (event) => {\n\t\t\tif (!predicate(event)) return;\n\t\t\tthis.deliverSectionEventSafely(sub.listener, event);\n\t\t});\n\n\t\tconst contentLoadedReplays =\n\t\t\tthis.buildContentLoadedReplayEvents(controller);\n\t\tfor (const event of contentLoadedReplays) {\n\t\t\tif (predicate(event)) {\n\t\t\t\tthis.deliverSectionEventSafely(sub.listener, event);\n\t\t\t}\n\t\t}\n\t\tconst loadingComplete = this.buildLoadingCompleteReplayEvent(controller);\n\t\tif (loadingComplete && predicate(loadingComplete)) {\n\t\t\tthis.deliverSectionEventSafely(sub.listener, loadingComplete);\n\t\t}\n\t}\n\n\tprivate deliverSectionEventSafely(\n\t\tlistener: (event: SectionControllerEvent) => void,\n\t\tevent: SectionControllerEvent,\n\t): void {\n\t\ttry {\n\t\t\tlistener(event);\n\t\t} catch (error) {\n\t\t\tconsole.warn(\n\t\t\t\t\"[ToolkitCoordinator] section-event listener failed:\",\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Mark the given map key as the active section cohort. Called from\n\t * `getOrCreateSectionController` (both create-new and resolve-existing\n\t * paths) so a cohort transition through either path migrates active\n\t * subscriptions.\n\t *\n\t * Same-cohort re-entry is a no-op so a same-cohort `updateInput`\n\t * (PnP toggle, prompt edit) doesn't double-replay snapshots to\n\t * already-bound listeners.\n\t */\n\tprivate setActiveCohort(mapKey: string): void {\n\t\tif (this.activeCohortMapKey === mapKey) return;\n\t\tthis.activeCohortMapKey = mapKey;\n\t\tconst controller = this.sectionControllers.get(mapKey);\n\t\tif (!controller) return;\n\t\t// Snapshot the subscription list before iterating: a listener may\n\t\t// synchronously call `subscribeSectionEvents(...)` from inside its\n\t\t// replay delivery, which inserts a new entry into\n\t\t// `activeSubscriptions`. Map iteration yields keys inserted\n\t\t// during the loop; without snapshotting, the inner subscribe path\n\t\t// would bind the new listener once (correctly, with replay) and\n\t\t// the outer loop would then visit it a second time, double-\n\t\t// replaying the snapshot. Snapshot keeps \"replay once per cohort\n\t\t// transition\" intact.\n\t\tfor (const sub of Array.from(this.activeSubscriptions.values())) {\n\t\t\tthis.bindSubscriptionToController(sub, controller);\n\t\t}\n\t}\n\n\tprivate setActiveCohortIfLatestRequest(mapKey: string): void {\n\t\tif (this.latestRequestedActiveCohortMapKey !== mapKey) return;\n\t\tthis.setActiveCohort(mapKey);\n\t}\n\n\tprivate suspendActiveCohortIfSuperseded(mapKey: string): void {\n\t\tif (this.activeCohortMapKey === null) return;\n\t\tif (this.activeCohortMapKey === mapKey) return;\n\t\tthis.activeCohortMapKey = null;\n\t\tfor (const sub of Array.from(this.activeSubscriptions.values())) {\n\t\t\tsub.unsubscribeCurrent?.();\n\t\t\tsub.unsubscribeCurrent = null;\n\t\t}\n\t}\n\n\t/**\n\t * Clear the active cohort if `mapKey` matches it, detaching every\n\t * active subscription's current controller binding. Subscriptions\n\t * stay in the registry — a subsequent `setActiveCohort(...)` will\n\t * re-bind them to the new controller.\n\t */\n\tprivate clearActiveCohortIfMatches(mapKey: string): void {\n\t\tif (this.activeCohortMapKey !== mapKey) return;\n\t\tthis.activeCohortMapKey = null;\n\t\t// Symmetric snapshot for safety: a disposer fired during detach\n\t\t// could mutate `activeSubscriptions`. Detach is silent (no listener\n\t\t// fan-out), so re-entrancy exposure is lower than `setActiveCohort`,\n\t\t// but the snapshot keeps both paths uniform.\n\t\tfor (const sub of Array.from(this.activeSubscriptions.values())) {\n\t\t\tsub.unsubscribeCurrent?.();\n\t\t\tsub.unsubscribeCurrent = null;\n\t\t}\n\t}\n\n\tprivate buildSectionEventPredicate(\n\t\targs: Pick<SectionEventSubscriptionArgs, \"eventTypes\" | \"itemIds\">,\n\t): (event: SectionControllerEvent) => boolean {\n\t\tconst eventTypeFilter = args.eventTypes ? new Set(args.eventTypes) : null;\n\t\tconst itemIdFilter = args.itemIds ? new Set(args.itemIds) : null;\n\t\treturn (event: SectionControllerEvent): boolean => {\n\t\t\tif (eventTypeFilter || itemIdFilter) {\n\t\t\t\tconst eventType = event?.type || null;\n\t\t\t\tif (\n\t\t\t\t\teventTypeFilter &&\n\t\t\t\t\t(!eventType || !eventTypeFilter.has(eventType))\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (itemIdFilter) {\n\t\t\t\t\tconst hasMatchingItem = Array.from(\n\t\t\t\t\t\tthis.collectEventItemIds(event),\n\t\t\t\t\t).some((itemId) => itemIdFilter.has(itemId));\n\t\t\t\t\tif (!hasMatchingItem) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t}\n\n\tprivate collectEventItemIds(event: SectionControllerEvent): Set<string> {\n\t\tconst itemIds = new Set<string>();\n\t\tif (\"itemId\" in event && typeof event.itemId === \"string\") {\n\t\t\titemIds.add(event.itemId);\n\t\t}\n\t\tif (\n\t\t\t\"canonicalItemId\" in event &&\n\t\t\ttypeof event.canonicalItemId === \"string\"\n\t\t) {\n\t\t\titemIds.add(event.canonicalItemId);\n\t\t}\n\t\tif (\"currentItemId\" in event && typeof event.currentItemId === \"string\") {\n\t\t\titemIds.add(event.currentItemId);\n\t\t}\n\t\tif (\"previousItemId\" in event && typeof event.previousItemId === \"string\") {\n\t\t\titemIds.add(event.previousItemId);\n\t\t}\n\t\treturn itemIds;\n\t}\n\n\t/**\n\t * Build replay `content-loaded` events for renderables the controller has\n\t * already finished loading.\n\t *\n\t * Strict by design: only renderables explicitly reported in\n\t * `runtimeState.loadedRenderables` are replayed. Synthetic test harnesses\n\t * that omit the field (or controllers from older revisions that did not\n\t * populate it) get an empty replay set rather than a fabricated one — that\n\t * preserves the contract that replays mirror events that actually fired.\n\t *\n\t * Order follows registration order from\n\t * `SectionController.collectLoadedRenderableSnapshot`, which mirrors the\n\t * order live `content-loaded` events were emitted in.\n\t */\n\tprivate buildContentLoadedReplayEvents(\n\t\tcontroller: SectionControllerHandle,\n\t): SectionControllerEvent[] {\n\t\tconst runtimeState = controller.getRuntimeState?.();\n\t\tconst loadedRenderables = runtimeState?.loadedRenderables;\n\t\tif (!Array.isArray(loadedRenderables) || loadedRenderables.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst currentItemIndex =\n\t\t\ttypeof runtimeState?.currentItemIndex === \"number\" &&\n\t\t\tNumber.isFinite(runtimeState.currentItemIndex)\n\t\t\t\t? runtimeState.currentItemIndex\n\t\t\t\t: 0;\n\t\tconst timestamp = Date.now();\n\t\tconst events: SectionControllerEvent[] = [];\n\t\tfor (const renderable of loadedRenderables) {\n\t\t\tif (!renderable) continue;\n\t\t\tconst itemId = renderable.itemId;\n\t\t\tconst canonicalItemId =\n\t\t\t\ttypeof renderable.canonicalItemId === \"string\" &&\n\t\t\t\trenderable.canonicalItemId\n\t\t\t\t\t? renderable.canonicalItemId\n\t\t\t\t\t: itemId;\n\t\t\tif (typeof itemId !== \"string\" || !itemId) continue;\n\t\t\tevents.push({\n\t\t\t\ttype: \"content-loaded\",\n\t\t\t\tcontentKind: renderable.contentKind ?? \"unknown\",\n\t\t\t\titemId,\n\t\t\t\tcanonicalItemId,\n\t\t\t\tcurrentItemIndex,\n\t\t\t\ttimestamp,\n\t\t\t});\n\t\t}\n\t\treturn events;\n\t}\n\n\tprivate buildLoadingCompleteReplayEvent(\n\t\tcontroller: SectionControllerHandle,\n\t): SectionControllerEvent | null {\n\t\tconst runtimeState = controller.getRuntimeState?.();\n\t\tif (runtimeState?.loadingComplete !== true) return null;\n\t\tconst totalRegistered =\n\t\t\ttypeof runtimeState.totalRegistered === \"number\" &&\n\t\t\tNumber.isFinite(runtimeState.totalRegistered)\n\t\t\t\t? Math.max(0, runtimeState.totalRegistered)\n\t\t\t\t: 0;\n\t\tconst totalLoaded =\n\t\t\ttypeof runtimeState.totalLoaded === \"number\" &&\n\t\t\tNumber.isFinite(runtimeState.totalLoaded)\n\t\t\t\t? Math.max(0, runtimeState.totalLoaded)\n\t\t\t\t: totalRegistered;\n\t\treturn {\n\t\t\ttype: \"section-loading-complete\",\n\t\t\ttotalRegistered,\n\t\t\ttotalLoaded,\n\t\t\tcurrentItemIndex: runtimeState.currentItemIndex,\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to item-scoped controller events.\n\t *\n\t * Same active-cohort binding contract as\n\t * {@link subscribeSectionEvents}; defaults `eventTypes` to the\n\t * item-scoped subset.\n\t */\n\tpublic subscribeItemEvents(\n\t\targs: SectionItemEventSubscriptionArgs,\n\t): () => void {\n\t\treturn this.subscribeSectionEvents({\n\t\t\teventTypes: args.eventTypes || SECTION_ITEM_EVENT_TYPES,\n\t\t\titemIds: args.itemIds,\n\t\t\tlistener: args.listener as (event: SectionControllerEvent) => void,\n\t\t});\n\t}\n\n\t/**\n\t * Subscribe to section-scoped controller events.\n\t *\n\t * Same active-cohort binding contract as\n\t * {@link subscribeSectionEvents}; defaults `eventTypes` to the\n\t * section-scoped subset. Section-scoped events do not carry item\n\t * identifiers, so this helper intentionally does not expose\n\t * `itemIds` filtering.\n\t */\n\tpublic subscribeSectionLifecycleEvents(\n\t\targs: SectionScopedEventSubscriptionArgs,\n\t): () => void {\n\t\treturn this.subscribeSectionEvents({\n\t\t\teventTypes: args.eventTypes || SECTION_SCOPED_EVENT_TYPES,\n\t\t\tlistener: args.listener as (event: SectionControllerEvent) => void,\n\t\t});\n\t}\n\n\tpublic onSectionControllerLifecycle(\n\t\tlistener: (event: SectionControllerLifecycleEvent) => void,\n\t): () => void {\n\t\tthis.sectionControllerLifecycleListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.sectionControllerLifecycleListeners.delete(listener);\n\t\t};\n\t}\n\n\tpublic async getOrCreateSectionController(args: {\n\t\tsectionId: string;\n\t\tattemptId?: string;\n\t\tinput?: unknown;\n\t\tupdateExisting?: boolean;\n\t\tcreateDefaultController: () =>\n\t\t\t| SectionControllerHandle\n\t\t\t| Promise<SectionControllerHandle>;\n\t}): Promise<SectionControllerHandle> {\n\t\tconst key: SectionControllerKey = {\n\t\t\tassessmentId: this.assessmentId,\n\t\t\tsectionId: args.sectionId,\n\t\t\tattemptId: args.attemptId,\n\t\t};\n\t\tconst mapKey = this.getSectionControllerMapKey(key);\n\t\tthis.latestRequestedActiveCohortMapKey = mapKey;\n\t\tthis.suspendActiveCohortIfSuperseded(mapKey);\n\t\tconst existingController = await this.resolveExistingSectionController({\n\t\t\tmapKey,\n\t\t\tkey,\n\t\t\tinput: args.input,\n\t\t\tupdateExisting: args.updateExisting,\n\t\t});\n\t\tif (existingController) return existingController;\n\n\t\tconst existingPromise = this.sectionControllerInitPromises.get(mapKey);\n\t\tif (existingPromise) return existingPromise;\n\n\t\tconst initPromise = this.initializeNewSectionController({\n\t\t\targs,\n\t\t\tkey,\n\t\t\tmapKey,\n\t\t})\n\t\t\t.catch((err) => {\n\t\t\t\tthis.handleSectionControllerInitError(err, args);\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.sectionControllerInitPromises.delete(mapKey);\n\t\t\t});\n\n\t\tthis.sectionControllerInitPromises.set(mapKey, initPromise);\n\t\treturn initPromise;\n\t}\n\n\tprivate async resolveExistingSectionController(args: {\n\t\tmapKey: string;\n\t\tkey: SectionControllerKey;\n\t\tinput: unknown;\n\t\tupdateExisting?: boolean;\n\t}): Promise<SectionControllerHandle | undefined> {\n\t\tconst existingController = this.sectionControllers.get(args.mapKey);\n\t\tif (!existingController) return undefined;\n\t\tthis.sectionControllerKeys.set(args.mapKey, args.key);\n\t\tif (args.updateExisting !== false) {\n\t\t\t// Existing controllers keep their in-memory session state across\n\t\t\t// input refresh; updateInput should rebuild composition/runtime view\n\t\t\t// without resetting responses.\n\t\t\tawait existingController.updateInput?.(args.input);\n\t\t}\n\t\t// PIE-512 Phase D: a `getOrCreateSectionController` call that\n\t\t// resolves to a previously-created controller still represents a\n\t\t// cohort transition from the toolkit's perspective (same-cohort\n\t\t// re-entry is a no-op inside `setActiveCohort`). Active\n\t\t// subscriptions migrate here so a host that subscribed once on\n\t\t// `toolkit-ready` keeps receiving events after navigating back\n\t\t// to a section it visited earlier.\n\t\tthis.setActiveCohortIfLatestRequest(args.mapKey);\n\t\treturn existingController;\n\t}\n\n\tprivate createSectionControllerContext(args: {\n\t\tkey: SectionControllerKey;\n\t\tinput: unknown;\n\t}): SectionControllerContext {\n\t\treturn {\n\t\t\tkey: args.key,\n\t\t\tcoordinator: this,\n\t\t\tinput: args.input,\n\t\t};\n\t}\n\n\tprivate async initializeNewSectionController(args: {\n\t\targs: {\n\t\t\tsectionId: string;\n\t\t\tattemptId?: string;\n\t\t\tinput?: unknown;\n\t\t\tcreateDefaultController: () =>\n\t\t\t\t| SectionControllerHandle\n\t\t\t\t| Promise<SectionControllerHandle>;\n\t\t};\n\t\tkey: SectionControllerKey;\n\t\tmapKey: string;\n\t}): Promise<SectionControllerHandle> {\n\t\tconst context = this.createSectionControllerContext({\n\t\t\tkey: args.key,\n\t\t\tinput: args.args.input,\n\t\t});\n\t\tconst persistence = await this.resolveSectionPersistence(context);\n\t\tconst defaults: SectionControllerFactoryDefaults = {\n\t\t\tcreateDefaultController: args.args.createDefaultController,\n\t\t};\n\t\tconst controller =\n\t\t\t(await this.hooks.createSectionController?.(context, defaults)) ??\n\t\t\t(await defaults.createDefaultController());\n\t\tawait controller.configureSessionPersistence?.({\n\t\t\tstrategy: persistence,\n\t\t\tcontext,\n\t\t});\n\t\tawait controller.initialize?.(args.args.input);\n\t\tawait controller.hydrate?.();\n\t\tawait this.finalizeSectionControllerReady({\n\t\t\tmapKey: args.mapKey,\n\t\t\tkey: args.key,\n\t\t\tcontext,\n\t\t\tcontroller,\n\t\t});\n\t\treturn controller;\n\t}\n\n\tprivate async finalizeSectionControllerReady(args: {\n\t\tmapKey: string;\n\t\tkey: SectionControllerKey;\n\t\tcontext: SectionControllerContext;\n\t\tcontroller: SectionControllerHandle;\n\t}): Promise<void> {\n\t\tthis.sectionControllers.set(args.mapKey, args.controller);\n\t\tthis.sectionControllerKeys.set(args.mapKey, args.key);\n\t\t// PIE-512 Phase D: a freshly-resolved controller becomes the\n\t\t// active cohort. Active subscriptions migrate to it before the\n\t\t// `ready` lifecycle event and `onSectionControllerReady` hook\n\t\t// fire so any synchronous post-ready work observes a coherent\n\t\t// active-cohort view.\n\t\tthis.setActiveCohortIfLatestRequest(args.mapKey);\n\t\tthis.emitSectionControllerLifecycle({\n\t\t\ttype: \"ready\",\n\t\t\tkey: args.key,\n\t\t\tcontroller: args.controller,\n\t\t});\n\t\tawait this.hooks.onSectionControllerReady?.(args.context, args.controller);\n\t\tawait this.emitTelemetry(\"pie-toolkit-section-controller-ready\", {\n\t\t\tassessmentId: args.key.assessmentId,\n\t\t\tsectionId: args.key.sectionId,\n\t\t\tattemptId: args.key.attemptId,\n\t\t});\n\t}\n\n\tprivate handleSectionControllerInitError(\n\t\terr: unknown,\n\t\targs: { sectionId: string; attemptId?: string },\n\t): void {\n\t\tthis.handleError(err, {\n\t\t\tphase: \"section-controller-init\",\n\t\t\tdetails: {\n\t\t\t\tsectionId: args.sectionId,\n\t\t\t\tattemptId: args.attemptId,\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic async disposeSectionController(args: {\n\t\tsectionId: string;\n\t\tattemptId?: string;\n\t\tpersistBeforeDispose?: boolean;\n\t\tclearPersistence?: boolean;\n\t}): Promise<void> {\n\t\tconst key: SectionControllerKey = {\n\t\t\tassessmentId: this.assessmentId,\n\t\t\tsectionId: args.sectionId,\n\t\t\tattemptId: args.attemptId,\n\t\t};\n\t\tconst mapKey = this.getSectionControllerMapKey(key);\n\t\tconst controller = this.sectionControllers.get(mapKey);\n\t\tif (!controller) return;\n\t\t// PIE-512 Phase D: if the disposing cohort is the active one,\n\t\t// detach all listener-controller bindings before the controller\n\t\t// itself disposes. The subscription registry stays intact so a\n\t\t// later `getOrCreateSectionController(...)` re-binds the same\n\t\t// listeners to the new controller.\n\t\tthis.clearActiveCohortIfMatches(mapKey);\n\n\t\tconst context = this.createSectionControllerContext({\n\t\t\tkey,\n\t\t\tinput: undefined,\n\t\t});\n\n\t\ttry {\n\t\t\tawait this.runSectionControllerDisposePipeline({\n\t\t\t\tkey,\n\t\t\t\tcontext,\n\t\t\t\tcontroller,\n\t\t\t\tpersistBeforeDispose: args.persistBeforeDispose,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tthis.handleError(err, {\n\t\t\t\tphase: \"section-controller-dispose\",\n\t\t\t\tdetails: {\n\t\t\t\t\tsectionId: args.sectionId,\n\t\t\t\t\tattemptId: args.attemptId,\n\t\t\t\t},\n\t\t\t});\n\t\t} finally {\n\t\t\tawait this.finalizeSectionControllerDispose({\n\t\t\t\tmapKey,\n\t\t\t\tkey,\n\t\t\t\tcontext,\n\t\t\t\tclearPersistence: args.clearPersistence,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async runSectionControllerDisposePipeline(args: {\n\t\tkey: SectionControllerKey;\n\t\tcontext: SectionControllerContext;\n\t\tcontroller: SectionControllerHandle;\n\t\tpersistBeforeDispose?: boolean;\n\t}): Promise<void> {\n\t\tif (args.persistBeforeDispose !== false) {\n\t\t\tawait args.controller.persist?.();\n\t\t}\n\t\tawait args.controller.dispose?.();\n\t\tawait this.hooks.onSectionControllerDispose?.(\n\t\t\targs.context,\n\t\t\targs.controller,\n\t\t);\n\t\tawait this.emitTelemetry(\"pie-toolkit-section-controller-disposed\", {\n\t\t\tassessmentId: args.key.assessmentId,\n\t\t\tsectionId: args.key.sectionId,\n\t\t\tattemptId: args.key.attemptId,\n\t\t});\n\t}\n\n\tprivate async finalizeSectionControllerDispose(args: {\n\t\tmapKey: string;\n\t\tkey: SectionControllerKey;\n\t\tcontext: SectionControllerContext;\n\t\tclearPersistence?: boolean;\n\t}): Promise<void> {\n\t\tthis.sectionControllers.delete(args.mapKey);\n\t\tthis.sectionControllerKeys.delete(args.mapKey);\n\t\tthis.emitSectionControllerLifecycle({\n\t\t\ttype: \"disposed\",\n\t\t\tkey: args.key,\n\t\t});\n\t\tif (args.clearPersistence) {\n\t\t\tconst strategy = this.sectionPersistenceStrategies.get(args.mapKey);\n\t\t\tawait strategy?.clearSession?.(args.context);\n\t\t}\n\t\tthis.sectionPersistenceStrategies.delete(args.mapKey);\n\t}\n\n\t/**\n\t * Initialize TTS service with provider\n\t */\n\tpublic async ensureTTSReady(config?: TTSToolConfig): Promise<void> {\n\t\tawait this.waitForPendingTTSReconfigure();\n\t\tif (this.ttsInitialized) return;\n\t\tif (this.ttsInitPromise) return this.ttsInitPromise;\n\t\tthis.ttsInitPromise = this._initializeTTS(config).finally(() => {\n\t\t\tthis.ttsInitPromise = undefined;\n\t\t});\n\t\treturn this.ttsInitPromise;\n\t}\n\n\tprivate async waitForPendingTTSReconfigure(): Promise<void> {\n\t\tlet pending = this.ttsReconfigurePromise;\n\t\twhile (pending) {\n\t\t\tawait pending;\n\t\t\tpending = this.ttsReconfigurePromise;\n\t\t}\n\t}\n\n\tprivate async _initializeTTS(config?: TTSToolConfig): Promise<void> {\n\t\tif (this.ttsInitialized) return;\n\t\tconst resolvedToolConfig = this.resolveTTSToolConfig(config);\n\t\tconst runtimeSettings = resolveTTSRuntimeSettings(resolvedToolConfig);\n\t\tconst resolvedBackend = resolveTTSBackend(runtimeSettings);\n\t\tconst runtimeTTSConfig = buildRuntimeTTSConfig(runtimeSettings);\n\t\tawait this.hooks.onBeforeTTSInit?.({\n\t\t\tphase: \"tts-init\",\n\t\t\tdetails: {\n\t\t\t\tbackend: resolvedBackend,\n\t\t\t},\n\t\t});\n\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-start\", {\n\t\t\tbackend: resolvedBackend,\n\t\t});\n\t\tawait this.emitTelemetry(\"pie-tool-init-start\", {\n\t\t\ttoolId: \"textToSpeech\",\n\t\t\toperation: \"tts-init\",\n\t\t\tbackend: resolvedBackend,\n\t\t});\n\n\t\t// Try to use TTS provider from registry if available\n\t\tif (this.toolProviderRegistry.has(\"tts\")) {\n\t\t\ttry {\n\t\t\t\tconst ttsProvider = await this.ensureProviderReady(\"tts\");\n\t\t\t\tconst providerInstance = await ttsProvider.createInstance();\n\t\t\t\tawait this.initializeTTSService(providerInstance, runtimeTTSConfig);\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-success\", {\n\t\t\t\t\tprovider: \"registry\",\n\t\t\t\t});\n\t\t\t\tawait this.emitTelemetry(\"pie-tool-init-success\", {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\toperation: \"tts-init\",\n\t\t\t\t\tbackend: resolvedBackend,\n\t\t\t\t\tprovider: \"registry\",\n\t\t\t\t});\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"[ToolkitCoordinator] TTS initialized via ToolProviderRegistry\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tconst normalized =\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error));\n\t\t\t\tawait this.emitTelemetry(\"pie-tool-init-error\", {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\tproviderId: \"tts\",\n\t\t\t\t\toperation: \"tts-init\",\n\t\t\t\t\tbackend: resolvedBackend,\n\t\t\t\t\terrorType: \"TTSRegistryInitError\",\n\t\t\t\t\tmessage: normalized.message,\n\t\t\t\t\trecovered: true,\n\t\t\t\t});\n\t\t\t\tawait this.emitTelemetry(\"pie-tool-init-fallback\", {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\tproviderId: \"tts\",\n\t\t\t\t\toperation: \"tts-init\",\n\t\t\t\t\tbackend: resolvedBackend,\n\t\t\t\t\tfromProvider: \"registry\",\n\t\t\t\t\ttoProvider: \"browser\",\n\t\t\t\t\treason: normalized.message,\n\t\t\t\t});\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] Failed to initialize TTS via registry, falling back to browser provider:\",\n\t\t\t\t\tnormalized,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to browser provider\n\t\tconst provider = new BrowserTTSProvider();\n\t\ttry {\n\t\t\tawait this.initializeTTSService(provider, runtimeTTSConfig);\n\t\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-success\", {\n\t\t\t\tprovider: \"browser-fallback\",\n\t\t\t});\n\t\t\tawait this.emitTelemetry(\"pie-tool-init-success\", {\n\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\toperation: \"tts-init\",\n\t\t\t\tbackend: resolvedBackend,\n\t\t\t\tprovider: \"browser-fallback\",\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst normalized =\n\t\t\t\terror instanceof Error ? error : new Error(String(error));\n\t\t\tthis.handleError(normalized, { phase: \"tts-init\" });\n\t\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-error\", {\n\t\t\t\tmessage: normalized.message,\n\t\t\t});\n\t\t\tawait this.emitTelemetry(\"pie-tool-init-error\", {\n\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\toperation: \"tts-init\",\n\t\t\t\tbackend: resolvedBackend,\n\t\t\t\terrorType: \"TTSInitError\",\n\t\t\t\tmessage: normalized.message,\n\t\t\t});\n\t\t\tthrow normalized;\n\t\t}\n\t}\n\n\tprivate resolveTTSToolConfig(config?: TTSToolConfig): TTSToolConfig {\n\t\treturn config || this.getTTSConfigFromProviders() || {};\n\t}\n\n\tprivate async initializeTTSService(\n\t\tprovider: ITTSProvider,\n\t\tconfig: Partial<TTSConfig>,\n\t): Promise<void> {\n\t\tconst nextProviderOptions = {\n\t\t\t...(((config.providerOptions || {}) as Record<string, unknown>) || {}),\n\t\t\t__pieTelemetry: async (\n\t\t\t\teventName: string,\n\t\t\t\tpayload?: Record<string, unknown>,\n\t\t\t) => {\n\t\t\t\tawait this.emitTelemetry(eventName, {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\t...(payload || {}),\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t\tconst nextConfig = {\n\t\t\t...config,\n\t\t\tproviderOptions: nextProviderOptions,\n\t\t} as Partial<TTSConfig>;\n\t\tawait this.ttsService.initialize(provider, nextConfig);\n\t\tawait this.ensureBrowserVoicesReady(provider);\n\t\tthis.ttsService.setCatalogResolver(this.catalogResolver);\n\t\tthis.ttsInitialized = true;\n\t\tawait this.hooks.onTTSReady?.();\n\t}\n\n\tprivate async ensureBrowserVoicesReady(\n\t\tprovider: ITTSProvider,\n\t\ttimeoutMs = 1200,\n\t): Promise<void> {\n\t\tif (provider.providerId !== \"browser\") return;\n\t\tif (typeof window === \"undefined\") return;\n\t\tif (!(\"speechSynthesis\" in window)) return;\n\t\tconst synth = window.speechSynthesis;\n\t\tconst voices = synth.getVoices();\n\t\tif (voices.length > 0) return;\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tconst canUseEventTarget =\n\t\t\t\ttypeof synth.addEventListener === \"function\" &&\n\t\t\t\ttypeof synth.removeEventListener === \"function\";\n\t\t\tconst canUseHandler = !canUseEventTarget && \"onvoiceschanged\" in synth;\n\t\t\tconst previousHandler = canUseHandler ? synth.onvoiceschanged : null;\n\t\t\tlet assignedHandler = false;\n\t\t\tconst finish = () => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\twindow.clearTimeout(timeoutId);\n\t\t\t\tif (canUseEventTarget) {\n\t\t\t\t\tsynth.removeEventListener(\"voiceschanged\", onVoicesChanged);\n\t\t\t\t} else if (assignedHandler && synth.onvoiceschanged === onVoicesChanged) {\n\t\t\t\t\tsynth.onvoiceschanged = previousHandler;\n\t\t\t\t}\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tconst onVoicesChanged = (event?: Event) => {\n\t\t\t\tif (!canUseEventTarget && typeof previousHandler === \"function\" && event) {\n\t\t\t\t\tpreviousHandler.call(synth, event);\n\t\t\t\t}\n\t\t\t\tfinish();\n\t\t\t};\n\t\t\tconst timeoutId = window.setTimeout(finish, timeoutMs);\n\t\t\tif (canUseEventTarget) {\n\t\t\t\tsynth.addEventListener(\"voiceschanged\", onVoicesChanged, {\n\t\t\t\t\tonce: true,\n\t\t\t\t});\n\t\t\t} else if (canUseHandler) {\n\t\t\t\tsynth.onvoiceschanged = onVoicesChanged;\n\t\t\t\tassignedHandler = true;\n\t\t\t}\n\t\t});\n\t\tconst voicesAfterWait = synth.getVoices();\n\t\tawait this.emitTelemetry(\"pie-toolkit-tts-browser-voices-ready\", {\n\t\t\tvoiceCount: voicesAfterWait.length,\n\t\t\ttimedOut: voicesAfterWait.length === 0,\n\t\t});\n\t}\n\n\t/**\n\t * Get all services as a bundle for section player convenience.\n\t * Section player can extract and pass services to child components.\n\t */\n\tgetServiceBundle(): ToolkitServiceBundle {\n\t\treturn {\n\t\t\tttsService: this.ttsService,\n\t\t\ttoolCoordinator: this.toolCoordinator,\n\t\t\thighlightCoordinator: this.highlightCoordinator,\n\t\t\telementToolStateStore: this.elementToolStateStore,\n\t\t\tcatalogResolver: this.catalogResolver,\n\t\t\ttoolProviderRegistry: this.toolProviderRegistry,\n\t\t};\n\t}\n\n\t/**\n\t * Get a tool provider from the registry\n\t *\n\t * @param providerId Provider identifier\n\t * @returns Tool provider instance\n\t */\n\tasync getToolProvider(providerId: string) {\n\t\treturn this.ensureProviderReady(providerId);\n\t}\n\n\tasync waitUntilReady(): Promise<void> {\n\t\tif (this.isReady()) return;\n\t\tif (this.coordinatorReadyPromise) return this.coordinatorReadyPromise;\n\t\tthis.coordinatorReadyPromise = (async () => {\n\t\t\tawait this.ensureStateLoaded();\n\t\t\tconst ttsConfig = this.getTTSConfigFromProviders();\n\t\t\tif (ttsConfig?.enabled !== false) {\n\t\t\t\tawait this.ensureTTSReady(ttsConfig);\n\t\t\t}\n\t\t\tif (!this.coordinatorReadyNotified) {\n\t\t\t\tthis.coordinatorReadyNotified = true;\n\t\t\t\tawait this.hooks.onCoordinatorReady?.(this);\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-coordinator-ready\", {\n\t\t\t\t\tassessmentId: this.assessmentId,\n\t\t\t\t});\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tthis.coordinatorReadyPromise = undefined;\n\t\t});\n\t\treturn this.coordinatorReadyPromise;\n\t}\n\n\tisReady(): boolean {\n\t\treturn this.getInitStatus().coordinator;\n\t}\n\n\tgetInitStatus(): ToolkitInitStatus {\n\t\tconst providers: Record<string, boolean> = {};\n\t\tfor (const providerId of this.toolProviderRegistry.getProviderIds()) {\n\t\t\tproviders[providerId] =\n\t\t\t\tthis.toolProviderRegistry.isInitialized(providerId);\n\t\t}\n\t\tconst ttsConfig = this.getTTSConfigFromProviders();\n\t\treturn {\n\t\t\ttts: this.ttsInitialized,\n\t\t\tstateLoaded: this.stateLoaded || !this.hooks.loadToolState,\n\t\t\tcoordinator:\n\t\t\t\t(this.stateLoaded || !this.hooks.loadToolState) &&\n\t\t\t\t(this.ttsInitialized || ttsConfig?.enabled === false),\n\t\t\tproviders,\n\t\t};\n\t}\n\n\tprivate getTTSConfigFromProviders(): TTSToolConfig | undefined {\n\t\tconst providers =\n\t\t\t(\n\t\t\t\tthis.config.tools as {\n\t\t\t\t\tproviders?: Record<string, ToolProviderConfig | undefined>;\n\t\t\t\t}\n\t\t\t)?.providers || {};\n\t\treturn providers.textToSpeech as TTSToolConfig | undefined;\n\t}\n\n\tprivate assertCanonicalToolId(toolId: string): void {\n\t\tif (typeof toolId !== \"string\" || toolId.trim().length === 0) {\n\t\t\tthrow new Error(\"Tool id must be a non-empty string.\");\n\t\t}\n\t\tif (toolId === \"tts\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Tool id \"tts\" is no longer supported. Use \"textToSpeech\".`,\n\t\t\t);\n\t\t}\n\t\tif (!this.toolRegistry.get(toolId)) {\n\t\t\tthrow new Error(`Unknown tool id \"${toolId}\".`);\n\t\t}\n\t}\n\n\tprivate installToolContextResolvers(\n\t\tresolvers: ToolContextResolverMap | undefined,\n\t): void {\n\t\tif (!resolvers) return;\n\t\tfor (const [toolId, resolver] of Object.entries(resolvers)) {\n\t\t\tif (resolver == null) continue;\n\t\t\tthis.assertCanonicalToolId(toolId);\n\t\t\tif (typeof resolver !== \"function\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid tool context resolver for \"${toolId}\": expected a function.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.toolContextResolvers.set(toolId, resolver);\n\t\t}\n\t}\n\n\tsetToolContextResolvers(\n\t\tresolvers: ToolContextResolverMap | null | undefined,\n\t): void {\n\t\tthis.toolContextResolvers.clear();\n\t\tthis.installToolContextResolvers(resolvers ?? undefined);\n\t\tthis.notifyToolContextResolverChange();\n\t}\n\n\tprivate notifyToolContextResolverChange(): void {\n\t\tfor (const listener of this.toolContextResolverChangeListeners) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] Tool context resolver listener threw:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Check if a tool is enabled.\n\t * Tools are enabled by default unless explicitly disabled.\n\t *\n\t * @param toolId Tool identifier (e.g., 'textToSpeech', 'answerEliminator')\n\t * @returns True if tool is enabled\n\t */\n\tisToolEnabled(toolId: string): boolean {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\tconst toolConfig = (this.config.tools as any)?.providers?.[toolId];\n\t\t// Enabled by default unless explicitly set to false\n\t\treturn toolConfig?.enabled !== false;\n\t}\n\n\t/**\n\t * Get tool configuration.\n\t *\n\t * @param toolId Tool identifier\n\t * @returns Tool configuration or null if not configured\n\t */\n\tgetToolConfig(toolId: string): ToolProviderConfig | null {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\treturn (\n\t\t\t((\n\t\t\t\tthis.config.tools as {\n\t\t\t\t\tproviders?: Record<string, ToolProviderConfig | undefined>;\n\t\t\t\t}\n\t\t\t)?.providers?.[toolId] as ToolProviderConfig | undefined) || null\n\t\t);\n\t}\n\n\t/**\n\t * Update tool configuration.\n\t * Applies changes to underlying services.\n\t *\n\t * @param toolId Tool identifier\n\t * @param updates Partial configuration updates\n\t */\n\tupdateToolConfig(\n\t\ttoolId: \"textToSpeech\",\n\t\tupdates: Partial<TTSToolConfig>,\n\t): void;\n\tupdateToolConfig(toolId: string, updates: Partial<ToolProviderConfig>): void;\n\tupdateToolConfig(\n\t\ttoolId: string,\n\t\tupdates: Partial<ToolProviderConfig> | Partial<TTSToolConfig>,\n\t): void {\n\t\t// Update config\n\t\tthis.assertCanonicalToolId(toolId);\n\t\tconst current = this.getToolConfig(toolId) || {};\n\t\tif (!this.config.tools) {\n\t\t\tthis.config.tools = normalizeAndValidateToolsConfig(undefined, {\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolConfig\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t}).config;\n\t\t}\n\t\tif (!(this.config.tools as any).providers) {\n\t\t\t(this.config.tools as any).providers = {};\n\t\t}\n\t\tconst nextProviders = {\n\t\t\t...((this.config.tools as any).providers || {}),\n\t\t\t[toolId]: mergeToolConfigUpdate(toolId, current, updates),\n\t\t};\n\t\tconst validated = normalizeAndValidateToolsConfig(\n\t\t\t{\n\t\t\t\t...(this.config.tools as CanonicalToolsConfig),\n\t\t\t\tproviders: nextProviders,\n\t\t\t},\n\t\t\t{\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolConfig\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t},\n\t\t);\n\t\tthis.config.tools = validated.config;\n\t\t// M8 PR 2 — keep the policy engine's tools input in lockstep\n\t\t// with the validated coordinator config. The engine emits an\n\t\t// `inputs` change event so subscribers (e.g. PR 3 toolbars) can\n\t\t// re-decide without us managing a parallel pub/sub.\n\t\tthis.policyEngine.updateInputs({\n\t\t\ttools: this.config.tools as CanonicalToolsConfig,\n\t\t});\n\t\tvoid this.emitTelemetry(\"pie-toolkit-tool-config-updated\", { toolId });\n\n\t\t// Apply configuration changes to services\n\t\tthis._applyToolConfigChange(toolId, updates);\n\t}\n\n\t/**\n\t * Update the enabled tool list for one placement level.\n\t *\n\t * This is the generic placement companion to {@link updateToolConfig}:\n\t * it validates the next canonical tools config, keeps the policy\n\t * engine in lockstep, and emits the same policy-change event used by\n\t * live toolbars/debug panels.\n\t */\n\tupdateToolPlacement(level: ToolPlacementLevel, toolIds: string[]): void {\n\t\tthis.updateToolsPlacement({ [level]: [...toolIds] });\n\t}\n\n\t/**\n\t * Patch one or more placement levels in the canonical tools config.\n\t */\n\tupdateToolsPlacement(partial: ToolPlacementConfig): void {\n\t\tif (!this.config.tools) {\n\t\t\tthis.config.tools = normalizeAndValidateToolsConfig(undefined, {\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolsPlacement\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t}).config;\n\t\t}\n\t\tconst currentPlacement = this.config.tools?.placement ?? {\n\t\t\tsection: [],\n\t\t\titem: [],\n\t\t\tpassage: [],\n\t\t};\n\t\tconst nextPlacement: Required<ToolPlacementConfig> = {\n\t\t\tsection: [...(partial.section ?? currentPlacement.section ?? [])],\n\t\t\titem: [...(partial.item ?? currentPlacement.item ?? [])],\n\t\t\tpassage: [...(partial.passage ?? currentPlacement.passage ?? [])],\n\t\t};\n\t\tconst validated = normalizeAndValidateToolsConfig(\n\t\t\t{\n\t\t\t\t...(this.config.tools as CanonicalToolsConfig),\n\t\t\t\tplacement: nextPlacement,\n\t\t\t},\n\t\t\t{\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolsPlacement\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t},\n\t\t);\n\t\tvalidated.config.placement = nextPlacement;\n\t\tthis.config.tools = validated.config;\n\t\tthis.policyEngine.updateInputs({\n\t\t\ttools: this.config.tools as CanonicalToolsConfig,\n\t\t});\n\t}\n\n\t/**\n\t * Resolve the visible tool set for a given placement level + scope.\n\t *\n\t * Thin shim over the owned tool-policy engine.\n\t */\n\tdecideToolPolicy(request: ToolPolicyDecisionRequest): ToolPolicyDecision {\n\t\treturn this.policyEngine.decide(request);\n\t}\n\n\t/**\n\t * Subscribe to policy-engine change events. Fires whenever the\n\t * coordinator's bound inputs change (`updateToolConfig`,\n\t * `updateToolPlacement`, `updateAssessment`, `updateCurrentItemRef`,\n\t * `setPnpEnforcement`) or a custom `PolicySource` is registered /\n\t * removed via {@link registerPolicySource}.\n\t *\n\t * The listener receives a `ToolPolicyChangeEvent` with the event\n\t * `reason` and a frozen snapshot of the engine inputs. Listeners\n\t * that want the new visible tool set should call\n\t * {@link decideToolPolicy} with their level / scope.\n\t *\n\t * Note: the engine itself can also emit `reason: \"disposed\"`, but\n\t * the coordinator does not dispose its engine on teardown today,\n\t * so subscribers attached via this method will not observe that\n\t * reason. Detach via the returned unsubscribe function instead of\n\t * relying on a `disposed` event.\n\t */\n\tonPolicyChange(listener: ToolPolicyChangeListener): () => void {\n\t\treturn this.policyEngine.onPolicyChange(listener);\n\t}\n\n\t/**\n\t * Bind (or clear) the active assessment for PNP/profile policy decisions.\n\t *\n\t * Under auto-mode (no host override via {@link setPnpEnforcement}),\n\t * the coordinator promotes the engine to `pnpEnforcement: \"on\"`\n\t * iff the assessment carries any profile precedence material\n\t * (`personalNeedsProfile`, `settings.districtPolicy`,\n\t * `settings.testAdministration`) or the currently-bound item ref\n\t * carries item-level profile policy inputs. A bare assessment record (just\n\t * `id` / `name`, no PNP, no settings) keeps `\"off\"`.\n\t *\n\t * The host override set via {@link setPnpEnforcement} is sticky\n\t * across assessment swaps; calling with `null` clears the binding\n\t * and re-runs the auto-mode helper.\n\t */\n\tupdateAssessment(assessment: AssessmentEntity | null): void {\n\t\tthis.boundAssessment = assessment;\n\t\tthis.policyEngine.updateInputs({\n\t\t\tassessment,\n\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t});\n\t}\n\n\t/**\n\t * Bind (or clear) the current item reference for policy decisions.\n\t *\n\t * Used by item-level profile gates (item `requiredTools` /\n\t * `restrictedTools` / `toolParameters`). Item-level profile material\n\t * also feeds {@link resolveEffectivePnpEnforcement} — navigating\n\t * to an item with profile settings can flip auto-mode to `\"on\"` even\n\t * when the parent assessment carries no profile block of its own.\n\t */\n\tupdateCurrentItemRef(itemRef: AssessmentItemRef | null): void {\n\t\tthis.boundCurrentItemRef = itemRef;\n\t\tthis.policyEngine.updateInputs({\n\t\t\tcurrentItemRef: itemRef,\n\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t});\n\t}\n\n\t/**\n\t * Override the auto-mode PNP/profile enforcement decision.\n\t */\n\tsetPnpEnforcement(mode: PnpEnforcementMode | null): void {\n\t\tthis.pnpEnforcementOverride = mode;\n\t\tthis.policyEngine.updateInputs({\n\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t});\n\t}\n\n\t/**\n\t * Get the policy engine inputs currently driving decisions. Useful\n\t * for debugging / instrumentation; do not mutate.\n\t */\n\tgetPolicyInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn this.policyEngine.getInputs();\n\t}\n\n\t/**\n\t * Register a custom {@link PolicySource} with the owned policy\n\t * engine. The source participates in every subsequent\n\t * {@link decideToolPolicy} call until disposed (the returned\n\t * function detaches and emits a `policy-source-removed` event).\n\t *\n\t * Delegates verbatim to\n\t * {@link ToolPolicyEngine.registerPolicySource} — see that\n\t * method for the full contract (event ordering, idempotency of\n\t * the returned dispose function, and how registered sources\n\t * compose with the built-in PNP policy source).\n\t */\n\tregisterPolicySource(source: PolicySource): () => void {\n\t\treturn this.policyEngine.registerPolicySource(source);\n\t}\n\n\t/**\n\t * Register a host-owned resolver for one tool's render context.\n\t *\n\t * Resolvers are evaluated only for tools that already survived the\n\t * framework policy pipeline. They can hide the tool for the current\n\t * scope or attach render params consumed by the packaged registration;\n\t * they cannot re-enable tools blocked by placement, provider config,\n\t * host policy, or PNP/profile rules.\n\t */\n\tregisterToolContextResolver(\n\t\ttoolId: string,\n\t\tresolver: ToolContextResolver,\n\t): () => void {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\tif (typeof resolver !== \"function\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tool context resolver for \"${toolId}\": expected a function.`,\n\t\t\t);\n\t\t}\n\t\tthis.toolContextResolvers.set(toolId, resolver);\n\t\tthis.notifyToolContextResolverChange();\n\t\treturn () => {\n\t\t\tif (this.toolContextResolvers.get(toolId) !== resolver) return;\n\t\t\tthis.toolContextResolvers.delete(toolId);\n\t\t\tthis.notifyToolContextResolverChange();\n\t\t};\n\t}\n\n\thasToolContextResolver(toolId: string): boolean {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\treturn this.toolContextResolvers.has(toolId);\n\t}\n\n\tresolveToolContext(\n\t\tcontext: ToolContextResolverContext,\n\t): ResolvedToolContext | null {\n\t\tthis.assertCanonicalToolId(context.toolId);\n\t\tconst resolver = this.toolContextResolvers.get(context.toolId);\n\t\tif (!resolver) return null;\n\n\t\tlet result: ReturnType<ToolContextResolver>;\n\t\ttry {\n\t\t\tresult = resolver(context);\n\t\t} catch (error) {\n\t\t\tconsole.error(\n\t\t\t\t`[ToolkitCoordinator] Tool context resolver for \"${context.toolId}\" threw:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\ttoolId: context.toolId,\n\t\t\t\tvisible: false,\n\t\t\t\tparams: {},\n\t\t\t\treason: \"Tool context resolver threw.\",\n\t\t\t};\n\t\t}\n\t\tif (!result) {\n\t\t\treturn {\n\t\t\t\ttoolId: context.toolId,\n\t\t\t\tvisible: true,\n\t\t\t\tparams: {},\n\t\t\t};\n\t\t}\n\n\t\tconst params =\n\t\t\tresult.params &&\n\t\t\ttypeof result.params === \"object\" &&\n\t\t\t!Array.isArray(result.params)\n\t\t\t\t? result.params\n\t\t\t\t: {};\n\t\treturn {\n\t\t\ttoolId: context.toolId,\n\t\t\tvisible: result.visible !== false,\n\t\t\tparams,\n\t\t\treason: typeof result.reason === \"string\" ? result.reason : undefined,\n\t\t};\n\t}\n\n\tonToolContextResolverChange(listener: () => void): () => void {\n\t\tthis.toolContextResolverChangeListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.toolContextResolverChangeListeners.delete(listener);\n\t\t};\n\t}\n\n\t/**\n\t * Compute the effective PNP/profile enforcement mode given the explicit\n\t * host override and the auto-mode helper.\n\t *\n\t * Auto-mode (no override) defers to\n\t * {@link resolveDefaultPnpEnforcement}, which returns `\"on\"`\n\t * exactly when the bound assessment or current item ref carries\n\t * profile precedence material (PNP, district policy, test\n\t * administration, item-level required/restricted/parameters), and\n\t * `\"off\"` otherwise. Profile gates engage the moment profile material\n\t * is present.\n\t */\n\tprivate resolveEffectivePnpEnforcement(): PnpEnforcementMode {\n\t\tif (this.pnpEnforcementOverride !== null) {\n\t\t\treturn this.pnpEnforcementOverride;\n\t\t}\n\t\treturn resolveDefaultPnpEnforcement({\n\t\t\tassessment: this.boundAssessment,\n\t\t\tcurrentItemRef: this.boundCurrentItemRef,\n\t\t});\n\t}\n\n\tprivate resolveConfiguredPnpEnforcement(): PnpEnforcementMode | null {\n\t\tconst tools = this.config.tools as CanonicalToolsConfig | undefined;\n\t\treturn tools?.pnpEnforcement ?? null;\n\t}\n\n\t/**\n\t * Apply tool configuration changes to underlying services.\n\t * Called after updateToolConfig().\n\t */\n\tprivate _applyToolConfigChange(\n\t\ttoolId: string,\n\t\t_updates: Partial<ToolProviderConfig> | Partial<TTSToolConfig>,\n\t): void {\n\t\t// Apply configuration changes based on tool\n\t\tswitch (toolId) {\n\t\t\tcase \"textToSpeech\": {\n\t\t\t\tconst reconfigurePromise = this._reconfigureTTSProvider();\n\t\t\t\tthis.ttsReconfigurePromise = reconfigurePromise;\n\t\t\t\tvoid reconfigurePromise.finally(() => {\n\t\t\t\t\tif (this.ttsReconfigurePromise === reconfigurePromise) {\n\t\t\t\t\t\tthis.ttsReconfigurePromise = undefined;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tvoid reconfigurePromise.then(async () => {\n\t\t\t\t\tconst ttsConfig = this.getTTSConfigFromProviders();\n\t\t\t\t\tif (!this.lazyInit && ttsConfig?.enabled !== false) {\n\t\t\t\t\t\tawait this.ensureTTSReady(ttsConfig);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"answerEliminator\":\n\t\t\t\t// Future: Could notify answer eliminator tools of strategy change\n\t\t\t\tbreak;\n\n\t\t\t// Add cases for other tools as needed\n\t\t}\n\t}\n\n\tprivate async _reconfigureTTSProvider(): Promise<void> {\n\t\tthis.ttsInitialized = false;\n\t\tthis.ttsInitPromise = undefined;\n\t\ttry {\n\t\t\tthis.ttsService.stop();\n\t\t} catch {\n\t\t\t// noop: stop best effort\n\t\t}\n\n\t\tif (this.toolProviderRegistry.has(\"tts\")) {\n\t\t\tawait this.toolProviderRegistry.unregister(\"tts\");\n\t\t}\n\t\tconst ttsRegistration = this.getProviderDescriptorTools().find(\n\t\t\t(tool) => tool.toolId === \"textToSpeech\",\n\t\t);\n\t\tif (!ttsRegistration) return;\n\t\tawait this.registerProviderFromTool(ttsRegistration);\n\t}\n}\n"]}
1
+ {"version":3,"file":"ToolkitCoordinator.js","sourceRoot":"","sources":["../../src/services/ToolkitCoordinator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,EAON,oBAAoB,GACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,+BAA+B,EAC/B,6BAA6B,GAE7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;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AAc,CAAC,SAAS,CAAC,CAAC;oBACtC,CAAC;gBACF,CAAC,CAAC,CAAC;gBACH,MAAM;YACP,CAAC;YAED,KAAK,kBAAkB;gBACtB,kEAAkE;gBAClE,MAAM;YAEP,sCAAsC;QACvC,CAAC;IACF,CAAC;IAEO,KAAK,CAAC,uBAAuB;QACpC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,IAAI,CAAC;YACJ,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACR,yBAAyB;QAC1B,CAAC;QAED,IAAI,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,eAAe,GAAG,IAAI,CAAC,0BAA0B,EAAE,CAAC,IAAI,CAC7D,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,cAAc,CACxC,CAAC;QACF,IAAI,CAAC,eAAe;YAAE,OAAO;QAC7B,MAAM,IAAI,CAAC,wBAAwB,CAAC,eAAe,CAAC,CAAC;IACtD,CAAC;CACD","sourcesContent":["/**\n * ToolkitCoordinator - Centralized Assessment Toolkit Service Management\n *\n * Orchestrates all toolkit services (TTS, tools, accessibility, state management) from a single entry point.\n * Provides centralized configuration for tool availability and settings.\n *\n * Key features:\n * - Owns all toolkit services (TTSService, ToolCoordinator, HighlightCoordinator, ElementToolStateStore, AccessibilityCatalogResolver)\n * - Single configuration point for tool availability and settings\n * - Sensible defaults for standalone usage\n * - Direct access for settings widgets (no player dependency)\n * - Clean separation: toolkit concerns only (NOT assessment state like navigation, timing, progress)\n *\n * Part of PIE Assessment Toolkit.\n */\n\nimport type {\n\tAccessibilityCatalog,\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\nimport {\n\ttype CanonicalToolsConfig,\n\ttype ToolPlacementConfig,\n\ttype ToolPlacementLevel,\n\ttype ToolPolicyConfig,\n\ttype ToolProviderConfig,\n\ttype ToolProvidersConfig,\n\tnormalizeToolsConfig,\n} from \"./tools-config-normalizer.js\";\nimport {\n\tnormalizeAndValidateToolsConfig,\n\tnormalizeToolConfigStrictness,\n\ttype ToolConfigStrictness,\n} from \"./tool-config-validation.js\";\nimport { AccessibilityCatalogResolver } from \"./AccessibilityCatalogResolver.js\";\nimport { ElementToolStateStore } from \"./ElementToolStateStore.js\";\nimport {\n\tframeworkErrorFromCoordinatorContext,\n\ttype FrameworkErrorModel,\n} from \"./framework-error.js\";\nimport {\n\tFrameworkErrorBus,\n\ttype FrameworkErrorListener,\n} from \"./framework-error-bus.js\";\nimport { HighlightCoordinator } from \"./HighlightCoordinator.js\";\nimport { ToolCoordinator } from \"./ToolCoordinator.js\";\nimport { TTSService, type ITTSProvider, type TTSConfig } from \"./TTSService.js\";\nimport { BrowserTTSProvider } from \"./tts/browser-provider.js\";\nimport {\n\tbuildRuntimeTTSConfig,\n\tresolveTTSBackend,\n\tresolveTTSRuntimeSettings,\n\ttype TTSSpeedOption,\n\ttype TTSLayoutMode,\n} from \"./tts-runtime-config.js\";\nimport type { SREMathSpeechOptions } from \"./tts/math-speech.js\";\nimport { ToolProviderRegistry } from \"./tool-providers/index.js\";\nimport type { ToolProviderApi } from \"./tool-providers/ToolProviderApi.js\";\nimport type { TTSToolProviderConfig } from \"./tool-providers/index.js\";\nimport { createPackagedToolRegistry } from \"./createDefaultToolRegistry.js\";\nimport type {\n\tResolvedToolContext,\n\tToolContextResolver,\n\tToolContextResolverContext,\n\tToolContextResolverMap,\n\tToolRegistration,\n\tToolRegistry,\n} from \"./ToolRegistry.js\";\nimport {\n\tToolPolicyEngine,\n\ttype PnpEnforcementMode,\n\ttype PolicySource,\n\ttype ResolvedEngineInputs,\n\ttype ToolPolicyChangeListener,\n\ttype ToolPolicyDecision,\n\ttype ToolPolicyDecisionRequest,\n} from \"../policy/engine.js\";\nimport { resolveDefaultPnpEnforcement } from \"../policy/internal.js\";\nimport type {\n\tSectionControllerContext,\n\tSectionControllerEvent,\n\tSectionControllerEventType,\n\tSectionControllerFactoryDefaults,\n\tSectionControllerHandle,\n\tSectionControllerKey,\n\tSectionSessionPersistenceStrategy,\n\tSectionPersistenceFactoryDefaults,\n} from \"./section-controller-types.js\";\nexport type {\n\tSectionControllerContext,\n\tSectionControllerEvent,\n\tSectionControllerEventType,\n\tSectionControllerFactoryDefaults,\n\tSectionControllerHandle,\n\tSectionControllerKey,\n\tSectionControllerLoadedRenderable,\n\tSectionSessionPersistenceConfig,\n\tSectionSessionPersistenceStrategy,\n\tSectionControllerRuntimeState,\n\tSectionControllerSessionState,\n\tSectionPersistenceFactoryDefaults,\n} from \"./section-controller-types.js\";\nexport type {\n\tPnpEnforcementMode,\n\tResolvedEngineInputs,\n\tToolPolicyChangeListener,\n\tToolPolicyDecision,\n\tToolPolicyDecisionRequest,\n} from \"../policy/engine.js\";\n\n/**\n * Generic tool configuration\n */\nexport interface ToolConfig {\n\tenabled?: boolean;\n\tprovider?: unknown;\n\tsettings?: Record<string, unknown>;\n\t[key: string]: unknown;\n}\n\n/**\n * TTS tool configuration\n */\nexport interface TTSToolConfig extends ToolConfig {\n\tbackend?: \"browser\" | \"polly\" | \"google\" | \"server\";\n\tprovider?: \"polly\" | \"google\" | \"custom\";\n\tserverProvider?: \"polly\" | \"google\" | \"custom\";\n\tengine?: \"standard\" | \"neural\";\n\tsampleRate?: number;\n\tformat?: \"mp3\" | \"ogg\" | \"pcm\";\n\tspeechMarksMode?: \"word\" | \"word+sentence\";\n\tdefaultVoice?: string;\n\trate?: number;\n\tpitch?: number;\n\tapiEndpoint?: string;\n\tlanguage?: string;\n\ttransportMode?: \"pie\" | \"custom\";\n\tendpointMode?: \"synthesizePath\" | \"rootPost\";\n\tendpointValidationMode?: \"voices\" | \"endpoint\" | \"none\";\n\tincludeAuthOnAssetFetch?: boolean;\n\tvalidateEndpoint?: boolean;\n\tcache?: boolean;\n\tspeedRate?: \"slow\" | \"medium\" | \"fast\";\n\tlang_id?: string;\n\t/**\n\t * Optional inline TTS speed buttons.\n\t * - Omitted/non-array: default speed buttons are shown.\n\t * - Empty array: hide speed buttons.\n\t * - Arrays that sanitize to no valid values: default speed buttons are shown.\n\t * - Object entries can customize button text while preserving numeric rates.\n\t */\n\tspeedOptions?: TTSSpeedOption[];\n\tlayoutMode?: TTSLayoutMode;\n\t/** Speech Rule Engine options for generated MathML speech. */\n\tmathSpeech?: SREMathSpeechOptions;\n\tsettings?: Record<string, unknown> & { mathSpeech?: SREMathSpeechOptions };\n\tauthFetcher?: () => Promise<Partial<TTSToolProviderConfig>>;\n}\n\nconst isPlainRecord = (value: unknown): value is Record<string, unknown> =>\n\t!!value && typeof value === \"object\" && !Array.isArray(value);\n\nconst mergeToolConfigUpdate = (\n\ttoolId: string,\n\tcurrent: ToolConfig,\n\tupdates: Partial<ToolProviderConfig> | Partial<TTSToolConfig>,\n): ToolConfig => {\n\tconst next = { ...current, ...updates };\n\tif (\n\t\ttoolId === \"textToSpeech\" &&\n\t\tisPlainRecord(current.settings) &&\n\t\tisPlainRecord(updates.settings)\n\t) {\n\t\tnext.settings = { ...current.settings, ...updates.settings };\n\t\tif (\n\t\t\tisPlainRecord(current.settings.mathSpeech) &&\n\t\t\tisPlainRecord(updates.settings.mathSpeech)\n\t\t) {\n\t\t\tnext.settings.mathSpeech = {\n\t\t\t\t...current.settings.mathSpeech,\n\t\t\t\t...updates.settings.mathSpeech,\n\t\t\t};\n\t\t}\n\t}\n\treturn next;\n};\n\n/**\n * Answer eliminator tool configuration\n */\nexport interface AnswerEliminatorToolConfig extends ToolConfig {\n\tstrategy?: \"strikethrough\" | \"hide\";\n}\n\nexport interface ToolkitToolsConfig extends CanonicalToolsConfig {\n\tpolicy: ToolPolicyConfig;\n\tplacement: Required<ToolPlacementConfig>;\n\tproviders: ToolProvidersConfig;\n}\n\n/**\n * Configuration for ToolkitCoordinator\n */\nexport interface ToolkitCoordinatorConfig {\n\t/**\n\t * Unique identifier for the assessment content.\n\t * Used for scoping tool state across sections.\n\t */\n\tassessmentId: string;\n\n\t/**\n\t * Tool availability and configuration.\n\t * Defaults: all tools enabled with default settings.\n\t */\n\ttools?: Partial<CanonicalToolsConfig>;\n\n\t/**\n\t * Validation strictness for tool config contracts.\n\t * - off: keep diagnostics internal (no warnings or throws)\n\t * - warn: log diagnostics and continue\n\t * - error: throw on diagnostics\n\t *\n\t * @default \"error\"\n\t */\n\ttoolConfigStrictness?: ToolConfigStrictness;\n\n\t/**\n\t * Optional registry used for tool-config validation and provider descriptor resolution.\n\t * Defaults to packaged PIE tools when omitted.\n\t */\n\ttoolRegistry?: ToolRegistry | null;\n\n\t/**\n\t * Host-owned per-tool render-context resolvers. These run after\n\t * framework policy gates (placement, provider config, host policy,\n\t * PNP/profile rules, and custom policy sources) and can hide a\n\t * surviving tool or attach render params for the tool registration.\n\t * They cannot re-enable a tool removed by policy.\n\t */\n\ttoolContextResolvers?: ToolContextResolverMap;\n\n\t/**\n\t * Accessibility configuration.\n\t * Includes QTI 3.0 accessibility catalogs and language settings.\n\t */\n\taccessibility?: {\n\t\tcatalogs?: AccessibilityCatalog[];\n\t\tlanguage?: string;\n\t};\n\n\t/**\n\t * Optional lifecycle and extension hooks for runtime customization.\n\t */\n\thooks?: ToolkitCoordinatorHooks;\n\n\t/**\n\t * Lazy initialization mode.\n\t * When true, async service/provider initialization is deferred until ensure methods are called.\n\t *\n\t * @default false\n\t */\n\tlazyInit?: boolean;\n\n\t/**\n\t * Internal bootstrap escape hatch used by framework-owned hosts.\n\t * When true, constructor skips throwing validation and expects caller\n\t * to pass a pre-validated tools config.\n\t *\n\t * @internal\n\t */\n\tdeferToolConfigValidation?: boolean;\n\n\t/**\n\t * Optional pre-constructed framework-error bus.\n\t *\n\t * Pass a bus owned by the embedding host (typically\n\t * `<pie-assessment-toolkit>`) when the host wants pre-coordinator\n\t * failures (e.g. `coordinator-init` itself) to flow through the same\n\t * fan-out as post-coordinator failures. When omitted, the coordinator\n\t * constructs its own private bus, which is what standalone embeds get.\n\t *\n\t * @internal\n\t */\n\tframeworkErrorBus?: FrameworkErrorBus;\n}\n\nexport interface ToolkitErrorContext {\n\tphase:\n\t\t| \"coordinator-ready\"\n\t\t| \"state-load\"\n\t\t| \"state-save\"\n\t\t| \"provider-register\"\n\t\t| \"provider-init\"\n\t\t| \"tts-init\"\n\t\t| \"section-controller-init\"\n\t\t| \"section-controller-dispose\";\n\tproviderId?: string;\n\tdetails?: Record<string, unknown>;\n}\n\nexport interface ProviderLifecycleContext {\n\tproviderId: string;\n\tproviderName?: string;\n}\n\nexport interface ToolkitInitStatus {\n\ttts: boolean;\n\tstateLoaded: boolean;\n\tcoordinator: boolean;\n\tproviders: Record<string, boolean>;\n}\n\nexport interface SectionControllerLifecycleEvent {\n\ttype: \"ready\" | \"disposed\";\n\tkey: SectionControllerKey;\n\tcontroller?: SectionControllerHandle;\n}\n\n/**\n * Subscribe-time arguments for {@link ToolkitCoordinator.subscribeSectionEvents}.\n *\n * Phase D contract: subscriptions follow the toolkit's *active section\n * cohort* automatically. The listener is bound to whatever section\n * controller is active at subscribe time and is migrated, with snapshot\n * replay, on every cohort transition. There is no per-subscription\n * `(sectionId, attemptId)` binding.\n */\nexport interface SectionEventSubscriptionArgs {\n\tlistener: (event: SectionControllerEvent) => void;\n\teventTypes?: readonly SectionControllerEventType[];\n\titemIds?: readonly string[];\n}\n\n/**\n * Internal Phase D subscription record. Holds a listener's filter args\n * and the disposer for whichever section controller it is currently\n * bound to. Detached and re-attached by the coordinator on every cohort\n * transition.\n *\n * @internal\n */\ninterface ActiveSectionSubscription {\n\tlistener: (event: SectionControllerEvent) => void;\n\teventTypes?: readonly SectionControllerEventType[];\n\titemIds?: readonly string[];\n\t/**\n\t * Disposer for the controller `subscribe(...)` call backing this\n\t * subscription, or `null` when no cohort is currently active. Cleared\n\t * on every detach so subsequent re-binds start from a clean slate.\n\t */\n\tunsubscribeCurrent: (() => void) | null;\n}\n\nexport type SectionItemEventType = Exclude<\n\tSectionControllerEventType,\n\t| \"section-navigation-change\"\n\t| \"section-session-applied\"\n\t| \"section-loading-complete\"\n\t| \"section-items-complete-changed\"\n\t| \"section-error\"\n>;\n\nexport type SectionScopedEventType = Extract<\n\tSectionControllerEventType,\n\t| \"section-navigation-change\"\n\t| \"section-session-applied\"\n\t| \"section-loading-complete\"\n\t| \"section-items-complete-changed\"\n\t| \"section-error\"\n>;\n\nexport type SectionItemEvent = Extract<\n\tSectionControllerEvent,\n\t{ type: SectionItemEventType }\n>;\n\nexport type SectionScopedEvent = Extract<\n\tSectionControllerEvent,\n\t{ type: SectionScopedEventType }\n>;\n\n/**\n * Subscribe-time arguments for {@link ToolkitCoordinator.subscribeItemEvents}.\n *\n * See {@link SectionEventSubscriptionArgs} for the Phase D active-cohort\n * binding contract.\n */\nexport interface SectionItemEventSubscriptionArgs {\n\tlistener: (event: SectionItemEvent) => void;\n\teventTypes?: readonly SectionItemEventType[];\n\titemIds?: readonly string[];\n}\n\n/**\n * Subscribe-time arguments for\n * {@link ToolkitCoordinator.subscribeSectionLifecycleEvents}.\n *\n * See {@link SectionEventSubscriptionArgs} for the Phase D active-cohort\n * binding contract.\n */\nexport interface SectionScopedEventSubscriptionArgs {\n\tlistener: (event: SectionScopedEvent) => void;\n\teventTypes?: readonly SectionScopedEventType[];\n}\n\nconst SECTION_ITEM_EVENT_TYPES: readonly SectionItemEventType[] = [\n\t\"item-selected\",\n\t\"item-session-data-changed\",\n\t\"item-session-meta-changed\",\n\t\"item-complete-changed\",\n\t\"content-loaded\",\n\t\"item-player-error\",\n];\n\nconst SECTION_SCOPED_EVENT_TYPES: readonly SectionScopedEventType[] = [\n\t\"section-navigation-change\",\n\t\"section-session-applied\",\n\t\"section-loading-complete\",\n\t\"section-items-complete-changed\",\n\t\"section-error\",\n];\n\nexport interface ToolkitCoordinatorHooks {\n\t/**\n\t * Canonical framework-error hook.\n\t *\n\t * Called once per framework-level failure (tool-config validation,\n\t * provider register / init, TTS bring-up, state load / save, section\n\t * controller init / dispose, coordinator init). The model carries the\n\t * canonical {@link FrameworkErrorModel} shape — `kind`, `severity`,\n\t * `source`, `message`, `details`, `recoverable`, and the original\n\t * thrown value as `cause`.\n\t *\n\t * Listeners should return synchronously and avoid throwing; a thrown\n\t * hook is caught and logged but does not stop fan-out to the other\n\t * subscribers (DOM event, prop callback, `subscribeFrameworkErrors`\n\t * listeners).\n\t */\n\tonFrameworkError?: (model: FrameworkErrorModel) => void;\n\n\tonBeforeTTSInit?: (context: ToolkitErrorContext) => void | Promise<void>;\n\tonTTSReady?: () => void | Promise<void>;\n\tonCoordinatorReady?: (\n\t\tcoordinator: ToolkitCoordinator,\n\t) => void | Promise<void>;\n\n\tonProviderRegistered?: (\n\t\tproviderId: string,\n\t\tmeta: ProviderLifecycleContext,\n\t) => void | Promise<void>;\n\tonProviderInitStart?: (\n\t\tproviderId: string,\n\t\tmeta: ProviderLifecycleContext,\n\t) => void | Promise<void>;\n\tonProviderReady?: (\n\t\tproviderId: string,\n\t\tmeta: ProviderLifecycleContext,\n\t) => void | Promise<void>;\n\n\tonTelemetry?: (\n\t\teventName: string,\n\t\tpayload?: Record<string, unknown>,\n\t) => void | Promise<void>;\n\n\tloadToolState?: () =>\n\t\t| Record<string, Record<string, unknown>>\n\t\t| Promise<Record<string, Record<string, unknown>> | null | undefined>\n\t\t| null\n\t\t| undefined;\n\tsaveToolState?: (\n\t\tstate: Record<string, Record<string, unknown>>,\n\t) => void | Promise<void>;\n\n\t/**\n\t * Provide section-level controller overrides only.\n\t * Avoid instantiating per-item controller graphs here unless item lifecycle\n\t * requirements explicitly demand it.\n\t */\n\tcreateSectionController?: (\n\t\tcontext: SectionControllerContext,\n\t\tdefaults: SectionControllerFactoryDefaults,\n\t) => SectionControllerHandle | Promise<SectionControllerHandle>;\n\n\tcreateSectionSessionPersistence?: (\n\t\tcontext: SectionControllerContext,\n\t\tdefaults: SectionPersistenceFactoryDefaults,\n\t) =>\n\t\t| SectionSessionPersistenceStrategy\n\t\t| Promise<SectionSessionPersistenceStrategy>;\n\n\tonSectionControllerReady?: (\n\t\tcontext: SectionControllerContext,\n\t\tcontroller: SectionControllerHandle,\n\t) => void | Promise<void>;\n\n\tonSectionControllerDispose?: (\n\t\tcontext: SectionControllerContext,\n\t\tcontroller: SectionControllerHandle,\n\t) => void | Promise<void>;\n}\n\nexport type ToolkitTelemetryListener = (args: {\n\teventName: string;\n\tpayload?: Record<string, unknown>;\n}) => void;\n\n/**\n * Service bundle returned by getServiceBundle()\n */\nexport interface ToolkitServiceBundle {\n\tttsService: TTSService;\n\ttoolCoordinator: ToolCoordinator;\n\thighlightCoordinator: HighlightCoordinator;\n\telementToolStateStore: ElementToolStateStore;\n\tcatalogResolver: AccessibilityCatalogResolver;\n\ttoolProviderRegistry: ToolProviderRegistry;\n}\n\n/**\n * ToolkitCoordinator - Orchestrates all assessment toolkit services\n *\n * @example\n * ```typescript\n * // Create coordinator with configuration\n * const coordinator = new ToolkitCoordinator({\n * assessmentId: 'demo-three-questions',\n * tools: {\n * providers: {\n * textToSpeech: { enabled: true, defaultVoice: 'en-US' },\n * answerEliminator: { enabled: true, strategy: 'strikethrough' }\n * },\n * placement: {\n * item: ['textToSpeech', 'answerEliminator']\n * }\n * }\n * });\n *\n * // Pass to section player\n * player.toolkitCoordinator = coordinator;\n *\n * // Access services directly\n * const ttsService = coordinator.ttsService;\n * const toolState = coordinator.elementToolStateStore.getAllState();\n * ```\n */\nexport class ToolkitCoordinator {\n\t/** Assessment identifier (for scoping tool state) */\n\treadonly assessmentId: string;\n\n\t/** Configuration */\n\treadonly config: ToolkitCoordinatorConfig;\n\n\t/** Managed services (public for direct access) */\n\treadonly ttsService: TTSService;\n\treadonly toolCoordinator: ToolCoordinator;\n\treadonly highlightCoordinator: HighlightCoordinator;\n\treadonly elementToolStateStore: ElementToolStateStore;\n\treadonly catalogResolver: AccessibilityCatalogResolver;\n\treadonly toolProviderRegistry: ToolProviderRegistry;\n\treadonly hooks: ToolkitCoordinatorHooks;\n\treadonly lazyInit: boolean;\n\n\t/** Track TTS initialization state */\n\tprivate ttsInitialized = false;\n\tprivate ttsInitPromise?: Promise<void>;\n\tprivate ttsReconfigurePromise?: Promise<void>;\n\tprivate stateLoaded = false;\n\tprivate stateLoadPromise?: Promise<void>;\n\tprivate coordinatorReadyPromise?: Promise<void>;\n\tprivate coordinatorReadyNotified = false;\n\tprivate readonly providerInitPromises = new Map<\n\t\tstring,\n\t\tPromise<ToolProviderApi>\n\t>();\n\tprivate readonly toolRegistry: ToolRegistry;\n\tprivate readonly toolContextResolvers = new Map<\n\t\tstring,\n\t\tToolContextResolver\n\t>();\n\tprivate readonly toolContextResolverChangeListeners = new Set<() => void>();\n\tprivate readonly sectionControllers = new Map<\n\t\tstring,\n\t\tSectionControllerHandle\n\t>();\n\tprivate readonly sectionControllerKeys = new Map<\n\t\tstring,\n\t\tSectionControllerKey\n\t>();\n\tprivate readonly sectionControllerInitPromises = new Map<\n\t\tstring,\n\t\tPromise<SectionControllerHandle>\n\t>();\n\tprivate readonly sectionPersistenceStrategies = new Map<\n\t\tstring,\n\t\tSectionSessionPersistenceStrategy\n\t>();\n\tprivate readonly sectionControllerLifecycleListeners = new Set<\n\t\t(event: SectionControllerLifecycleEvent) => void\n\t>();\n\t/**\n\t * Phase D: every active section-event subscription, indexed by\n\t * listener identity. The listener follows the toolkit's active\n\t * section cohort across transitions; this map is the registry the\n\t * coordinator iterates on every cohort change to detach the listener\n\t * from the outgoing controller, attach it to the new one, and replay\n\t * the snapshot (content-loaded × N then section-loading-complete) in\n\t * canonical order.\n\t *\n\t * Dedup is by listener identity: subscribing the same listener\n\t * function twice replaces the prior subscription's filter args.\n\t */\n\tprivate readonly activeSubscriptions = new Map<\n\t\t(event: SectionControllerEvent) => void,\n\t\tActiveSectionSubscription\n\t>();\n\t/**\n\t * Phase D: map key of the section controller currently treated as\n\t * the *active cohort*. Set by `getOrCreateSectionController` (both\n\t * the create-new and resolve-existing paths) and cleared when the\n\t * matching controller is disposed. `null` while no cohort exists,\n\t * which is the only state where `subscribeSectionEvents` throws.\n\t */\n\tprivate activeCohortMapKey: string | null = null;\n\t/**\n\t * Latest requested active cohort. Async controller initialization can\n\t * resolve out of order; only the most recent request may migrate active\n\t * subscriptions. Older completions still populate the controller cache.\n\t */\n\tprivate latestRequestedActiveCohortMapKey: string | null = null;\n\tprivate readonly telemetryListeners = new Set<ToolkitTelemetryListener>();\n\tprivate readonly frameworkErrorBus: FrameworkErrorBus;\n\tprivate readonly ownsFrameworkErrorBus: boolean;\n\n\t/**\n\t * Unified Tool Policy Engine. Owned by the coordinator and lives\n\t * for the lifetime of the coordinator instance — there is no\n\t * explicit teardown path today; the engine and its listener set\n\t * are reclaimed by GC when the coordinator becomes unreachable.\n\t * Subscribers attached via {@link onPolicyChange} must therefore\n\t * detach via the unsubscribe function the engine returns; do not\n\t * rely on a `disposed` event being emitted on coordinator teardown.\n\t *\n\t * Hosts read decisions via {@link decideToolPolicy} or subscribe\n\t * to changes via {@link onPolicyChange}.\n\t */\n\tprivate readonly policyEngine: ToolPolicyEngine;\n\n\t/**\n\t * Host-set override for PNP/profile enforcement. `null` (the default) means\n\t * \"auto\" — the coordinator infers the effective mode from the\n\t * PNP/profile policy inputs the bound `AssessmentEntity` and `AssessmentItemRef`\n\t * actually carry (see {@link resolveEffectivePnpEnforcement}).\n\t * `\"on\"` / `\"off\"` are explicit host opt-in / opt-out and stick\n\t * across subsequent assessment / item swaps until the host clears\n\t * the override by calling `setPnpEnforcement(null)`.\n\t */\n\tprivate pnpEnforcementOverride: PnpEnforcementMode | null = null;\n\n\t/**\n\t * Last assessment passed to {@link updateAssessment}. Read by\n\t * {@link resolveEffectivePnpEnforcement} to compute auto-mode.\n\t * The engine's own copy is the canonical record for decisions;\n\t * this mirror exists only so the auto-mode helper does not need\n\t * to round-trip through {@link policyEngine}'s frozen snapshot.\n\t */\n\tprivate boundAssessment: AssessmentEntity | null = null;\n\n\t/**\n\t * Last item reference passed to {@link updateCurrentItemRef}.\n\t * Mirrored alongside {@link boundAssessment} so\n\t * {@link resolveEffectivePnpEnforcement} can detect item-level\n\t * profile policy inputs (`requiredTools` / `restrictedTools` /\n\t * `toolParameters`) without round-tripping through the engine's\n\t * frozen snapshot.\n\t */\n\tprivate boundCurrentItemRef: AssessmentItemRef | null = null;\n\n\tprivate static resolveConfig(\n\t\tconfig: ToolkitCoordinatorConfig,\n\t): ToolkitCoordinatorConfig {\n\t\tconst strictness = normalizeToolConfigStrictness(\n\t\t\tconfig.toolConfigStrictness,\n\t\t);\n\t\tconst toolRegistry = config.toolRegistry ?? createPackagedToolRegistry();\n\t\tconst normalized =\n\t\t\tconfig.deferToolConfigValidation === true\n\t\t\t\t? normalizeToolsConfig(config.tools as any)\n\t\t\t\t: normalizeAndValidateToolsConfig(config.tools as any, {\n\t\t\t\t\t\tstrictness,\n\t\t\t\t\t\tsource: \"ToolkitCoordinator.init\",\n\t\t\t\t\t\ttoolRegistry,\n\t\t\t\t\t}).config;\n\t\tconst defaultProviders: ToolkitToolsConfig[\"providers\"] = {\n\t\t\ttextToSpeech: {\n\t\t\t\tenabled: true,\n\t\t\t\tbackend: \"browser\",\n\t\t\t},\n\t\t\tannotationToolbar: {\n\t\t\t\tenabled: true,\n\t\t\t},\n\t\t};\n\n\t\treturn {\n\t\t\t...config,\n\t\t\ttoolConfigStrictness: strictness,\n\t\t\ttoolRegistry,\n\t\t\ttools: {\n\t\t\t\t...normalized,\n\t\t\t\tproviders: {\n\t\t\t\t\t...defaultProviders,\n\t\t\t\t\t...normalized.providers,\n\t\t\t\t},\n\t\t\t},\n\t\t\taccessibility: {\n\t\t\t\tlanguage: \"en-US\",\n\t\t\t\t...(config.accessibility ?? {}),\n\t\t\t\tcatalogs: config.accessibility?.catalogs ?? [],\n\t\t\t},\n\t\t};\n\t}\n\n\tconstructor(config: ToolkitCoordinatorConfig) {\n\t\tif (!config.assessmentId) {\n\t\t\tthrow new Error(\"ToolkitCoordinator requires assessmentId in config\");\n\t\t}\n\n\t\tconst resolvedConfig = ToolkitCoordinator.resolveConfig(config);\n\n\t\tthis.assessmentId = resolvedConfig.assessmentId;\n\t\tthis.config = resolvedConfig;\n\t\tthis.toolRegistry =\n\t\t\tresolvedConfig.toolRegistry ?? createPackagedToolRegistry();\n\t\tthis.installToolContextResolvers(resolvedConfig.toolContextResolvers);\n\t\tthis.hooks = resolvedConfig.hooks ?? {};\n\t\tthis.lazyInit = config.lazyInit === true;\n\t\tthis.pnpEnforcementOverride = this.resolveConfiguredPnpEnforcement();\n\n\t\t// Use the host-provided framework-error bus if one was passed\n\t\t// (typical when embedded inside <pie-assessment-toolkit>, so\n\t\t// pre-coordinator failures from the CE flow through the same\n\t\t// fan-out as coordinator failures). Otherwise own a private one.\n\t\tthis.frameworkErrorBus =\n\t\t\tconfig.frameworkErrorBus ?? new FrameworkErrorBus();\n\t\tthis.ownsFrameworkErrorBus = !config.frameworkErrorBus;\n\t\tthis.subscribeFrameworkErrorHookAdapters();\n\n\t\t// Initialize all services\n\t\tthis.toolCoordinator = new ToolCoordinator();\n\t\tthis.highlightCoordinator = new HighlightCoordinator();\n\t\tthis.elementToolStateStore = new ElementToolStateStore();\n\t\tthis.catalogResolver = new AccessibilityCatalogResolver(\n\t\t\tresolvedConfig.accessibility?.catalogs || [],\n\t\t\tresolvedConfig.accessibility?.language || \"en-US\",\n\t\t);\n\n\t\t// Initialize tool provider registry\n\t\tthis.toolProviderRegistry = new ToolProviderRegistry();\n\t\tthis._registerToolProviders();\n\n\t\t// Initialize TTS service based on config\n\t\tthis.ttsService = new TTSService();\n\t\tthis.setupStatePersistenceHooks();\n\n\t\t// M8 PR 2 — construct the unified ToolPolicyEngine seeded with\n\t\t// the validated tools config. PNP/profile inputs (`assessment`,\n\t\t// `currentItemRef`) start `null`; `pnpEnforcement` is resolved\n\t\t// through {@link resolveEffectivePnpEnforcement}, which flips\n\t\t// to `\"on\"` only once the bound assessment or item carries\n\t\t// actual profile material. Hosts that only consume the\n\t\t// engine for placement/policy gating get the pre-PR-2 behavior\n\t\t// bit-for-bit.\n\t\tthis.policyEngine = new ToolPolicyEngine({\n\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\tcontextId: `toolkit-coordinator:${this.assessmentId}`,\n\t\t\tinputs: {\n\t\t\t\ttools: this.config.tools as CanonicalToolsConfig,\n\t\t\t\tassessment: null,\n\t\t\t\tcurrentItemRef: null,\n\t\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t\t},\n\t\t});\n\n\t\tif (!this.lazyInit) {\n\t\t\tvoid this.waitUntilReady().catch((err) => {\n\t\t\t\tconsole.error(\"[ToolkitCoordinator] Failed eager initialization:\", err);\n\t\t\t\tthis.handleError(err, { phase: \"coordinator-ready\" });\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Subscribe the canonical `onFrameworkError` hook adapter to the\n\t * framework-error bus.\n\t *\n\t * Called once from the constructor. The adapter inspects the live\n\t * `this.hooks` reference, so a hook added later via {@link setHooks}\n\t * is picked up automatically without re-subscribing.\n\t */\n\tprivate subscribeFrameworkErrorHookAdapters(): void {\n\t\tthis.frameworkErrorBus.subscribeFrameworkErrors((model) => {\n\t\t\tconst hook = this.hooks.onFrameworkError;\n\t\t\tif (!hook) return;\n\t\t\ttry {\n\t\t\t\thook(model);\n\t\t\t} catch (hookError) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] onFrameworkError hook failed:\",\n\t\t\t\t\thookError,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Emit a telemetry event to `onTelemetry` hook + all `subscribeTelemetry`\n\t * listeners.\n\t *\n\t * **Naming convention.** Event names MUST be prefixed at the call site,\n\t * not auto-decorated here. The convention is:\n\t *\n\t * - `pie-toolkit-*` for toolkit lifecycle (state load, providers,\n\t * coordinator readiness, section-controller register/dispose, TTS\n\t * bring-up, tool-config updates, etc.).\n\t * - `pie-tool-*` for individual tool events (provider init lifecycle,\n\t * provider backend calls, tool-specific telemetry forwarded from\n\t * `__pieTelemetry`).\n\t * - `pie-section-*` is reserved for section-player layout events\n\t * surfaced via `attachInstrumentationEventBridge` and is not emitted\n\t * from this method directly.\n\t *\n\t * Anything that does not fit a documented prefix is a deliberate decision\n\t * to be raised in code review, not a fallback. There is no \"auto prefix\"\n\t * here on purpose: it keeps every emit-site honest about which namespace\n\t * it owns, and lets `subscribeTelemetry` consumers compare against\n\t * documented strings without per-consumer normalization.\n\t */\n\tprivate async emitTelemetry(\n\t\teventName: string,\n\t\tpayload?: Record<string, unknown>,\n\t): Promise<void> {\n\t\ttry {\n\t\t\tawait this.hooks.onTelemetry?.(eventName, payload);\n\t\t} catch (err) {\n\t\t\tconsole.warn(\"[ToolkitCoordinator] telemetry hook failed:\", err);\n\t\t}\n\t\tconst nextPayload = payload ? { ...payload } : undefined;\n\t\tfor (const listener of this.telemetryListeners) {\n\t\t\ttry {\n\t\t\t\tlistener({\n\t\t\t\t\teventName,\n\t\t\t\t\tpayload: nextPayload ? { ...nextPayload } : undefined,\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\tconsole.warn(\"[ToolkitCoordinator] telemetry listener failed:\", err);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate emitSectionControllerLifecycle(\n\t\tevent: SectionControllerLifecycleEvent,\n\t): void {\n\t\tfor (const listener of this.sectionControllerLifecycleListeners) {\n\t\t\ttry {\n\t\t\t\tlistener(event);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] section controller lifecycle listener failed:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate handleError(error: unknown, context: ToolkitErrorContext): void {\n\t\tconst model = frameworkErrorFromCoordinatorContext({\n\t\t\terror,\n\t\t\tcontext,\n\t\t});\n\t\tthis.frameworkErrorBus.reportFrameworkError(model);\n\t}\n\n\t/**\n\t * Subscribe to framework-error events emitted by this coordinator.\n\t *\n\t * See `ToolkitCoordinatorApi.subscribeFrameworkErrors` for the\n\t * contract. The bus is shared with the canonical\n\t * `onFrameworkError` lifecycle hook, so a listener registered here\n\t * sees the same fan-out the hook sees.\n\t */\n\tpublic subscribeFrameworkErrors(\n\t\tlistener: FrameworkErrorListener,\n\t): () => void {\n\t\treturn this.frameworkErrorBus.subscribeFrameworkErrors(listener);\n\t}\n\n\t/**\n\t * Report a framework-error model directly into this coordinator's bus.\n\t *\n\t * Used by embedding hosts (e.g. `<pie-assessment-toolkit>`) that\n\t * pre-construct their own framework-error model in a path that does\n\t * not go through `handleError` — for example, `runtime-init` failures\n\t * raised before any coordinator phase, or `tool-config` failures\n\t * synthesized from validation diagnostics.\n\t *\n\t * Hosts that already share their bus via the constructor's\n\t * `frameworkErrorBus` config field do not need to call this; their\n\t * own `bus.reportFrameworkError(model)` is observed here.\n\t *\n\t * @internal\n\t */\n\tpublic reportFrameworkError(model: FrameworkErrorModel): void {\n\t\tthis.frameworkErrorBus.reportFrameworkError(model);\n\t}\n\n\tprivate getSectionControllerMapKey(key: SectionControllerKey): string {\n\t\treturn `${key.assessmentId}::${key.sectionId}::${key.attemptId || \"\"}`;\n\t}\n\n\tprivate createDefaultSectionPersistence(): SectionSessionPersistenceStrategy {\n\t\tconst storage = (() => {\n\t\t\ttry {\n\t\t\t\tif (typeof window === \"undefined\") return null;\n\t\t\t\treturn window.localStorage;\n\t\t\t} catch {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t})();\n\t\tconst getStorageKey = (context: SectionControllerContext): string => {\n\t\t\tconst { assessmentId, sectionId, attemptId } = context.key;\n\t\t\treturn `pie:section-controller:v1:${assessmentId}:${sectionId}:${attemptId || \"default\"}`;\n\t\t};\n\t\treturn {\n\t\t\tasync loadSession(context) {\n\t\t\t\tif (!storage) return null;\n\t\t\t\tconst value = storage.getItem(getStorageKey(context));\n\t\t\t\tif (!value) return null;\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(value);\n\t\t\t\t} catch {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync saveSession(context, session) {\n\t\t\t\tif (!storage) return;\n\t\t\t\tstorage.setItem(getStorageKey(context), JSON.stringify(session));\n\t\t\t},\n\t\t\tasync clearSession(context) {\n\t\t\t\tif (!storage) return;\n\t\t\t\tstorage.removeItem(getStorageKey(context));\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async resolveSectionPersistence(\n\t\tcontext: SectionControllerContext,\n\t): Promise<SectionSessionPersistenceStrategy> {\n\t\tconst cacheKey = this.getSectionControllerMapKey(context.key);\n\t\tconst existing = this.sectionPersistenceStrategies.get(cacheKey);\n\t\tif (existing) return existing;\n\n\t\tconst defaults: SectionPersistenceFactoryDefaults = {\n\t\t\tcreateDefaultPersistence: () => this.createDefaultSectionPersistence(),\n\t\t};\n\t\tconst strategy =\n\t\t\t(await this.hooks.createSectionSessionPersistence?.(context, defaults)) ??\n\t\t\t(await defaults.createDefaultPersistence());\n\t\tthis.sectionPersistenceStrategies.set(cacheKey, strategy);\n\t\treturn strategy;\n\t}\n\n\tprivate setupStatePersistenceHooks(): void {\n\t\tthis.elementToolStateStore.setOnStateChange((state) => {\n\t\t\tif (!this.hooks.saveToolState) return;\n\t\t\tvoid Promise.resolve(this.hooks.saveToolState(state)).catch((err) => {\n\t\t\t\tthis.handleError(err, { phase: \"state-save\" });\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate async ensureStateLoaded(): Promise<void> {\n\t\tif (this.stateLoaded) return;\n\t\tif (this.stateLoadPromise) return this.stateLoadPromise;\n\t\tthis.stateLoadPromise = (async () => {\n\t\t\tconst loader = this.hooks.loadToolState;\n\t\t\tif (!loader) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst state = await loader();\n\t\t\t\tif (state && typeof state === \"object\") {\n\t\t\t\t\tthis.elementToolStateStore.loadState(state);\n\t\t\t\t}\n\t\t\t\tthis.stateLoaded = true;\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-tool-state-loaded\", {\n\t\t\t\t\thasState: Boolean(state),\n\t\t\t\t});\n\t\t\t} catch (err) {\n\t\t\t\tthis.handleError(err, { phase: \"state-load\" });\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tthis.stateLoadPromise = undefined;\n\t\t});\n\t\treturn this.stateLoadPromise;\n\t}\n\n\t/**\n\t * Register tool providers in the registry\n\t */\n\tprivate _registerToolProviders(): void {\n\t\tconst descriptorTools = this.getProviderDescriptorTools();\n\t\tfor (const tool of descriptorTools) {\n\t\t\tvoid this.registerProviderFromTool(tool);\n\t\t}\n\t}\n\n\tprivate getProviderDescriptorTools(): ToolRegistration[] {\n\t\treturn this.toolRegistry.getAllTools().filter((tool) => !!tool.provider);\n\t}\n\n\tprivate async registerProviderFromTool(\n\t\ttool: ToolRegistration,\n\t): Promise<void> {\n\t\tconst descriptor = tool.provider;\n\t\tif (!descriptor) return;\n\t\tconst toolConfig = this.getToolConfig(tool.toolId) || undefined;\n\t\tif (toolConfig?.enabled === false) return;\n\t\tconst providerId =\n\t\t\tdescriptor.getProviderId?.(toolConfig) ??\n\t\t\ttoolConfig?.provider?.id ??\n\t\t\ttool.toolId;\n\t\tif (this.toolProviderRegistry.has(providerId)) return;\n\t\tconst provider = descriptor.createProvider(toolConfig);\n\t\tconst initConfig =\n\t\t\tdescriptor.getInitConfig?.(toolConfig) ??\n\t\t\ttoolConfig?.provider?.init ??\n\t\t\t{};\n\t\tconst initConfigWithTelemetry = this.addToolTelemetryReporter({\n\t\t\ttoolId: tool.toolId,\n\t\t\tproviderId,\n\t\t\tinitConfig,\n\t\t});\n\t\tconst registryTelemetry = this.createToolTelemetryForwarder({\n\t\t\ttoolId: tool.toolId,\n\t\t\tproviderId,\n\t\t});\n\t\tconst authFetcher =\n\t\t\tdescriptor.getAuthFetcher?.(toolConfig) ??\n\t\t\ttoolConfig?.provider?.runtime?.authFetcher;\n\t\tawait this.registerProvider(providerId, {\n\t\t\tprovider,\n\t\t\tconfig: initConfigWithTelemetry,\n\t\t\tlazy: descriptor.lazy ?? true,\n\t\t\tauthFetcher,\n\t\t\tonTelemetry: registryTelemetry,\n\t\t});\n\t}\n\n\tprivate createToolTelemetryForwarder(args: {\n\t\ttoolId: string;\n\t\tproviderId: string;\n\t}): (eventName: string, payload?: Record<string, unknown>) => Promise<void> {\n\t\treturn async (eventName: string, payload?: Record<string, unknown>) => {\n\t\t\tawait this.emitTelemetry(eventName, {\n\t\t\t\t...(payload || {}),\n\t\t\t\ttoolId: args.toolId,\n\t\t\t\tproviderId: args.providerId,\n\t\t\t});\n\t\t};\n\t}\n\n\tprivate addToolTelemetryReporter(args: {\n\t\ttoolId: string;\n\t\tproviderId: string;\n\t\tinitConfig: unknown;\n\t}): Record<string, unknown> {\n\t\tconst configObject =\n\t\t\targs.initConfig && typeof args.initConfig === \"object\"\n\t\t\t\t? { ...(args.initConfig as Record<string, unknown>) }\n\t\t\t\t: {};\n\t\tconst existingReporter =\n\t\t\ttypeof configObject.onTelemetry === \"function\"\n\t\t\t\t? (configObject.onTelemetry as (\n\t\t\t\t\t\teventName: string,\n\t\t\t\t\t\tpayload?: Record<string, unknown>,\n\t\t\t\t\t) => void | Promise<void>)\n\t\t\t\t: null;\n\t\tconst forwardTelemetry = this.createToolTelemetryForwarder({\n\t\t\ttoolId: args.toolId,\n\t\t\tproviderId: args.providerId,\n\t\t});\n\t\tconfigObject.onTelemetry = async (\n\t\t\teventName: string,\n\t\t\tpayload?: Record<string, unknown>,\n\t\t) => {\n\t\t\tif (existingReporter) {\n\t\t\t\tawait existingReporter(eventName, payload);\n\t\t\t}\n\t\t\tawait forwardTelemetry(eventName, payload);\n\t\t};\n\t\treturn configObject;\n\t}\n\n\tprivate async registerProvider(\n\t\tproviderId: string,\n\t\tconfig: Parameters<ToolProviderRegistry[\"register\"]>[1],\n\t): Promise<void> {\n\t\ttry {\n\t\t\tthis.toolProviderRegistry.register(providerId, config);\n\t\t\tconst meta: ProviderLifecycleContext = {\n\t\t\t\tproviderId,\n\t\t\t\tproviderName: config.provider.providerName,\n\t\t\t};\n\t\t\tawait this.hooks.onProviderRegistered?.(providerId, meta);\n\t\t\tawait this.emitTelemetry(\"pie-toolkit-provider-registered\", {\n\t\t\t\tproviderId,\n\t\t\t\tproviderName: config.provider.providerName,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tconsole.warn(\n\t\t\t\t`[ToolkitCoordinator] Failed to register provider \"${providerId}\":`,\n\t\t\t\terr,\n\t\t\t);\n\t\t\tthis.handleError(err, { phase: \"provider-register\", providerId });\n\t\t}\n\t}\n\n\tpublic async ensureProviderReady(\n\t\tproviderId: string,\n\t): Promise<ToolProviderApi> {\n\t\tconst existing = this.providerInitPromises.get(providerId);\n\t\tif (existing) return existing;\n\t\tconst promise = (async () => {\n\t\t\tconst provider = await this.toolProviderRegistry.getProvider(\n\t\t\t\tproviderId,\n\t\t\t\tfalse,\n\t\t\t);\n\t\t\tconst meta: ProviderLifecycleContext = {\n\t\t\t\tproviderId,\n\t\t\t\tproviderName: provider.providerName,\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tawait this.hooks.onProviderInitStart?.(providerId, meta);\n\t\t\t\tawait this.toolProviderRegistry.initialize(providerId);\n\t\t\t\tawait this.hooks.onProviderReady?.(providerId, meta);\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-provider-ready\", { providerId });\n\t\t\t\treturn provider;\n\t\t\t} catch (err) {\n\t\t\t\tconst error = err instanceof Error ? err : new Error(String(err));\n\t\t\t\tthis.handleError(error, { phase: \"provider-init\", providerId });\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tthis.providerInitPromises.delete(providerId);\n\t\t});\n\t\tthis.providerInitPromises.set(providerId, promise);\n\t\treturn promise;\n\t}\n\n\tpublic setHooks(hooks: ToolkitCoordinatorHooks): void {\n\t\tObject.assign(this.hooks, hooks);\n\t\tthis.setupStatePersistenceHooks();\n\n\t\tif (hooks.onCoordinatorReady && this.isReady()) {\n\t\t\tvoid Promise.resolve(hooks.onCoordinatorReady(this)).catch((err) => {\n\t\t\t\tthis.handleError(err, { phase: \"coordinator-ready\" });\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic subscribeTelemetry(listener: ToolkitTelemetryListener): () => void {\n\t\tthis.telemetryListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.telemetryListeners.delete(listener);\n\t\t};\n\t}\n\n\tpublic getSectionController(args: {\n\t\tsectionId: string;\n\t\tattemptId?: string;\n\t}): SectionControllerHandle | undefined {\n\t\tconst key: SectionControllerKey = {\n\t\t\tassessmentId: this.assessmentId,\n\t\t\tsectionId: args.sectionId,\n\t\t\tattemptId: args.attemptId,\n\t\t};\n\t\treturn this.sectionControllers.get(this.getSectionControllerMapKey(key));\n\t}\n\n\tpublic subscribeSectionEvents(\n\t\targs: SectionEventSubscriptionArgs,\n\t): () => void {\n\t\t// Phase D: subscriptions follow the toolkit's *active section\n\t\t// cohort* automatically. We bind the listener to whichever\n\t\t// controller is currently active and re-bind it on every\n\t\t// `getOrCreateSectionController` / `disposeSectionController`\n\t\t// transition, with snapshot replay on each migration.\n\t\tif (this.activeCohortMapKey === null) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[ToolkitCoordinator] subscribeSectionEvents requires an active section cohort; call getOrCreateSectionController first.\",\n\t\t\t);\n\t\t}\n\t\tconst previous = this.activeSubscriptions.get(args.listener);\n\t\tif (previous) {\n\t\t\tprevious.unsubscribeCurrent?.();\n\t\t\tprevious.unsubscribeCurrent = null;\n\t\t}\n\t\tconst sub: ActiveSectionSubscription = {\n\t\t\tlistener: args.listener,\n\t\t\teventTypes: args.eventTypes,\n\t\t\titemIds: args.itemIds,\n\t\t\tunsubscribeCurrent: null,\n\t\t};\n\t\tthis.activeSubscriptions.set(args.listener, sub);\n\n\t\tconst controller = this.sectionControllers.get(this.activeCohortMapKey);\n\t\tif (controller) {\n\t\t\tthis.bindSubscriptionToController(sub, controller);\n\t\t}\n\n\t\tlet detached = false;\n\t\treturn () => {\n\t\t\tif (detached) return;\n\t\t\tdetached = true;\n\t\t\tsub.unsubscribeCurrent?.();\n\t\t\tsub.unsubscribeCurrent = null;\n\t\t\t// Only delete if the registry still points at *this* sub. A\n\t\t\t// re-subscribe with the same listener replaces the entry; an\n\t\t\t// old disposer must not stomp the new one.\n\t\t\tif (this.activeSubscriptions.get(args.listener) === sub) {\n\t\t\t\tthis.activeSubscriptions.delete(args.listener);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Bind a Phase D subscription to a section controller. Detaches any\n\t * prior controller binding the subscription was holding, attaches a\n\t * fresh `controller.subscribe(...)` callback, and replays the\n\t * canonical late-subscribe sequence (content-loaded × N then\n\t * section-loading-complete) so the listener observes the same\n\t * ordering a fresh subscriber would have seen.\n\t *\n\t * Listener throws are caught and `console.warn`-logged; the throw\n\t * does not interrupt fan-out to the remaining listeners (matches\n\t * the {@link FrameworkErrorBus} isolation pattern).\n\t */\n\tprivate bindSubscriptionToController(\n\t\tsub: ActiveSectionSubscription,\n\t\tcontroller: SectionControllerHandle,\n\t): void {\n\t\tsub.unsubscribeCurrent?.();\n\t\tsub.unsubscribeCurrent = null;\n\n\t\tconst subscribe = controller.subscribe;\n\t\tif (typeof subscribe !== \"function\") return;\n\n\t\tconst predicate = this.buildSectionEventPredicate(sub);\n\n\t\tsub.unsubscribeCurrent = subscribe.call(controller, (event) => {\n\t\t\tif (!predicate(event)) return;\n\t\t\tthis.deliverSectionEventSafely(sub.listener, event);\n\t\t});\n\n\t\tconst contentLoadedReplays =\n\t\t\tthis.buildContentLoadedReplayEvents(controller);\n\t\tfor (const event of contentLoadedReplays) {\n\t\t\tif (predicate(event)) {\n\t\t\t\tthis.deliverSectionEventSafely(sub.listener, event);\n\t\t\t}\n\t\t}\n\t\tconst loadingComplete = this.buildLoadingCompleteReplayEvent(controller);\n\t\tif (loadingComplete && predicate(loadingComplete)) {\n\t\t\tthis.deliverSectionEventSafely(sub.listener, loadingComplete);\n\t\t}\n\t}\n\n\tprivate deliverSectionEventSafely(\n\t\tlistener: (event: SectionControllerEvent) => void,\n\t\tevent: SectionControllerEvent,\n\t): void {\n\t\ttry {\n\t\t\tlistener(event);\n\t\t} catch (error) {\n\t\t\tconsole.warn(\n\t\t\t\t\"[ToolkitCoordinator] section-event listener failed:\",\n\t\t\t\terror,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Mark the given map key as the active section cohort. Called from\n\t * `getOrCreateSectionController` (both create-new and resolve-existing\n\t * paths) so a cohort transition through either path migrates active\n\t * subscriptions.\n\t *\n\t * Same-cohort re-entry is a no-op so a same-cohort `updateInput`\n\t * (PnP toggle, prompt edit) doesn't double-replay snapshots to\n\t * already-bound listeners.\n\t */\n\tprivate setActiveCohort(mapKey: string): void {\n\t\tif (this.activeCohortMapKey === mapKey) return;\n\t\tthis.activeCohortMapKey = mapKey;\n\t\tconst controller = this.sectionControllers.get(mapKey);\n\t\tif (!controller) return;\n\t\t// Snapshot the subscription list before iterating: a listener may\n\t\t// synchronously call `subscribeSectionEvents(...)` from inside its\n\t\t// replay delivery, which inserts a new entry into\n\t\t// `activeSubscriptions`. Map iteration yields keys inserted\n\t\t// during the loop; without snapshotting, the inner subscribe path\n\t\t// would bind the new listener once (correctly, with replay) and\n\t\t// the outer loop would then visit it a second time, double-\n\t\t// replaying the snapshot. Snapshot keeps \"replay once per cohort\n\t\t// transition\" intact.\n\t\tfor (const sub of Array.from(this.activeSubscriptions.values())) {\n\t\t\tthis.bindSubscriptionToController(sub, controller);\n\t\t}\n\t}\n\n\tprivate setActiveCohortIfLatestRequest(mapKey: string): void {\n\t\tif (this.latestRequestedActiveCohortMapKey !== mapKey) return;\n\t\tthis.setActiveCohort(mapKey);\n\t}\n\n\tprivate suspendActiveCohortIfSuperseded(mapKey: string): void {\n\t\tif (this.activeCohortMapKey === null) return;\n\t\tif (this.activeCohortMapKey === mapKey) return;\n\t\tthis.activeCohortMapKey = null;\n\t\tfor (const sub of Array.from(this.activeSubscriptions.values())) {\n\t\t\tsub.unsubscribeCurrent?.();\n\t\t\tsub.unsubscribeCurrent = null;\n\t\t}\n\t}\n\n\t/**\n\t * Clear the active cohort if `mapKey` matches it, detaching every\n\t * active subscription's current controller binding. Subscriptions\n\t * stay in the registry — a subsequent `setActiveCohort(...)` will\n\t * re-bind them to the new controller.\n\t */\n\tprivate clearActiveCohortIfMatches(mapKey: string): void {\n\t\tif (this.activeCohortMapKey !== mapKey) return;\n\t\tthis.activeCohortMapKey = null;\n\t\t// Symmetric snapshot for safety: a disposer fired during detach\n\t\t// could mutate `activeSubscriptions`. Detach is silent (no listener\n\t\t// fan-out), so re-entrancy exposure is lower than `setActiveCohort`,\n\t\t// but the snapshot keeps both paths uniform.\n\t\tfor (const sub of Array.from(this.activeSubscriptions.values())) {\n\t\t\tsub.unsubscribeCurrent?.();\n\t\t\tsub.unsubscribeCurrent = null;\n\t\t}\n\t}\n\n\tprivate buildSectionEventPredicate(\n\t\targs: Pick<SectionEventSubscriptionArgs, \"eventTypes\" | \"itemIds\">,\n\t): (event: SectionControllerEvent) => boolean {\n\t\tconst eventTypeFilter = args.eventTypes ? new Set(args.eventTypes) : null;\n\t\tconst itemIdFilter = args.itemIds ? new Set(args.itemIds) : null;\n\t\treturn (event: SectionControllerEvent): boolean => {\n\t\t\tif (eventTypeFilter || itemIdFilter) {\n\t\t\t\tconst eventType = event?.type || null;\n\t\t\t\tif (\n\t\t\t\t\teventTypeFilter &&\n\t\t\t\t\t(!eventType || !eventTypeFilter.has(eventType))\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (itemIdFilter) {\n\t\t\t\t\tconst hasMatchingItem = Array.from(\n\t\t\t\t\t\tthis.collectEventItemIds(event),\n\t\t\t\t\t).some((itemId) => itemIdFilter.has(itemId));\n\t\t\t\t\tif (!hasMatchingItem) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t}\n\n\tprivate collectEventItemIds(event: SectionControllerEvent): Set<string> {\n\t\tconst itemIds = new Set<string>();\n\t\tif (\"itemId\" in event && typeof event.itemId === \"string\") {\n\t\t\titemIds.add(event.itemId);\n\t\t}\n\t\tif (\n\t\t\t\"canonicalItemId\" in event &&\n\t\t\ttypeof event.canonicalItemId === \"string\"\n\t\t) {\n\t\t\titemIds.add(event.canonicalItemId);\n\t\t}\n\t\tif (\"currentItemId\" in event && typeof event.currentItemId === \"string\") {\n\t\t\titemIds.add(event.currentItemId);\n\t\t}\n\t\tif (\"previousItemId\" in event && typeof event.previousItemId === \"string\") {\n\t\t\titemIds.add(event.previousItemId);\n\t\t}\n\t\treturn itemIds;\n\t}\n\n\t/**\n\t * Build replay `content-loaded` events for renderables the controller has\n\t * already finished loading.\n\t *\n\t * Strict by design: only renderables explicitly reported in\n\t * `runtimeState.loadedRenderables` are replayed. Synthetic test harnesses\n\t * that omit the field (or controllers from older revisions that did not\n\t * populate it) get an empty replay set rather than a fabricated one — that\n\t * preserves the contract that replays mirror events that actually fired.\n\t *\n\t * Order follows registration order from\n\t * `SectionController.collectLoadedRenderableSnapshot`, which mirrors the\n\t * order live `content-loaded` events were emitted in.\n\t */\n\tprivate buildContentLoadedReplayEvents(\n\t\tcontroller: SectionControllerHandle,\n\t): SectionControllerEvent[] {\n\t\tconst runtimeState = controller.getRuntimeState?.();\n\t\tconst loadedRenderables = runtimeState?.loadedRenderables;\n\t\tif (!Array.isArray(loadedRenderables) || loadedRenderables.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst currentItemIndex =\n\t\t\ttypeof runtimeState?.currentItemIndex === \"number\" &&\n\t\t\tNumber.isFinite(runtimeState.currentItemIndex)\n\t\t\t\t? runtimeState.currentItemIndex\n\t\t\t\t: 0;\n\t\tconst timestamp = Date.now();\n\t\tconst events: SectionControllerEvent[] = [];\n\t\tfor (const renderable of loadedRenderables) {\n\t\t\tif (!renderable) continue;\n\t\t\tconst itemId = renderable.itemId;\n\t\t\tconst canonicalItemId =\n\t\t\t\ttypeof renderable.canonicalItemId === \"string\" &&\n\t\t\t\trenderable.canonicalItemId\n\t\t\t\t\t? renderable.canonicalItemId\n\t\t\t\t\t: itemId;\n\t\t\tif (typeof itemId !== \"string\" || !itemId) continue;\n\t\t\tevents.push({\n\t\t\t\ttype: \"content-loaded\",\n\t\t\t\tcontentKind: renderable.contentKind ?? \"unknown\",\n\t\t\t\titemId,\n\t\t\t\tcanonicalItemId,\n\t\t\t\tcurrentItemIndex,\n\t\t\t\ttimestamp,\n\t\t\t});\n\t\t}\n\t\treturn events;\n\t}\n\n\tprivate buildLoadingCompleteReplayEvent(\n\t\tcontroller: SectionControllerHandle,\n\t): SectionControllerEvent | null {\n\t\tconst runtimeState = controller.getRuntimeState?.();\n\t\tif (runtimeState?.loadingComplete !== true) return null;\n\t\tconst totalRegistered =\n\t\t\ttypeof runtimeState.totalRegistered === \"number\" &&\n\t\t\tNumber.isFinite(runtimeState.totalRegistered)\n\t\t\t\t? Math.max(0, runtimeState.totalRegistered)\n\t\t\t\t: 0;\n\t\tconst totalLoaded =\n\t\t\ttypeof runtimeState.totalLoaded === \"number\" &&\n\t\t\tNumber.isFinite(runtimeState.totalLoaded)\n\t\t\t\t? Math.max(0, runtimeState.totalLoaded)\n\t\t\t\t: totalRegistered;\n\t\treturn {\n\t\t\ttype: \"section-loading-complete\",\n\t\t\ttotalRegistered,\n\t\t\ttotalLoaded,\n\t\t\tcurrentItemIndex: runtimeState.currentItemIndex,\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to item-scoped controller events.\n\t *\n\t * Same active-cohort binding contract as\n\t * {@link subscribeSectionEvents}; defaults `eventTypes` to the\n\t * item-scoped subset.\n\t */\n\tpublic subscribeItemEvents(\n\t\targs: SectionItemEventSubscriptionArgs,\n\t): () => void {\n\t\treturn this.subscribeSectionEvents({\n\t\t\teventTypes: args.eventTypes || SECTION_ITEM_EVENT_TYPES,\n\t\t\titemIds: args.itemIds,\n\t\t\tlistener: args.listener as (event: SectionControllerEvent) => void,\n\t\t});\n\t}\n\n\t/**\n\t * Subscribe to section-scoped controller events.\n\t *\n\t * Same active-cohort binding contract as\n\t * {@link subscribeSectionEvents}; defaults `eventTypes` to the\n\t * section-scoped subset. Section-scoped events do not carry item\n\t * identifiers, so this helper intentionally does not expose\n\t * `itemIds` filtering.\n\t */\n\tpublic subscribeSectionLifecycleEvents(\n\t\targs: SectionScopedEventSubscriptionArgs,\n\t): () => void {\n\t\treturn this.subscribeSectionEvents({\n\t\t\teventTypes: args.eventTypes || SECTION_SCOPED_EVENT_TYPES,\n\t\t\tlistener: args.listener as (event: SectionControllerEvent) => void,\n\t\t});\n\t}\n\n\tpublic onSectionControllerLifecycle(\n\t\tlistener: (event: SectionControllerLifecycleEvent) => void,\n\t): () => void {\n\t\tthis.sectionControllerLifecycleListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.sectionControllerLifecycleListeners.delete(listener);\n\t\t};\n\t}\n\n\tpublic async getOrCreateSectionController(args: {\n\t\tsectionId: string;\n\t\tattemptId?: string;\n\t\tinput?: unknown;\n\t\tupdateExisting?: boolean;\n\t\tcreateDefaultController: () =>\n\t\t\t| SectionControllerHandle\n\t\t\t| Promise<SectionControllerHandle>;\n\t}): Promise<SectionControllerHandle> {\n\t\tconst key: SectionControllerKey = {\n\t\t\tassessmentId: this.assessmentId,\n\t\t\tsectionId: args.sectionId,\n\t\t\tattemptId: args.attemptId,\n\t\t};\n\t\tconst mapKey = this.getSectionControllerMapKey(key);\n\t\tthis.latestRequestedActiveCohortMapKey = mapKey;\n\t\tthis.suspendActiveCohortIfSuperseded(mapKey);\n\t\tconst existingController = await this.resolveExistingSectionController({\n\t\t\tmapKey,\n\t\t\tkey,\n\t\t\tinput: args.input,\n\t\t\tupdateExisting: args.updateExisting,\n\t\t});\n\t\tif (existingController) return existingController;\n\n\t\tconst existingPromise = this.sectionControllerInitPromises.get(mapKey);\n\t\tif (existingPromise) return existingPromise;\n\n\t\tconst initPromise = this.initializeNewSectionController({\n\t\t\targs,\n\t\t\tkey,\n\t\t\tmapKey,\n\t\t})\n\t\t\t.catch((err) => {\n\t\t\t\tthis.handleSectionControllerInitError(err, args);\n\t\t\t\tthrow err;\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tthis.sectionControllerInitPromises.delete(mapKey);\n\t\t\t});\n\n\t\tthis.sectionControllerInitPromises.set(mapKey, initPromise);\n\t\treturn initPromise;\n\t}\n\n\tprivate async resolveExistingSectionController(args: {\n\t\tmapKey: string;\n\t\tkey: SectionControllerKey;\n\t\tinput: unknown;\n\t\tupdateExisting?: boolean;\n\t}): Promise<SectionControllerHandle | undefined> {\n\t\tconst existingController = this.sectionControllers.get(args.mapKey);\n\t\tif (!existingController) return undefined;\n\t\tthis.sectionControllerKeys.set(args.mapKey, args.key);\n\t\tif (args.updateExisting !== false) {\n\t\t\t// Existing controllers keep their in-memory session state across\n\t\t\t// input refresh; updateInput should rebuild composition/runtime view\n\t\t\t// without resetting responses.\n\t\t\tawait existingController.updateInput?.(args.input);\n\t\t}\n\t\t// PIE-512 Phase D: a `getOrCreateSectionController` call that\n\t\t// resolves to a previously-created controller still represents a\n\t\t// cohort transition from the toolkit's perspective (same-cohort\n\t\t// re-entry is a no-op inside `setActiveCohort`). Active\n\t\t// subscriptions migrate here so a host that subscribed once on\n\t\t// `toolkit-ready` keeps receiving events after navigating back\n\t\t// to a section it visited earlier.\n\t\tthis.setActiveCohortIfLatestRequest(args.mapKey);\n\t\treturn existingController;\n\t}\n\n\tprivate createSectionControllerContext(args: {\n\t\tkey: SectionControllerKey;\n\t\tinput: unknown;\n\t}): SectionControllerContext {\n\t\treturn {\n\t\t\tkey: args.key,\n\t\t\tcoordinator: this,\n\t\t\tinput: args.input,\n\t\t};\n\t}\n\n\tprivate async initializeNewSectionController(args: {\n\t\targs: {\n\t\t\tsectionId: string;\n\t\t\tattemptId?: string;\n\t\t\tinput?: unknown;\n\t\t\tcreateDefaultController: () =>\n\t\t\t\t| SectionControllerHandle\n\t\t\t\t| Promise<SectionControllerHandle>;\n\t\t};\n\t\tkey: SectionControllerKey;\n\t\tmapKey: string;\n\t}): Promise<SectionControllerHandle> {\n\t\tconst context = this.createSectionControllerContext({\n\t\t\tkey: args.key,\n\t\t\tinput: args.args.input,\n\t\t});\n\t\tconst persistence = await this.resolveSectionPersistence(context);\n\t\tconst defaults: SectionControllerFactoryDefaults = {\n\t\t\tcreateDefaultController: args.args.createDefaultController,\n\t\t};\n\t\tconst controller =\n\t\t\t(await this.hooks.createSectionController?.(context, defaults)) ??\n\t\t\t(await defaults.createDefaultController());\n\t\tawait controller.configureSessionPersistence?.({\n\t\t\tstrategy: persistence,\n\t\t\tcontext,\n\t\t});\n\t\tawait controller.initialize?.(args.args.input);\n\t\tawait controller.hydrate?.();\n\t\tawait this.finalizeSectionControllerReady({\n\t\t\tmapKey: args.mapKey,\n\t\t\tkey: args.key,\n\t\t\tcontext,\n\t\t\tcontroller,\n\t\t});\n\t\treturn controller;\n\t}\n\n\tprivate async finalizeSectionControllerReady(args: {\n\t\tmapKey: string;\n\t\tkey: SectionControllerKey;\n\t\tcontext: SectionControllerContext;\n\t\tcontroller: SectionControllerHandle;\n\t}): Promise<void> {\n\t\tthis.sectionControllers.set(args.mapKey, args.controller);\n\t\tthis.sectionControllerKeys.set(args.mapKey, args.key);\n\t\t// PIE-512 Phase D: a freshly-resolved controller becomes the\n\t\t// active cohort. Active subscriptions migrate to it before the\n\t\t// `ready` lifecycle event and `onSectionControllerReady` hook\n\t\t// fire so any synchronous post-ready work observes a coherent\n\t\t// active-cohort view.\n\t\tthis.setActiveCohortIfLatestRequest(args.mapKey);\n\t\tthis.emitSectionControllerLifecycle({\n\t\t\ttype: \"ready\",\n\t\t\tkey: args.key,\n\t\t\tcontroller: args.controller,\n\t\t});\n\t\tawait this.hooks.onSectionControllerReady?.(args.context, args.controller);\n\t\tawait this.emitTelemetry(\"pie-toolkit-section-controller-ready\", {\n\t\t\tassessmentId: args.key.assessmentId,\n\t\t\tsectionId: args.key.sectionId,\n\t\t\tattemptId: args.key.attemptId,\n\t\t});\n\t}\n\n\tprivate handleSectionControllerInitError(\n\t\terr: unknown,\n\t\targs: { sectionId: string; attemptId?: string },\n\t): void {\n\t\tthis.handleError(err, {\n\t\t\tphase: \"section-controller-init\",\n\t\t\tdetails: {\n\t\t\t\tsectionId: args.sectionId,\n\t\t\t\tattemptId: args.attemptId,\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic async disposeSectionController(args: {\n\t\tsectionId: string;\n\t\tattemptId?: string;\n\t\tpersistBeforeDispose?: boolean;\n\t\tclearPersistence?: boolean;\n\t}): Promise<void> {\n\t\tconst key: SectionControllerKey = {\n\t\t\tassessmentId: this.assessmentId,\n\t\t\tsectionId: args.sectionId,\n\t\t\tattemptId: args.attemptId,\n\t\t};\n\t\tconst mapKey = this.getSectionControllerMapKey(key);\n\t\tconst controller = this.sectionControllers.get(mapKey);\n\t\tif (!controller) return;\n\t\t// PIE-512 Phase D: if the disposing cohort is the active one,\n\t\t// detach all listener-controller bindings before the controller\n\t\t// itself disposes. The subscription registry stays intact so a\n\t\t// later `getOrCreateSectionController(...)` re-binds the same\n\t\t// listeners to the new controller.\n\t\tthis.clearActiveCohortIfMatches(mapKey);\n\n\t\tconst context = this.createSectionControllerContext({\n\t\t\tkey,\n\t\t\tinput: undefined,\n\t\t});\n\n\t\ttry {\n\t\t\tawait this.runSectionControllerDisposePipeline({\n\t\t\t\tkey,\n\t\t\t\tcontext,\n\t\t\t\tcontroller,\n\t\t\t\tpersistBeforeDispose: args.persistBeforeDispose,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tthis.handleError(err, {\n\t\t\t\tphase: \"section-controller-dispose\",\n\t\t\t\tdetails: {\n\t\t\t\t\tsectionId: args.sectionId,\n\t\t\t\t\tattemptId: args.attemptId,\n\t\t\t\t},\n\t\t\t});\n\t\t} finally {\n\t\t\tawait this.finalizeSectionControllerDispose({\n\t\t\t\tmapKey,\n\t\t\t\tkey,\n\t\t\t\tcontext,\n\t\t\t\tclearPersistence: args.clearPersistence,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async runSectionControllerDisposePipeline(args: {\n\t\tkey: SectionControllerKey;\n\t\tcontext: SectionControllerContext;\n\t\tcontroller: SectionControllerHandle;\n\t\tpersistBeforeDispose?: boolean;\n\t}): Promise<void> {\n\t\tif (args.persistBeforeDispose !== false) {\n\t\t\tawait args.controller.persist?.();\n\t\t}\n\t\tawait args.controller.dispose?.();\n\t\tawait this.hooks.onSectionControllerDispose?.(\n\t\t\targs.context,\n\t\t\targs.controller,\n\t\t);\n\t\tawait this.emitTelemetry(\"pie-toolkit-section-controller-disposed\", {\n\t\t\tassessmentId: args.key.assessmentId,\n\t\t\tsectionId: args.key.sectionId,\n\t\t\tattemptId: args.key.attemptId,\n\t\t});\n\t}\n\n\tprivate async finalizeSectionControllerDispose(args: {\n\t\tmapKey: string;\n\t\tkey: SectionControllerKey;\n\t\tcontext: SectionControllerContext;\n\t\tclearPersistence?: boolean;\n\t}): Promise<void> {\n\t\tthis.sectionControllers.delete(args.mapKey);\n\t\tthis.sectionControllerKeys.delete(args.mapKey);\n\t\tthis.emitSectionControllerLifecycle({\n\t\t\ttype: \"disposed\",\n\t\t\tkey: args.key,\n\t\t});\n\t\tif (args.clearPersistence) {\n\t\t\tconst strategy = this.sectionPersistenceStrategies.get(args.mapKey);\n\t\t\tawait strategy?.clearSession?.(args.context);\n\t\t}\n\t\tthis.sectionPersistenceStrategies.delete(args.mapKey);\n\t}\n\n\t/**\n\t * Initialize TTS service with provider\n\t */\n\tpublic async ensureTTSReady(config?: TTSToolConfig): Promise<void> {\n\t\tawait this.waitForPendingTTSReconfigure();\n\t\tif (this.ttsInitialized) return;\n\t\tif (this.ttsInitPromise) return this.ttsInitPromise;\n\t\tthis.ttsInitPromise = this._initializeTTS(config).finally(() => {\n\t\t\tthis.ttsInitPromise = undefined;\n\t\t});\n\t\treturn this.ttsInitPromise;\n\t}\n\n\tprivate async waitForPendingTTSReconfigure(): Promise<void> {\n\t\tlet pending = this.ttsReconfigurePromise;\n\t\twhile (pending) {\n\t\t\tawait pending;\n\t\t\tpending = this.ttsReconfigurePromise;\n\t\t}\n\t}\n\n\tprivate async _initializeTTS(config?: TTSToolConfig): Promise<void> {\n\t\tif (this.ttsInitialized) return;\n\t\tconst resolvedToolConfig = this.resolveTTSToolConfig(config);\n\t\tconst runtimeSettings = resolveTTSRuntimeSettings(resolvedToolConfig);\n\t\tconst resolvedBackend = resolveTTSBackend(runtimeSettings);\n\t\tconst runtimeTTSConfig = buildRuntimeTTSConfig(runtimeSettings);\n\t\tawait this.hooks.onBeforeTTSInit?.({\n\t\t\tphase: \"tts-init\",\n\t\t\tdetails: {\n\t\t\t\tbackend: resolvedBackend,\n\t\t\t},\n\t\t});\n\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-start\", {\n\t\t\tbackend: resolvedBackend,\n\t\t});\n\t\tawait this.emitTelemetry(\"pie-tool-init-start\", {\n\t\t\ttoolId: \"textToSpeech\",\n\t\t\toperation: \"tts-init\",\n\t\t\tbackend: resolvedBackend,\n\t\t});\n\n\t\t// Try to use TTS provider from registry if available\n\t\tif (this.toolProviderRegistry.has(\"tts\")) {\n\t\t\ttry {\n\t\t\t\tconst ttsProvider = await this.ensureProviderReady(\"tts\");\n\t\t\t\tconst providerInstance = await ttsProvider.createInstance();\n\t\t\t\tawait this.initializeTTSService(providerInstance, runtimeTTSConfig);\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-success\", {\n\t\t\t\t\tprovider: \"registry\",\n\t\t\t\t});\n\t\t\t\tawait this.emitTelemetry(\"pie-tool-init-success\", {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\toperation: \"tts-init\",\n\t\t\t\t\tbackend: resolvedBackend,\n\t\t\t\t\tprovider: \"registry\",\n\t\t\t\t});\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"[ToolkitCoordinator] TTS initialized via ToolProviderRegistry\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t} catch (error) {\n\t\t\t\tconst normalized =\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error));\n\t\t\t\tawait this.emitTelemetry(\"pie-tool-init-error\", {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\tproviderId: \"tts\",\n\t\t\t\t\toperation: \"tts-init\",\n\t\t\t\t\tbackend: resolvedBackend,\n\t\t\t\t\terrorType: \"TTSRegistryInitError\",\n\t\t\t\t\tmessage: normalized.message,\n\t\t\t\t\trecovered: true,\n\t\t\t\t});\n\t\t\t\tawait this.emitTelemetry(\"pie-tool-init-fallback\", {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\tproviderId: \"tts\",\n\t\t\t\t\toperation: \"tts-init\",\n\t\t\t\t\tbackend: resolvedBackend,\n\t\t\t\t\tfromProvider: \"registry\",\n\t\t\t\t\ttoProvider: \"browser\",\n\t\t\t\t\treason: normalized.message,\n\t\t\t\t});\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] Failed to initialize TTS via registry, falling back to browser provider:\",\n\t\t\t\t\tnormalized,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to browser provider\n\t\tconst provider = new BrowserTTSProvider();\n\t\ttry {\n\t\t\tawait this.initializeTTSService(provider, runtimeTTSConfig);\n\t\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-success\", {\n\t\t\t\tprovider: \"browser-fallback\",\n\t\t\t});\n\t\t\tawait this.emitTelemetry(\"pie-tool-init-success\", {\n\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\toperation: \"tts-init\",\n\t\t\t\tbackend: resolvedBackend,\n\t\t\t\tprovider: \"browser-fallback\",\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst normalized =\n\t\t\t\terror instanceof Error ? error : new Error(String(error));\n\t\t\tthis.handleError(normalized, { phase: \"tts-init\" });\n\t\t\tawait this.emitTelemetry(\"pie-toolkit-tts-init-error\", {\n\t\t\t\tmessage: normalized.message,\n\t\t\t});\n\t\t\tawait this.emitTelemetry(\"pie-tool-init-error\", {\n\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\toperation: \"tts-init\",\n\t\t\t\tbackend: resolvedBackend,\n\t\t\t\terrorType: \"TTSInitError\",\n\t\t\t\tmessage: normalized.message,\n\t\t\t});\n\t\t\tthrow normalized;\n\t\t}\n\t}\n\n\tprivate resolveTTSToolConfig(config?: TTSToolConfig): TTSToolConfig {\n\t\treturn config || this.getTTSConfigFromProviders() || {};\n\t}\n\n\tprivate async initializeTTSService(\n\t\tprovider: ITTSProvider,\n\t\tconfig: Partial<TTSConfig>,\n\t): Promise<void> {\n\t\tconst nextProviderOptions = {\n\t\t\t...(((config.providerOptions || {}) as Record<string, unknown>) || {}),\n\t\t\t__pieTelemetry: async (\n\t\t\t\teventName: string,\n\t\t\t\tpayload?: Record<string, unknown>,\n\t\t\t) => {\n\t\t\t\tawait this.emitTelemetry(eventName, {\n\t\t\t\t\ttoolId: \"textToSpeech\",\n\t\t\t\t\t...(payload || {}),\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t\tconst nextConfig = {\n\t\t\t...config,\n\t\t\tproviderOptions: nextProviderOptions,\n\t\t} as Partial<TTSConfig>;\n\t\tawait this.ttsService.initialize(provider, nextConfig);\n\t\tawait this.ensureBrowserVoicesReady(provider);\n\t\tthis.ttsService.setCatalogResolver(this.catalogResolver);\n\t\tthis.ttsInitialized = true;\n\t\tawait this.hooks.onTTSReady?.();\n\t}\n\n\tprivate async ensureBrowserVoicesReady(\n\t\tprovider: ITTSProvider,\n\t\ttimeoutMs = 1200,\n\t): Promise<void> {\n\t\tif (provider.providerId !== \"browser\") return;\n\t\tif (typeof window === \"undefined\") return;\n\t\tif (!(\"speechSynthesis\" in window)) return;\n\t\tconst synth = window.speechSynthesis;\n\t\tconst voices = synth.getVoices();\n\t\tif (voices.length > 0) return;\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tconst canUseEventTarget =\n\t\t\t\ttypeof synth.addEventListener === \"function\" &&\n\t\t\t\ttypeof synth.removeEventListener === \"function\";\n\t\t\tconst canUseHandler = !canUseEventTarget && \"onvoiceschanged\" in synth;\n\t\t\tconst previousHandler = canUseHandler ? synth.onvoiceschanged : null;\n\t\t\tlet assignedHandler = false;\n\t\t\tconst finish = () => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\twindow.clearTimeout(timeoutId);\n\t\t\t\tif (canUseEventTarget) {\n\t\t\t\t\tsynth.removeEventListener(\"voiceschanged\", onVoicesChanged);\n\t\t\t\t} else if (assignedHandler && synth.onvoiceschanged === onVoicesChanged) {\n\t\t\t\t\tsynth.onvoiceschanged = previousHandler;\n\t\t\t\t}\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tconst onVoicesChanged = (event?: Event) => {\n\t\t\t\tif (!canUseEventTarget && typeof previousHandler === \"function\" && event) {\n\t\t\t\t\tpreviousHandler.call(synth, event);\n\t\t\t\t}\n\t\t\t\tfinish();\n\t\t\t};\n\t\t\tconst timeoutId = window.setTimeout(finish, timeoutMs);\n\t\t\tif (canUseEventTarget) {\n\t\t\t\tsynth.addEventListener(\"voiceschanged\", onVoicesChanged, {\n\t\t\t\t\tonce: true,\n\t\t\t\t});\n\t\t\t} else if (canUseHandler) {\n\t\t\t\tsynth.onvoiceschanged = onVoicesChanged;\n\t\t\t\tassignedHandler = true;\n\t\t\t}\n\t\t});\n\t\tconst voicesAfterWait = synth.getVoices();\n\t\tawait this.emitTelemetry(\"pie-toolkit-tts-browser-voices-ready\", {\n\t\t\tvoiceCount: voicesAfterWait.length,\n\t\t\ttimedOut: voicesAfterWait.length === 0,\n\t\t});\n\t}\n\n\t/**\n\t * Get all services as a bundle for section player convenience.\n\t * Section player can extract and pass services to child components.\n\t */\n\tgetServiceBundle(): ToolkitServiceBundle {\n\t\treturn {\n\t\t\tttsService: this.ttsService,\n\t\t\ttoolCoordinator: this.toolCoordinator,\n\t\t\thighlightCoordinator: this.highlightCoordinator,\n\t\t\telementToolStateStore: this.elementToolStateStore,\n\t\t\tcatalogResolver: this.catalogResolver,\n\t\t\ttoolProviderRegistry: this.toolProviderRegistry,\n\t\t};\n\t}\n\n\t/**\n\t * Get a tool provider from the registry\n\t *\n\t * @param providerId Provider identifier\n\t * @returns Tool provider instance\n\t */\n\tasync getToolProvider(providerId: string) {\n\t\treturn this.ensureProviderReady(providerId);\n\t}\n\n\tasync waitUntilReady(): Promise<void> {\n\t\tif (this.isReady()) return;\n\t\tif (this.coordinatorReadyPromise) return this.coordinatorReadyPromise;\n\t\tthis.coordinatorReadyPromise = (async () => {\n\t\t\tawait this.ensureStateLoaded();\n\t\t\tconst ttsConfig = this.getTTSConfigFromProviders();\n\t\t\tif (ttsConfig?.enabled !== false) {\n\t\t\t\tawait this.ensureTTSReady(ttsConfig);\n\t\t\t}\n\t\t\tif (!this.coordinatorReadyNotified) {\n\t\t\t\tthis.coordinatorReadyNotified = true;\n\t\t\t\tawait this.hooks.onCoordinatorReady?.(this);\n\t\t\t\tawait this.emitTelemetry(\"pie-toolkit-coordinator-ready\", {\n\t\t\t\t\tassessmentId: this.assessmentId,\n\t\t\t\t});\n\t\t\t}\n\t\t})().finally(() => {\n\t\t\tthis.coordinatorReadyPromise = undefined;\n\t\t});\n\t\treturn this.coordinatorReadyPromise;\n\t}\n\n\tisReady(): boolean {\n\t\treturn this.getInitStatus().coordinator;\n\t}\n\n\tgetInitStatus(): ToolkitInitStatus {\n\t\tconst providers: Record<string, boolean> = {};\n\t\tfor (const providerId of this.toolProviderRegistry.getProviderIds()) {\n\t\t\tproviders[providerId] =\n\t\t\t\tthis.toolProviderRegistry.isInitialized(providerId);\n\t\t}\n\t\tconst ttsConfig = this.getTTSConfigFromProviders();\n\t\treturn {\n\t\t\ttts: this.ttsInitialized,\n\t\t\tstateLoaded: this.stateLoaded || !this.hooks.loadToolState,\n\t\t\tcoordinator:\n\t\t\t\t(this.stateLoaded || !this.hooks.loadToolState) &&\n\t\t\t\t(this.ttsInitialized || ttsConfig?.enabled === false),\n\t\t\tproviders,\n\t\t};\n\t}\n\n\tprivate getTTSConfigFromProviders(): TTSToolConfig | undefined {\n\t\tconst providers =\n\t\t\t(\n\t\t\t\tthis.config.tools as {\n\t\t\t\t\tproviders?: Record<string, ToolProviderConfig | undefined>;\n\t\t\t\t}\n\t\t\t)?.providers || {};\n\t\treturn providers.textToSpeech as TTSToolConfig | undefined;\n\t}\n\n\tprivate assertCanonicalToolId(toolId: string): void {\n\t\tif (typeof toolId !== \"string\" || toolId.trim().length === 0) {\n\t\t\tthrow new Error(\"Tool id must be a non-empty string.\");\n\t\t}\n\t\tif (toolId === \"tts\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Tool id \"tts\" is no longer supported. Use \"textToSpeech\".`,\n\t\t\t);\n\t\t}\n\t\tif (!this.toolRegistry.get(toolId)) {\n\t\t\tthrow new Error(`Unknown tool id \"${toolId}\".`);\n\t\t}\n\t}\n\n\tprivate installToolContextResolvers(\n\t\tresolvers: ToolContextResolverMap | undefined,\n\t): void {\n\t\tif (!resolvers) return;\n\t\tfor (const [toolId, resolver] of Object.entries(resolvers)) {\n\t\t\tif (resolver == null) continue;\n\t\t\tthis.assertCanonicalToolId(toolId);\n\t\t\tif (typeof resolver !== \"function\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid tool context resolver for \"${toolId}\": expected a function.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.toolContextResolvers.set(toolId, resolver);\n\t\t}\n\t}\n\n\tsetToolContextResolvers(\n\t\tresolvers: ToolContextResolverMap | null | undefined,\n\t): void {\n\t\tthis.toolContextResolvers.clear();\n\t\tthis.installToolContextResolvers(resolvers ?? undefined);\n\t\tthis.notifyToolContextResolverChange();\n\t}\n\n\tprivate notifyToolContextResolverChange(): void {\n\t\tfor (const listener of this.toolContextResolverChangeListeners) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[ToolkitCoordinator] Tool context resolver listener threw:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Check if a tool is enabled.\n\t * Tools are enabled by default unless explicitly disabled.\n\t *\n\t * @param toolId Tool identifier (e.g., 'textToSpeech', 'answerEliminator')\n\t * @returns True if tool is enabled\n\t */\n\tisToolEnabled(toolId: string): boolean {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\tconst toolConfig = (this.config.tools as any)?.providers?.[toolId];\n\t\t// Enabled by default unless explicitly set to false\n\t\treturn toolConfig?.enabled !== false;\n\t}\n\n\t/**\n\t * Get tool configuration.\n\t *\n\t * @param toolId Tool identifier\n\t * @returns Tool configuration or null if not configured\n\t */\n\tgetToolConfig(toolId: string): ToolProviderConfig | null {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\treturn (\n\t\t\t((\n\t\t\t\tthis.config.tools as {\n\t\t\t\t\tproviders?: Record<string, ToolProviderConfig | undefined>;\n\t\t\t\t}\n\t\t\t)?.providers?.[toolId] as ToolProviderConfig | undefined) || null\n\t\t);\n\t}\n\n\t/**\n\t * Update tool configuration.\n\t * Applies changes to underlying services.\n\t *\n\t * @param toolId Tool identifier\n\t * @param updates Partial configuration updates\n\t */\n\tupdateToolConfig(\n\t\ttoolId: \"textToSpeech\",\n\t\tupdates: Partial<TTSToolConfig>,\n\t): void;\n\tupdateToolConfig(toolId: string, updates: Partial<ToolProviderConfig>): void;\n\tupdateToolConfig(\n\t\ttoolId: string,\n\t\tupdates: Partial<ToolProviderConfig> | Partial<TTSToolConfig>,\n\t): void {\n\t\t// Update config\n\t\tthis.assertCanonicalToolId(toolId);\n\t\tconst current = this.getToolConfig(toolId) || {};\n\t\tif (!this.config.tools) {\n\t\t\tthis.config.tools = normalizeAndValidateToolsConfig(undefined, {\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolConfig\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t}).config;\n\t\t}\n\t\tif (!(this.config.tools as any).providers) {\n\t\t\t(this.config.tools as any).providers = {};\n\t\t}\n\t\tconst nextProviders = {\n\t\t\t...((this.config.tools as any).providers || {}),\n\t\t\t[toolId]: mergeToolConfigUpdate(toolId, current, updates),\n\t\t};\n\t\tconst validated = normalizeAndValidateToolsConfig(\n\t\t\t{\n\t\t\t\t...(this.config.tools as CanonicalToolsConfig),\n\t\t\t\tproviders: nextProviders,\n\t\t\t},\n\t\t\t{\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolConfig\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t},\n\t\t);\n\t\tthis.config.tools = validated.config;\n\t\t// M8 PR 2 — keep the policy engine's tools input in lockstep\n\t\t// with the validated coordinator config. The engine emits an\n\t\t// `inputs` change event so subscribers (e.g. PR 3 toolbars) can\n\t\t// re-decide without us managing a parallel pub/sub.\n\t\tthis.policyEngine.updateInputs({\n\t\t\ttools: this.config.tools as CanonicalToolsConfig,\n\t\t});\n\t\tvoid this.emitTelemetry(\"pie-toolkit-tool-config-updated\", { toolId });\n\n\t\t// Apply configuration changes to services\n\t\tthis._applyToolConfigChange(toolId, updates);\n\t}\n\n\t/**\n\t * Update the enabled tool list for one placement level.\n\t *\n\t * This is the generic placement companion to {@link updateToolConfig}:\n\t * it validates the next canonical tools config, keeps the policy\n\t * engine in lockstep, and emits the same policy-change event used by\n\t * live toolbars/debug panels.\n\t */\n\tupdateToolPlacement(level: ToolPlacementLevel, toolIds: string[]): void {\n\t\tthis.updateToolsPlacement({ [level]: [...toolIds] });\n\t}\n\n\t/**\n\t * Patch one or more placement levels in the canonical tools config.\n\t */\n\tupdateToolsPlacement(partial: ToolPlacementConfig): void {\n\t\tif (!this.config.tools) {\n\t\t\tthis.config.tools = normalizeAndValidateToolsConfig(undefined, {\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolsPlacement\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t}).config;\n\t\t}\n\t\tconst currentPlacement = this.config.tools?.placement ?? {\n\t\t\tsection: [],\n\t\t\titem: [],\n\t\t\tpassage: [],\n\t\t};\n\t\tconst nextPlacement: Required<ToolPlacementConfig> = {\n\t\t\tsection: [...(partial.section ?? currentPlacement.section ?? [])],\n\t\t\titem: [...(partial.item ?? currentPlacement.item ?? [])],\n\t\t\tpassage: [...(partial.passage ?? currentPlacement.passage ?? [])],\n\t\t};\n\t\tconst validated = normalizeAndValidateToolsConfig(\n\t\t\t{\n\t\t\t\t...(this.config.tools as CanonicalToolsConfig),\n\t\t\t\tplacement: nextPlacement,\n\t\t\t},\n\t\t\t{\n\t\t\t\tstrictness: this.config.toolConfigStrictness ?? \"error\",\n\t\t\t\tsource: \"ToolkitCoordinator.updateToolsPlacement\",\n\t\t\t\ttoolRegistry: this.toolRegistry,\n\t\t\t},\n\t\t);\n\t\tvalidated.config.placement = nextPlacement;\n\t\tthis.config.tools = validated.config;\n\t\tthis.policyEngine.updateInputs({\n\t\t\ttools: this.config.tools as CanonicalToolsConfig,\n\t\t});\n\t}\n\n\t/**\n\t * Resolve the visible tool set for a given placement level + scope.\n\t *\n\t * Thin shim over the owned tool-policy engine.\n\t */\n\tdecideToolPolicy(request: ToolPolicyDecisionRequest): ToolPolicyDecision {\n\t\treturn this.policyEngine.decide(request);\n\t}\n\n\t/**\n\t * Subscribe to policy-engine change events. Fires whenever the\n\t * coordinator's bound inputs change (`updateToolConfig`,\n\t * `updateToolPlacement`, `updateAssessment`, `updateCurrentItemRef`,\n\t * `setPnpEnforcement`) or a custom `PolicySource` is registered /\n\t * removed via {@link registerPolicySource}.\n\t *\n\t * The listener receives a `ToolPolicyChangeEvent` with the event\n\t * `reason` and a frozen snapshot of the engine inputs. Listeners\n\t * that want the new visible tool set should call\n\t * {@link decideToolPolicy} with their level / scope.\n\t *\n\t * Note: the engine itself can also emit `reason: \"disposed\"`, but\n\t * the coordinator does not dispose its engine on teardown today,\n\t * so subscribers attached via this method will not observe that\n\t * reason. Detach via the returned unsubscribe function instead of\n\t * relying on a `disposed` event.\n\t */\n\tonPolicyChange(listener: ToolPolicyChangeListener): () => void {\n\t\treturn this.policyEngine.onPolicyChange(listener);\n\t}\n\n\t/**\n\t * Bind (or clear) the active assessment for PNP/profile policy decisions.\n\t *\n\t * Under auto-mode (no host override via {@link setPnpEnforcement}),\n\t * the coordinator promotes the engine to `pnpEnforcement: \"on\"`\n\t * iff the assessment carries any profile precedence material\n\t * (`personalNeedsProfile`, `settings.districtPolicy`,\n\t * `settings.testAdministration`) or the currently-bound item ref\n\t * carries item-level profile policy inputs. A bare assessment record (just\n\t * `id` / `name`, no PNP, no settings) keeps `\"off\"`.\n\t *\n\t * The host override set via {@link setPnpEnforcement} is sticky\n\t * across assessment swaps; calling with `null` clears the binding\n\t * and re-runs the auto-mode helper.\n\t */\n\tupdateAssessment(assessment: AssessmentEntity | null): void {\n\t\tthis.boundAssessment = assessment;\n\t\tthis.policyEngine.updateInputs({\n\t\t\tassessment,\n\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t});\n\t}\n\n\t/**\n\t * Bind (or clear) the current item reference for policy decisions.\n\t *\n\t * Used by item-level profile gates (item `requiredTools` /\n\t * `restrictedTools` / `toolParameters`). Item-level profile material\n\t * also feeds {@link resolveEffectivePnpEnforcement} — navigating\n\t * to an item with profile settings can flip auto-mode to `\"on\"` even\n\t * when the parent assessment carries no profile block of its own.\n\t */\n\tupdateCurrentItemRef(itemRef: AssessmentItemRef | null): void {\n\t\tthis.boundCurrentItemRef = itemRef;\n\t\tthis.policyEngine.updateInputs({\n\t\t\tcurrentItemRef: itemRef,\n\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t});\n\t}\n\n\t/**\n\t * Override the auto-mode PNP/profile enforcement decision.\n\t */\n\tsetPnpEnforcement(mode: PnpEnforcementMode | null): void {\n\t\tthis.pnpEnforcementOverride = mode;\n\t\tthis.policyEngine.updateInputs({\n\t\t\tpnpEnforcement: this.resolveEffectivePnpEnforcement(),\n\t\t});\n\t}\n\n\t/**\n\t * Get the policy engine inputs currently driving decisions. Useful\n\t * for debugging / instrumentation; do not mutate.\n\t */\n\tgetPolicyInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn this.policyEngine.getInputs();\n\t}\n\n\t/**\n\t * Register a custom {@link PolicySource} with the owned policy\n\t * engine. The source participates in every subsequent\n\t * {@link decideToolPolicy} call until disposed (the returned\n\t * function detaches and emits a `policy-source-removed` event).\n\t *\n\t * Delegates verbatim to\n\t * {@link ToolPolicyEngine.registerPolicySource} — see that\n\t * method for the full contract (event ordering, idempotency of\n\t * the returned dispose function, and how registered sources\n\t * compose with the built-in PNP policy source).\n\t */\n\tregisterPolicySource(source: PolicySource): () => void {\n\t\treturn this.policyEngine.registerPolicySource(source);\n\t}\n\n\t/**\n\t * Register a host-owned resolver for one tool's render context.\n\t *\n\t * Resolvers are evaluated only for tools that already survived the\n\t * framework policy pipeline. They can hide the tool for the current\n\t * scope or attach render params consumed by the packaged registration;\n\t * they cannot re-enable tools blocked by placement, provider config,\n\t * host policy, or PNP/profile rules.\n\t */\n\tregisterToolContextResolver(\n\t\ttoolId: string,\n\t\tresolver: ToolContextResolver,\n\t): () => void {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\tif (typeof resolver !== \"function\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid tool context resolver for \"${toolId}\": expected a function.`,\n\t\t\t);\n\t\t}\n\t\tthis.toolContextResolvers.set(toolId, resolver);\n\t\tthis.notifyToolContextResolverChange();\n\t\treturn () => {\n\t\t\tif (this.toolContextResolvers.get(toolId) !== resolver) return;\n\t\t\tthis.toolContextResolvers.delete(toolId);\n\t\t\tthis.notifyToolContextResolverChange();\n\t\t};\n\t}\n\n\thasToolContextResolver(toolId: string): boolean {\n\t\tthis.assertCanonicalToolId(toolId);\n\t\treturn this.toolContextResolvers.has(toolId);\n\t}\n\n\tresolveToolContext(\n\t\tcontext: ToolContextResolverContext,\n\t): ResolvedToolContext | null {\n\t\tthis.assertCanonicalToolId(context.toolId);\n\t\tconst resolver = this.toolContextResolvers.get(context.toolId);\n\t\tif (!resolver) return null;\n\n\t\tlet result: ReturnType<ToolContextResolver>;\n\t\ttry {\n\t\t\tresult = resolver(context);\n\t\t} catch (error) {\n\t\t\tconsole.error(\n\t\t\t\t`[ToolkitCoordinator] Tool context resolver for \"${context.toolId}\" threw:`,\n\t\t\t\terror,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\ttoolId: context.toolId,\n\t\t\t\tvisible: false,\n\t\t\t\tparams: {},\n\t\t\t\treason: \"Tool context resolver threw.\",\n\t\t\t};\n\t\t}\n\t\tif (!result) {\n\t\t\treturn {\n\t\t\t\ttoolId: context.toolId,\n\t\t\t\tvisible: true,\n\t\t\t\tparams: {},\n\t\t\t};\n\t\t}\n\n\t\tconst params =\n\t\t\tresult.params &&\n\t\t\ttypeof result.params === \"object\" &&\n\t\t\t!Array.isArray(result.params)\n\t\t\t\t? result.params\n\t\t\t\t: {};\n\t\treturn {\n\t\t\ttoolId: context.toolId,\n\t\t\tvisible: result.visible !== false,\n\t\t\tparams,\n\t\t\treason: typeof result.reason === \"string\" ? result.reason : undefined,\n\t\t};\n\t}\n\n\tonToolContextResolverChange(listener: () => void): () => void {\n\t\tthis.toolContextResolverChangeListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.toolContextResolverChangeListeners.delete(listener);\n\t\t};\n\t}\n\n\t/**\n\t * Compute the effective PNP/profile enforcement mode given the explicit\n\t * host override and the auto-mode helper.\n\t *\n\t * Auto-mode (no override) defers to\n\t * {@link resolveDefaultPnpEnforcement}, which returns `\"on\"`\n\t * exactly when the bound assessment or current item ref carries\n\t * profile precedence material (PNP, district policy, test\n\t * administration, item-level required/restricted/parameters), and\n\t * `\"off\"` otherwise. Profile gates engage the moment profile material\n\t * is present.\n\t */\n\tprivate resolveEffectivePnpEnforcement(): PnpEnforcementMode {\n\t\tif (this.pnpEnforcementOverride !== null) {\n\t\t\treturn this.pnpEnforcementOverride;\n\t\t}\n\t\treturn resolveDefaultPnpEnforcement({\n\t\t\tassessment: this.boundAssessment,\n\t\t\tcurrentItemRef: this.boundCurrentItemRef,\n\t\t});\n\t}\n\n\tprivate resolveConfiguredPnpEnforcement(): PnpEnforcementMode | null {\n\t\tconst tools = this.config.tools as CanonicalToolsConfig | undefined;\n\t\treturn tools?.pnpEnforcement ?? null;\n\t}\n\n\t/**\n\t * Apply tool configuration changes to underlying services.\n\t * Called after updateToolConfig().\n\t */\n\tprivate _applyToolConfigChange(\n\t\ttoolId: string,\n\t\t_updates: Partial<ToolProviderConfig> | Partial<TTSToolConfig>,\n\t): void {\n\t\t// Apply configuration changes based on tool\n\t\tswitch (toolId) {\n\t\t\tcase \"textToSpeech\": {\n\t\t\t\tconst reconfigurePromise = this._reconfigureTTSProvider();\n\t\t\t\tthis.ttsReconfigurePromise = reconfigurePromise;\n\t\t\t\tvoid reconfigurePromise.finally(() => {\n\t\t\t\t\tif (this.ttsReconfigurePromise === reconfigurePromise) {\n\t\t\t\t\t\tthis.ttsReconfigurePromise = undefined;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tvoid reconfigurePromise.then(async () => {\n\t\t\t\t\tconst ttsConfig = this.getTTSConfigFromProviders();\n\t\t\t\t\tif (!this.lazyInit && ttsConfig?.enabled !== false) {\n\t\t\t\t\t\tawait this.ensureTTSReady(ttsConfig);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase \"answerEliminator\":\n\t\t\t\t// Future: Could notify answer eliminator tools of strategy change\n\t\t\t\tbreak;\n\n\t\t\t// Add cases for other tools as needed\n\t\t}\n\t}\n\n\tprivate async _reconfigureTTSProvider(): Promise<void> {\n\t\tthis.ttsInitialized = false;\n\t\tthis.ttsInitPromise = undefined;\n\t\ttry {\n\t\t\tthis.ttsService.stop();\n\t\t} catch {\n\t\t\t// noop: stop best effort\n\t\t}\n\n\t\tif (this.toolProviderRegistry.has(\"tts\")) {\n\t\t\tawait this.toolProviderRegistry.unregister(\"tts\");\n\t\t}\n\t\tconst ttsRegistration = this.getProviderDescriptorTools().find(\n\t\t\t(tool) => tool.toolId === \"textToSpeech\",\n\t\t);\n\t\tif (!ttsRegistration) return;\n\t\tawait this.registerProviderFromTool(ttsRegistration);\n\t}\n}\n"]}