@intellectif/lk-core 1.2.0 → 1.3.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 (103) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +2 -2
  3. package/dist/ai-B222dtHH.d.cts +2154 -0
  4. package/dist/ai-B222dtHH.d.cts.map +1 -0
  5. package/dist/ai-B222dtHH.d.ts +2154 -0
  6. package/dist/ai-B222dtHH.d.ts.map +1 -0
  7. package/dist/ai-check.cjs +749 -617
  8. package/dist/ai-check.cjs.map +1 -1
  9. package/dist/ai-check.d.cts +82 -80
  10. package/dist/ai-check.d.cts.map +1 -0
  11. package/dist/ai-check.d.ts +82 -80
  12. package/dist/ai-check.d.ts.map +1 -0
  13. package/dist/ai-check.js +747 -618
  14. package/dist/ai-check.js.map +1 -1
  15. package/dist/ai-writing-CCBjTOM3.js +2496 -0
  16. package/dist/ai-writing-CCBjTOM3.js.map +1 -0
  17. package/dist/ai-writing-DCVkv4Zj.cjs +2735 -0
  18. package/dist/ai-writing-DCVkv4Zj.cjs.map +1 -0
  19. package/dist/{index-BChYtrEe.d.ts → index-BWPRPIXL.d.ts} +263 -258
  20. package/dist/index-BWPRPIXL.d.ts.map +1 -0
  21. package/dist/index-CXyOV8sm.d.cts +153 -0
  22. package/dist/index-CXyOV8sm.d.cts.map +1 -0
  23. package/dist/index-CegM8o15.d.ts +153 -0
  24. package/dist/index-CegM8o15.d.ts.map +1 -0
  25. package/dist/index-Dyu66R4-.d.cts +1071 -0
  26. package/dist/index-Dyu66R4-.d.cts.map +1 -0
  27. package/dist/{index-VXt_v3YI.d.cts → index-O4_ExlAD.d.cts} +263 -258
  28. package/dist/index-O4_ExlAD.d.cts.map +1 -0
  29. package/dist/index-UGxRSopE.d.ts +1071 -0
  30. package/dist/index-UGxRSopE.d.ts.map +1 -0
  31. package/dist/index.cjs +1210 -1146
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +909 -857
  34. package/dist/index.d.cts.map +1 -0
  35. package/dist/index.d.ts +909 -857
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +1063 -1147
  38. package/dist/index.js.map +1 -1
  39. package/dist/item-group-DXiR8nOr.js +445 -0
  40. package/dist/item-group-DXiR8nOr.js.map +1 -0
  41. package/dist/item-group-DroFXgLb.cjs +505 -0
  42. package/dist/item-group-DroFXgLb.cjs.map +1 -0
  43. package/dist/registry-DVi0LR_i.cjs +5915 -0
  44. package/dist/registry-DVi0LR_i.cjs.map +1 -0
  45. package/dist/registry-Dsx9mNsS.js +5449 -0
  46. package/dist/registry-Dsx9mNsS.js.map +1 -0
  47. package/dist/schemas-Bdw0nGPo.js +152 -0
  48. package/dist/schemas-Bdw0nGPo.js.map +1 -0
  49. package/dist/schemas-DVbAOrtd.cjs +224 -0
  50. package/dist/schemas-DVbAOrtd.cjs.map +1 -0
  51. package/dist/schemas.cjs +16 -34
  52. package/dist/schemas.d.cts +2 -2
  53. package/dist/schemas.d.ts +2 -2
  54. package/dist/schemas.js +3 -34
  55. package/dist/scoring-B2_HEhMT.cjs +1748 -0
  56. package/dist/scoring-B2_HEhMT.cjs.map +1 -0
  57. package/dist/scoring-BZqUkuDF.js +1604 -0
  58. package/dist/scoring-BZqUkuDF.js.map +1 -0
  59. package/dist/scoring.cjs +37 -75
  60. package/dist/scoring.d.cts +3 -1103
  61. package/dist/scoring.d.ts +3 -1103
  62. package/dist/scoring.js +3 -75
  63. package/dist/xapi-CMTph7wG.js +332 -0
  64. package/dist/xapi-CMTph7wG.js.map +1 -0
  65. package/dist/xapi-DNzkSJ0S.cjs +362 -0
  66. package/dist/xapi-DNzkSJ0S.cjs.map +1 -0
  67. package/dist/xapi.cjs +7 -16
  68. package/dist/xapi.d.cts +2 -150
  69. package/dist/xapi.d.ts +2 -150
  70. package/dist/xapi.js +2 -16
  71. package/package.json +4 -4
  72. package/dist/activity-D705CXng.d.cts +0 -2162
  73. package/dist/activity-D705CXng.d.ts +0 -2162
  74. package/dist/chunk-46BXIGLG.cjs +0 -272
  75. package/dist/chunk-46BXIGLG.cjs.map +0 -1
  76. package/dist/chunk-4YANYTFN.cjs +0 -1256
  77. package/dist/chunk-4YANYTFN.cjs.map +0 -1
  78. package/dist/chunk-7KOWU4RO.js +0 -2207
  79. package/dist/chunk-7KOWU4RO.js.map +0 -1
  80. package/dist/chunk-7THXD7AN.cjs +0 -5057
  81. package/dist/chunk-7THXD7AN.cjs.map +0 -1
  82. package/dist/chunk-CYCTIXUN.cjs +0 -118
  83. package/dist/chunk-CYCTIXUN.cjs.map +0 -1
  84. package/dist/chunk-CYPA5BW5.js +0 -118
  85. package/dist/chunk-CYPA5BW5.js.map +0 -1
  86. package/dist/chunk-JTNDIBZO.js +0 -272
  87. package/dist/chunk-JTNDIBZO.js.map +0 -1
  88. package/dist/chunk-MV2N2WNS.js +0 -352
  89. package/dist/chunk-MV2N2WNS.js.map +0 -1
  90. package/dist/chunk-MXI26H62.cjs +0 -2207
  91. package/dist/chunk-MXI26H62.cjs.map +0 -1
  92. package/dist/chunk-QS7B42ZR.js +0 -5057
  93. package/dist/chunk-QS7B42ZR.js.map +0 -1
  94. package/dist/chunk-QX2ERL72.js +0 -1256
  95. package/dist/chunk-QX2ERL72.js.map +0 -1
  96. package/dist/chunk-ZWXQSKCX.cjs +0 -352
  97. package/dist/chunk-ZWXQSKCX.cjs.map +0 -1
  98. package/dist/schemas.cjs.map +0 -1
  99. package/dist/schemas.js.map +0 -1
  100. package/dist/scoring.cjs.map +0 -1
  101. package/dist/scoring.js.map +0 -1
  102. package/dist/xapi.cjs.map +0 -1
  103. package/dist/xapi.js.map +0 -1
