@khanacademy/perseus-core 0.0.0-PR3089-20251204205538 → 0.0.0-PR3091-20251204213510
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/dist/es/index.js +12 -1
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/extract-perseus-ai-data.d.ts +39 -0
- package/dist/validation.types.d.ts +22 -2
- package/dist/validation.typetest.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PerseusItem, PerseusWidgetsMap, PerseusRenderer } from "../data-schema";
|
|
2
|
+
/**
|
|
3
|
+
* This function extracts the answers from the widgets.
|
|
4
|
+
*
|
|
5
|
+
* For each widget type, we first check to make sure the path to the answer exists,
|
|
6
|
+
* then we extract the answer and add it to the list of answers.
|
|
7
|
+
*
|
|
8
|
+
* A list is returned because some widgets, like multi-select radio widgets and groups
|
|
9
|
+
* can have multiple answers.
|
|
10
|
+
*
|
|
11
|
+
* @param {PerseusRenderer["widgets"]} widgets
|
|
12
|
+
* @returns a list of strings that are the answers to the widgets
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAnswersFromWidgets(widgets: PerseusRenderer["widgets"]): ReadonlyArray<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Inject a string equivalent of the widgets into the content.
|
|
17
|
+
*
|
|
18
|
+
* Content may contain Perseus widgets, that looks like this: '[[☃ Radio 1]]'.
|
|
19
|
+
* This function replaces those widgets with its equivalent string.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} content
|
|
22
|
+
* @param {PerseusRenderer["widgets"]} widgets
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function injectWidgets(content: string, widgets: PerseusRenderer["widgets"], widgetProps?: PerseusWidgetsMap): string;
|
|
26
|
+
/**
|
|
27
|
+
* Get AI-ready data from a Perseus item for Khanmigo.
|
|
28
|
+
*
|
|
29
|
+
* This function extracts the correct answers from widgets and injects
|
|
30
|
+
* widget content into hints to provide Khanmigo with the context it needs
|
|
31
|
+
* to help students without requiring React rendering.
|
|
32
|
+
*
|
|
33
|
+
* @param {PerseusItem} perseusItem - The Perseus item containing question and hints
|
|
34
|
+
* @returns Object containing answers and processed hints
|
|
35
|
+
*/
|
|
36
|
+
export declare function getPerseusAIData(perseusItem: PerseusItem): {
|
|
37
|
+
answers: ReadonlyArray<string>;
|
|
38
|
+
hints: ReadonlyArray<string>;
|
|
39
|
+
};
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* } & Perseus<Widget>ValidationData;
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
import type { GrapherAnswerTypes, PerseusDropdownChoice, PerseusExpressionAnswerForm, PerseusGradedGroupSetWidgetOptions, PerseusGradedGroupWidgetOptions, PerseusGraphType, PerseusGroupWidgetOptions, PerseusMatrixWidgetAnswers, PerseusNumericInputAnswer, PerseusOrdererWidgetOptions, PerseusRadioChoice, PerseusGraphCorrectType, MakeWidgetMap, PerseusFreeResponseWidgetScoringCriterion
|
|
31
|
+
import type { GrapherAnswerTypes, PerseusDropdownChoice, PerseusExpressionAnswerForm, PerseusGradedGroupSetWidgetOptions, PerseusGradedGroupWidgetOptions, PerseusGraphType, PerseusGroupWidgetOptions, PerseusMatrixWidgetAnswers, PerseusNumericInputAnswer, PerseusOrdererWidgetOptions, PerseusRadioChoice, PerseusGraphCorrectType, MakeWidgetMap, PerseusFreeResponseWidgetScoringCriterion } from "./data-schema";
|
|
32
32
|
import type { ErrorCode } from "./error-codes";
|
|
33
33
|
import type { Relationship } from "./types";
|
|
34
34
|
export type WidgetValidatorFunction = (userInput: UserInput | undefined, validationData: ValidationData, locale: string) => ValidationResult;
|
|
@@ -72,7 +72,9 @@ export type PerseusExpressionRubric = {
|
|
|
72
72
|
};
|
|
73
73
|
export type PerseusExpressionUserInput = string;
|
|
74
74
|
export type PerseusGroupRubric = PerseusGroupWidgetOptions;
|
|
75
|
-
export type PerseusGroupValidationData =
|
|
75
|
+
export type PerseusGroupValidationData = {
|
|
76
|
+
widgets: ValidationDataMap;
|
|
77
|
+
};
|
|
76
78
|
export type PerseusGroupUserInput = UserInputMap;
|
|
77
79
|
export type PerseusGradedGroupRubric = PerseusGradedGroupWidgetOptions;
|
|
78
80
|
export type PerseusGradedGroupSetRubric = PerseusGradedGroupSetWidgetOptions;
|
|
@@ -265,6 +267,24 @@ export interface ValidationDataTypes {
|
|
|
265
267
|
group: PerseusGroupValidationData;
|
|
266
268
|
plotter: PerseusPlotterValidationData;
|
|
267
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* A map of validation data, keyed by `widgetId`. This data is used to check if
|
|
272
|
+
* a question is answerable. This data represents the minimal intersection of
|
|
273
|
+
* data that's available in the client (widget options) and server (scoring
|
|
274
|
+
* data) and is represented by a group of types known as "validation data".
|
|
275
|
+
*
|
|
276
|
+
* NOTE: The value in this map is intentionally a subset of WidgetOptions<T>.
|
|
277
|
+
* By using the same shape (minus any unneeded data), we are able to pass a
|
|
278
|
+
* `PerseusWidgetsMap` or ` into any function that accepts a
|
|
279
|
+
* `ValidationDataMap` without any mutation of data.
|
|
280
|
+
*/
|
|
281
|
+
export type ValidationDataMap = {
|
|
282
|
+
[Property in keyof ValidationDataTypes as `${Property} ${number}`]: {
|
|
283
|
+
type: Property;
|
|
284
|
+
static?: boolean;
|
|
285
|
+
options: ValidationDataTypes[Property];
|
|
286
|
+
};
|
|
287
|
+
};
|
|
268
288
|
/**
|
|
269
289
|
* A union type of all the different widget validation data types that exist.
|
|
270
290
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|