@intellectif/lk-core 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/{chunk-QOAORTA4.cjs → chunk-4JR3UXX6.cjs} +51 -2
  2. package/dist/chunk-4JR3UXX6.cjs.map +1 -0
  3. package/dist/{chunk-A6JXV5GP.js → chunk-DUQVGLQ3.js} +56 -57
  4. package/dist/chunk-DUQVGLQ3.js.map +1 -0
  5. package/dist/chunk-FCM5VJBS.cjs +187 -0
  6. package/dist/chunk-FCM5VJBS.cjs.map +1 -0
  7. package/dist/chunk-LSHDNA2T.js +187 -0
  8. package/dist/chunk-LSHDNA2T.js.map +1 -0
  9. package/dist/{chunk-5GJJHGY5.js → chunk-NUCEUU4P.js} +50 -1
  10. package/dist/chunk-NUCEUU4P.js.map +1 -0
  11. package/dist/{chunk-RUZ52Q7A.cjs → chunk-R7PDJBRX.cjs} +19 -4
  12. package/dist/chunk-R7PDJBRX.cjs.map +1 -0
  13. package/dist/{chunk-5ZAW76F3.cjs → chunk-SM5HUGYU.cjs} +59 -60
  14. package/dist/chunk-SM5HUGYU.cjs.map +1 -0
  15. package/dist/{chunk-APDLWLYD.js → chunk-WV5WQ3SZ.js} +19 -4
  16. package/dist/chunk-WV5WQ3SZ.js.map +1 -0
  17. package/dist/index-BKyZrd94.d.cts +732 -0
  18. package/dist/index-CLmXzBhB.d.ts +732 -0
  19. package/dist/index.cjs +192 -15
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +133 -3
  22. package/dist/index.d.ts +133 -3
  23. package/dist/index.js +189 -12
  24. package/dist/index.js.map +1 -1
  25. package/dist/schemas.cjs +17 -4
  26. package/dist/schemas.cjs.map +1 -1
  27. package/dist/schemas.d.cts +3 -460
  28. package/dist/schemas.d.ts +3 -460
  29. package/dist/schemas.js +16 -3
  30. package/dist/scoring.cjs +3 -4
  31. package/dist/scoring.cjs.map +1 -1
  32. package/dist/scoring.d.cts +9 -1
  33. package/dist/scoring.d.ts +9 -1
  34. package/dist/scoring.js +2 -3
  35. package/dist/xapi.cjs +5 -3
  36. package/dist/xapi.cjs.map +1 -1
  37. package/dist/xapi.d.cts +18 -1
  38. package/dist/xapi.d.ts +18 -1
  39. package/dist/xapi.js +6 -4
  40. package/package.json +3 -2
  41. package/dist/chunk-3YAVDV5F.js +0 -47
  42. package/dist/chunk-3YAVDV5F.js.map +0 -1
  43. package/dist/chunk-55O4M45K.js +0 -57
  44. package/dist/chunk-55O4M45K.js.map +0 -1
  45. package/dist/chunk-5GJJHGY5.js.map +0 -1
  46. package/dist/chunk-5ZAW76F3.cjs.map +0 -1
  47. package/dist/chunk-A6JXV5GP.js.map +0 -1
  48. package/dist/chunk-APDLWLYD.js.map +0 -1
  49. package/dist/chunk-PIMX4B4D.cjs +0 -47
  50. package/dist/chunk-PIMX4B4D.cjs.map +0 -1
  51. package/dist/chunk-QOAORTA4.cjs.map +0 -1
  52. package/dist/chunk-RUZ52Q7A.cjs.map +0 -1
  53. package/dist/chunk-YNTYWHZI.cjs +0 -57
  54. package/dist/chunk-YNTYWHZI.cjs.map +0 -1