package/dist/ai-check.cjs CHANGED
@@ -1,662 +1,794 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
- var _chunkMXI26H62cjs = require('./chunk-MXI26H62.cjs');
15
-
16
-
17
- var _chunk4YANYTFNcjs = require('./chunk-4YANYTFN.cjs');
18
- require('./chunk-ZWXQSKCX.cjs');
19
- require('./chunk-7THXD7AN.cjs');
20
-
21
- // src/ai-check/cases.ts
22
- var capital = {
23
- schemaVersion: "1.0",
24
- type: "multiple-choice",
25
- id: "ai-check-mc",
26
- title: "Capital cities",
27
- question: "What is the capital of Spain?",
28
- mode: "single",
29
- scoringStrategy: "all-or-nothing",
30
- options: [
31
- { id: "madrid", text: "Madrid", isCorrect: true },
32
- { id: "barcelona", text: "Barcelona", isCorrect: false },
33
- { id: "seville", text: "Seville", isCorrect: false }
34
- ]
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_ai_writing = require("./ai-writing-DCVkv4Zj.cjs");
3
+ const require_scoring = require("./scoring-B2_HEhMT.cjs");
4
+ //#region src/ai-check/cases.ts
5
+ /**
6
+ * The items the cases are built from. Small, ordinary language-course content
7
+ * — and deliberately awkward in the places a model slips:
8
+ *
9
+ * - an answer a hint can hardly avoid naming (`Madrid`);
10
+ * - an answer of one short word (`is`), which a hint may write as an ordinary
11
+ * word and must not write beside its neighbour in the passage;
12
+ * - an accented answer (`cañón`), so a hint that spells it without the accent
13
+ * is still caught;
14
+ * - a passage with more than one blank, so a hint can be about the wrong one;
15
+ * - a short essay whose mistakes a model must quote exactly as the learner
16
+ * wrote them — straight apostrophes a model likes to curl, a mistake made
17
+ * twice — so a correction of words nobody wrote is caught.
18
+ */
19
+ const capital = {
20
+ schemaVersion: "1.0",
21
+ type: "multiple-choice",
22
+ id: "ai-check-mc",
23
+ title: "Capital cities",
24
+ question: "What is the capital of Spain?",
25
+ mode: "single",
26
+ scoringStrategy: "all-or-nothing",
27
+ options: [
28
+ {
29
+ id: "madrid",
30
+ text: "Madrid",
31
+ isCorrect: true
32
+ },
33
+ {
34
+ id: "barcelona",
35
+ text: "Barcelona",
36
+ isCorrect: false
37
+ },
38
+ {
39
+ id: "seville",
40
+ text: "Seville",
41
+ isCorrect: false
42
+ }
43
+ ]
35
44
  };
36
- var introduction = {
37
- schemaVersion: "1.0",
38
- type: "fill-in-the-blanks",
39
- id: "ai-check-fib",
40
- title: "Introducing yourself",
41
- passage: "My name {{be}} Rossi and I {{live}} in Madrid.",
42
- blanks: [
43
- { id: "be", acceptedAnswers: ["is"] },
44
- { id: "live", acceptedAnswers: ["live"], hint: "Present simple, first person." }
45
- ],
46
- scoringStrategy: "partial"
45
+ const introduction = {
46
+ schemaVersion: "1.0",
47
+ type: "fill-in-the-blanks",
48
+ id: "ai-check-fib",
49
+ title: "Introducing yourself",
50
+ passage: "My name {{be}} Rossi and I {{live}} in Madrid.",
51
+ blanks: [{
52
+ id: "be",
53
+ acceptedAnswers: ["is"]
54
+ }, {
55
+ id: "live",
56
+ acceptedAnswers: ["live"],
57
+ hint: "Present simple, first person."
58
+ }],
59
+ scoringStrategy: "partial"
47
60
  };
48
- var landscape = {
49
- schemaVersion: "1.0",
50
- type: "gap-select",
51
- id: "ai-check-gap",
52
- title: "Geography",
53
- locale: "es-ES",
54
- passage: "El r\xEDo pasa por un {{g1}} muy profundo, y el agua {{g2}} fr\xEDa.",
55
- gaps: [
56
- {
57
- id: "g1",
58
- choices: [
59
- { id: "canon", text: "ca\xF1\xF3n" },
60
- { id: "campo", text: "campo" }
61
- ],
62
- correctChoiceId: "canon"
63
- },
64
- {
65
- id: "g2",
66
- choices: [
67
- { id: "esta", text: "est\xE1" },
68
- { id: "es", text: "es" }
69
- ],
70
- correctChoiceId: "esta"
71
- }
72
- ],
73
- scoringStrategy: "partial"
61
+ const landscape = {
62
+ schemaVersion: "1.0",
63
+ type: "gap-select",
64
+ id: "ai-check-gap",
65
+ title: "Geography",
66
+ locale: "es-ES",
67
+ passage: "El río pasa por un {{g1}} muy profundo, y el agua {{g2}} fría.",
68
+ gaps: [{
69
+ id: "g1",
70
+ choices: [{
71
+ id: "canon",
72
+ text: "cañón"
73
+ }, {
74
+ id: "campo",
75
+ text: "campo"
76
+ }],
77
+ correctChoiceId: "canon"
78
+ }, {
79
+ id: "g2",
80
+ choices: [{
81
+ id: "esta",
82
+ text: "está"
83
+ }, {
84
+ id: "es",
85
+ text: "es"
86
+ }],
87
+ correctChoiceId: "esta"
88
+ }],
89
+ scoringStrategy: "partial"
74
90
  };
75
- var listening = {
76
- schemaVersion: "1.0",
77
- type: "dictation",
78
- id: "ai-check-dictation",
79
- title: "Listen and type",
80
- transcript: "The train leaves at half past nine."
91
+ const listening = {
92
+ schemaVersion: "1.0",
93
+ type: "dictation",
94
+ id: "ai-check-dictation",
95
+ title: "Listen and type",
96
+ transcript: "The train leaves at half past nine."
81
97
  };
82
- var weekend = {
83
- schemaVersion: "1.0",
84
- type: "written-response",
85
- id: "ai-check-writing",
86
- title: "Your weekend",
87
- prompt: "Write a few sentences about what you did last weekend.",
88
- minWords: 15,
89
- maxWords: 120,
90
- languageTarget: "en-A2",
91
- rubric: {
92
- criteria: [
93
- { name: "Grammar", description: "Past tenses, articles, agreement", weight: 2 },
94
- { name: "Vocabulary", description: "Everyday words, used correctly", weight: 1 },
95
- { name: "Task", description: "Says what the learner did, in order", weight: 1 }
96
- ]
97
- }
98
+ const weekend = {
99
+ schemaVersion: "1.0",
100
+ type: "written-response",
101
+ id: "ai-check-writing",
102
+ title: "Your weekend",
103
+ prompt: "Write a few sentences about what you did last weekend.",
104
+ minWords: 15,
105
+ maxWords: 120,
106
+ languageTarget: "en-A2",
107
+ rubric: { criteria: [
108
+ {
109
+ name: "Grammar",
110
+ description: "Past tenses, articles, agreement",
111
+ weight: 2
112
+ },
113
+ {
114
+ name: "Vocabulary",
115
+ description: "Everyday words, used correctly",
116
+ weight: 1
117
+ },
118
+ {
119
+ name: "Task",
120
+ description: "Says what the learner did, in order",
121
+ weight: 1
122
+ }
123
+ ] }
98
124
  };
99
- var weather = {
100
- schemaVersion: "1.0",
101
- type: "read-aloud",
102
- id: "ai-check-reading",
103
- title: "Read the forecast aloud",
104
- referenceText: "The weather is warm in the north.",
105
- locale: "en-US",
106
- recording: { maxSeconds: 20 },
107
- scoring: {
108
- dimensions: [
109
- { name: "accuracy", weight: 2 },
110
- { name: "fluency", weight: 1 }
111
- ]
112
- }
125
+ const weather = {
126
+ schemaVersion: "1.0",
127
+ type: "read-aloud",
128
+ id: "ai-check-reading",
129
+ title: "Read the forecast aloud",
130
+ referenceText: "The weather is warm in the north.",
131
+ locale: "en-US",
132
+ recording: { maxSeconds: 20 },
133
+ scoring: { dimensions: [{
134
+ name: "accuracy",
135
+ weight: 2
136
+ }, {
137
+ name: "fluency",
138
+ weight: 1
139
+ }] }
113
140
  };
114
- var said = (text, over = {}) => ({
115
- text,
116
- error: "none",
117
- accuracy: 92,
118
- ...over
141
+ /** A word of the forecast as an engine reports it. */
142
+ const said = (text, over = {}) => ({
143
+ text,
144
+ error: "none",
145
+ accuracy: 92,
146
+ ...over
119
147
  });
148
+ /**
149
+ * An engine's assessment of the forecast. With `slips`, "weather" is
150
+ * mispronounced — its "th" heard as /d/ or /z/ — and "north" is left out: the
151
+ * marks a model must coach, and no others.
152
+ */
120
153
  function forecast(slips) {
121
- return {
122
- assessmentVersion: "1.0",
123
- status: "assessed",
124
- task: "scripted",
125
- locale: "en-US",
126
- referenceText: weather.referenceText,
127
- recordingKey: "ai-check-take",
128
- assessor: { kind: "auto", id: "pronunciation-engine" },
129
- scale: 100,
130
- scores: slips ? { accuracy: 68, fluency: 81, completeness: 86 } : { accuracy: 94, fluency: 90 },
131
- miscue: "assessor",
132
- phonemeAlphabet: "ipa",
133
- words: [
134
- said("The"),
135
- slips ? said("weather", {
136
- accuracy: 38,
137
- error: "mispronunciation",
138
- phonemes: [
139
- { symbol: "w", accuracy: 90 },
140
- { symbol: "\u025B", accuracy: 85 },
141
- {
142
- symbol: "\xF0",
143
- accuracy: 12,
144
- heardAs: [
145
- { symbol: "d", score: 64 },
146
- { symbol: "z", score: 21 },
147
- { symbol: "\xF0", score: 12 }
148
- ]
149
- },
150
- { symbol: "\u025A", accuracy: 80 }
151
- ]
152
- }) : said("weather"),
153
- said("is"),
154
- said("warm"),
155
- said("in"),
156
- said("the"),
157
- slips ? { text: "north", error: "omission" } : said("north")
158
- ]
159
- };
154
+ return {
155
+ assessmentVersion: "1.0",
156
+ status: "assessed",
157
+ task: "scripted",
158
+ locale: "en-US",
159
+ referenceText: weather.referenceText,
160
+ recordingKey: "ai-check-take",
161
+ assessor: {
162
+ kind: "auto",
163
+ id: "pronunciation-engine"
164
+ },
165
+ scale: 100,
166
+ scores: slips ? {
167
+ accuracy: 68,
168
+ fluency: 81,
169
+ completeness: 86
170
+ } : {
171
+ accuracy: 94,
172
+ fluency: 90
173
+ },
174
+ miscue: "assessor",
175
+ phonemeAlphabet: "ipa",
176
+ words: [
177
+ said("The"),
178
+ slips ? said("weather", {
179
+ accuracy: 38,
180
+ error: "mispronunciation",
181
+ phonemes: [
182
+ {
183
+ symbol: "w",
184
+ accuracy: 90
185
+ },
186
+ {
187
+ symbol: "ɛ",
188
+ accuracy: 85
189
+ },
190
+ {
191
+ symbol: "ð",
192
+ accuracy: 12,
193
+ heardAs: [
194
+ {
195
+ symbol: "d",
196
+ score: 64
197
+ },
198
+ {
199
+ symbol: "z",
200
+ score: 21
201
+ },
202
+ {
203
+ symbol: "ð",
204
+ score: 12
205
+ }
206
+ ]
207
+ },
208
+ {
209
+ symbol: "ɚ",
210
+ accuracy: 80
211
+ }
212
+ ]
213
+ }) : said("weather"),
214
+ said("is"),
215
+ said("warm"),
216
+ said("in"),
217
+ said("the"),
218
+ slips ? {
219
+ text: "north",
220
+ error: "omission"
221
+ } : said("north")
222
+ ]
223
+ };
160
224
  }
161
- var chose = (ids) => ({
162
- type: "multiple-choice",
163
- selectedOptionIds: ids
225
+ const chose = (ids) => ({
226
+ type: "multiple-choice",
227
+ selectedOptionIds: ids
164
228
  });
165
- var typed = (answers) => ({
166
- type: "fill-in-the-blanks",
167
- answers
229
+ const typed = (answers) => ({
230
+ type: "fill-in-the-blanks",
231
+ answers
168
232
  });
169
- var picked = (choices) => ({
170
- type: "gap-select",
171
- selections: choices
233
+ const picked = (choices) => ({
234
+ type: "gap-select",
235
+ selections: choices
172
236
  });
173
- var wrote = (text) => ({ type: "dictation", text });
174
- var drafted = (text) => ({
175
- type: "written-response",
176
- text,
177
- wordCount: 0
237
+ const wrote = (text) => ({
238
+ type: "dictation",
239
+ text
178
240
  });
179
- var fruit = {
180
- schemaVersion: "1.0",
181
- type: "multiple-choice",
182
- id: "ai-check-fruit",
183
- title: "Food words",
184
- question: "Which of these is a fruit?",
185
- mode: "single",
186
- scoringStrategy: "all-or-nothing",
187
- options: [
188
- { id: "f1", text: "Apple", isCorrect: true },
189
- { id: "f2", text: "Carrot", isCorrect: false },
190
- { id: "f3", text: "Tomato", isCorrect: false }
191
- ]
241
+ const drafted = (text) => ({
242
+ type: "written-response",
243
+ text,
244
+ wordCount: 0
245
+ });
246
+ /**
247
+ * Items an author asks a model to review. Each is valid, and each but the last
248
+ * has a flaw a rule cannot see: a distractor that is botanically a right
249
+ * answer, and a task far above the level it is set for.
250
+ */
251
+ const fruit = {
252
+ schemaVersion: "1.0",
253
+ type: "multiple-choice",
254
+ id: "ai-check-fruit",
255
+ title: "Food words",
256
+ question: "Which of these is a fruit?",
257
+ mode: "single",
258
+ scoringStrategy: "all-or-nothing",
259
+ options: [
260
+ {
261
+ id: "f1",
262
+ text: "Apple",
263
+ isCorrect: true
264
+ },
265
+ {
266
+ id: "f2",
267
+ text: "Carrot",
268
+ isCorrect: false
269
+ },
270
+ {
271
+ id: "f3",
272
+ text: "Tomato",
273
+ isCorrect: false
274
+ }
275
+ ]
192
276
  };
193
- var tooHard = {
194
- schemaVersion: "1.0",
195
- type: "written-response",
196
- id: "ai-check-too-hard",
197
- title: "Cities",
198
- prompt: "Discuss the socioeconomic ramifications of rapid urbanisation in developing economies.",
199
- minWords: 40,
200
- maxWords: 80
277
+ const tooHard = {
278
+ schemaVersion: "1.0",
279
+ type: "written-response",
280
+ id: "ai-check-too-hard",
281
+ title: "Cities",
282
+ prompt: "Discuss the socioeconomic ramifications of rapid urbanisation in developing economies.",
283
+ minWords: 40,
284
+ maxWords: 80
201
285
  };
202
- var cleanCloze = {
203
- schemaVersion: "1.0",
204
- type: "fill-in-the-blanks",
205
- id: "ai-check-clean-cloze",
206
- title: "Daily routine",
207
- passage: "Every morning I {{1}} up at seven and {{2}} a shower.",
208
- blanks: [
209
- { id: "1", acceptedAnswers: ["get", "wake"] },
210
- { id: "2", acceptedAnswers: ["take", "have"] }
211
- ],
212
- scoringStrategy: "partial"
286
+ const cleanCloze = {
287
+ schemaVersion: "1.0",
288
+ type: "fill-in-the-blanks",
289
+ id: "ai-check-clean-cloze",
290
+ title: "Daily routine",
291
+ passage: "Every morning I {{1}} up at seven and {{2}} a shower.",
292
+ blanks: [{
293
+ id: "1",
294
+ acceptedAnswers: ["get", "wake"]
295
+ }, {
296
+ id: "2",
297
+ acceptedAnswers: ["take", "have"]
298
+ }],
299
+ scoringStrategy: "partial"
213
300
  };
214
301
  function critiqueCase(id, about, type, draft, extra = {}) {
215
- const request = _chunkMXI26H62cjs.aiCritiqueRequest.call(void 0, { type, draft, ...extra });
216
- if (request === null) {
217
- throw new Error(`ai-check: no critique request for "${id}"`);
218
- }
219
- return { id, feature: "item-critique", about, request };
302
+ const request = require_ai_writing.aiCritiqueRequest({
303
+ type,
304
+ draft,
305
+ ...extra
306
+ });
307
+ if (request === null) throw new Error(`ai-check: no critique request for "${id}"`);
308
+ return {
309
+ id,
310
+ feature: "item-critique",
311
+ about,
312
+ request
313
+ };
220
314
  }
221
- var MARKET = "Maria lives in Seville, in the south of Spain. Every Saturday she walks to the market with her grandmother. They buy oranges, fresh bread and a little cheese. On the way home they stop at a caf\xE9, where Maria drinks hot chocolate and her grandmother reads the newspaper.";
222
- var MARKET_CAPTIONS = [
223
- { start: 0, end: 4.2, text: "Maria lives in Seville, in the south of Spain." },
224
- { start: 4.2, end: 8.9, text: "Every Saturday she walks to the market with her grandmother." },
225
- { start: 8.9, end: 12.6, text: "They buy oranges, fresh bread and a little cheese." },
226
- { start: 12.6, end: 18.1, text: "On the way home they stop at a caf\xE9." }
315
+ /** A short reading to draft from: plain, and with facts a question can be asked about. */
316
+ const MARKET = "Maria lives in Seville, in the south of Spain. Every Saturday she walks to the market with her grandmother. They buy oranges, fresh bread and a little cheese. On the way home they stop at a café, where Maria drinks hot chocolate and her grandmother reads the newspaper.";
317
+ /** The same reading as a video's captions, with times in seconds. */
318
+ const MARKET_CAPTIONS = [
319
+ {
320
+ start: 0,
321
+ end: 4.2,
322
+ text: "Maria lives in Seville, in the south of Spain."
323
+ },
324
+ {
325
+ start: 4.2,
326
+ end: 8.9,
327
+ text: "Every Saturday she walks to the market with her grandmother."
328
+ },
329
+ {
330
+ start: 8.9,
331
+ end: 12.6,
332
+ text: "They buy oranges, fresh bread and a little cheese."
333
+ },
334
+ {
335
+ start: 12.6,
336
+ end: 18.1,
337
+ text: "On the way home they stop at a café."
338
+ }
227
339
  ];
228
340
  function draftsCase(id, about, types, source, extra = {}) {
229
- const request = _chunkMXI26H62cjs.aiDraftsRequest.call(void 0, { types, source, ...extra });
230
- if (request === null) {
231
- throw new Error(`ai-check: no drafts request for "${id}"`);
232
- }
233
- return { id, feature: "draft-generation", about, request };
341
+ const request = require_ai_writing.aiDraftsRequest({
342
+ types,
343
+ source,
344
+ ...extra
345
+ });
346
+ if (request === null) throw new Error(`ai-check: no drafts request for "${id}"`);
347
+ return {
348
+ id,
349
+ feature: "draft-generation",
350
+ about,
351
+ request
352
+ };
234
353
  }
235
- var READ_ALOUD_SETTINGS = {
236
- locale: "en-US",
237
- recording: { maxSeconds: 20 },
238
- scoring: { dimensions: [{ name: "accuracy", weight: 1 }] }
354
+ /**
355
+ * What a host sets on every read-aloud it drafts: the SDK has no default for a
356
+ * recording's length or the dimensions a reading is graded on.
357
+ */
358
+ const READ_ALOUD_SETTINGS = {
359
+ locale: "en-US",
360
+ recording: { maxSeconds: 20 },
361
+ scoring: { dimensions: [{
362
+ name: "accuracy",
363
+ weight: 1
364
+ }] }
239
365
  };
366
+ /** Builds a case, failing loudly rather than shipping a case with no request. */
240
367
  function explanationCase(id, about, data, response) {
241
- const request = _chunkMXI26H62cjs.aiExplanationRequest.call(void 0, { data, response });
242
- if (request === null) {
243
- throw new Error(`ai-check: no explanation request for "${id}"`);
244
- }
245
- return { id, feature: "explanation", about, request };
368
+ const request = require_ai_writing.aiExplanationRequest({
369
+ data,
370
+ response
371
+ });
372
+ if (request === null) throw new Error(`ai-check: no explanation request for "${id}"`);
373
+ return {
374
+ id,
375
+ feature: "explanation",
376
+ about,
377
+ request
378
+ };
246
379
  }
247
380
  function hintCase(id, about, data, response, previousHints = []) {
248
- const request = _chunkMXI26H62cjs.aiHintRequest.call(void 0, { data, response, previousHints });
249
- if (request === null) {
250
- throw new Error(`ai-check: no hint request for "${id}"`);
251
- }
252
- return { id, feature: "hint", about, request };
381
+ const request = require_ai_writing.aiHintRequest({
382
+ data,
383
+ response,
384
+ previousHints
385
+ });
386
+ if (request === null) throw new Error(`ai-check: no hint request for "${id}"`);
387
+ return {
388
+ id,
389
+ feature: "hint",
390
+ about,
391
+ request
392
+ };
253
393
  }
254
394
  function writingCase(id, about, text, previousFeedback = [], learnerLocale) {
255
- const request = _chunkMXI26H62cjs.aiWritingFeedbackRequest.call(void 0, {
256
- data: weekend,
257
- response: drafted(text),
258
- previousFeedback,
259
- ...learnerLocale !== void 0 ? { learnerLocale } : {}
260
- });
261
- if (request === null) {
262
- throw new Error(`ai-check: no writing feedback request for "${id}"`);
263
- }
264
- return { id, feature: "writing-feedback", about, request };
395
+ const request = require_ai_writing.aiWritingFeedbackRequest({
396
+ data: weekend,
397
+ response: drafted(text),
398
+ previousFeedback,
399
+ ...learnerLocale !== void 0 ? { learnerLocale } : {}
400
+ });
401
+ if (request === null) throw new Error(`ai-check: no writing feedback request for "${id}"`);
402
+ return {
403
+ id,
404
+ feature: "writing-feedback",
405
+ about,
406
+ request
407
+ };
265
408
  }
266
409
  function coachingCase(id, about, marks, learnerLocale) {
267
- const assessment = _nullishCoalesce(marks.assessment, () => ( forecast(true)));
268
- const grade = _chunk4YANYTFNcjs.gradeReadAloud.call(void 0,
269
- weather,
270
- { type: "read-aloud", recording: { key: "ai-check-take", mimeType: "audio/wav" } },
271
- assessment,
272
- {
273
- measured: { durationMs: 4e3, voicedMs: 3e3 },
274
- plausibility: { maxWordsPerSecond: 6, minVoicedMs: 500 }
275
- }
276
- );
277
- if ("unscorable" in grade) {
278
- throw new Error(`ai-check: the reading for "${id}" did not grade: ${grade.reason}`);
279
- }
280
- const request = _chunkMXI26H62cjs.aiCoachingRequest.call(void 0, {
281
- data: weather,
282
- ...marks.fromGradeOnly === true ? {} : { assessment },
283
- grade,
284
- ...learnerLocale !== void 0 ? { learnerLocale } : {}
285
- });
286
- if (request === null) {
287
- throw new Error(`ai-check: no coaching request for "${id}"`);
288
- }
289
- return { id, feature: "pronunciation-coaching", about, request };
410
+ const assessment = marks.assessment ?? forecast(true);
411
+ const grade = require_scoring.gradeReadAloud(weather, {
412
+ type: "read-aloud",
413
+ recording: {
414
+ key: "ai-check-take",
415
+ mimeType: "audio/wav"
416
+ }
417
+ }, assessment, {
418
+ measured: {
419
+ durationMs: 4e3,
420
+ voicedMs: 3e3
421
+ },
422
+ plausibility: {
423
+ maxWordsPerSecond: 6,
424
+ minVoicedMs: 500
425
+ }
426
+ });
427
+ if ("unscorable" in grade) throw new Error(`ai-check: the reading for "${id}" did not grade: ${grade.reason}`);
428
+ const request = require_ai_writing.aiCoachingRequest({
429
+ data: weather,
430
+ ...marks.fromGradeOnly === true ? {} : { assessment },
431
+ grade,
432
+ ...learnerLocale !== void 0 ? { learnerLocale } : {}
433
+ });
434
+ if (request === null) throw new Error(`ai-check: no coaching request for "${id}"`);
435
+ return {
436
+ id,
437
+ feature: "pronunciation-coaching",
438
+ about,
439
+ request
440
+ };
290
441
  }
442
+ /**
443
+ * The cases {@link runAiCheck} runs: every type the SDK explains, answered
444
+ * right, wrong and — where a type can be — partly right; every type it hints
445
+ * for, before an answer and after a wrong one; and drafts of an essay, with
446
+ * mistakes, without, and revised.
447
+ *
448
+ * They are ordinary calls. What makes them a test is that the SDK knows the
449
+ * answer to each, so it can check what your model writes about it.
450
+ *
451
+ * A fresh array each call, so a caller may filter, slice or add to it without
452
+ * changing what the next caller gets.
453
+ */
291
454
  function aiCheckCases() {
292
- return [
293
- explanationCase("mc-correct", "Chose the right city", capital, chose(["madrid"])),
294
- explanationCase("mc-wrong", "Chose Barcelona", capital, chose(["barcelona"])),
295
- explanationCase("mc-blank", "Chose nothing and submitted", capital, chose([])),
296
- explanationCase(
297
- "fib-correct",
298
- "Filled both blanks correctly",
299
- introduction,
300
- typed({ be: "is", live: "live" })
301
- ),
302
- explanationCase(
303
- "fib-partly",
304
- "One blank right, one wrong",
305
- introduction,
306
- typed({ be: "is", live: "lives" })
307
- ),
308
- explanationCase(
309
- "fib-wrong",
310
- "Both blanks wrong",
311
- introduction,
312
- typed({ be: "are", live: "living" })
313
- ),
314
- explanationCase(
315
- "gap-partly",
316
- "One gap right, one wrong, in Spanish",
317
- landscape,
318
- picked({ g1: "canon", g2: "es" })
319
- ),
320
- explanationCase(
321
- "gap-wrong",
322
- "Both gaps wrong, in Spanish",
323
- landscape,
324
- picked({ g1: "campo", g2: "es" })
325
- ),
326
- explanationCase(
327
- "dictation-near",
328
- "Typed the sentence with two words wrong",
329
- listening,
330
- wrote("The train leaves at half past five")
331
- ),
332
- explanationCase(
333
- "dictation-correct",
334
- "Typed the sentence correctly",
335
- listening,
336
- wrote("The train leaves at half past nine.")
337
- ),
338
- hintCase("mc-hint-1", "Has not answered yet", capital, chose([])),
339
- hintCase("mc-hint-2", "Asked again after choosing Seville", capital, chose(["seville"]), [
340
- "Think about where the government sits."
341
- ]),
342
- hintCase("fib-hint-1", "Both blanks empty", introduction, typed({})),
343
- hintCase(
344
- "fib-hint-2",
345
- "Asked again with one blank wrong",
346
- introduction,
347
- typed({ be: "are", live: "" }),
348
- ["Look again at the first blank."]
349
- ),
350
- hintCase("gap-hint-1", "Neither gap chosen, in Spanish", landscape, picked({})),
351
- hintCase(
352
- "gap-hint-2",
353
- "Asked again with the first gap wrong",
354
- landscape,
355
- picked({ g1: "campo" }),
356
- ["Piensa en la forma del terreno."]
357
- ),
358
- writingCase(
359
- "writing-mistakes",
360
- "A first draft with tense, article and agreement mistakes",
361
- "Last weekend I go to the market and buyed a apple. My friends was there too, so we don't go home early. Then I go to the cinema."
362
- ),
363
- writingCase(
364
- "writing-clean",
365
- "A first draft with no mistakes to correct",
366
- "Last weekend I went to the market and bought an apple. My friends were there too, so we stayed until the evening. Then we went to the cinema."
367
- ),
368
- writingCase(
369
- "writing-revised",
370
- "A second draft that fixed some mistakes",
371
- "Last weekend I went to the market and bought a apple. My friends was there too, so we didn't go home early.",
372
- ['Check your past tenses: "go" and "buyed" should be past forms.']
373
- ),
374
- writingCase(
375
- "writing-feedback-in-spanish",
376
- "A first draft, with feedback asked for in Spanish",
377
- "Last weekend I visit my grandmother. She cook a big lunch and we eat together in the garden.",
378
- [],
379
- "es"
380
- ),
381
- coachingCase("coaching-slips", 'A reading with a mispronounced "th" and a word left out', {
382
- assessment: forecast(true)
383
- }),
384
- coachingCase("coaching-clean", "A reading the engine marked correct throughout", {
385
- assessment: forecast(false)
386
- }),
387
- coachingCase(
388
- "coaching-from-grade",
389
- "The same slips, from a stored grade: marks without sounds",
390
- { fromGradeOnly: true }
391
- ),
392
- coachingCase(
393
- "coaching-in-spanish",
394
- "The same slips, with coaching asked for in Spanish",
395
- { assessment: forecast(true) },
396
- "es"
397
- ),
398
- critiqueCase(
399
- "critique-second-answer",
400
- 'A question whose distractor "Tomato" is botanically a fruit',
401
- "multiple-choice",
402
- fruit,
403
- { level: "A1" }
404
- ),
405
- critiqueCase(
406
- "critique-level",
407
- "A writing task far above the A1 level it is set for",
408
- "written-response",
409
- tooHard,
410
- { level: "A1" }
411
- ),
412
- critiqueCase(
413
- "critique-clean",
414
- "A cloze with nothing wrong in it",
415
- "fill-in-the-blanks",
416
- cleanCloze,
417
- {
418
- level: "A2"
419
- }
420
- ),
421
- critiqueCase(
422
- "critique-in-spanish",
423
- "The fruit question, reviewed in Spanish for its author",
424
- "multiple-choice",
425
- fruit,
426
- { level: "A1", authorLocale: "es" }
427
- ),
428
- draftsCase(
429
- "drafts-questions",
430
- "Four multiple-choice questions on a short reading",
431
- ["multiple-choice"],
432
- { kind: "passage", text: MARKET },
433
- { count: 4, level: "A2", locale: "en" }
434
- ),
435
- draftsCase(
436
- "drafts-cloze",
437
- "A cloze on the same reading, from its transcript",
438
- ["fill-in-the-blanks"],
439
- { kind: "transcript", text: MARKET },
440
- { count: 1, level: "A2", locale: "en", instructions: "Blank the verbs." }
441
- ),
442
- draftsCase(
443
- "drafts-gaps",
444
- "A choose-the-word item on the same reading",
445
- ["gap-select"],
446
- { kind: "passage", text: MARKET },
447
- { count: 1, level: "A2", locale: "en" }
448
- ),
449
- draftsCase(
450
- "drafts-writing",
451
- "A writing task that follows on from the reading",
452
- ["written-response"],
453
- { kind: "passage", text: MARKET },
454
- { count: 1, level: "A2", locale: "en" }
455
- ),
456
- draftsCase(
457
- "drafts-video",
458
- "A video quiz from timed captions: multiple choice, then dictation, then read-aloud, as many as the video is worth",
459
- ["multiple-choice", "dictation", "read-aloud"],
460
- { kind: "captions", cues: MARKET_CAPTIONS },
461
- { level: "A2", locale: "en", settings: { "read-aloud": READ_ALOUD_SETTINGS } }
462
- ),
463
- draftsCase(
464
- "drafts-script",
465
- "The same video from its script alone, with no times, and what the author asked for",
466
- ["multiple-choice", "dictation", "read-aloud"],
467
- { kind: "transcript", text: MARKET },
468
- {
469
- level: "A2",
470
- locale: "en",
471
- instructions: "Focus on what Maria and her grandmother buy.",
472
- settings: { "read-aloud": READ_ALOUD_SETTINGS }
473
- }
474
- )
475
- ];
455
+ return [
456
+ explanationCase("mc-correct", "Chose the right city", capital, chose(["madrid"])),
457
+ explanationCase("mc-wrong", "Chose Barcelona", capital, chose(["barcelona"])),
458
+ explanationCase("mc-blank", "Chose nothing and submitted", capital, chose([])),
459
+ explanationCase("fib-correct", "Filled both blanks correctly", introduction, typed({
460
+ be: "is",
461
+ live: "live"
462
+ })),
463
+ explanationCase("fib-partly", "One blank right, one wrong", introduction, typed({
464
+ be: "is",
465
+ live: "lives"
466
+ })),
467
+ explanationCase("fib-wrong", "Both blanks wrong", introduction, typed({
468
+ be: "are",
469
+ live: "living"
470
+ })),
471
+ explanationCase("gap-partly", "One gap right, one wrong, in Spanish", landscape, picked({
472
+ g1: "canon",
473
+ g2: "es"
474
+ })),
475
+ explanationCase("gap-wrong", "Both gaps wrong, in Spanish", landscape, picked({
476
+ g1: "campo",
477
+ g2: "es"
478
+ })),
479
+ explanationCase("dictation-near", "Typed the sentence with two words wrong", listening, wrote("The train leaves at half past five")),
480
+ explanationCase("dictation-correct", "Typed the sentence correctly", listening, wrote("The train leaves at half past nine.")),
481
+ hintCase("mc-hint-1", "Has not answered yet", capital, chose([])),
482
+ hintCase("mc-hint-2", "Asked again after choosing Seville", capital, chose(["seville"]), ["Think about where the government sits."]),
483
+ hintCase("fib-hint-1", "Both blanks empty", introduction, typed({})),
484
+ hintCase("fib-hint-2", "Asked again with one blank wrong", introduction, typed({
485
+ be: "are",
486
+ live: ""
487
+ }), ["Look again at the first blank."]),
488
+ hintCase("gap-hint-1", "Neither gap chosen, in Spanish", landscape, picked({})),
489
+ hintCase("gap-hint-2", "Asked again with the first gap wrong", landscape, picked({ g1: "campo" }), ["Piensa en la forma del terreno."]),
490
+ writingCase("writing-mistakes", "A first draft with tense, article and agreement mistakes", "Last weekend I go to the market and buyed a apple. My friends was there too, so we don't go home early. Then I go to the cinema."),
491
+ writingCase("writing-clean", "A first draft with no mistakes to correct", "Last weekend I went to the market and bought an apple. My friends were there too, so we stayed until the evening. Then we went to the cinema."),
492
+ writingCase("writing-revised", "A second draft that fixed some mistakes", "Last weekend I went to the market and bought a apple. My friends was there too, so we didn't go home early.", ["Check your past tenses: \"go\" and \"buyed\" should be past forms."]),
493
+ writingCase("writing-feedback-in-spanish", "A first draft, with feedback asked for in Spanish", "Last weekend I visit my grandmother. She cook a big lunch and we eat together in the garden.", [], "es"),
494
+ coachingCase("coaching-slips", "A reading with a mispronounced \"th\" and a word left out", { assessment: forecast(true) }),
495
+ coachingCase("coaching-clean", "A reading the engine marked correct throughout", { assessment: forecast(false) }),
496
+ coachingCase("coaching-from-grade", "The same slips, from a stored grade: marks without sounds", { fromGradeOnly: true }),
497
+ coachingCase("coaching-in-spanish", "The same slips, with coaching asked for in Spanish", { assessment: forecast(true) }, "es"),
498
+ critiqueCase("critique-second-answer", "A question whose distractor \"Tomato\" is botanically a fruit", "multiple-choice", fruit, { level: "A1" }),
499
+ critiqueCase("critique-level", "A writing task far above the A1 level it is set for", "written-response", tooHard, { level: "A1" }),
500
+ critiqueCase("critique-clean", "A cloze with nothing wrong in it", "fill-in-the-blanks", cleanCloze, { level: "A2" }),
501
+ critiqueCase("critique-in-spanish", "The fruit question, reviewed in Spanish for its author", "multiple-choice", fruit, {
502
+ level: "A1",
503
+ authorLocale: "es"
504
+ }),
505
+ draftsCase("drafts-questions", "Four multiple-choice questions on a short reading", ["multiple-choice"], {
506
+ kind: "passage",
507
+ text: MARKET
508
+ }, {
509
+ count: 4,
510
+ level: "A2",
511
+ locale: "en"
512
+ }),
513
+ draftsCase("drafts-cloze", "A cloze on the same reading, from its transcript", ["fill-in-the-blanks"], {
514
+ kind: "transcript",
515
+ text: MARKET
516
+ }, {
517
+ count: 1,
518
+ level: "A2",
519
+ locale: "en",
520
+ instructions: "Blank the verbs."
521
+ }),
522
+ draftsCase("drafts-gaps", "A choose-the-word item on the same reading", ["gap-select"], {
523
+ kind: "passage",
524
+ text: MARKET
525
+ }, {
526
+ count: 1,
527
+ level: "A2",
528
+ locale: "en"
529
+ }),
530
+ draftsCase("drafts-writing", "A writing task that follows on from the reading", ["written-response"], {
531
+ kind: "passage",
532
+ text: MARKET
533
+ }, {
534
+ count: 1,
535
+ level: "A2",
536
+ locale: "en"
537
+ }),
538
+ draftsCase("drafts-video", "A video quiz from timed captions: multiple choice, then dictation, then read-aloud, as many as the video is worth", [
539
+ "multiple-choice",
540
+ "dictation",
541
+ "read-aloud"
542
+ ], {
543
+ kind: "captions",
544
+ cues: MARKET_CAPTIONS
545
+ }, {
546
+ level: "A2",
547
+ locale: "en",
548
+ settings: { "read-aloud": READ_ALOUD_SETTINGS }
549
+ }),
550
+ draftsCase("drafts-script", "The same video from its script alone, with no times, and what the author asked for", [
551
+ "multiple-choice",
552
+ "dictation",
553
+ "read-aloud"
554
+ ], {
555
+ kind: "transcript",
556
+ text: MARKET
557
+ }, {
558
+ level: "A2",
559
+ locale: "en",
560
+ instructions: "Focus on what Maria and her grandmother buy.",
561
+ settings: { "read-aloud": READ_ALOUD_SETTINGS }
562
+ })
563
+ ];
476
564
  }
477
-
478
- // src/ai-check/index.ts
479
- var REFUSALS = [
480
- "malformed",
481
- "empty",
482
- "too-long",
483
- "contradicts-grade",
484
- "reveals-answer",
485
- "misquotes-answer",
486
- "contradicts-marks",
487
- "contradicts-item"
565
+ //#endregion
566
+ //#region src/ai-check/index.ts
567
+ /**
568
+ * A test kit for the prompts behind your AI ports.
569
+ *
570
+ * The SDK cannot test your model, and will not try. What it can do is make the
571
+ * calls a learner's questions would make — on items whose answers it knows —
572
+ * and run the same checks it runs before a learner sees anything. What comes
573
+ * back is a count of what would have been shown and what would have been
574
+ * refused, and why.
575
+ *
576
+ * Run it where you change a prompt or a model, in your own CI, with your own
577
+ * key. It is a separate entry point (`@intellectif/lk-core/ai-check`) because
578
+ * it is for your test run, not for a learner's browser: nothing here is
579
+ * imported by anything a page renders.
580
+ *
581
+ * ```ts
582
+ * import { aiCheckCases, formatAiCheckReport, runAiCheck } from '@intellectif/lk-core/ai-check';
583
+ *
584
+ * const report = await runAiCheck({
585
+ * explain: (request) => callMyModel(EXPLAIN_PROMPT, request),
586
+ * hint: (request) => callMyModel(HINT_PROMPT, request),
587
+ * writingFeedback: (request) => callMyModel(FEEDBACK_PROMPT, request),
588
+ * pronunciationCoaching: (request) => callMyModel(COACHING_PROMPT, request),
589
+ * critique: (request) => callMyModel(CRITIQUE_PROMPT, request),
590
+ * drafts: (request) => callMyModel(DRAFTS_PROMPT, request),
591
+ * });
592
+ * console.log(formatAiCheckReport(report));
593
+ * if (report.refused > 0 || report.errors > 0) {
594
+ * process.exitCode = 1;
595
+ * }
596
+ * ```
597
+ *
598
+ * A refusal is a real failure, not a warning: it is an answer a learner would
599
+ * have asked for and not received. `reveals-answer` on a hint case is the one
600
+ * to take most seriously — that prompt gives answers away. Next come
601
+ * `misquotes-answer` on a writing case — that prompt corrects words the learner
602
+ * never wrote — and `contradicts-marks` on a coaching case: that prompt coaches
603
+ * words the engine heard as right, or sounds it never reported.
604
+ */
605
+ const REFUSALS = [
606
+ "malformed",
607
+ "empty",
608
+ "too-long",
609
+ "contradicts-grade",
610
+ "reveals-answer",
611
+ "misquotes-answer",
612
+ "contradicts-marks",
613
+ "contradicts-item"
488
614
  ];
615
+ /** The port a case is for. */
489
616
  function portFor(ports, one) {
490
- switch (one.request.feature) {
491
- case "explanation":
492
- return ports.explain;
493
- case "hint":
494
- return ports.hint;
495
- case "pronunciation-coaching":
496
- return ports.pronunciationCoaching;
497
- case "item-critique":
498
- return ports.critique;
499
- case "draft-generation":
500
- return ports.drafts;
501
- default:
502
- return ports.writingFeedback;
503
- }
617
+ switch (one.request.feature) {
618
+ case "explanation": return ports.explain;
619
+ case "hint": return ports.hint;
620
+ case "pronunciation-coaching": return ports.pronunciationCoaching;
621
+ case "item-critique": return ports.critique;
622
+ case "draft-generation": return ports.drafts;
623
+ default: return ports.writingFeedback;
624
+ }
504
625
  }
505
- var now = () => Date.now();
626
+ /** Milliseconds, from whichever clock this runtime has. */
627
+ const now = () => Date.now();
628
+ /** Runs one case: calls the port, times it, and checks what came back. */
506
629
  async function runCase(ports, one) {
507
- const started = now();
508
- const port = portFor(ports, one);
509
- if (port === void 0) {
510
- throw new Error(`ai-check: no port for "${one.id}"`);
511
- }
512
- let raw;
513
- try {
514
- raw = await port(one.request);
515
- } catch (error) {
516
- return {
517
- case: one,
518
- ok: false,
519
- error: error instanceof Error ? error.message : String(error),
520
- ms: now() - started
521
- };
522
- }
523
- const ms = now() - started;
524
- if (one.request.feature === "draft-generation") {
525
- let next = 0;
526
- const checked2 = _chunkMXI26H62cjs.checkAiDrafts.call(void 0, raw, one.request, {
527
- newId: () => {
528
- next += 1;
529
- return `ai-check-${next}`;
530
- }
531
- });
532
- return checked2.ok ? { case: one, ok: true, drafts: checked2.drafts, ms } : refused(one, raw, checked2.refusal, ms);
533
- }
534
- if (one.request.feature === "item-critique") {
535
- const checked2 = _chunkMXI26H62cjs.checkAiCritique.call(void 0, raw, one.request);
536
- return checked2.ok ? { case: one, ok: true, critique: checked2.critique, ms } : refused(one, raw, checked2.refusal, ms);
537
- }
538
- if (one.request.feature === "pronunciation-coaching") {
539
- const checked2 = _chunkMXI26H62cjs.checkAiCoaching.call(void 0, raw, one.request);
540
- if (checked2.ok) {
541
- const { text, provenance, usage } = checked2.coaching;
542
- return {
543
- case: one,
544
- ok: true,
545
- result: {
546
- text,
547
- ...provenance !== void 0 ? { provenance } : {},
548
- ...usage !== void 0 ? { usage } : {}
549
- },
550
- coaching: checked2.coaching,
551
- ms
552
- };
553
- }
554
- return refused(one, raw, checked2.refusal, ms);
555
- }
556
- if (one.request.feature === "writing-feedback") {
557
- const checked2 = _chunkMXI26H62cjs.checkAiWritingFeedback.call(void 0, raw, one.request);
558
- if (checked2.ok) {
559
- const { text, provenance, usage } = checked2.feedback;
560
- return {
561
- case: one,
562
- ok: true,
563
- result: {
564
- text,
565
- ...provenance !== void 0 ? { provenance } : {},
566
- ...usage !== void 0 ? { usage } : {}
567
- },
568
- feedback: checked2.feedback,
569
- ms
570
- };
571
- }
572
- return refused(one, raw, checked2.refusal, ms);
573
- }
574
- const checked = one.request.feature === "explanation" ? _chunkMXI26H62cjs.checkAiExplanation.call(void 0, raw, one.request) : _chunkMXI26H62cjs.checkAiHint.call(void 0, raw, one.request);
575
- if (checked.ok) {
576
- return { case: one, ok: true, result: checked.result, ms };
577
- }
578
- return refused(one, raw, checked.refusal, ms);
630
+ const started = now();
631
+ const port = portFor(ports, one);
632
+ if (port === void 0) throw new Error(`ai-check: no port for "${one.id}"`);
633
+ let raw;
634
+ try {
635
+ raw = await port(one.request);
636
+ } catch (error) {
637
+ return {
638
+ case: one,
639
+ ok: false,
640
+ error: error instanceof Error ? error.message : String(error),
641
+ ms: now() - started
642
+ };
643
+ }
644
+ const ms = now() - started;
645
+ if (one.request.feature === "draft-generation") {
646
+ let next = 0;
647
+ const checked = require_ai_writing.checkAiDrafts(raw, one.request, { newId: () => {
648
+ next += 1;
649
+ return `ai-check-${next}`;
650
+ } });
651
+ return checked.ok ? {
652
+ case: one,
653
+ ok: true,
654
+ drafts: checked.drafts,
655
+ ms
656
+ } : refused(one, raw, checked.refusal, ms);
657
+ }
658
+ if (one.request.feature === "item-critique") {
659
+ const checked = require_ai_writing.checkAiCritique(raw, one.request);
660
+ return checked.ok ? {
661
+ case: one,
662
+ ok: true,
663
+ critique: checked.critique,
664
+ ms
665
+ } : refused(one, raw, checked.refusal, ms);
666
+ }
667
+ if (one.request.feature === "pronunciation-coaching") {
668
+ const checked = require_ai_writing.checkAiCoaching(raw, one.request);
669
+ if (checked.ok) {
670
+ const { text, provenance, usage } = checked.coaching;
671
+ return {
672
+ case: one,
673
+ ok: true,
674
+ result: {
675
+ text,
676
+ ...provenance !== void 0 ? { provenance } : {},
677
+ ...usage !== void 0 ? { usage } : {}
678
+ },
679
+ coaching: checked.coaching,
680
+ ms
681
+ };
682
+ }
683
+ return refused(one, raw, checked.refusal, ms);
684
+ }
685
+ if (one.request.feature === "writing-feedback") {
686
+ const checked = require_ai_writing.checkAiWritingFeedback(raw, one.request);
687
+ if (checked.ok) {
688
+ const { text, provenance, usage } = checked.feedback;
689
+ return {
690
+ case: one,
691
+ ok: true,
692
+ result: {
693
+ text,
694
+ ...provenance !== void 0 ? { provenance } : {},
695
+ ...usage !== void 0 ? { usage } : {}
696
+ },
697
+ feedback: checked.feedback,
698
+ ms
699
+ };
700
+ }
701
+ return refused(one, raw, checked.refusal, ms);
702
+ }
703
+ const checked = one.request.feature === "explanation" ? require_ai_writing.checkAiExplanation(raw, one.request) : require_ai_writing.checkAiHint(raw, one.request);
704
+ if (checked.ok) return {
705
+ case: one,
706
+ ok: true,
707
+ result: checked.result,
708
+ ms
709
+ };
710
+ return refused(one, raw, checked.refusal, ms);
579
711
  }
712
+ /** A case whose answer was refused, with the text that came back when there was one to read. */
580
713
  function refused(one, raw, refusal, ms) {
581
- const text = typeof _optionalChain([raw, 'optionalAccess', _ => _.text]) === "string" ? raw : void 0;
582
- return {
583
- case: one,
584
- ok: false,
585
- refusal,
586
- ...text !== void 0 ? { result: text } : {},
587
- ms
588
- };
714
+ const text = typeof raw?.text === "string" ? raw : void 0;
715
+ return {
716
+ case: one,
717
+ ok: false,
718
+ refusal,
719
+ ...text !== void 0 ? { result: text } : {},
720
+ ms
721
+ };
589
722
  }
723
+ /**
724
+ * Calls your ports on every case and reports what a learner would have seen.
725
+ *
726
+ * It never throws for a failing case: a port that rejects is an `error` in the
727
+ * report, so one bad call cannot hide the rest.
728
+ */
590
729
  async function runAiCheck(ports, options = {}) {
591
- const all = _nullishCoalesce(options.cases, () => ( aiCheckCases()));
592
- const asked = Math.trunc(_nullishCoalesce(options.concurrency, () => ( 1)));
593
- const lanes = Number.isFinite(asked) && asked >= 1 ? Math.min(asked, 16) : 1;
594
- const runnable = all.filter((one) => portFor(ports, one) !== void 0);
595
- const results = new Array(runnable.length);
596
- let next = 0;
597
- const lane = async () => {
598
- while (next < runnable.length) {
599
- const mine = next;
600
- next += 1;
601
- const one = runnable[mine];
602
- if (one === void 0) {
603
- return;
604
- }
605
- results[mine] = await runCase(ports, one);
606
- }
607
- };
608
- await Promise.all(Array.from({ length: Math.min(lanes, runnable.length) }, lane));
609
- const byRefusal = Object.fromEntries(REFUSALS.map((reason) => [reason, 0]));
610
- let shown = 0;
611
- let refused2 = 0;
612
- let errors = 0;
613
- for (const result of results) {
614
- if (result.ok) {
615
- shown += 1;
616
- } else if (result.refusal !== void 0) {
617
- refused2 += 1;
618
- byRefusal[result.refusal] += 1;
619
- } else {
620
- errors += 1;
621
- }
622
- }
623
- return {
624
- total: results.length,
625
- shown,
626
- refused: refused2,
627
- errors,
628
- skipped: all.length - runnable.length,
629
- byRefusal,
630
- results
631
- };
730
+ const all = options.cases ?? aiCheckCases();
731
+ const asked = Math.trunc(options.concurrency ?? 1);
732
+ const lanes = Number.isFinite(asked) && asked >= 1 ? Math.min(asked, 16) : 1;
733
+ const runnable = all.filter((one) => portFor(ports, one) !== void 0);
734
+ const results = new Array(runnable.length);
735
+ let next = 0;
736
+ const lane = async () => {
737
+ while (next < runnable.length) {
738
+ const mine = next;
739
+ next += 1;
740
+ const one = runnable[mine];
741
+ if (one === void 0) return;
742
+ results[mine] = await runCase(ports, one);
743
+ }
744
+ };
745
+ await Promise.all(Array.from({ length: Math.min(lanes, runnable.length) }, lane));
746
+ const byRefusal = Object.fromEntries(REFUSALS.map((reason) => [reason, 0]));
747
+ let shown = 0;
748
+ let refused = 0;
749
+ let errors = 0;
750
+ for (const result of results) if (result.ok) shown += 1;
751
+ else if (result.refusal !== void 0) {
752
+ refused += 1;
753
+ byRefusal[result.refusal] += 1;
754
+ } else errors += 1;
755
+ return {
756
+ total: results.length,
757
+ shown,
758
+ refused,
759
+ errors,
760
+ skipped: all.length - runnable.length,
761
+ byRefusal,
762
+ results
763
+ };
632
764
  }
765
+ /**
766
+ * The report as a few lines for a CI log: the counts, then every case that
767
+ * failed, with what came back.
768
+ *
769
+ * The refused text is printed — this is your own test run, not a learner's
770
+ * screen, and a hint that gives the answer away is only fixable if you can
771
+ * read it.
772
+ */
633
773
  function formatAiCheckReport(report) {
634
- const lines = [];
635
- const slowest = report.results.reduce((worst, one) => Math.max(worst, one.ms), 0);
636
- lines.push(
637
- `ai-check: ${report.shown}/${report.total} shown, ${report.refused} refused, ${report.errors} failed${report.skipped > 0 ? `, ${report.skipped} skipped (no port)` : ""} \u2014 slowest ${slowest} ms`
638
- );
639
- for (const reason of REFUSALS) {
640
- const count = report.byRefusal[reason];
641
- if (count > 0) {
642
- lines.push(` ${reason}: ${count}`);
643
- }
644
- }
645
- for (const result of report.results) {
646
- if (result.ok) {
647
- continue;
648
- }
649
- const why = _nullishCoalesce(result.refusal, () => ( `port failed (${_nullishCoalesce(result.error, () => ( "no message"))})`));
650
- lines.push(` \u2717 ${result.case.id} [${result.case.feature}] ${result.case.about}: ${why}`);
651
- if (result.result !== void 0) {
652
- lines.push(` ${result.result.text.replace(/\s+/g, " ").slice(0, 200)}`);
653
- }
654
- }
655
- return lines.join("\n");
774
+ const lines = [];
775
+ const slowest = report.results.reduce((worst, one) => Math.max(worst, one.ms), 0);
776
+ lines.push(`ai-check: ${report.shown}/${report.total} shown, ${report.refused} refused, ${report.errors} failed${report.skipped > 0 ? `, ${report.skipped} skipped (no port)` : ""} — slowest ${slowest} ms`);
777
+ for (const reason of REFUSALS) {
778
+ const count = report.byRefusal[reason];
779
+ if (count > 0) lines.push(` ${reason}: ${count}`);
780
+ }
781
+ for (const result of report.results) {
782
+ if (result.ok) continue;
783
+ const why = result.refusal ?? `port failed (${result.error ?? "no message"})`;
784
+ lines.push(` ✗ ${result.case.id} [${result.case.feature}] ${result.case.about}: ${why}`);
785
+ if (result.result !== void 0) lines.push(` ${result.result.text.replace(/\s+/g, " ").slice(0, 200)}`);
786
+ }
787
+ return lines.join("\n");
656
788
  }
789
+ //#endregion
790
+ exports.aiCheckCases = aiCheckCases;
791
+ exports.formatAiCheckReport = formatAiCheckReport;
792
+ exports.runAiCheck = runAiCheck;
657
793
 
658
-
659
-
660
-
661
- exports.aiCheckCases = aiCheckCases; exports.formatAiCheckReport = formatAiCheckReport; exports.runAiCheck = runAiCheck;
662
794
  //# sourceMappingURL=ai-check.cjs.map