@pie-players/pie-assessment-toolkit 0.3.75 → 1.0.0-beta.1
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.
- package/README.md +451 -541
- package/custom-elements.json +1315 -0
- package/dist/attempt/TestSession.d.ts +0 -1
- package/dist/attempt/TestSession.js +10 -5
- package/dist/components/ItemScope.custom-element.js +1 -1
- package/dist/components/ItemToolBar.custom-element.js +1 -1
- package/dist/components/PieAssessmentToolkit.custom-element.js +8 -8
- package/dist/components/SectionToolBar.custom-element.js +1 -1
- package/dist/components/chunks/{ItemToolBar-7tt7v2xp.js → ItemToolBar-3zrc4p3d.js} +4 -4
- package/dist/components/chunks/{ItemToolBar-jx38w99s.js → ItemToolBar-66hcwmfw.js} +2 -2
- package/dist/components/chunks/ItemToolBar-asenkvx6.js +40 -0
- package/dist/components/chunks/ItemToolBar-hzc5wyjp.js +2 -0
- package/dist/components/chunks/{ItemToolBar-97hx60z4.js → ItemToolBar-kkj69ptr.js} +1 -1
- package/dist/components/chunks/sre-engine-bj997w4b.js +1 -0
- package/dist/context/assessment-toolkit-context.d.ts +6 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -10
- package/dist/policy/core/PolicySource.d.ts +1 -1
- package/dist/policy/core/ToolPolicyEngine.d.ts +46 -7
- package/dist/policy/core/ToolPolicyEngine.js +73 -16
- package/dist/policy/core/compose-decision.d.ts +3 -3
- package/dist/policy/core/compose-decision.js +32 -30
- package/dist/policy/core/decision-types.d.ts +51 -34
- package/dist/policy/core/feature-decision.d.ts +17 -15
- package/dist/policy/core/feature-decision.js +11 -13
- package/dist/policy/core/pnp-policy-inputs.d.ts +7 -3
- package/dist/policy/core/pnp-policy-inputs.js +17 -33
- package/dist/policy/core/provenance.d.ts +2 -2
- package/dist/policy/core/tool-parameters.d.ts +12 -0
- package/dist/policy/core/tool-parameters.js +27 -0
- package/dist/policy/engine.d.ts +1 -1
- package/dist/policy/sources/PnpPolicySource.d.ts +18 -24
- package/dist/policy/sources/PnpPolicySource.js +57 -29
- package/dist/runtime/SectionControllerBinding.d.ts +6 -2
- package/dist/runtime/SectionControllerBinding.js +21 -15
- package/dist/runtime/adapter/subscriber-fanout.d.ts +0 -1
- package/dist/runtime/adapter/subscriber-fanout.js +1 -4
- package/dist/runtime/composition-emit-scheduler.d.ts +3 -3
- package/dist/runtime/composition-emit-scheduler.js +1 -1
- package/dist/runtime/content-region.d.ts +0 -4
- package/dist/runtime/content-region.js +2 -2
- package/dist/runtime/core/SectionEngineCore.d.ts +0 -2
- package/dist/runtime/core/SectionEngineCore.js +0 -4
- package/dist/runtime/core/cohort.d.ts +0 -5
- package/dist/runtime/core/cohort.js +0 -9
- package/dist/runtime/core/engine-output.d.ts +3 -2
- package/dist/runtime/core/engine-transition.js +3 -2
- package/dist/runtime/registration-events.d.ts +11 -14
- package/dist/runtime/runtime-id.d.ts +1 -1
- package/dist/runtime/runtime-id.js +1 -1
- package/dist/runtime/shell-scope.d.ts +4 -4
- package/dist/runtime/shell-scope.js +15 -9
- package/dist/runtime/tool-host-contract.d.ts +0 -4
- package/dist/runtime/tool-host-contract.js +1 -1
- package/dist/services/AccessibilityCatalogResolver.d.ts +21 -31
- package/dist/services/AccessibilityCatalogResolver.js +29 -42
- package/dist/services/ElementToolStateStore.d.ts +32 -61
- package/dist/services/ElementToolStateStore.js +37 -67
- package/dist/services/HighlightCoordinator.d.ts +9 -21
- package/dist/services/HighlightCoordinator.js +52 -80
- package/dist/services/RangeSerializer.d.ts +4 -35
- package/dist/services/RangeSerializer.js +4 -48
- package/dist/services/SSMLExtractor.d.ts +8 -31
- package/dist/services/SSMLExtractor.js +18 -40
- package/dist/services/TTSService.d.ts +51 -57
- package/dist/services/TTSService.js +323 -284
- package/dist/services/ToolCoordinator.d.ts +6 -49
- package/dist/services/ToolCoordinator.js +25 -61
- package/dist/services/ToolRegistry.d.ts +83 -80
- package/dist/services/ToolRegistry.js +91 -67
- package/dist/services/ToolkitCoordinator.d.ts +83 -81
- package/dist/services/ToolkitCoordinator.js +186 -174
- package/dist/services/framework-error.d.ts +30 -7
- package/dist/services/framework-error.js +10 -13
- package/dist/services/interfaces.d.ts +51 -71
- package/dist/services/section-controller-types.d.ts +7 -7
- package/dist/services/section-session-assignment.js +6 -8
- package/dist/services/spoken-audio-cards.d.ts +2 -4
- package/dist/services/spoken-audio-cards.js +2 -4
- package/dist/services/tool-config-validation.d.ts +5 -7
- package/dist/services/tool-config-validation.js +11 -26
- package/dist/services/tool-context.d.ts +39 -24
- package/dist/services/tool-context.js +158 -92
- package/dist/services/tool-failure.d.ts +30 -0
- package/dist/services/tool-failure.js +11 -0
- package/dist/services/tool-icons.d.ts +1 -2
- package/dist/services/tool-icons.js +2 -2
- package/dist/services/tool-instance-id.d.ts +8 -6
- package/dist/services/tool-instance-id.js +12 -18
- package/dist/services/tool-providers/TTSToolProvider.d.ts +6 -43
- package/dist/services/tool-providers/TTSToolProvider.js +7 -63
- package/dist/services/tool-providers/ToolProviderApi.d.ts +0 -7
- package/dist/services/tool-providers/ToolProviderRegistry.d.ts +7 -42
- package/dist/services/tool-providers/ToolProviderRegistry.js +21 -63
- package/dist/services/tool-request.d.ts +4 -0
- package/dist/services/tool-request.js +7 -2
- package/dist/services/toolbar-decided-tools.d.ts +2 -0
- package/dist/services/toolbar-decided-tools.js +2 -0
- package/dist/services/toolbar-items.js +2 -5
- package/dist/services/tools-config-normalizer.d.ts +18 -9
- package/dist/services/tools-config-normalizer.js +25 -19
- package/dist/services/tts/browser-provider.d.ts +2 -5
- package/dist/services/tts/browser-provider.js +13 -22
- package/dist/services/tts/catalog-span-alignment.js +14 -7
- package/dist/services/tts/flat-tree.d.ts +0 -7
- package/dist/services/tts/flat-tree.js +2 -2
- package/dist/services/tts/generated-speech/dom/to-chunk-inputs.d.ts +2 -2
- package/dist/services/tts/generated-speech/index.d.ts +1 -1
- package/dist/services/tts/generated-speech/index.js +1 -1
- package/dist/services/tts/generated-speech/types.d.ts +1 -1
- package/dist/services/tts/generated-speech/types.js +1 -1
- package/dist/services/tts/highlight-pipeline/create-highlight-plan.js +10 -12
- package/dist/services/tts/highlight-target-resolver.d.ts +12 -0
- package/dist/services/tts/math-aware-text-processing.js +10 -29
- package/dist/services/tts/math-speech.d.ts +1 -1
- package/dist/services/tts/math-speech.js +3 -0
- package/dist/services/tts/mathml-sanitization.d.ts +7 -0
- package/dist/services/tts/mathml-sanitization.js +9 -1
- package/dist/services/tts/provider-options.d.ts +12 -1
- package/dist/services/tts/ssml/spoken-text.js +1 -1
- package/dist/services/tts/start-failure.d.ts +0 -7
- package/dist/services/tts/start-failure.js +1 -1
- package/dist/services/tts/text-segmentation.d.ts +5 -0
- package/dist/services/tts/text-segmentation.js +13 -10
- package/dist/services/tts-runtime-config.d.ts +32 -12
- package/dist/services/tts-runtime-config.js +14 -20
- package/dist/tools/content-capability-resolution.d.ts +2 -2
- package/dist/tools/registration.d.ts +7 -6
- package/dist/tools/registration.js +10 -9
- package/dist/tools/registrations/toolbar-registration-helpers.d.ts +6 -0
- package/dist/tools/registrations/toolbar-registration-helpers.js +6 -0
- package/dist/tools/tool-surface-host.js +1 -8
- package/package.json +8 -6
- package/dist/components/chunks/ItemToolBar-bxwyhr5p.js +0 -2
- package/dist/components/chunks/ItemToolBar-rd2bb4p6.js +0 -40
- package/dist/components/chunks/sre-engine-jd8cc08x.js +0 -1
- package/dist/services/ContextVariableStore.d.ts +0 -113
- package/dist/services/ContextVariableStore.js +0 -206
- package/dist/services/tts-control-events.d.ts +0 -13
- package/dist/services/tts-control-events.js +0 -7
- package/dist/utils/logger.d.ts +0 -6
- package/dist/utils/logger.js +0 -10
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
* coordinator's alone: an element bound to a tool (`registerTool` with an
|
|
9
9
|
* element, or `updateToolElement`) takes a z-index in the tool's layer and comes
|
|
10
10
|
* to the front of that layer when shown or pressed.
|
|
11
|
-
*
|
|
12
|
-
* Part of PIE Assessment Toolkit.
|
|
13
11
|
*/
|
|
14
12
|
import type { ToolCoordinatorApi, ToolState, ToolStateFilter } from "./interfaces.js";
|
|
15
13
|
/**
|
|
@@ -34,70 +32,36 @@ export declare class ToolCoordinator implements ToolCoordinatorApi {
|
|
|
34
32
|
/**
|
|
35
33
|
* Register a tool with the coordinator. Registering a known id keeps its
|
|
36
34
|
* on/off state and takes the name, the element when one is given, and the
|
|
37
|
-
* layer when none was declared before.
|
|
38
|
-
*
|
|
39
|
-
* @param id Unique tool identifier
|
|
40
|
-
* @param name Display name
|
|
41
|
-
* @param element DOM element to stack (optional)
|
|
42
|
-
* @param layer Z-index layer. Without one the tool stacks on TOOL until a
|
|
43
|
-
* registration names one.
|
|
35
|
+
* layer when none was declared before. Without a `layer` the tool stacks on
|
|
36
|
+
* TOOL until a registration names one.
|
|
44
37
|
*/
|
|
45
38
|
registerTool(id: string, name: string, element?: HTMLElement, layer?: ZIndexLayer): void;
|
|
46
39
|
/**
|
|
47
40
|
* Unregister a tool's element binding, keeping its on/off state so a
|
|
48
41
|
* re-registration of the same id (an item re-render) restores it. Use
|
|
49
42
|
* {@link releaseTool} on genuine teardown.
|
|
50
|
-
*
|
|
51
|
-
* @param id Tool identifier
|
|
52
43
|
*/
|
|
53
44
|
unregisterTool(id: string): void;
|
|
54
45
|
/**
|
|
55
46
|
* Fully release a tool: unregister its element binding and discard its
|
|
56
47
|
* on/off state. Call this on genuine teardown (leaving the item or section
|
|
57
48
|
* that owns the tool).
|
|
58
|
-
*
|
|
59
|
-
* @param id Tool identifier
|
|
60
49
|
*/
|
|
61
50
|
releaseTool(id: string): void;
|
|
62
|
-
/**
|
|
63
|
-
* Show a tool
|
|
64
|
-
*
|
|
65
|
-
* @param id Tool identifier
|
|
66
|
-
*/
|
|
67
51
|
showTool(id: string): void;
|
|
68
|
-
/**
|
|
69
|
-
* Hide a tool
|
|
70
|
-
*
|
|
71
|
-
* @param id Tool identifier
|
|
72
|
-
*/
|
|
73
52
|
hideTool(id: string): void;
|
|
74
|
-
/**
|
|
75
|
-
* Toggle tool visibility
|
|
76
|
-
*
|
|
77
|
-
* @param id Tool identifier
|
|
78
|
-
*/
|
|
79
53
|
toggleTool(id: string): void;
|
|
80
|
-
/**
|
|
81
|
-
* Check if tool is visible
|
|
82
|
-
*
|
|
83
|
-
* @param id Tool identifier
|
|
84
|
-
*/
|
|
85
54
|
isToolVisible(id: string): boolean;
|
|
86
55
|
/**
|
|
87
56
|
* Bring a bound element to the front of its tool's layer. An element no tool
|
|
88
57
|
* is bound to is left alone.
|
|
89
|
-
*
|
|
90
|
-
* @param element DOM element to bring forward
|
|
91
58
|
*/
|
|
92
59
|
bringToFront(element: HTMLElement): void;
|
|
93
60
|
/**
|
|
94
|
-
*
|
|
61
|
+
* Release every tool, registered or not, and drop the subscribers. The
|
|
62
|
+
* owning toolkit coordinator calls this when it is disposed.
|
|
95
63
|
*/
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Get tool element by ID
|
|
99
|
-
*/
|
|
100
|
-
getToolElement(id: string): HTMLElement | null;
|
|
64
|
+
destroy(): void;
|
|
101
65
|
private setVisible;
|
|
102
66
|
private detachElement;
|
|
103
67
|
/**
|
|
@@ -112,9 +76,6 @@ export declare class ToolCoordinator implements ToolCoordinatorApi {
|
|
|
112
76
|
* The outermost element stacks: binding an element inside the bound one keeps
|
|
113
77
|
* the binding, so a tool rendered inside a toolbar's floating window stacks
|
|
114
78
|
* by that window whichever binds first.
|
|
115
|
-
*
|
|
116
|
-
* @param id Tool identifier
|
|
117
|
-
* @param element New DOM element
|
|
118
79
|
*/
|
|
119
80
|
updateToolElement(id: string, element: HTMLElement): void;
|
|
120
81
|
/**
|
|
@@ -122,11 +83,7 @@ export declare class ToolCoordinator implements ToolCoordinatorApi {
|
|
|
122
83
|
* `{ baseId }`, notifying subscribers once.
|
|
123
84
|
*/
|
|
124
85
|
hideAllTools(filter?: ToolStateFilter): void;
|
|
125
|
-
/**
|
|
126
|
-
* State of a tool an element registration holds.
|
|
127
|
-
*
|
|
128
|
-
* @param id Tool identifier
|
|
129
|
-
*/
|
|
86
|
+
/** State of a tool an element registration holds. */
|
|
130
87
|
getToolState(id: string): ToolState | undefined;
|
|
131
88
|
/**
|
|
132
89
|
* Every visible tool, or every visible instance of one tool with
|
|
@@ -8,12 +8,10 @@
|
|
|
8
8
|
* coordinator's alone: an element bound to a tool (`registerTool` with an
|
|
9
9
|
* element, or `updateToolElement`) takes a z-index in the tool's layer and comes
|
|
10
10
|
* to the front of that layer when shown or pressed.
|
|
11
|
-
*
|
|
12
|
-
* Part of PIE Assessment Toolkit.
|
|
13
11
|
*/
|
|
14
|
-
import {
|
|
12
|
+
import { createPieLogger, isGlobalDebugEnabled, } from "@pie-players/pie-players-shared/pie";
|
|
15
13
|
import { parseScopedToolId } from "./tool-instance-id.js";
|
|
16
|
-
const
|
|
14
|
+
const logger = createPieLogger("ToolCoordinator", isGlobalDebugEnabled);
|
|
17
15
|
/**
|
|
18
16
|
* Z-index layers for assessment components
|
|
19
17
|
*/
|
|
@@ -65,16 +63,16 @@ export class ToolCoordinator {
|
|
|
65
63
|
/**
|
|
66
64
|
* Register a tool with the coordinator. Registering a known id keeps its
|
|
67
65
|
* on/off state and takes the name, the element when one is given, and the
|
|
68
|
-
* layer when none was declared before.
|
|
69
|
-
*
|
|
70
|
-
* @param id Unique tool identifier
|
|
71
|
-
* @param name Display name
|
|
72
|
-
* @param element DOM element to stack (optional)
|
|
73
|
-
* @param layer Z-index layer. Without one the tool stacks on TOOL until a
|
|
74
|
-
* registration names one.
|
|
66
|
+
* layer when none was declared before. Without a `layer` the tool stacks on
|
|
67
|
+
* TOOL until a registration names one.
|
|
75
68
|
*/
|
|
76
69
|
registerTool(id, name, element, layer) {
|
|
77
|
-
|
|
70
|
+
logger.debug("registerTool called:", {
|
|
71
|
+
id,
|
|
72
|
+
name,
|
|
73
|
+
hasElement: !!element,
|
|
74
|
+
layer,
|
|
75
|
+
});
|
|
78
76
|
let entry = this.tools.get(id);
|
|
79
77
|
if (entry) {
|
|
80
78
|
entry.name = name;
|
|
@@ -110,8 +108,6 @@ export class ToolCoordinator {
|
|
|
110
108
|
* Unregister a tool's element binding, keeping its on/off state so a
|
|
111
109
|
* re-registration of the same id (an item re-render) restores it. Use
|
|
112
110
|
* {@link releaseTool} on genuine teardown.
|
|
113
|
-
*
|
|
114
|
-
* @param id Tool identifier
|
|
115
111
|
*/
|
|
116
112
|
unregisterTool(id) {
|
|
117
113
|
const entry = this.tools.get(id);
|
|
@@ -124,8 +120,6 @@ export class ToolCoordinator {
|
|
|
124
120
|
* Fully release a tool: unregister its element binding and discard its
|
|
125
121
|
* on/off state. Call this on genuine teardown (leaving the item or section
|
|
126
122
|
* that owns the tool).
|
|
127
|
-
*
|
|
128
|
-
* @param id Tool identifier
|
|
129
123
|
*/
|
|
130
124
|
releaseTool(id) {
|
|
131
125
|
const entry = this.tools.get(id);
|
|
@@ -136,43 +130,28 @@ export class ToolCoordinator {
|
|
|
136
130
|
if (entry.isVisible)
|
|
137
131
|
this.notifyListeners();
|
|
138
132
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Show a tool
|
|
141
|
-
*
|
|
142
|
-
* @param id Tool identifier
|
|
143
|
-
*/
|
|
144
133
|
showTool(id) {
|
|
145
134
|
const entry = this.tools.get(id);
|
|
146
135
|
if (!entry) {
|
|
147
|
-
|
|
136
|
+
logger.debug(`Tool ${id} not found`);
|
|
148
137
|
return;
|
|
149
138
|
}
|
|
150
139
|
if (entry.element)
|
|
151
140
|
this.bringToFront(entry.element);
|
|
152
141
|
this.setVisible(entry, true);
|
|
153
142
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Hide a tool
|
|
156
|
-
*
|
|
157
|
-
* @param id Tool identifier
|
|
158
|
-
*/
|
|
159
143
|
hideTool(id) {
|
|
160
144
|
const entry = this.tools.get(id);
|
|
161
145
|
if (!entry) {
|
|
162
|
-
|
|
146
|
+
logger.debug(`Tool ${id} not found`);
|
|
163
147
|
return;
|
|
164
148
|
}
|
|
165
149
|
this.setVisible(entry, false);
|
|
166
150
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Toggle tool visibility
|
|
169
|
-
*
|
|
170
|
-
* @param id Tool identifier
|
|
171
|
-
*/
|
|
172
151
|
toggleTool(id) {
|
|
173
152
|
const entry = this.tools.get(id);
|
|
174
153
|
if (!entry) {
|
|
175
|
-
|
|
154
|
+
logger.debug(`Tool ${id} not found`);
|
|
176
155
|
return;
|
|
177
156
|
}
|
|
178
157
|
if (entry.isVisible) {
|
|
@@ -182,19 +161,12 @@ export class ToolCoordinator {
|
|
|
182
161
|
this.showTool(id);
|
|
183
162
|
}
|
|
184
163
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Check if tool is visible
|
|
187
|
-
*
|
|
188
|
-
* @param id Tool identifier
|
|
189
|
-
*/
|
|
190
164
|
isToolVisible(id) {
|
|
191
165
|
return this.tools.get(id)?.isVisible ?? false;
|
|
192
166
|
}
|
|
193
167
|
/**
|
|
194
168
|
* Bring a bound element to the front of its tool's layer. An element no tool
|
|
195
169
|
* is bound to is left alone.
|
|
196
|
-
*
|
|
197
|
-
* @param element DOM element to bring forward
|
|
198
170
|
*/
|
|
199
171
|
bringToFront(element) {
|
|
200
172
|
const entry = Array.from(this.tools.values()).find((t) => t.element === element);
|
|
@@ -203,18 +175,17 @@ export class ToolCoordinator {
|
|
|
203
175
|
this.stackOnTop(entry);
|
|
204
176
|
}
|
|
205
177
|
/**
|
|
206
|
-
*
|
|
178
|
+
* Release every tool, registered or not, and drop the subscribers. The
|
|
179
|
+
* owning toolkit coordinator calls this when it is disposed.
|
|
207
180
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
getToolElement(id) {
|
|
217
|
-
return this.tools.get(id)?.element ?? null;
|
|
181
|
+
destroy() {
|
|
182
|
+
const anyVisible = Array.from(this.tools.values()).some((entry) => entry.isVisible);
|
|
183
|
+
for (const entry of this.tools.values())
|
|
184
|
+
this.detachElement(entry);
|
|
185
|
+
this.tools.clear();
|
|
186
|
+
if (anyVisible)
|
|
187
|
+
this.notifyListeners();
|
|
188
|
+
this.listeners.clear();
|
|
218
189
|
}
|
|
219
190
|
setVisible(entry, visible) {
|
|
220
191
|
if (entry.isVisible === visible)
|
|
@@ -256,14 +227,11 @@ export class ToolCoordinator {
|
|
|
256
227
|
* The outermost element stacks: binding an element inside the bound one keeps
|
|
257
228
|
* the binding, so a tool rendered inside a toolbar's floating window stacks
|
|
258
229
|
* by that window whichever binds first.
|
|
259
|
-
*
|
|
260
|
-
* @param id Tool identifier
|
|
261
|
-
* @param element New DOM element
|
|
262
230
|
*/
|
|
263
231
|
updateToolElement(id, element) {
|
|
264
232
|
const entry = this.tools.get(id);
|
|
265
233
|
if (!entry?.registered) {
|
|
266
|
-
|
|
234
|
+
logger.debug(`Tool ${id} not found`);
|
|
267
235
|
return;
|
|
268
236
|
}
|
|
269
237
|
if (entry.element === element)
|
|
@@ -294,11 +262,7 @@ export class ToolCoordinator {
|
|
|
294
262
|
if (changed)
|
|
295
263
|
this.notifyListeners();
|
|
296
264
|
}
|
|
297
|
-
/**
|
|
298
|
-
* State of a tool an element registration holds.
|
|
299
|
-
*
|
|
300
|
-
* @param id Tool identifier
|
|
301
|
-
*/
|
|
265
|
+
/** State of a tool an element registration holds. */
|
|
302
266
|
getToolState(id) {
|
|
303
267
|
const entry = this.tools.get(id);
|
|
304
268
|
return entry?.registered ? toToolState(entry) : undefined;
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tool
|
|
2
|
+
* Tool registry: the registration contract every tool declares itself with,
|
|
3
|
+
* the shape validation `register` and `override` run, and the `ToolRegistry`
|
|
4
|
+
* class.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
+
* Layout: the exported contract types come first, ending with
|
|
7
|
+
* `ToolRegistration`, then `assertToolRegistrationShape`, then the class. Its
|
|
8
|
+
* members run from mutation and change observation, through queries and the
|
|
9
|
+
* filters for the second and third passes of tool resolution (relevance in
|
|
10
|
+
* `filterVisibleInContext`, applicability in `filterDecidedToolIds`; the policy
|
|
11
|
+
* engine owns the first), to module loading with its undefined-element
|
|
12
|
+
* warnings and the toolbar and surface render helpers.
|
|
6
13
|
*/
|
|
7
14
|
import type { I18nProvider } from "@pie-players/pie-players-shared/i18n/types";
|
|
15
|
+
import type { ToolParametersFor } from "@pie-players/pie-players-shared/types";
|
|
8
16
|
import type { CatalogOwnerSnapshot } from "./AccessibilityCatalogResolver.js";
|
|
17
|
+
import type { ToolPolicyEntry } from "../policy/core/decision-types.js";
|
|
9
18
|
import type { ToolContext, ToolLevel } from "./tool-context.js";
|
|
19
|
+
import type { ToolScopeLevel } from "./tool-instance-id.js";
|
|
10
20
|
import { type ToolComponentOverrides } from "../tools/tool-tag-map.js";
|
|
11
21
|
import type { AccessibilityCatalogResolverApi, ElementToolStateStoreApi, ToolCoordinatorApi, ToolkitCoordinatorApi, TtsServiceApi } from "./interfaces.js";
|
|
12
22
|
import type { ToolProviderApi } from "./tool-providers/ToolProviderApi.js";
|
|
13
|
-
import type { ToolProviderConfig
|
|
23
|
+
import type { ToolProviderConfig } from "./tools-config-normalizer.js";
|
|
14
24
|
import type { ToolConfigDiagnostic } from "./tool-config-validation.js";
|
|
25
|
+
import type { ToolFailurePhase } from "./tool-failure.js";
|
|
15
26
|
export type ToolModuleLoader = () => Promise<unknown>;
|
|
27
|
+
/** Receives a registration callback's throw, from which the registry recovers. */
|
|
28
|
+
export type ToolCallbackFailureHandler = (toolId: string, phase: Extract<ToolFailurePhase, "tool-visibility" | "tool-applicability">, error: unknown) => void;
|
|
16
29
|
export type ToolRegistryChangeKind = "register" | "override" | "unregister" | "clear" | "component-overrides" | "module-loaders";
|
|
17
30
|
/** A successful mutation to discoverable or rendering registry state. */
|
|
18
31
|
export interface ToolRegistryChangeEvent {
|
|
@@ -24,18 +37,16 @@ export interface ToolToolbarButtonDefinition {
|
|
|
24
37
|
toolId: string;
|
|
25
38
|
label: string;
|
|
26
39
|
/**
|
|
27
|
-
* Optional to match
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* on. A registration that renders a button still has to declare an icon —
|
|
40
|
+
* Optional to match the renderer: `ItemToolBar.svelte` guards on
|
|
41
|
+
* `button.icon`, and `ToolbarItem.icon` is optional too. A registration that
|
|
42
|
+
* renders a button still has to declare an icon —
|
|
31
43
|
* `assertToolRegistrationShape` enforces that.
|
|
32
44
|
*/
|
|
33
45
|
icon?: string;
|
|
34
46
|
/**
|
|
35
47
|
* FontAwesome icon name, opting this button into `<nds-icon-button>` rendering
|
|
36
48
|
* where the host enables NDS icons (`ndsIcons`). Absent means the toolbar keeps
|
|
37
|
-
* its own button rendering
|
|
38
|
-
* button existed.
|
|
49
|
+
* its own button rendering.
|
|
39
50
|
*
|
|
40
51
|
* A declaration rather than a toolId lookup in the toolbar: which capabilities
|
|
41
52
|
* a deployment renders through the host's design system is a composition-layer
|
|
@@ -51,7 +62,7 @@ export interface ToolToolbarButtonDefinition {
|
|
|
51
62
|
}
|
|
52
63
|
export interface ToolbarContext {
|
|
53
64
|
scope: {
|
|
54
|
-
level:
|
|
65
|
+
level: ToolScopeLevel;
|
|
55
66
|
scopeId: string;
|
|
56
67
|
assessmentId?: string;
|
|
57
68
|
sectionId?: string;
|
|
@@ -102,6 +113,13 @@ export interface ToolbarContext {
|
|
|
102
113
|
componentOverrides?: ToolComponentOverrides;
|
|
103
114
|
getResolvedToolContext?: (toolId: string) => ResolvedToolContext | null;
|
|
104
115
|
getToolRenderParams?: (toolId: string) => Record<string, unknown> | null;
|
|
116
|
+
/**
|
|
117
|
+
* The tool's policy parameters on this toolbar: the profile's, assessment's
|
|
118
|
+
* and, on an item's own toolbar, item's `toolParameters` entries merged key by
|
|
119
|
+
* key, later ones winning. Authored content, so a registration checks what it
|
|
120
|
+
* reads.
|
|
121
|
+
*/
|
|
122
|
+
getToolParameters?: <K extends string>(toolId: K) => ToolParametersFor<K> | null;
|
|
105
123
|
}
|
|
106
124
|
export interface ToolContextResolverContext {
|
|
107
125
|
toolId: string;
|
|
@@ -222,9 +240,9 @@ export interface HostedToolSize {
|
|
|
222
240
|
* renames the registration.
|
|
223
241
|
*/
|
|
224
242
|
export interface ToolProviderDescriptor {
|
|
225
|
-
createProvider: (config:
|
|
226
|
-
getInitConfig?: (config:
|
|
227
|
-
getAuthFetcher?: (config:
|
|
243
|
+
createProvider: (config: ToolProviderConfig | undefined) => ToolProviderApi;
|
|
244
|
+
getInitConfig?: (config: ToolProviderConfig | undefined) => Record<string, unknown>;
|
|
245
|
+
getAuthFetcher?: (config: ToolProviderConfig | undefined) => (() => Promise<Record<string, unknown>>) | undefined;
|
|
228
246
|
lazy?: boolean;
|
|
229
247
|
}
|
|
230
248
|
export interface ToolToolbarRenderResult {
|
|
@@ -293,7 +311,7 @@ export interface ToolSurfaceRenderContext {
|
|
|
293
311
|
/** Host slot being filled. */
|
|
294
312
|
surface: string;
|
|
295
313
|
/** Feature parameters from the policy decision, if any. */
|
|
296
|
-
parameters?: unknown
|
|
314
|
+
parameters?: Record<string, unknown>;
|
|
297
315
|
/** Resolved content dependency, when the capability declares one. */
|
|
298
316
|
content?: unknown;
|
|
299
317
|
services: ToolSurfaceServices;
|
|
@@ -305,7 +323,7 @@ export interface ToolSurfaceRenderContext {
|
|
|
305
323
|
*/
|
|
306
324
|
export interface ToolContentDependencyContext {
|
|
307
325
|
/** Feature parameters from the policy decision, if any. */
|
|
308
|
-
parameters?: unknown
|
|
326
|
+
parameters?: Record<string, unknown>;
|
|
309
327
|
/**
|
|
310
328
|
* Owner-scoped catalog cards, or `null` when no resolver is available.
|
|
311
329
|
*
|
|
@@ -333,8 +351,8 @@ export interface ToolContentDependencyContext {
|
|
|
333
351
|
* It is intrinsic to the capability, unlike eligibility tier, which is a property
|
|
334
352
|
* of the program.
|
|
335
353
|
*
|
|
336
|
-
* Two independent things follow from declaring it,
|
|
337
|
-
*
|
|
354
|
+
* Two independent things follow from declaring it, neither of which needs core
|
|
355
|
+
* to name a capability id:
|
|
338
356
|
*
|
|
339
357
|
* 1. **Availability is grant AND content.** The host renders only when policy
|
|
340
358
|
* granted the feature *and* `resolve` returned something. Neither half
|
|
@@ -398,7 +416,8 @@ export interface ToolSurfaceRenderResult {
|
|
|
398
416
|
destroy?: () => void;
|
|
399
417
|
}
|
|
400
418
|
/**
|
|
401
|
-
*
|
|
419
|
+
* The contract a tool declares itself with; `ToolRegistry.register` validates
|
|
420
|
+
* its shape.
|
|
402
421
|
*/
|
|
403
422
|
export interface ToolRegistration {
|
|
404
423
|
/** Unique tool identifier (e.g., 'calculator', 'textToSpeech') */
|
|
@@ -489,11 +508,11 @@ export interface ToolRegistration {
|
|
|
489
508
|
* validation runs it before {@link ToolRegistration.validateConfig}; a throw is
|
|
490
509
|
* reported as a diagnostic and the entry passes through unchanged.
|
|
491
510
|
*/
|
|
492
|
-
sanitizeConfig?: (config:
|
|
511
|
+
sanitizeConfig?: (config: ToolProviderConfig) => ToolProviderConfig;
|
|
493
512
|
/**
|
|
494
513
|
* Diagnostics for this tool's sanitized `tools.providers.<toolId>` entry.
|
|
495
514
|
*/
|
|
496
|
-
validateConfig?: (config:
|
|
515
|
+
validateConfig?: (config: ToolProviderConfig) => ToolConfigDiagnostic[];
|
|
497
516
|
/**
|
|
498
517
|
* Optional shell-host lifecycle hooks for hosted (floating) tools.
|
|
499
518
|
*/
|
|
@@ -501,17 +520,14 @@ export interface ToolRegistration {
|
|
|
501
520
|
onHostedResize?: (size: HostedToolSize, element: HTMLElement, context: HostedToolContext) => void | Promise<void>;
|
|
502
521
|
onHostedUnmount?: (element: HTMLElement, context: HostedToolContext) => void | Promise<void>;
|
|
503
522
|
/**
|
|
504
|
-
*
|
|
505
|
-
*
|
|
523
|
+
* Whether the tool is relevant in this context (pass 2). Asked only for a
|
|
524
|
+
* tool policy already allows (pass 1).
|
|
506
525
|
*
|
|
507
526
|
* Required for the toolbar activations, and meaningless for `activation:
|
|
508
527
|
* "region"`: a region capability has no toolbar presence to be relevant to, and
|
|
509
528
|
* the question it *would* answer — is there anything to show here — is
|
|
510
529
|
* `requiresAuthoredContent`. A registration that omits this is never returned
|
|
511
|
-
* by `
|
|
512
|
-
*
|
|
513
|
-
* @param context - Rich context about where tool is being evaluated
|
|
514
|
-
* @returns true if tool should be visible, false to hide
|
|
530
|
+
* by `filterVisibleInContext`.
|
|
515
531
|
*/
|
|
516
532
|
isVisibleInContext?(context: ToolContext): boolean;
|
|
517
533
|
/**
|
|
@@ -529,9 +545,6 @@ export interface ToolRegistration {
|
|
|
529
545
|
* Declare this only where the tool's own controls provably do nothing:
|
|
530
546
|
* withdrawing a granted accommodation on a false negative is the more
|
|
531
547
|
* expensive failure. Omitting it means "applicable".
|
|
532
|
-
*
|
|
533
|
-
* @param context - The item or element context the tool would act on
|
|
534
|
-
* @returns false to withdraw the tool from this context
|
|
535
548
|
*/
|
|
536
549
|
isApplicableToContent?(context: ToolContext): boolean;
|
|
537
550
|
/**
|
|
@@ -580,56 +593,25 @@ export declare class ToolRegistry {
|
|
|
580
593
|
*/
|
|
581
594
|
normalizeToolIds(toolIds: string[]): string[];
|
|
582
595
|
/**
|
|
583
|
-
* Register a tool
|
|
584
|
-
*
|
|
585
|
-
* @param registration - Tool registration
|
|
586
|
-
* @throws Error if toolId is already registered
|
|
596
|
+
* Register a tool. Throws when its `toolId` is already registered.
|
|
587
597
|
*/
|
|
588
598
|
register(registration: ToolRegistration): void;
|
|
589
599
|
/**
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
* @param registration - New tool registration (must have existing toolId)
|
|
600
|
+
* Replace an existing tool registration. Throws when its `toolId` is not
|
|
601
|
+
* registered.
|
|
593
602
|
*/
|
|
594
603
|
override(registration: ToolRegistration): void;
|
|
595
604
|
/**
|
|
596
|
-
* Unregister a tool
|
|
597
|
-
*
|
|
598
|
-
* @param toolId - Tool ID to remove
|
|
605
|
+
* Unregister a tool. An unknown id is a no-op and emits no change.
|
|
599
606
|
*/
|
|
600
607
|
unregister(toolId: string): void;
|
|
601
|
-
/**
|
|
602
|
-
* Get a tool registration by ID
|
|
603
|
-
*
|
|
604
|
-
* @param toolId - Tool ID
|
|
605
|
-
* @returns Tool registration or undefined
|
|
606
|
-
*/
|
|
607
608
|
get(toolId: string): ToolRegistration | undefined;
|
|
608
|
-
/**
|
|
609
|
-
* Check if a tool is registered
|
|
610
|
-
*
|
|
611
|
-
* @param toolId - Tool ID
|
|
612
|
-
* @returns true if registered
|
|
613
|
-
*/
|
|
614
609
|
has(toolId: string): boolean;
|
|
615
|
-
/**
|
|
616
|
-
* Get all registered tool IDs
|
|
617
|
-
*
|
|
618
|
-
* @returns Array of tool IDs
|
|
619
|
-
*/
|
|
610
|
+
/** Registered tool ids, in registration order. */
|
|
620
611
|
getAllToolIds(): string[];
|
|
621
|
-
/**
|
|
622
|
-
* Get all tool registrations
|
|
623
|
-
*
|
|
624
|
-
* @returns Array of tool registrations
|
|
625
|
-
*/
|
|
612
|
+
/** Registrations, in registration order. */
|
|
626
613
|
getAllTools(): ToolRegistration[];
|
|
627
|
-
/**
|
|
628
|
-
* Get tools that support a specific level
|
|
629
|
-
*
|
|
630
|
-
* @param level - Tool level (assessment, section, item, passage, element)
|
|
631
|
-
* @returns Array of tool registrations that support this level
|
|
632
|
-
*/
|
|
614
|
+
/** Registrations whose `supportedLevels` include `level`. */
|
|
633
615
|
getToolsByLevel(level: ToolLevel): ToolRegistration[];
|
|
634
616
|
/**
|
|
635
617
|
* Resolve tool activation, defaulting to toolbar-toggle.
|
|
@@ -662,16 +644,14 @@ export declare class ToolRegistry {
|
|
|
662
644
|
*/
|
|
663
645
|
filterToolIdsByActivation(toolIds: string[], activation: ToolActivation): string[];
|
|
664
646
|
/**
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
* ask each tool if it's relevant in this context.
|
|
647
|
+
* Pass 2 of tool resolution: the registrations among `allowedToolIds` (the
|
|
648
|
+
* ids policy allowed in pass 1) that support `context.level` and answer
|
|
649
|
+
* `isVisibleInContext` with `true`.
|
|
669
650
|
*
|
|
670
|
-
* @param
|
|
671
|
-
*
|
|
672
|
-
* @returns Array of visible tool registrations
|
|
651
|
+
* @param onFailure - Receives a relevance check's throw; the tool is then not
|
|
652
|
+
* visible. Logs when omitted.
|
|
673
653
|
*/
|
|
674
|
-
filterVisibleInContext(allowedToolIds: string[], context: ToolContext): ToolRegistration[];
|
|
654
|
+
filterVisibleInContext(allowedToolIds: string[], context: ToolContext, onFailure?: ToolCallbackFailureHandler): ToolRegistration[];
|
|
675
655
|
/**
|
|
676
656
|
* Whether a tool can act on any of the contexts it would be placed against.
|
|
677
657
|
* Unlike the relevance pass this is a veto: a `false` here removes the tool
|
|
@@ -684,13 +664,34 @@ export declare class ToolRegistry {
|
|
|
684
664
|
*
|
|
685
665
|
* @param toolId - Tool to ask
|
|
686
666
|
* @param contexts - Every context the tool could act on at this placement
|
|
667
|
+
* @param onFailure - Receives the gate's throw; the tool then counts as
|
|
668
|
+
* applicable. Logs when omitted.
|
|
687
669
|
*/
|
|
688
|
-
isApplicableToAnyContext(toolId: string, contexts: readonly ToolContext[]): boolean;
|
|
670
|
+
isApplicableToAnyContext(toolId: string, contexts: readonly ToolContext[], onFailure?: ToolCallbackFailureHandler): boolean;
|
|
689
671
|
/**
|
|
690
|
-
*
|
|
691
|
-
*
|
|
672
|
+
* Passes 2 and 3 over a policy decision's tools: the ids a surface at `level`
|
|
673
|
+
* shows against `contexts`, in decision order. This is the rule a toolbar
|
|
674
|
+
* applies, for a host that builds its own tool surface.
|
|
692
675
|
*
|
|
693
|
-
*
|
|
676
|
+
* - A tool that does not support `level` is dropped.
|
|
677
|
+
* - Relevance (`isVisibleInContext`) keeps a tool visible in any one context.
|
|
678
|
+
* It does not run for a granted entry (`required` or `alwaysAvailable`),
|
|
679
|
+
* at section level, whose relevance is item-dependent, or when `contexts`
|
|
680
|
+
* is empty, since content that has not resolved cannot rule a tool out.
|
|
681
|
+
* - Applicability (`isApplicableToContent`) then removes a tool that can act
|
|
682
|
+
* on none of `contexts`, granted or not. It does not run at section level.
|
|
683
|
+
*
|
|
684
|
+
* @param entries - The decision's surviving entries (Pass 1), such as
|
|
685
|
+
* `ToolPolicyDecision.visibleTools`
|
|
686
|
+
* @param level - The level of the surface the tools render on
|
|
687
|
+
* @param contexts - Every context the tools could act on at that surface
|
|
688
|
+
* @param onFailure - Receives a relevance or applicability check's throw.
|
|
689
|
+
* Logs when omitted.
|
|
690
|
+
*/
|
|
691
|
+
filterDecidedToolIds(entries: readonly Pick<ToolPolicyEntry, "toolId" | "required" | "alwaysAvailable">[], level: ToolLevel, contexts: readonly ToolContext[], onFailure?: ToolCallbackFailureHandler): string[];
|
|
692
|
+
/**
|
|
693
|
+
* Plain metadata for every registration, in registration order, for UIs
|
|
694
|
+
* such as a PNP configuration screen.
|
|
694
695
|
*/
|
|
695
696
|
getToolMetadata(): Array<{
|
|
696
697
|
toolId: string;
|
|
@@ -765,4 +766,6 @@ export declare class ToolRegistry {
|
|
|
765
766
|
* context still win, matching the toolbar path's precedence.
|
|
766
767
|
*/
|
|
767
768
|
renderForSurface(toolId: string, context: ToolSurfaceRenderContext): ToolSurfaceRenderResult | null;
|
|
769
|
+
/** The registry's component overrides, with the caller's taking precedence. */
|
|
770
|
+
private mergeComponentOverrides;
|
|
768
771
|
}
|