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