@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.js CHANGED
@@ -1,662 +1,791 @@
1
- import {
2
- aiCoachingRequest,
3
- aiCritiqueRequest,
4
- aiDraftsRequest,
5
- aiExplanationRequest,
6
- aiHintRequest,
7
- aiWritingFeedbackRequest,
8
- checkAiCoaching,
9
- checkAiCritique,
10
- checkAiDrafts,
11
- checkAiExplanation,
12
- checkAiHint,
13
- checkAiWritingFeedback
14
- } from "./chunk-7KOWU4RO.js";
15
- import {
16
- gradeReadAloud
17
- } from "./chunk-QX2ERL72.js";
18
- import "./chunk-MV2N2WNS.js";
19
- import "./chunk-QS7B42ZR.js";
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
+ 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
+ ]
35
43
  };
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"
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"
47
59
  };
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"
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"
74
89
  };
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."
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."
81
96
  };
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
- }
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
+ ] }
98
123
  };
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
- }
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
+ }] }
113
139
  };
114
- var said = (text, over = {}) => ({
115
- text,
116
- error: "none",
117
- accuracy: 92,
118
- ...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
119
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
+ */
120
152
  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
- };
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
+ };
160
223
  }
161
- var chose = (ids) => ({
162
- type: "multiple-choice",
163
- 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
164
231
  });
165
- var typed = (answers) => ({
166
- type: "fill-in-the-blanks",
167
- answers
232
+ const picked = (choices) => ({
233
+ type: "gap-select",
234
+ selections: choices
168
235
  });
169
- var picked = (choices) => ({
170
- type: "gap-select",
171
- selections: choices
236
+ const wrote = (text) => ({
237
+ type: "dictation",
238
+ text
172
239
  });
173
- var wrote = (text) => ({ type: "dictation", text });
174
- var drafted = (text) => ({
175
- type: "written-response",
176
- text,
177
- wordCount: 0
240
+ const drafted = (text) => ({
241
+ type: "written-response",
242
+ text,
243
+ wordCount: 0
178
244
  });
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
- ]
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
+ ]
192
275
  };
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
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
201
284
  };
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"
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"
213
299
  };
214
300
  function critiqueCase(id, about, type, draft, extra = {}) {
215
- const request = aiCritiqueRequest({ 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 };
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
+ };
220
313
  }
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." }
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
+ }
227
338
  ];
228
339
  function draftsCase(id, about, types, source, extra = {}) {
229
- const request = aiDraftsRequest({ 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 };
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
+ };
234
352
  }
235
- var READ_ALOUD_SETTINGS = {
236
- locale: "en-US",
237
- recording: { maxSeconds: 20 },
238
- scoring: { dimensions: [{ name: "accuracy", weight: 1 }] }
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
+ }] }
239
364
  };
365
+ /** Builds a case, failing loudly rather than shipping a case with no request. */
240
366
  function explanationCase(id, about, data, response) {
241
- const request = aiExplanationRequest({ 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 };
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
+ };
246
378
  }
247
379
  function hintCase(id, about, data, response, previousHints = []) {
248
- const request = aiHintRequest({ 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 };
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
+ };
253
392
  }
254
393
  function writingCase(id, about, text, previousFeedback = [], learnerLocale) {
255
- const request = aiWritingFeedbackRequest({
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 };
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
+ };
265
407
  }
266
408
  function coachingCase(id, about, marks, learnerLocale) {
267
- const assessment = marks.assessment ?? forecast(true);
268
- const grade = gradeReadAloud(
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 = aiCoachingRequest({
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 };
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
+ };
290
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
+ */
291
453
  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
- ];
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
+ ];
476
563
  }
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"
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"
488
613
  ];
614
+ /** The port a case is for. */
489
615
  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
- }
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
+ }
504
624
  }
505
- 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. */
506
628
  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 = checkAiDrafts(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 = checkAiCritique(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 = checkAiCoaching(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 = checkAiWritingFeedback(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" ? checkAiExplanation(raw, one.request) : checkAiHint(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);
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);
579
710
  }
711
+ /** A case whose answer was refused, with the text that came back when there was one to read. */
580
712
  function refused(one, raw, refusal, ms) {
581
- const text = typeof raw?.text === "string" ? raw : void 0;
582
- return {
583
- case: one,
584
- ok: false,
585
- refusal,
586
- ...text !== void 0 ? { result: text } : {},
587
- ms
588
- };
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
+ };
589
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
+ */
590
728
  async function runAiCheck(ports, options = {}) {
591
- const all = options.cases ?? aiCheckCases();
592
- const asked = Math.trunc(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
- };
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
+ };
632
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
+ */
633
772
  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 = result.refusal ?? `port failed (${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");
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");
656
787
  }
657
- export {
658
- aiCheckCases,
659
- formatAiCheckReport,
660
- runAiCheck
661
- };
788
+ //#endregion
789
+ export { aiCheckCases, formatAiCheckReport, runAiCheck };
790
+
662
791
  //# sourceMappingURL=ai-check.js.map