@@ -0,0 +1,187 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _chunk4JR3UXX6cjs = require('./chunk-4JR3UXX6.cjs');
9
+
10
+ // src/schemas/item-group.ts
11
+ var _v4 = require('zod/v4');
12
+ function hasBody(stimulus) {
13
+ return typeof stimulus.body === "string" && stimulus.body.trim().length > 0;
14
+ }
15
+ function mediaFits(kind, mediaType) {
16
+ switch (kind) {
17
+ case "audio":
18
+ return mediaType === "audio";
19
+ case "video":
20
+ return mediaType === "video" || mediaType === "embed";
21
+ case "image":
22
+ return mediaType === "image";
23
+ default:
24
+ return true;
25
+ }
26
+ }
27
+ var StimulusSchema = _v4.z.looseObject({
28
+ id: _v4.z.string().min(1),
29
+ kind: _v4.z.enum(["text", "audio", "video", "image", "mixed"]),
30
+ title: _v4.z.string().optional(),
31
+ body: _v4.z.string().optional(),
32
+ bodyHtml: _v4.z.string().optional(),
33
+ media: _chunk4JR3UXX6cjs.MediaSchema.optional(),
34
+ transcript: _v4.z.string().optional(),
35
+ locale: _v4.z.string().optional(),
36
+ attribution: _v4.z.string().optional()
37
+ }).refine((stimulus) => stimulus.bodyHtml === void 0 || hasBody(stimulus), {
38
+ error: "bodyHtml requires a plain-text body: it is the accessible fallback rendered when no sanitiser is supplied.",
39
+ path: ["body"]
40
+ }).refine(
41
+ (stimulus) => stimulus.kind !== "text" && stimulus.kind !== "mixed" || hasBody(stimulus),
42
+ {
43
+ error: "A text or mixed stimulus needs a non-empty body.",
44
+ path: ["body"]
45
+ }
46
+ ).refine((stimulus) => stimulus.kind === "text" || stimulus.media !== void 0, {
47
+ error: "An audio, video, image or mixed stimulus needs media.",
48
+ path: ["media"]
49
+ }).refine(
50
+ (stimulus) => stimulus.media === void 0 || mediaFits(stimulus.kind, stimulus.media.type),
51
+ {
52
+ error: "media.type does not fit the stimulus kind: audio needs audio; video needs video or embed; image needs image.",
53
+ path: ["media", "type"]
54
+ }
55
+ );
56
+ var ItemShapeSchema = _v4.z.looseObject({
57
+ type: _v4.z.string().min(1),
58
+ id: _v4.z.string().min(1)
59
+ });
60
+ var ItemGroupSchema = _v4.z.looseObject({
61
+ schemaVersion: _v4.z.literal("1.0"),
62
+ type: _v4.z.literal("item-group"),
63
+ id: _v4.z.string().min(1),
64
+ title: _v4.z.string().optional(),
65
+ stimulus: StimulusSchema,
66
+ items: _v4.z.array(ItemShapeSchema).min(1),
67
+ shuffle: _v4.z.enum(["none", "within-group"]).optional()
68
+ }).refine((group) => group.items.every((item) => item.type !== "item-group"), {
69
+ error: "Item groups do not nest: every item must be an activity.",
70
+ path: ["items"]
71
+ }).refine((group) => new Set(group.items.map((item) => item.id)).size === group.items.length, {
72
+ error: "Item ids must be unique within a group.",
73
+ path: ["items"]
74
+ });
75
+ var RedactedStimulusSchema = _v4.z.strictObject({
76
+ id: _v4.z.string().min(1),
77
+ kind: _v4.z.enum(["text", "audio", "video", "image", "mixed"]),
78
+ title: _v4.z.string().optional(),
79
+ body: _v4.z.string().optional(),
80
+ bodyHtml: _v4.z.string().optional(),
81
+ media: _chunk4JR3UXX6cjs.MediaSchema.optional(),
82
+ locale: _v4.z.string().optional(),
83
+ attribution: _v4.z.string().optional()
84
+ });
85
+ var RedactedItemGroupSchema = _v4.z.strictObject({
86
+ redacted: _v4.z.literal(true),
87
+ schemaVersion: _v4.z.literal("1.0"),
88
+ type: _v4.z.literal("item-group"),
89
+ id: _v4.z.string().min(1),
90
+ title: _v4.z.string().optional(),
91
+ stimulus: RedactedStimulusSchema,
92
+ items: _v4.z.array(_v4.z.unknown()).min(1),
93
+ shuffle: _v4.z.enum(["none", "within-group"]).optional()
94
+ });
95
+ function toValidationErrors(issues, prefix) {
96
+ return issues.map((issue) => ({
97
+ path: [...prefix, ...issue.path.map(String)],
98
+ message: issue.message,
99
+ code: issue.code
100
+ }));
101
+ }
102
+ function validateItemGroup(data) {
103
+ const container = ItemGroupSchema.safeParse(data);
104
+ if (!container.success) {
105
+ return { success: false, errors: toValidationErrors(container.error.issues, []) };
106
+ }
107
+ const errors = [];
108
+ const items = [];
109
+ container.data.items.forEach((item, index) => {
110
+ const descriptor = _chunk4JR3UXX6cjs.getActivityTypeDescriptor.call(void 0, item.type);
111
+ if (descriptor === void 0) {
112
+ errors.push({
113
+ path: ["items", String(index), "type"],
114
+ message: `Activity type "${item.type}" is not registered`,
115
+ code: "unknown_activity_type"
116
+ });
117
+ return;
118
+ }
119
+ const parsed = descriptor.schema.safeParse(item);
120
+ if (!parsed.success) {
121
+ errors.push(...toValidationErrors(parsed.error.issues, ["items", String(index)]));
122
+ return;
123
+ }
124
+ items.push(parsed.data);
125
+ });
126
+ if (errors.length > 0) {
127
+ return { success: false, errors };
128
+ }
129
+ return { success: true, data: { ...container.data, items } };
130
+ }
131
+
132
+ // src/schemas/json-schema.ts
133
+
134
+ var stimulusJsonSchema = _v4.z.toJSONSchema(StimulusSchema, { target: "draft-7" });
135
+ var itemGroupJsonSchema = _v4.z.toJSONSchema(ItemGroupSchema, { target: "draft-7" });
136
+ var multipleChoiceJsonSchema = _v4.z.toJSONSchema(_chunk4JR3UXX6cjs.MultipleChoiceDataSchema, {
137
+ target: "draft-7"
138
+ });
139
+ var fillInTheBlanksJsonSchema = _v4.z.toJSONSchema(_chunk4JR3UXX6cjs.FillInTheBlanksDataSchema, {
140
+ target: "draft-7"
141
+ });
142
+ var writtenResponseJsonSchema = _v4.z.toJSONSchema(_chunk4JR3UXX6cjs.WrittenResponseDataSchema, {
143
+ target: "draft-7"
144
+ });
145
+ function jsonSchemaFor(type) {
146
+ const descriptor = _chunk4JR3UXX6cjs.getActivityTypeDescriptor.call(void 0, type);
147
+ if (descriptor === void 0) {
148
+ throw new (0, _chunk4JR3UXX6cjs.UnknownActivityTypeError)(type);
149
+ }
150
+ return _v4.z.toJSONSchema(descriptor.schema, { target: "draft-7" });
151
+ }
152
+
153
+ // src/schemas/index.ts
154
+ function validateActivity(type, data) {
155
+ const descriptor = _chunk4JR3UXX6cjs.getActivityTypeDescriptor.call(void 0, type);
156
+ if (descriptor === void 0) {
157
+ throw new (0, _chunk4JR3UXX6cjs.UnknownActivityTypeError)(String(type));
158
+ }
159
+ const result = descriptor.schema.safeParse(data);
160
+ if (result.success) {
161
+ return { success: true, data: result.data };
162
+ }
163
+ return {
164
+ success: false,
165
+ errors: result.error.issues.map((issue) => ({
166
+ path: issue.path.map(String),
167
+ message: issue.message,
168
+ code: issue.code
169
+ }))
170
+ };
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+ exports.StimulusSchema = StimulusSchema; exports.ItemGroupSchema = ItemGroupSchema; exports.RedactedStimulusSchema = RedactedStimulusSchema; exports.RedactedItemGroupSchema = RedactedItemGroupSchema; exports.validateItemGroup = validateItemGroup; exports.stimulusJsonSchema = stimulusJsonSchema; exports.itemGroupJsonSchema = itemGroupJsonSchema; exports.multipleChoiceJsonSchema = multipleChoiceJsonSchema; exports.fillInTheBlanksJsonSchema = fillInTheBlanksJsonSchema; exports.writtenResponseJsonSchema = writtenResponseJsonSchema; exports.jsonSchemaFor = jsonSchemaFor; exports.validateActivity = validateActivity;
187
+ //# sourceMappingURL=chunk-FCM5VJBS.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/learning-kit/learning-kit/packages/lk-core/dist/chunk-FCM5VJBS.cjs","../src/schemas/item-group.ts","../src/schemas/json-schema.ts","../src/schemas/index.ts"],"names":["z"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACTA,4BAAkB;AAMlB,SAAS,OAAA,CAAQ,QAAA,EAAkD;AACjE,EAAA,OAAO,OAAO,QAAA,CAAS,KAAA,IAAS,SAAA,GAAY,QAAA,CAAS,IAAA,CAAK,IAAA,CAAK,CAAA,CAAE,OAAA,EAAS,CAAA;AAC5E;AAGA,SAAS,SAAA,CAAU,IAAA,EAAoB,SAAA,EAAwC;AAC7E,EAAA,OAAA,CAAQ,IAAA,EAAM;AAAA,IACZ,KAAK,OAAA;AACH,MAAA,OAAO,UAAA,IAAc,OAAA;AAAA,IACvB,KAAK,OAAA;AACH,MAAA,OAAO,UAAA,IAAc,QAAA,GAAW,UAAA,IAAc,OAAA;AAAA,IAChD,KAAK,OAAA;AACH,MAAA,OAAO,UAAA,IAAc,OAAA;AAAA,IACvB,OAAA;AACE,MAAA,OAAO,IAAA;AAAA,EACX;AACF;AAWO,IAAM,eAAA,EAAiB,KAAA,CAC3B,WAAA,CAAY;AAAA,EACX,EAAA,EAAI,KAAA,CAAE,MAAA,CAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA;AAAA,EACpB,IAAA,EAAM,KAAA,CAAE,IAAA,CAAK,CAAC,MAAA,EAAQ,OAAA,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A,EAAS,IAAA,EAAM,IAAA,EAAM,MAAA,CAAO,KAA2B,CAAA;AAAA,EAClE;AAEA,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,KAAA;AAAA,IACT,MAAA,EAAQ,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAA,GAAA,CAAW;AAAA,MAC1C,IAAA,EAAM,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA;AAAA,MAC3B,OAAA,EAAS,KAAA,CAAM,OAAA;AAAA,MACf,IAAA,EAAM,KAAA,CAAM;AAAA,IACd,CAAA,CAAE;AAAA,EACJ,CAAA;AACF;AHgGA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,ymBAAC","file":"/home/runner/work/learning-kit/learning-kit/packages/lk-core/dist/chunk-FCM5VJBS.cjs","sourcesContent":[null,"import { z } from 'zod/v4';\nimport { getActivityTypeDescriptor } from '../registry/index.js';\nimport type { ActivityData, ValidationError, ValidationResult } from '../types/activity.js';\nimport type { ItemGroup, StimulusKind } from '../types/item-group.js';\nimport { MediaSchema } from './media.js';\n\nfunction hasBody(stimulus: { body?: string | undefined }): boolean {\n return typeof stimulus.body === 'string' && stimulus.body.trim().length > 0;\n}\n\n/** Which media types can carry a stimulus of each kind. `text`/`mixed` accept any. */\nfunction mediaFits(kind: StimulusKind, mediaType: string | undefined): boolean {\n switch (kind) {\n case 'audio':\n return mediaType === 'audio';\n case 'video':\n return mediaType === 'video' || mediaType === 'embed';\n case 'image':\n return mediaType === 'image';\n default:\n return true;\n }\n}\n\n/**\n * Zod schema for a {@link Stimulus}. Loose: unknown keys preserved.\n *\n * The semantic guards exist because a stimulus that does not carry what its\n * `kind` promises is an authoring error that must not reach an exam: an\n * \"audio\" stimulus with no recording renders as a blank panel above six\n * listening questions. Unrepresentable in JSON Schema; dropped from\n * `stimulusJsonSchema` by design.\n */\nexport const StimulusSchema = z\n .looseObject({\n id: z.string().min(1),\n kind: z.enum(['text', 'audio', 'video', 'image', 'mixed']),\n title: z.string().optional(),\n body: z.string().optional(),\n bodyHtml: z.string().optional(),\n media: MediaSchema.optional(),\n transcript: z.string().optional(),\n locale: z.string().optional(),\n attribution: z.string().optional(),\n })\n .refine((stimulus) => stimulus.bodyHtml === undefined || hasBody(stimulus), {\n error:\n 'bodyHtml requires a plain-text body: it is the accessible fallback rendered when no sanitiser is supplied.',\n path: ['body'],\n })\n .refine(\n (stimulus) => (stimulus.kind !== 'text' && stimulus.kind !== 'mixed') || hasBody(stimulus),\n {\n error: 'A text or mixed stimulus needs a non-empty body.',\n path: ['body'],\n },\n )\n .refine((stimulus) => stimulus.kind === 'text' || stimulus.media !== undefined, {\n error: 'An audio, video, image or mixed stimulus needs media.',\n path: ['media'],\n })\n .refine(\n (stimulus) => stimulus.media === undefined || mediaFits(stimulus.kind, stimulus.media.type),\n {\n error:\n 'media.type does not fit the stimulus kind: audio needs audio; video needs video or embed; image needs image.',\n path: ['media', 'type'],\n },\n );\n\n/**\n * The structural minimum of an item as seen by the CONTAINER schema. Each\n * item's own contract is checked against its registered schema by\n * {@link validateItemGroup} — a zod schema cannot dispatch on a registry\n * that consumers extend at runtime.\n */\nconst ItemShapeSchema = z.looseObject({\n type: z.string().min(1),\n id: z.string().min(1),\n});\n\n/**\n * Zod schema for an {@link ItemGroup} CONTAINER. Loose: unknown keys\n * preserved. Validates the group's own fields and the stimulus in full, and\n * each item only structurally (`type` and `id`); use {@link validateItemGroup}\n * to validate the items against their registered schemas as well.\n */\nexport const ItemGroupSchema = z\n .looseObject({\n schemaVersion: z.literal('1.0'),\n type: z.literal('item-group'),\n id: z.string().min(1),\n title: z.string().optional(),\n stimulus: StimulusSchema,\n items: z.array(ItemShapeSchema).min(1),\n shuffle: z.enum(['none', 'within-group']).optional(),\n })\n .refine((group) => group.items.every((item) => item.type !== 'item-group'), {\n error: 'Item groups do not nest: every item must be an activity.',\n path: ['items'],\n })\n .refine((group) => new Set(group.items.map((item) => item.id)).size === group.items.length, {\n error: 'Item ids must be unique within a group.',\n path: ['items'],\n });\n\n/** Strict learner-safe stimulus: everything but the author-only `transcript`. */\nexport const RedactedStimulusSchema = z.strictObject({\n id: z.string().min(1),\n kind: z.enum(['text', 'audio', 'video', 'image', 'mixed']),\n title: z.string().optional(),\n body: z.string().optional(),\n bodyHtml: z.string().optional(),\n media: MediaSchema.optional(),\n locale: z.string().optional(),\n attribution: z.string().optional(),\n});\n\n/**\n * Strict learner-safe item group. Items are left opaque here — each is proven\n * learner-safe by `assertRedacted` against its OWN type's redacted schema,\n * which is the only place that knowledge lives.\n */\nexport const RedactedItemGroupSchema = z.strictObject({\n redacted: z.literal(true),\n schemaVersion: z.literal('1.0'),\n type: z.literal('item-group'),\n id: z.string().min(1),\n title: z.string().optional(),\n stimulus: RedactedStimulusSchema,\n items: z.array(z.unknown()).min(1),\n shuffle: z.enum(['none', 'within-group']).optional(),\n});\n\nfunction toValidationErrors(\n issues: readonly { path: PropertyKey[]; message: string; code: string }[],\n prefix: string[],\n): ValidationError[] {\n return issues.map((issue) => ({\n path: [...prefix, ...issue.path.map(String)],\n message: issue.message,\n code: issue.code,\n }));\n}\n\n/**\n * Validates an item group in full: the container and stimulus against\n * {@link ItemGroupSchema}, then every item against the schema registered for\n * its `type`. Errors from items are reported at `items.<index>.…`.\n *\n * Unlike `validateActivity`, an item whose type is not registered is REPORTED\n * (code `unknown_activity_type`) rather than thrown: a group is validated as\n * a whole, and an author fixing a six-item group wants every problem listed,\n * not the first one that happened to throw.\n */\nexport function validateItemGroup(data: unknown): ValidationResult<ItemGroup> {\n const container = ItemGroupSchema.safeParse(data);\n if (!container.success) {\n return { success: false, errors: toValidationErrors(container.error.issues, []) };\n }\n\n const errors: ValidationError[] = [];\n const items: ActivityData[] = [];\n container.data.items.forEach((item, index) => {\n const descriptor = getActivityTypeDescriptor(item.type);\n if (descriptor === undefined) {\n errors.push({\n path: ['items', String(index), 'type'],\n message: `Activity type \"${item.type}\" is not registered`,\n code: 'unknown_activity_type',\n });\n return;\n }\n const parsed = descriptor.schema.safeParse(item);\n if (!parsed.success) {\n errors.push(...toValidationErrors(parsed.error.issues, ['items', String(index)]));\n return;\n }\n items.push(parsed.data as ActivityData);\n });\n\n if (errors.length > 0) {\n return { success: false, errors };\n }\n // zod4 optional outputs are `T | undefined`; the wire type uses exact\n // optionals. Structurally identical at runtime — the cast is type-level.\n return { success: true, data: { ...container.data, items } as unknown as ItemGroup };\n}\n","import { z } from 'zod/v4';\nimport { UnknownActivityTypeError } from '../errors.js';\nimport { getActivityTypeDescriptor } from '../registry/index.js';\nimport { FillInTheBlanksDataSchema } from './fill-in-the-blanks.js';\nimport { ItemGroupSchema, StimulusSchema } from './item-group.js';\nimport { MultipleChoiceDataSchema } from './multiple-choice.js';\nimport { WrittenResponseDataSchema } from './written-response.js';\n\n/**\n * JSON Schema (Draft 7) for a `Stimulus`. Structural contract only — the\n * kind/media/body consistency guards are Zod-only.\n */\nexport const stimulusJsonSchema = z.toJSONSchema(StimulusSchema, { target: 'draft-7' });\n\n/**\n * JSON Schema (Draft 7) for an `ItemGroup` CONTAINER. Items appear as objects\n * with `type` and `id` only; each item's own contract is `jsonSchemaFor(type)`.\n * For an AI generation pipeline, ask for the group and each item separately\n * rather than a single nested schema — that keeps the per-type schema the\n * registry's, not a copy.\n */\nexport const itemGroupJsonSchema = z.toJSONSchema(ItemGroupSchema, { target: 'draft-7' });\n\n/**\n * JSON Schema (Draft 7) representation of the Multiple Choice activity data\n * contract, generated natively by Zod 4. Draft 7 is mandated by Requirement\n * 2.2 for the widest AI-prompt / OpenAPI tooling compatibility. The semantic\n * `.refine()` guards are not representable in JSON Schema and are\n * intentionally omitted — the export captures the *structural* contract only.\n * Since v0.3 the source schemas are loose, so these no longer emit\n * `additionalProperties: false` — the JSON Schema and `validateActivity` now\n * agree on unknown-key handling.\n */\nexport const multipleChoiceJsonSchema = z.toJSONSchema(MultipleChoiceDataSchema, {\n target: 'draft-7',\n});\n\n/**\n * JSON Schema (Draft 7) representation of the Fill-in-the-Blanks activity data\n * contract, generated natively by Zod 4. Structural contract only (semantic\n * `.refine()` guards are Zod-only and not representable in JSON Schema).\n */\nexport const fillInTheBlanksJsonSchema = z.toJSONSchema(FillInTheBlanksDataSchema, {\n target: 'draft-7',\n});\n\n/**\n * JSON Schema (Draft 7) representation of the Written Response activity data\n * contract. Structural contract only.\n */\nexport const writtenResponseJsonSchema = z.toJSONSchema(WrittenResponseDataSchema, {\n target: 'draft-7',\n});\n\n/**\n * Derives the JSON Schema (Draft 7) for any REGISTERED activity type — the\n * live, registry-backed replacement for the static per-type exports above,\n * and the building block for AI generation pipelines (R6.1): pass the result\n * as a structured-output schema so a model can only emit valid items.\n *\n * @throws UnknownActivityTypeError when `type` has no registered descriptor.\n */\nexport function jsonSchemaFor(type: string): Record<string, unknown> {\n const descriptor = getActivityTypeDescriptor(type);\n if (descriptor === undefined) {\n throw new UnknownActivityTypeError(type);\n }\n return z.toJSONSchema(descriptor.schema as never, { target: 'draft-7' }) as Record<\n string,\n unknown\n >;\n}\n","import { UnknownActivityTypeError } from '../errors.js';\nimport { getActivityTypeDescriptor } from '../registry/index.js';\nimport type { ActivityDataMap, ActivityType, ValidationResult } from '../types/activity.js';\n\nexport { FeedbackSchema } from './feedback.js';\nexport {\n BlankConfigSchema,\n FillInTheBlanksDataSchema,\n TextMatchPolicySchema,\n} from './fill-in-the-blanks.js';\nexport {\n ItemGroupSchema,\n RedactedItemGroupSchema,\n RedactedStimulusSchema,\n StimulusSchema,\n validateItemGroup,\n} from './item-group.js';\nexport {\n fillInTheBlanksJsonSchema,\n itemGroupJsonSchema,\n jsonSchemaFor,\n multipleChoiceJsonSchema,\n stimulusJsonSchema,\n writtenResponseJsonSchema,\n} from './json-schema.js';\nexport { MediaSchema, MediaUrlSchema } from './media.js';\nexport { MultipleChoiceDataSchema, MultipleChoiceOptionSchema } from './multiple-choice.js';\nexport {\n RedactedBlankConfigSchema,\n RedactedFillInTheBlanksDataSchema,\n RedactedMultipleChoiceDataSchema,\n RedactedMultipleChoiceOptionSchema,\n RedactedWrittenResponseDataSchema,\n} from './redacted.js';\nexport {\n WrittenResponseDataSchema,\n WrittenResponseRubricCriterionSchema,\n WrittenResponseRubricSchema,\n} from './written-response.js';\n\n/**\n * Validates raw activity data against the schema registered for the given\n * activity type (built-in or consumer-registered via `registerActivityType`).\n *\n * Unknown keys are PRESERVED, not stripped: every built-in schema is loose,\n * so consumer sidecar fields and forward-version fields survive validation\n * verbatim in the returned `data`.\n *\n * @returns `{ success: true, data }` with the typed, validated data, or\n * `{ success: false, errors }` with one entry per failed constraint.\n * @throws UnknownActivityTypeError when `type` has no registered descriptor.\n */\nexport function validateActivity<T extends ActivityType>(\n type: T,\n data: unknown,\n): ValidationResult<ActivityDataMap[T]> {\n const descriptor = getActivityTypeDescriptor(type);\n if (descriptor === undefined) {\n throw new UnknownActivityTypeError(String(type));\n }\n\n const result = descriptor.schema.safeParse(data);\n\n if (result.success) {\n return { success: true, data: result.data as ActivityDataMap[T] };\n }\n\n return {\n success: false,\n errors: result.error.issues.map((issue) => ({\n path: issue.path.map(String),\n message: issue.message,\n code: issue.code,\n })),\n };\n}\n"]}
@@ -0,0 +1,187 @@
1
+ import {
2
+ FillInTheBlanksDataSchema,
3
+ MediaSchema,
4
+ MultipleChoiceDataSchema,
5
+ UnknownActivityTypeError,
6
+ WrittenResponseDataSchema,
7
+ getActivityTypeDescriptor
8
+ } from "./chunk-NUCEUU4P.js";
9
+
10
+ // src/schemas/item-group.ts
11
+ import { z } from "zod/v4";
12
+ function hasBody(stimulus) {
13
+ return typeof stimulus.body === "string" && stimulus.body.trim().length > 0;
14
+ }
15
+ function mediaFits(kind, mediaType) {
16
+ switch (kind) {
17
+ case "audio":
18
+ return mediaType === "audio";
19
+ case "video":
20
+ return mediaType === "video" || mediaType === "embed";
21
+ case "image":
22
+ return mediaType === "image";
23
+ default:
24
+ return true;
25
+ }
26
+ }
27
+ var StimulusSchema = z.looseObject({
28
+ id: z.string().min(1),
29
+ kind: z.enum(["text", "audio", "video", "image", "mixed"]),
30
+ title: z.string().optional(),
31
+ body: z.string().optional(),
32
+ bodyHtml: z.string().optional(),
33
+ media: MediaSchema.optional(),
34
+ transcript: z.string().optional(),
35
+ locale: z.string().optional(),
36
+ attribution: z.string().optional()
37
+ }).refine((stimulus) => stimulus.bodyHtml === void 0 || hasBody(stimulus), {
38
+ error: "bodyHtml requires a plain-text body: it is the accessible fallback rendered when no sanitiser is supplied.",
39
+ path: ["body"]
40
+ }).refine(
41
+ (stimulus) => stimulus.kind !== "text" && stimulus.kind !== "mixed" || hasBody(stimulus),
42
+ {
43
+ error: "A text or mixed stimulus needs a non-empty body.",
44
+ path: ["body"]
45
+ }
46
+ ).refine((stimulus) => stimulus.kind === "text" || stimulus.media !== void 0, {
47
+ error: "An audio, video, image or mixed stimulus needs media.",
48
+ path: ["media"]
49
+ }).refine(
50
+ (stimulus) => stimulus.media === void 0 || mediaFits(stimulus.kind, stimulus.media.type),
51
+ {
52
+ error: "media.type does not fit the stimulus kind: audio needs audio; video needs video or embed; image needs image.",
53
+ path: ["media", "type"]
54
+ }
55
+ );
56
+ var ItemShapeSchema = z.looseObject({
57
+ type: z.string().min(1),
58
+ id: z.string().min(1)
59
+ });
60
+ var ItemGroupSchema = z.looseObject({
61
+ schemaVersion: z.literal("1.0"),
62
+ type: z.literal("item-group"),
63
+ id: z.string().min(1),
64
+ title: z.string().optional(),
65
+ stimulus: StimulusSchema,
66
+ items: z.array(ItemShapeSchema).min(1),
67
+ shuffle: z.enum(["none", "within-group"]).optional()
68
+ }).refine((group) => group.items.every((item) => item.type !== "item-group"), {
69
+ error: "Item groups do not nest: every item must be an activity.",
70
+ path: ["items"]
71
+ }).refine((group) => new Set(group.items.map((item) => item.id)).size === group.items.length, {
72
+ error: "Item ids must be unique within a group.",
73
+ path: ["items"]
74
+ });
75
+ var RedactedStimulusSchema = z.strictObject({
76
+ id: z.string().min(1),
77
+ kind: z.enum(["text", "audio", "video", "image", "mixed"]),
78
+ title: z.string().optional(),
79
+ body: z.string().optional(),
80
+ bodyHtml: z.string().optional(),
81
+ media: MediaSchema.optional(),
82
+ locale: z.string().optional(),
83
+ attribution: z.string().optional()
84
+ });
85
+ var RedactedItemGroupSchema = z.strictObject({
86
+ redacted: z.literal(true),
87
+ schemaVersion: z.literal("1.0"),
88
+ type: z.literal("item-group"),
89
+ id: z.string().min(1),
90
+ title: z.string().optional(),
91
+ stimulus: RedactedStimulusSchema,
92
+ items: z.array(z.unknown()).min(1),
93
+ shuffle: z.enum(["none", "within-group"]).optional()
94
+ });
95
+ function toValidationErrors(issues, prefix) {
96
+ return issues.map((issue) => ({
97
+ path: [...prefix, ...issue.path.map(String)],
98
+ message: issue.message,
99
+ code: issue.code
100
+ }));
101
+ }
102
+ function validateItemGroup(data) {
103
+ const container = ItemGroupSchema.safeParse(data);
104
+ if (!container.success) {
105
+ return { success: false, errors: toValidationErrors(container.error.issues, []) };
106
+ }
107
+ const errors = [];
108
+ const items = [];
109
+ container.data.items.forEach((item, index) => {
110
+ const descriptor = getActivityTypeDescriptor(item.type);
111
+ if (descriptor === void 0) {
112
+ errors.push({
113
+ path: ["items", String(index), "type"],
114
+ message: `Activity type "${item.type}" is not registered`,
115
+ code: "unknown_activity_type"
116
+ });
117
+ return;
118
+ }
119
+ const parsed = descriptor.schema.safeParse(item);
120
+ if (!parsed.success) {
121
+ errors.push(...toValidationErrors(parsed.error.issues, ["items", String(index)]));
122
+ return;
123
+ }
124
+ items.push(parsed.data);
125
+ });
126
+ if (errors.length > 0) {
127
+ return { success: false, errors };
128
+ }
129
+ return { success: true, data: { ...container.data, items } };
130
+ }
131
+
132
+ // src/schemas/json-schema.ts
133
+ import { z as z2 } from "zod/v4";
134
+ var stimulusJsonSchema = z2.toJSONSchema(StimulusSchema, { target: "draft-7" });
135
+ var itemGroupJsonSchema = z2.toJSONSchema(ItemGroupSchema, { target: "draft-7" });
136
+ var multipleChoiceJsonSchema = z2.toJSONSchema(MultipleChoiceDataSchema, {
137
+ target: "draft-7"
138
+ });
139
+ var fillInTheBlanksJsonSchema = z2.toJSONSchema(FillInTheBlanksDataSchema, {
140
+ target: "draft-7"
141
+ });
142
+ var writtenResponseJsonSchema = z2.toJSONSchema(WrittenResponseDataSchema, {
143
+ target: "draft-7"
144
+ });
145
+ function jsonSchemaFor(type) {
146
+ const descriptor = getActivityTypeDescriptor(type);
147
+ if (descriptor === void 0) {
148
+ throw new UnknownActivityTypeError(type);
149
+ }
150
+ return z2.toJSONSchema(descriptor.schema, { target: "draft-7" });
151
+ }
152
+
153
+ // src/schemas/index.ts
154
+ function validateActivity(type, data) {
155
+ const descriptor = getActivityTypeDescriptor(type);
156
+ if (descriptor === void 0) {
157
+ throw new UnknownActivityTypeError(String(type));
158
+ }
159
+ const result = descriptor.schema.safeParse(data);
160
+ if (result.success) {
161
+ return { success: true, data: result.data };
162
+ }
163
+ return {
164
+ success: false,
165
+ errors: result.error.issues.map((issue) => ({
166
+ path: issue.path.map(String),
167
+ message: issue.message,
168
+ code: issue.code
169
+ }))
170
+ };
171
+ }
172
+
173
+ export {
174
+ StimulusSchema,
175
+ ItemGroupSchema,
176
+ RedactedStimulusSchema,
177
+ RedactedItemGroupSchema,
178
+ validateItemGroup,
179
+ stimulusJsonSchema,
180
+ itemGroupJsonSchema,
181
+ multipleChoiceJsonSchema,
182
+ fillInTheBlanksJsonSchema,
183
+ writtenResponseJsonSchema,
184
+ jsonSchemaFor,
185
+ validateActivity
186
+ };
187
+ //# sourceMappingURL=chunk-LSHDNA2T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schemas/item-group.ts","../src/schemas/json-schema.ts","../src/schemas/index.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport { getActivityTypeDescriptor } from '../registry/index.js';\nimport type { ActivityData, ValidationError, ValidationResult } from '../types/activity.js';\nimport type { ItemGroup, StimulusKind } from '../types/item-group.js';\nimport { MediaSchema } from './media.js';\n\nfunction hasBody(stimulus: { body?: string | undefined }): boolean {\n return typeof stimulus.body === 'string' && stimulus.body.trim().length > 0;\n}\n\n/** Which media types can carry a stimulus of each kind. `text`/`mixed` accept any. */\nfunction mediaFits(kind: StimulusKind, mediaType: string | undefined): boolean {\n switch (kind) {\n case 'audio':\n return mediaType === 'audio';\n case 'video':\n return mediaType === 'video' || mediaType === 'embed';\n case 'image':\n return mediaType === 'image';\n default:\n return true;\n }\n}\n\n/**\n * Zod schema for a {@link Stimulus}. Loose: unknown keys preserved.\n *\n * The semantic guards exist because a stimulus that does not carry what its\n * `kind` promises is an authoring error that must not reach an exam: an\n * \"audio\" stimulus with no recording renders as a blank panel above six\n * listening questions. Unrepresentable in JSON Schema; dropped from\n * `stimulusJsonSchema` by design.\n */\nexport const StimulusSchema = z\n .looseObject({\n id: z.string().min(1),\n kind: z.enum(['text', 'audio', 'video', 'image', 'mixed']),\n title: z.string().optional(),\n body: z.string().optional(),\n bodyHtml: z.string().optional(),\n media: MediaSchema.optional(),\n transcript: z.string().optional(),\n locale: z.string().optional(),\n attribution: z.string().optional(),\n })\n .refine((stimulus) => stimulus.bodyHtml === undefined || hasBody(stimulus), {\n error:\n 'bodyHtml requires a plain-text body: it is the accessible fallback rendered when no sanitiser is supplied.',\n path: ['body'],\n })\n .refine(\n (stimulus) => (stimulus.kind !== 'text' && stimulus.kind !== 'mixed') || hasBody(stimulus),\n {\n error: 'A text or mixed stimulus needs a non-empty body.',\n path: ['body'],\n },\n )\n .refine((stimulus) => stimulus.kind === 'text' || stimulus.media !== undefined, {\n error: 'An audio, video, image or mixed stimulus needs media.',\n path: ['media'],\n })\n .refine(\n (stimulus) => stimulus.media === undefined || mediaFits(stimulus.kind, stimulus.media.type),\n {\n error:\n 'media.type does not fit the stimulus kind: audio needs audio; video needs video or embed; image needs image.',\n path: ['media', 'type'],\n },\n );\n\n/**\n * The structural minimum of an item as seen by the CONTAINER schema. Each\n * item's own contract is checked against its registered schema by\n * {@link validateItemGroup} — a zod schema cannot dispatch on a registry\n * that consumers extend at runtime.\n */\nconst ItemShapeSchema = z.looseObject({\n type: z.string().min(1),\n id: z.string().min(1),\n});\n\n/**\n * Zod schema for an {@link ItemGroup} CONTAINER. Loose: unknown keys\n * preserved. Validates the group's own fields and the stimulus in full, and\n * each item only structurally (`type` and `id`); use {@link validateItemGroup}\n * to validate the items against their registered schemas as well.\n */\nexport const ItemGroupSchema = z\n .looseObject({\n schemaVersion: z.literal('1.0'),\n type: z.literal('item-group'),\n id: z.string().min(1),\n title: z.string().optional(),\n stimulus: StimulusSchema,\n items: z.array(ItemShapeSchema).min(1),\n shuffle: z.enum(['none', 'within-group']).optional(),\n })\n .refine((group) => group.items.every((item) => item.type !== 'item-group'), {\n error: 'Item groups do not nest: every item must be an activity.',\n path: ['items'],\n })\n .refine((group) => new Set(group.items.map((item) => item.id)).size === group.items.length, {\n error: 'Item ids must be unique within a group.',\n path: ['items'],\n });\n\n/** Strict learner-safe stimulus: everything but the author-only `transcript`. */\nexport const RedactedStimulusSchema = z.strictObject({\n id: z.string().min(1),\n kind: z.enum(['text', 'audio', 'video', 'image', 'mixed']),\n title: z.string().optional(),\n body: z.string().optional(),\n bodyHtml: z.string().optional(),\n media: MediaSchema.optional(),\n locale: z.string().optional(),\n attribution: z.string().optional(),\n});\n\n/**\n * Strict learner-safe item group. Items are left opaque here — each is proven\n * learner-safe by `assertRedacted` against its OWN type's redacted schema,\n * which is the only place that knowledge lives.\n */\nexport const RedactedItemGroupSchema = z.strictObject({\n redacted: z.literal(true),\n schemaVersion: z.literal('1.0'),\n type: z.literal('item-group'),\n id: z.string().min(1),\n title: z.string().optional(),\n stimulus: RedactedStimulusSchema,\n items: z.array(z.unknown()).min(1),\n shuffle: z.enum(['none', 'within-group']).optional(),\n});\n\nfunction toValidationErrors(\n issues: readonly { path: PropertyKey[]; message: string; code: string }[],\n prefix: string[],\n): ValidationError[] {\n return issues.map((issue) => ({\n path: [...prefix, ...issue.path.map(String)],\n message: issue.message,\n code: issue.code,\n }));\n}\n\n/**\n * Validates an item group in full: the container and stimulus against\n * {@link ItemGroupSchema}, then every item against the schema registered for\n * its `type`. Errors from items are reported at `items.<index>.…`.\n *\n * Unlike `validateActivity`, an item whose type is not registered is REPORTED\n * (code `unknown_activity_type`) rather than thrown: a group is validated as\n * a whole, and an author fixing a six-item group wants every problem listed,\n * not the first one that happened to throw.\n */\nexport function validateItemGroup(data: unknown): ValidationResult<ItemGroup> {\n const container = ItemGroupSchema.safeParse(data);\n if (!container.success) {\n return { success: false, errors: toValidationErrors(container.error.issues, []) };\n }\n\n const errors: ValidationError[] = [];\n const items: ActivityData[] = [];\n container.data.items.forEach((item, index) => {\n const descriptor = getActivityTypeDescriptor(item.type);\n if (descriptor === undefined) {\n errors.push({\n path: ['items', String(index), 'type'],\n message: `Activity type \"${item.type}\" is not registered`,\n code: 'unknown_activity_type',\n });\n return;\n }\n const parsed = descriptor.schema.safeParse(item);\n if (!parsed.success) {\n errors.push(...toValidationErrors(parsed.error.issues, ['items', String(index)]));\n return;\n }\n items.push(parsed.data as ActivityData);\n });\n\n if (errors.length > 0) {\n return { success: false, errors };\n }\n // zod4 optional outputs are `T | undefined`; the wire type uses exact\n // optionals. Structurally identical at runtime — the cast is type-level.\n return { success: true, data: { ...container.data, items } as unknown as ItemGroup };\n}\n","import { z } from 'zod/v4';\nimport { UnknownActivityTypeError } from '../errors.js';\nimport { getActivityTypeDescriptor } from '../registry/index.js';\nimport { FillInTheBlanksDataSchema } from './fill-in-the-blanks.js';\nimport { ItemGroupSchema, StimulusSchema } from './item-group.js';\nimport { MultipleChoiceDataSchema } from './multiple-choice.js';\nimport { WrittenResponseDataSchema } from './written-response.js';\n\n/**\n * JSON Schema (Draft 7) for a `Stimulus`. Structural contract only — the\n * kind/media/body consistency guards are Zod-only.\n */\nexport const stimulusJsonSchema = z.toJSONSchema(StimulusSchema, { target: 'draft-7' });\n\n/**\n * JSON Schema (Draft 7) for an `ItemGroup` CONTAINER. Items appear as objects\n * with `type` and `id` only; each item's own contract is `jsonSchemaFor(type)`.\n * For an AI generation pipeline, ask for the group and each item separately\n * rather than a single nested schema — that keeps the per-type schema the\n * registry's, not a copy.\n */\nexport const itemGroupJsonSchema = z.toJSONSchema(ItemGroupSchema, { target: 'draft-7' });\n\n/**\n * JSON Schema (Draft 7) representation of the Multiple Choice activity data\n * contract, generated natively by Zod 4. Draft 7 is mandated by Requirement\n * 2.2 for the widest AI-prompt / OpenAPI tooling compatibility. The semantic\n * `.refine()` guards are not representable in JSON Schema and are\n * intentionally omitted — the export captures the *structural* contract only.\n * Since v0.3 the source schemas are loose, so these no longer emit\n * `additionalProperties: false` — the JSON Schema and `validateActivity` now\n * agree on unknown-key handling.\n */\nexport const multipleChoiceJsonSchema = z.toJSONSchema(MultipleChoiceDataSchema, {\n target: 'draft-7',\n});\n\n/**\n * JSON Schema (Draft 7) representation of the Fill-in-the-Blanks activity data\n * contract, generated natively by Zod 4. Structural contract only (semantic\n * `.refine()` guards are Zod-only and not representable in JSON Schema).\n */\nexport const fillInTheBlanksJsonSchema = z.toJSONSchema(FillInTheBlanksDataSchema, {\n target: 'draft-7',\n});\n\n/**\n * JSON Schema (Draft 7) representation of the Written Response activity data\n * contract. Structural contract only.\n */\nexport const writtenResponseJsonSchema = z.toJSONSchema(WrittenResponseDataSchema, {\n target: 'draft-7',\n});\n\n/**\n * Derives the JSON Schema (Draft 7) for any REGISTERED activity type — the\n * live, registry-backed replacement for the static per-type exports above,\n * and the building block for AI generation pipelines (R6.1): pass the result\n * as a structured-output schema so a model can only emit valid items.\n *\n * @throws UnknownActivityTypeError when `type` has no registered descriptor.\n */\nexport function jsonSchemaFor(type: string): Record<string, unknown> {\n const descriptor = getActivityTypeDescriptor(type);\n if (descriptor === undefined) {\n throw new UnknownActivityTypeError(type);\n }\n return z.toJSONSchema(descriptor.schema as never, { target: 'draft-7' }) as Record<\n string,\n unknown\n >;\n}\n","import { UnknownActivityTypeError } from '../errors.js';\nimport { getActivityTypeDescriptor } from '../registry/index.js';\nimport type { ActivityDataMap, ActivityType, ValidationResult } from '../types/activity.js';\n\nexport { FeedbackSchema } from './feedback.js';\nexport {\n BlankConfigSchema,\n FillInTheBlanksDataSchema,\n TextMatchPolicySchema,\n} from './fill-in-the-blanks.js';\nexport {\n ItemGroupSchema,\n RedactedItemGroupSchema,\n RedactedStimulusSchema,\n StimulusSchema,\n validateItemGroup,\n} from './item-group.js';\nexport {\n fillInTheBlanksJsonSchema,\n itemGroupJsonSchema,\n jsonSchemaFor,\n multipleChoiceJsonSchema,\n stimulusJsonSchema,\n writtenResponseJsonSchema,\n} from './json-schema.js';\nexport { MediaSchema, MediaUrlSchema } from './media.js';\nexport { MultipleChoiceDataSchema, MultipleChoiceOptionSchema } from './multiple-choice.js';\nexport {\n RedactedBlankConfigSchema,\n RedactedFillInTheBlanksDataSchema,\n RedactedMultipleChoiceDataSchema,\n RedactedMultipleChoiceOptionSchema,\n RedactedWrittenResponseDataSchema,\n} from './redacted.js';\nexport {\n WrittenResponseDataSchema,\n WrittenResponseRubricCriterionSchema,\n WrittenResponseRubricSchema,\n} from './written-response.js';\n\n/**\n * Validates raw activity data against the schema registered for the given\n * activity type (built-in or consumer-registered via `registerActivityType`).\n *\n * Unknown keys are PRESERVED, not stripped: every built-in schema is loose,\n * so consumer sidecar fields and forward-version fields survive validation\n * verbatim in the returned `data`.\n *\n * @returns `{ success: true, data }` with the typed, validated data, or\n * `{ success: false, errors }` with one entry per failed constraint.\n * @throws UnknownActivityTypeError when `type` has no registered descriptor.\n */\nexport function validateActivity<T extends ActivityType>(\n type: T,\n data: unknown,\n): ValidationResult<ActivityDataMap[T]> {\n const descriptor = getActivityTypeDescriptor(type);\n if (descriptor === undefined) {\n throw new UnknownActivityTypeError(String(type));\n }\n\n const result = descriptor.schema.safeParse(data);\n\n if (result.success) {\n return { success: true, data: result.data as ActivityDataMap[T] };\n }\n\n return {\n success: false,\n errors: result.error.issues.map((issue) => ({\n path: issue.path.map(String),\n message: issue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AAE,SAAS,MAAM,MAAM,OAAO,KAA2B;AAAA,EAClE;AAEA,SAAO;AAAA,IACL,SAAS;AAAA,IACT,QAAQ,OAAO,MAAM,OAAO,IAAI,CAAC,WAAW;AAAA,MAC1C,MAAM,MAAM,KAAK,IAAI,MAAM;AAAA,MAC3B,SAAS,MAAM;AAAA,MACf,MAAM,MAAM;AAAA,IACd,EAAE;AAAA,EACJ;AACF;","names":["z","z"]}
@@ -10,6 +10,46 @@ function countWords(text) {
10
10
  return trimmed.split(/\s+/).length;
11
11
  }
12
12
 
13
+ // src/errors.ts
14
+ var ActivitySchemaError = class extends Error {
15
+ constructor(activityType, errors) {
16
+ super(`Invalid activity data for type "${activityType}"`);
17
+ this.activityType = activityType;
18
+ this.errors = errors;
19
+ this.name = "ActivitySchemaError";
20
+ }
21
+ activityType;
22
+ errors;
23
+ };
24
+ var UnknownActivityTypeError = class extends Error {
25
+ constructor(activityType) {
26
+ super(`Activity type "${activityType}" is not registered`);
27
+ this.activityType = activityType;
28
+ this.name = "UnknownActivityTypeError";
29
+ }
30
+ activityType;
31
+ };
32
+ var RedactedScoringError = class extends Error {
33
+ constructor(activityType) {
34
+ super(
35
+ `Activity data for "${activityType}" carries no answer key (it looks redacted), so it cannot be scored. Score against the full activity data server-side, or use evaluate() which returns { status: "unscorable" }.`
36
+ );
37
+ this.activityType = activityType;
38
+ this.name = "RedactedScoringError";
39
+ }
40
+ activityType;
41
+ };
42
+ var DeferredScoringError = class extends Error {
43
+ constructor(activityType) {
44
+ super(
45
+ `Activity type "${activityType}" is graded asynchronously and has no synchronous score. Use evaluate() \u2014 it returns { status: 'deferred' } for this type.`
46
+ );
47
+ this.activityType = activityType;
48
+ this.name = "DeferredScoringError";
49
+ }
50
+ activityType;
51
+ };
52
+
13
53
  // src/schemas/feedback.ts
14
54
  import { z } from "zod/v4";
15
55
  var FeedbackSchema = z.looseObject({
@@ -316,6 +356,11 @@ function defineActivityType(descriptor) {
316
356
  return descriptor;
317
357
  }
318
358
  function registerActivityType(descriptor) {
359
+ if (descriptor.type === "item-group") {
360
+ throw new Error(
361
+ `"item-group" is reserved for the SDK's item-group container (see ItemGroup) and cannot be registered as an activity type.`
362
+ );
363
+ }
319
364
  const existing = registry.get(descriptor.type);
320
365
  if (existing !== void 0) {
321
366
  if (existing === descriptor) {
@@ -547,6 +592,10 @@ registerActivityType(writtenResponseType);
547
592
 
548
593
  export {
549
594
  countWords,
595
+ ActivitySchemaError,
596
+ UnknownActivityTypeError,
597
+ RedactedScoringError,
598
+ DeferredScoringError,
550
599
  FeedbackSchema,
551
600
  MediaUrlSchema,
552
601
  MediaSchema,
@@ -573,4 +622,4 @@ export {
573
622
  fillInTheBlanksType,
574
623
  writtenResponseType
575
624
  };
576
- //# sourceMappingURL=chunk-5GJJHGY5.js.map
625
+ //# sourceMappingURL=chunk-NUCEUU4P.js.map