@intellectif/lk-core 0.20.0 → 0.22.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.
- package/CHANGELOG.md +32 -0
- package/README.md +30 -1
- package/dist/{activity-f0bgZSTP.d.cts → activity-CYc7SD3d.d.cts} +157 -11
- package/dist/{activity-f0bgZSTP.d.ts → activity-CYc7SD3d.d.ts} +157 -11
- package/dist/ai-check.cjs +103 -15
- package/dist/ai-check.cjs.map +1 -1
- package/dist/ai-check.d.cts +9 -5
- package/dist/ai-check.d.ts +9 -5
- package/dist/ai-check.js +102 -14
- package/dist/ai-check.js.map +1 -1
- package/dist/{chunk-BIJCO2HM.js → chunk-5UCR4UNR.js} +301 -20
- package/dist/chunk-5UCR4UNR.js.map +1 -0
- package/dist/{chunk-FVZJ4X3Y.cjs → chunk-OPMY2MNS.cjs} +302 -21
- package/dist/chunk-OPMY2MNS.cjs.map +1 -0
- package/dist/{chunk-MMEQKFFQ.js → chunk-Q7MV3IXJ.js} +196 -8
- package/dist/chunk-Q7MV3IXJ.js.map +1 -0
- package/dist/{chunk-COBK2RUX.cjs → chunk-WQVZPIN7.cjs} +197 -9
- package/dist/chunk-WQVZPIN7.cjs.map +1 -0
- package/dist/{index-BA9f2ydg.d.ts → index-0Z3-nnAP.d.ts} +1 -1
- package/dist/{index-7S3-TLjT.d.cts → index-CxxiNSSH.d.cts} +1 -1
- package/dist/index.cjs +56 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -10
- package/dist/index.d.ts +93 -10
- package/dist/index.js +52 -5
- package/dist/index.js.map +1 -1
- package/dist/schemas.d.cts +2 -2
- package/dist/schemas.d.ts +2 -2
- package/dist/scoring.cjs +14 -2
- package/dist/scoring.cjs.map +1 -1
- package/dist/scoring.d.cts +240 -4
- package/dist/scoring.d.ts +240 -4
- package/dist/scoring.js +13 -1
- package/dist/xapi.d.cts +1 -1
- package/dist/xapi.d.ts +1 -1
- package/package.json +1 -1
- package/vectors/README.md +10 -0
- package/vectors/scoring.json +2127 -1
- package/dist/chunk-BIJCO2HM.js.map +0 -1
- package/dist/chunk-COBK2RUX.cjs.map +0 -1
- package/dist/chunk-FVZJ4X3Y.cjs.map +0 -1
- package/dist/chunk-MMEQKFFQ.js.map +0 -1
package/dist/ai-check.cjs
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkOPMY2MNScjs = require('./chunk-OPMY2MNS.cjs');
|
|
9
|
+
require('./chunk-WQVZPIN7.cjs');
|
|
8
10
|
require('./chunk-D4TOPSHV.cjs');
|
|
9
11
|
|
|
10
12
|
// src/ai-check/cases.ts
|
|
@@ -68,6 +70,23 @@ var listening = {
|
|
|
68
70
|
title: "Listen and type",
|
|
69
71
|
transcript: "The train leaves at half past nine."
|
|
70
72
|
};
|
|
73
|
+
var weekend = {
|
|
74
|
+
schemaVersion: "1.0",
|
|
75
|
+
type: "written-response",
|
|
76
|
+
id: "ai-check-writing",
|
|
77
|
+
title: "Your weekend",
|
|
78
|
+
prompt: "Write a few sentences about what you did last weekend.",
|
|
79
|
+
minWords: 15,
|
|
80
|
+
maxWords: 120,
|
|
81
|
+
languageTarget: "en-A2",
|
|
82
|
+
rubric: {
|
|
83
|
+
criteria: [
|
|
84
|
+
{ name: "Grammar", description: "Past tenses, articles, agreement", weight: 2 },
|
|
85
|
+
{ name: "Vocabulary", description: "Everyday words, used correctly", weight: 1 },
|
|
86
|
+
{ name: "Task", description: "Says what the learner did, in order", weight: 1 }
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
};
|
|
71
90
|
var chose = (ids) => ({
|
|
72
91
|
type: "multiple-choice",
|
|
73
92
|
selectedOptionIds: ids
|
|
@@ -81,20 +100,37 @@ var picked = (choices) => ({
|
|
|
81
100
|
selections: choices
|
|
82
101
|
});
|
|
83
102
|
var wrote = (text) => ({ type: "dictation", text });
|
|
103
|
+
var drafted = (text) => ({
|
|
104
|
+
type: "written-response",
|
|
105
|
+
text,
|
|
106
|
+
wordCount: 0
|
|
107
|
+
});
|
|
84
108
|
function explanationCase(id, about, data, response) {
|
|
85
|
-
const request =
|
|
109
|
+
const request = _chunkOPMY2MNScjs.aiExplanationRequest.call(void 0, { data, response });
|
|
86
110
|
if (request === null) {
|
|
87
111
|
throw new Error(`ai-check: no explanation request for "${id}"`);
|
|
88
112
|
}
|
|
89
113
|
return { id, feature: "explanation", about, request };
|
|
90
114
|
}
|
|
91
115
|
function hintCase(id, about, data, response, previousHints = []) {
|
|
92
|
-
const request =
|
|
116
|
+
const request = _chunkOPMY2MNScjs.aiHintRequest.call(void 0, { data, response, previousHints });
|
|
93
117
|
if (request === null) {
|
|
94
118
|
throw new Error(`ai-check: no hint request for "${id}"`);
|
|
95
119
|
}
|
|
96
120
|
return { id, feature: "hint", about, request };
|
|
97
121
|
}
|
|
122
|
+
function writingCase(id, about, text, previousFeedback = [], learnerLocale) {
|
|
123
|
+
const request = _chunkOPMY2MNScjs.aiWritingFeedbackRequest.call(void 0, {
|
|
124
|
+
data: weekend,
|
|
125
|
+
response: drafted(text),
|
|
126
|
+
previousFeedback,
|
|
127
|
+
...learnerLocale !== void 0 ? { learnerLocale } : {}
|
|
128
|
+
});
|
|
129
|
+
if (request === null) {
|
|
130
|
+
throw new Error(`ai-check: no writing feedback request for "${id}"`);
|
|
131
|
+
}
|
|
132
|
+
return { id, feature: "writing-feedback", about, request };
|
|
133
|
+
}
|
|
98
134
|
function aiCheckCases() {
|
|
99
135
|
return [
|
|
100
136
|
explanationCase("mc-correct", "Chose the right city", capital, chose(["madrid"])),
|
|
@@ -161,6 +197,29 @@ function aiCheckCases() {
|
|
|
161
197
|
landscape,
|
|
162
198
|
picked({ g1: "campo" }),
|
|
163
199
|
["Piensa en la forma del terreno."]
|
|
200
|
+
),
|
|
201
|
+
writingCase(
|
|
202
|
+
"writing-mistakes",
|
|
203
|
+
"A first draft with tense, article and agreement mistakes",
|
|
204
|
+
"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."
|
|
205
|
+
),
|
|
206
|
+
writingCase(
|
|
207
|
+
"writing-clean",
|
|
208
|
+
"A first draft with no mistakes to correct",
|
|
209
|
+
"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."
|
|
210
|
+
),
|
|
211
|
+
writingCase(
|
|
212
|
+
"writing-revised",
|
|
213
|
+
"A second draft that fixed some mistakes",
|
|
214
|
+
"Last weekend I went to the market and bought a apple. My friends was there too, so we didn't go home early.",
|
|
215
|
+
['Check your past tenses: "go" and "buyed" should be past forms.']
|
|
216
|
+
),
|
|
217
|
+
writingCase(
|
|
218
|
+
"writing-feedback-in-spanish",
|
|
219
|
+
"A first draft, with feedback asked for in Spanish",
|
|
220
|
+
"Last weekend I visit my grandmother. She cook a big lunch and we eat together in the garden.",
|
|
221
|
+
[],
|
|
222
|
+
"es"
|
|
164
223
|
)
|
|
165
224
|
];
|
|
166
225
|
}
|
|
@@ -171,13 +230,23 @@ var REFUSALS = [
|
|
|
171
230
|
"empty",
|
|
172
231
|
"too-long",
|
|
173
232
|
"contradicts-grade",
|
|
174
|
-
"reveals-answer"
|
|
233
|
+
"reveals-answer",
|
|
234
|
+
"misquotes-answer"
|
|
175
235
|
];
|
|
236
|
+
function portFor(ports, one) {
|
|
237
|
+
switch (one.request.feature) {
|
|
238
|
+
case "explanation":
|
|
239
|
+
return ports.explain;
|
|
240
|
+
case "hint":
|
|
241
|
+
return ports.hint;
|
|
242
|
+
default:
|
|
243
|
+
return ports.writingFeedback;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
176
246
|
var now = () => Date.now();
|
|
177
247
|
async function runCase(ports, one) {
|
|
178
248
|
const started = now();
|
|
179
|
-
const
|
|
180
|
-
const port = explaining ? ports.explain : ports.hint;
|
|
249
|
+
const port = portFor(ports, one);
|
|
181
250
|
if (port === void 0) {
|
|
182
251
|
throw new Error(`ai-check: no port for "${one.id}"`);
|
|
183
252
|
}
|
|
@@ -193,15 +262,36 @@ async function runCase(ports, one) {
|
|
|
193
262
|
};
|
|
194
263
|
}
|
|
195
264
|
const ms = now() - started;
|
|
196
|
-
|
|
265
|
+
if (one.request.feature === "writing-feedback") {
|
|
266
|
+
const checked2 = _chunkOPMY2MNScjs.checkAiWritingFeedback.call(void 0, raw, one.request);
|
|
267
|
+
if (checked2.ok) {
|
|
268
|
+
const { text, provenance, usage } = checked2.feedback;
|
|
269
|
+
return {
|
|
270
|
+
case: one,
|
|
271
|
+
ok: true,
|
|
272
|
+
result: {
|
|
273
|
+
text,
|
|
274
|
+
...provenance !== void 0 ? { provenance } : {},
|
|
275
|
+
...usage !== void 0 ? { usage } : {}
|
|
276
|
+
},
|
|
277
|
+
feedback: checked2.feedback,
|
|
278
|
+
ms
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return refused(one, raw, checked2.refusal, ms);
|
|
282
|
+
}
|
|
283
|
+
const checked = one.request.feature === "explanation" ? _chunkOPMY2MNScjs.checkAiExplanation.call(void 0, raw, one.request) : _chunkOPMY2MNScjs.checkAiHint.call(void 0, raw, one.request);
|
|
197
284
|
if (checked.ok) {
|
|
198
285
|
return { case: one, ok: true, result: checked.result, ms };
|
|
199
286
|
}
|
|
287
|
+
return refused(one, raw, checked.refusal, ms);
|
|
288
|
+
}
|
|
289
|
+
function refused(one, raw, refusal, ms) {
|
|
200
290
|
const text = typeof _optionalChain([raw, 'optionalAccess', _ => _.text]) === "string" ? raw : void 0;
|
|
201
291
|
return {
|
|
202
292
|
case: one,
|
|
203
293
|
ok: false,
|
|
204
|
-
refusal
|
|
294
|
+
refusal,
|
|
205
295
|
...text !== void 0 ? { result: text } : {},
|
|
206
296
|
ms
|
|
207
297
|
};
|
|
@@ -210,9 +300,7 @@ async function runAiCheck(ports, options = {}) {
|
|
|
210
300
|
const all = _nullishCoalesce(options.cases, () => ( aiCheckCases()));
|
|
211
301
|
const asked = Math.trunc(_nullishCoalesce(options.concurrency, () => ( 1)));
|
|
212
302
|
const lanes = Number.isFinite(asked) && asked >= 1 ? Math.min(asked, 16) : 1;
|
|
213
|
-
const runnable = all.filter(
|
|
214
|
-
(one) => one.request.feature === "explanation" ? ports.explain !== void 0 : ports.hint !== void 0
|
|
215
|
-
);
|
|
303
|
+
const runnable = all.filter((one) => portFor(ports, one) !== void 0);
|
|
216
304
|
const results = new Array(runnable.length);
|
|
217
305
|
let next = 0;
|
|
218
306
|
const lane = async () => {
|
|
@@ -229,13 +317,13 @@ async function runAiCheck(ports, options = {}) {
|
|
|
229
317
|
await Promise.all(Array.from({ length: Math.min(lanes, runnable.length) }, lane));
|
|
230
318
|
const byRefusal = Object.fromEntries(REFUSALS.map((reason) => [reason, 0]));
|
|
231
319
|
let shown = 0;
|
|
232
|
-
let
|
|
320
|
+
let refused2 = 0;
|
|
233
321
|
let errors = 0;
|
|
234
322
|
for (const result of results) {
|
|
235
323
|
if (result.ok) {
|
|
236
324
|
shown += 1;
|
|
237
325
|
} else if (result.refusal !== void 0) {
|
|
238
|
-
|
|
326
|
+
refused2 += 1;
|
|
239
327
|
byRefusal[result.refusal] += 1;
|
|
240
328
|
} else {
|
|
241
329
|
errors += 1;
|
|
@@ -244,7 +332,7 @@ async function runAiCheck(ports, options = {}) {
|
|
|
244
332
|
return {
|
|
245
333
|
total: results.length,
|
|
246
334
|
shown,
|
|
247
|
-
refused,
|
|
335
|
+
refused: refused2,
|
|
248
336
|
errors,
|
|
249
337
|
skipped: all.length - runnable.length,
|
|
250
338
|
byRefusal,
|
package/dist/ai-check.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/learning-kit/learning-kit/packages/lk-core/dist/ai-check.cjs","../src/ai-check/cases.ts","../src/ai-check/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7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,MAAA,CAAO,OAAO,CAAA,UAAA,EAAa,MAAA,CAAO,MAAM,CAAA,OAAA,EACvF,MAAA,CAAO,QAAA,EAAU,EAAA,EAAI,CAAA,EAAA,EAAK,MAAA,CAAO,OAAO,CAAA,kBAAA,EAAA,EAAuB,EAAE,CAAA,gBAAA,EAAc,OAAO,CAAA,GAAA;AAAA,EAC7F,CAAA;AACA,EAAA,IAAA,CAAA,MAAW,OAAA,GAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,MAAA,EAAQ,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACrC,IAAA,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAG;AACb,MAAA,KAAA,CAAM,IAAA,CAAK,CAAA,EAAA,EAAK,MAAM,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAClC,IAAA;AACF,EAAA;AACqC,EAAA;AACpB,IAAA;AACb,MAAA;AACF,IAAA;AAC8B,IAAA;AACA,IAAA;AACG,IAAA;AACJ,MAAA;AAC7B,IAAA;AACF,EAAA;AACsB,EAAA;AACxB;AFsCuC;AACA;AACA;AACA;AACA","file":"/home/runner/work/learning-kit/learning-kit/packages/lk-core/dist/ai-check.cjs","sourcesContent":[null,"import { aiExplanationRequest, aiHintRequest } from '../ai.js';\nimport type {\n DictationData,\n FillInTheBlanksData,\n GapSelectData,\n LearnerResponse,\n MultipleChoiceData,\n} from '../types/activity.js';\nimport type { AiExplanationRequest, AiHintRequest } from '../types/ai.js';\n\n/**\n * The items the cases are built from. Small, ordinary language-course content\n * — and deliberately awkward in the places a model slips:\n *\n * - an answer a hint can hardly avoid naming (`Madrid`);\n * - an answer of one short word (`is`), which a hint may write as an ordinary\n * word and must not write beside its neighbour in the passage;\n * - an accented answer (`cañón`), so a hint that spells it without the accent\n * is still caught;\n * - a passage with more than one blank, so a hint can be about the wrong one.\n */\nconst capital: MultipleChoiceData = {\n schemaVersion: '1.0',\n type: 'multiple-choice',\n id: 'ai-check-mc',\n title: 'Capital cities',\n question: 'What is the capital of Spain?',\n mode: 'single',\n scoringStrategy: 'all-or-nothing',\n options: [\n { id: 'madrid', text: 'Madrid', isCorrect: true },\n { id: 'barcelona', text: 'Barcelona', isCorrect: false },\n { id: 'seville', text: 'Seville', isCorrect: false },\n ],\n};\n\nconst introduction: FillInTheBlanksData = {\n schemaVersion: '1.0',\n type: 'fill-in-the-blanks',\n id: 'ai-check-fib',\n title: 'Introducing yourself',\n passage: 'My name {{be}} Rossi and I {{live}} in Madrid.',\n blanks: [\n { id: 'be', acceptedAnswers: ['is'] },\n { id: 'live', acceptedAnswers: ['live'], hint: 'Present simple, first person.' },\n ],\n scoringStrategy: 'partial',\n};\n\nconst landscape: GapSelectData = {\n schemaVersion: '1.0',\n type: 'gap-select',\n id: 'ai-check-gap',\n title: 'Geography',\n locale: 'es-ES',\n passage: 'El río pasa por un {{g1}} muy profundo, y el agua {{g2}} fría.',\n gaps: [\n {\n id: 'g1',\n choices: [\n { id: 'canon', text: 'cañón' },\n { id: 'campo', text: 'campo' },\n ],\n correctChoiceId: 'canon',\n },\n {\n id: 'g2',\n choices: [\n { id: 'esta', text: 'está' },\n { id: 'es', text: 'es' },\n ],\n correctChoiceId: 'esta',\n },\n ],\n scoringStrategy: 'partial',\n};\n\nconst listening: DictationData = {\n schemaVersion: '1.0',\n type: 'dictation',\n id: 'ai-check-dictation',\n title: 'Listen and type',\n transcript: 'The train leaves at half past nine.',\n};\n\n/**\n * One call to make against a host's port, and what a learner was looking at\n * when the SDK would have made it.\n */\nexport interface AiCheckCase {\n /** Stable across releases, so a host can name one in an allow-list or a report. */\n id: string;\n /** Which port the case is for. */\n feature: 'explanation' | 'hint';\n /** What the learner did, in a few words, for a report a person reads. */\n about: string;\n /** The request, built by the SDK exactly as a component builds it. */\n request: AiExplanationRequest | AiHintRequest;\n}\n\nconst chose = (ids: string[]): LearnerResponse => ({\n type: 'multiple-choice',\n selectedOptionIds: ids,\n});\nconst typed = (answers: Record<string, string>): LearnerResponse => ({\n type: 'fill-in-the-blanks',\n answers,\n});\nconst picked = (choices: Record<string, string>): LearnerResponse => ({\n type: 'gap-select',\n selections: choices,\n});\nconst wrote = (text: string): LearnerResponse => ({ type: 'dictation', text });\n\n/** Builds a case, failing loudly rather than shipping a case with no request. */\nfunction explanationCase(\n id: string,\n about: string,\n data: Parameters<typeof aiExplanationRequest>[0]['data'],\n response: LearnerResponse,\n): AiCheckCase {\n const request = aiExplanationRequest({ data, response });\n if (request === null) {\n throw new Error(`ai-check: no explanation request for \"${id}\"`);\n }\n return { id, feature: 'explanation', about, request };\n}\n\nfunction hintCase(\n id: string,\n about: string,\n data: Parameters<typeof aiHintRequest>[0]['data'],\n response: LearnerResponse,\n previousHints: string[] = [],\n): AiCheckCase {\n const request = aiHintRequest({ data, response, previousHints });\n if (request === null) {\n throw new Error(`ai-check: no hint request for \"${id}\"`);\n }\n return { id, feature: 'hint', about, request };\n}\n\n/**\n * The cases {@link runAiCheck} runs: every type the SDK explains, answered\n * right, wrong and — where a type can be — partly right; and every type it\n * hints for, before an answer and after a wrong one.\n *\n * They are ordinary calls. What makes them a test is that the SDK knows the\n * answer to each, so it can check what your model writes about it.\n *\n * A fresh array each call, so a caller may filter, slice or add to it without\n * changing what the next caller gets.\n */\nexport function aiCheckCases(): AiCheckCase[] {\n return [\n explanationCase('mc-correct', 'Chose the right city', capital, chose(['madrid'])),\n explanationCase('mc-wrong', 'Chose Barcelona', capital, chose(['barcelona'])),\n explanationCase('mc-blank', 'Chose nothing and submitted', capital, chose([])),\n explanationCase(\n 'fib-correct',\n 'Filled both blanks correctly',\n introduction,\n typed({ be: 'is', live: 'live' }),\n ),\n explanationCase(\n 'fib-partly',\n 'One blank right, one wrong',\n introduction,\n typed({ be: 'is', live: 'lives' }),\n ),\n explanationCase(\n 'fib-wrong',\n 'Both blanks wrong',\n introduction,\n typed({ be: 'are', live: 'living' }),\n ),\n explanationCase(\n 'gap-partly',\n 'One gap right, one wrong, in Spanish',\n landscape,\n picked({ g1: 'canon', g2: 'es' }),\n ),\n explanationCase(\n 'gap-wrong',\n 'Both gaps wrong, in Spanish',\n landscape,\n picked({ g1: 'campo', g2: 'es' }),\n ),\n explanationCase(\n 'dictation-near',\n 'Typed the sentence with two words wrong',\n listening,\n wrote('The train leaves at half past five'),\n ),\n explanationCase(\n 'dictation-correct',\n 'Typed the sentence correctly',\n listening,\n wrote('The train leaves at half past nine.'),\n ),\n hintCase('mc-hint-1', 'Has not answered yet', capital, chose([])),\n hintCase('mc-hint-2', 'Asked again after choosing Seville', capital, chose(['seville']), [\n 'Think about where the government sits.',\n ]),\n hintCase('fib-hint-1', 'Both blanks empty', introduction, typed({})),\n hintCase(\n 'fib-hint-2',\n 'Asked again with one blank wrong',\n introduction,\n typed({ be: 'are', live: '' }),\n ['Look again at the first blank.'],\n ),\n hintCase('gap-hint-1', 'Neither gap chosen, in Spanish', landscape, picked({})),\n hintCase(\n 'gap-hint-2',\n 'Asked again with the first gap wrong',\n landscape,\n picked({ g1: 'campo' }),\n ['Piensa en la forma del terreno.'],\n ),\n ];\n}\n","/**\n * A test kit for the prompts behind your AI ports.\n *\n * The SDK cannot test your model, and will not try. What it can do is make the\n * calls a learner's questions would make — on items whose answers it knows —\n * and run the same checks it runs before a learner sees anything. What comes\n * back is a count of what would have been shown and what would have been\n * refused, and why.\n *\n * Run it where you change a prompt or a model, in your own CI, with your own\n * key. It is a separate entry point (`@intellectif/lk-core/ai-check`) because\n * it is for your test run, not for a learner's browser: nothing here is\n * imported by anything a page renders.\n *\n * ```ts\n * import { aiCheckCases, formatAiCheckReport, runAiCheck } from '@intellectif/lk-core/ai-check';\n *\n * const report = await runAiCheck({\n * explain: (request) => callMyModel(EXPLAIN_PROMPT, request),\n * hint: (request) => callMyModel(HINT_PROMPT, request),\n * });\n * console.log(formatAiCheckReport(report));\n * if (report.refused > 0 || report.errors > 0) {\n * process.exitCode = 1;\n * }\n * ```\n *\n * A refusal is a real failure, not a warning: it is an answer a learner would\n * have asked for and not received. `reveals-answer` on a hint case is the one\n * to take most seriously — that prompt gives answers away.\n */\nimport { checkAiExplanation, checkAiHint } from '../ai.js';\nimport type { AiExplanationRequest, AiHintRequest, AiRefusal, AiTextResult } from '../types/ai.js';\nimport { type AiCheckCase, aiCheckCases } from './cases.js';\n\nexport { type AiCheckCase, aiCheckCases } from './cases.js';\n\n/**\n * Your ports, as this kit calls them. The same functions\n * `<LkAiProvider ai={…}>` takes, minus the `AbortSignal` a browser passes —\n * nothing here abandons a call.\n *\n * Leave one out and its cases are skipped rather than failed.\n */\nexport interface AiCheckPorts {\n explain?(request: AiExplanationRequest): Promise<unknown> | unknown;\n hint?(request: AiHintRequest): Promise<unknown> | unknown;\n}\n\n/** What happened on one case. */\nexport interface AiCheckResult {\n case: AiCheckCase;\n /** Whether a learner would have been shown what came back. */\n ok: boolean;\n /** Why it would not have been shown. */\n refusal?: AiRefusal;\n /** The port threw or rejected. Its message, as a string. */\n error?: string;\n /**\n * What came back, once the SDK had read it — so a refusal can be read beside\n * the text that caused it. Absent when the port failed or answered with\n * nothing the SDK could read.\n */\n result?: AiTextResult;\n /** How long the call took, in milliseconds. */\n ms: number;\n}\n\n/** What a run came to. */\nexport interface AiCheckReport {\n /** Cases run: the ones a port was supplied for. */\n total: number;\n /** Cases whose answer a learner would have been shown. */\n shown: number;\n /** Cases whose answer the SDK refused. */\n refused: number;\n /** Cases where the port itself failed. */\n errors: number;\n /** Cases skipped because no port was supplied for that feature. */\n skipped: number;\n /** How many refusals of each reason. */\n byRefusal: Record<AiRefusal, number>;\n results: AiCheckResult[];\n}\n\nexport interface AiCheckOptions {\n /**\n * The cases to run. Defaults to {@link aiCheckCases}. Pass a filtered list to\n * run one type, or your own cases — built with `aiExplanationRequest` and\n * `aiHintRequest` on your own items, which is how you test a prompt against\n * the content your learners actually see.\n */\n cases?: readonly AiCheckCase[];\n /**\n * How many cases to have in flight at once. Default 1: a run in CI hits a\n * rate limit far more often than it runs out of patience.\n */\n concurrency?: number;\n}\n\nconst REFUSALS: AiRefusal[] = [\n 'malformed',\n 'empty',\n 'too-long',\n 'contradicts-grade',\n 'reveals-answer',\n];\n\n/** Milliseconds, from whichever clock this runtime has. */\nconst now = (): number => Date.now();\n\n/** Runs one case: calls the port, times it, and checks what came back. */\nasync function runCase(ports: AiCheckPorts, one: AiCheckCase): Promise<AiCheckResult> {\n const started = now();\n const explaining = one.request.feature === 'explanation';\n const port = explaining ? ports.explain : ports.hint;\n if (port === undefined) {\n throw new Error(`ai-check: no port for \"${one.id}\"`);\n }\n let raw: unknown;\n try {\n raw = await port(one.request as never);\n } catch (error) {\n return {\n case: one,\n ok: false,\n error: error instanceof Error ? error.message : String(error),\n ms: now() - started,\n };\n }\n const ms = now() - started;\n const checked = explaining\n ? checkAiExplanation(raw, one.request as AiExplanationRequest)\n : checkAiHint(raw, one.request as AiHintRequest);\n if (checked.ok) {\n return { case: one, ok: true, result: checked.result, ms };\n }\n const text =\n typeof (raw as { text?: unknown })?.text === 'string' ? (raw as AiTextResult) : undefined;\n return {\n case: one,\n ok: false,\n refusal: checked.refusal,\n ...(text !== undefined ? { result: text } : {}),\n ms,\n };\n}\n\n/**\n * Calls your ports on every case and reports what a learner would have seen.\n *\n * It never throws for a failing case: a port that rejects is an `error` in the\n * report, so one bad call cannot hide the rest.\n */\nexport async function runAiCheck(\n ports: AiCheckPorts,\n options: AiCheckOptions = {},\n): Promise<AiCheckReport> {\n const all = options.cases ?? aiCheckCases();\n const asked = Math.trunc(options.concurrency ?? 1);\n const lanes = Number.isFinite(asked) && asked >= 1 ? Math.min(asked, 16) : 1;\n const runnable = all.filter((one) =>\n one.request.feature === 'explanation' ? ports.explain !== undefined : ports.hint !== undefined,\n );\n const results: AiCheckResult[] = new Array(runnable.length);\n let next = 0;\n const lane = async (): Promise<void> => {\n while (next < runnable.length) {\n const mine = next;\n next += 1;\n const one = runnable[mine];\n if (one === undefined) {\n return;\n }\n results[mine] = await runCase(ports, one);\n }\n };\n await Promise.all(Array.from({ length: Math.min(lanes, runnable.length) }, lane));\n\n const byRefusal = Object.fromEntries(REFUSALS.map((reason) => [reason, 0])) as Record<\n AiRefusal,\n number\n >;\n let shown = 0;\n let refused = 0;\n let errors = 0;\n for (const result of results) {\n if (result.ok) {\n shown += 1;\n } else if (result.refusal !== undefined) {\n refused += 1;\n byRefusal[result.refusal] += 1;\n } else {\n errors += 1;\n }\n }\n return {\n total: results.length,\n shown,\n refused,\n errors,\n skipped: all.length - runnable.length,\n byRefusal,\n results,\n };\n}\n\n/**\n * The report as a few lines for a CI log: the counts, then every case that\n * failed, with what came back.\n *\n * The refused text is printed — this is your own test run, not a learner's\n * screen, and a hint that gives the answer away is only fixable if you can\n * read it.\n */\nexport function formatAiCheckReport(report: AiCheckReport): string {\n const lines: string[] = [];\n const slowest = report.results.reduce((worst, one) => Math.max(worst, one.ms), 0);\n lines.push(\n `ai-check: ${report.shown}/${report.total} shown, ${report.refused} refused, ${report.errors} failed` +\n `${report.skipped > 0 ? `, ${report.skipped} skipped (no port)` : ''} — slowest ${slowest} ms`,\n );\n for (const reason of REFUSALS) {\n const count = report.byRefusal[reason];\n if (count > 0) {\n lines.push(` ${reason}: ${count}`);\n }\n }\n for (const result of report.results) {\n if (result.ok) {\n continue;\n }\n const why = result.refusal ?? `port failed (${result.error ?? 'no message'})`;\n lines.push(` ✗ ${result.case.id} [${result.case.feature}] ${result.case.about}: ${why}`);\n if (result.result !== undefined) {\n lines.push(` ${result.result.text.replace(/\\s+/g, ' ').slice(0, 200)}`);\n }\n }\n return lines.join('\\n');\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/learning-kit/learning-kit/packages/lk-core/dist/ai-check.cjs","../src/ai-check/cases.ts","../src/ai-check/index.ts"],"names":["checked","refused"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B,gCAA6B;AAC7B;AACA;ACeA,IAAM,QAAA,EAA8B;AAAA,EAClC,aAAA,EAAe,KAAA;AAAA,EACf,IAA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,EAAA,MAAM,QAAA,EAAU,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,CAAC,KAAA,EAAO,GAAA,EAAA,GAAQ,IAAA,CAAK,GAAA,CAAI,KAAA,EAAO,GAAA,CAAI,EAAE,CAAA,EAAG,CAAC,CAAA;AAChF,EAAA,KAAA,CAAM,IAAA;AAAA,IACJ,CAAA,UAAA,EAAa,MAAA,CAAO,KAAK,CAAA,CAAA,EAAI,MAAA,CAAO,KAAK,CAAA,QAAA,EAAW,MAAA,CAAO,OAAO,CAAA,UAAA,EAAa,MAAA,CAAO,MAAM,CAAA,OAAA,EACvF,MAAA,CAAO,QAAA,EAAU,EAAA,EAAI,CAAA,EAAA,EAAK,MAAA,CAAO,OAAO,CAAA,kBAAA,EAAA,EAAuB,EAAE,CAAA,gBAAA,EAAc,OAAO,CAAA,GAAA;AAAA,EAC7F,CAAA;AACA,EAAA,IAAA,CAAA,MAAW,OAAA,GAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,MAAA,EAAQ,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACrC,IAAA,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAG;AACb,MAAA,KAAA,CAAM,IAAA,CAAK,CAAA,EAAA,EAAK,MAAM,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAClC,IAAA;AACF,EAAA;AACqC,EAAA;AACpB,IAAA;AACb,MAAA;AACF,IAAA;AAC8B,IAAA;AACA,IAAA;AACG,IAAA;AACJ,MAAA;AAC7B,IAAA;AACF,EAAA;AACsB,EAAA;AACxB;AF2EuC;AACA;AACA;AACA;AACA","file":"/home/runner/work/learning-kit/learning-kit/packages/lk-core/dist/ai-check.cjs","sourcesContent":[null,"import { aiExplanationRequest, aiHintRequest } from '../ai.js';\nimport { aiWritingFeedbackRequest } from '../ai-writing.js';\nimport type {\n DictationData,\n FillInTheBlanksData,\n GapSelectData,\n LearnerResponse,\n MultipleChoiceData,\n WrittenResponseData,\n} from '../types/activity.js';\nimport type { AiExplanationRequest, AiHintRequest, AiWritingFeedbackRequest } from '../types/ai.js';\n\n/**\n * The items the cases are built from. Small, ordinary language-course content\n * — and deliberately awkward in the places a model slips:\n *\n * - an answer a hint can hardly avoid naming (`Madrid`);\n * - an answer of one short word (`is`), which a hint may write as an ordinary\n * word and must not write beside its neighbour in the passage;\n * - an accented answer (`cañón`), so a hint that spells it without the accent\n * is still caught;\n * - a passage with more than one blank, so a hint can be about the wrong one;\n * - a short essay whose mistakes a model must quote exactly as the learner\n * wrote them — straight apostrophes a model likes to curl, a mistake made\n * twice — so a correction of words nobody wrote is caught.\n */\nconst capital: MultipleChoiceData = {\n schemaVersion: '1.0',\n type: 'multiple-choice',\n id: 'ai-check-mc',\n title: 'Capital cities',\n question: 'What is the capital of Spain?',\n mode: 'single',\n scoringStrategy: 'all-or-nothing',\n options: [\n { id: 'madrid', text: 'Madrid', isCorrect: true },\n { id: 'barcelona', text: 'Barcelona', isCorrect: false },\n { id: 'seville', text: 'Seville', isCorrect: false },\n ],\n};\n\nconst introduction: FillInTheBlanksData = {\n schemaVersion: '1.0',\n type: 'fill-in-the-blanks',\n id: 'ai-check-fib',\n title: 'Introducing yourself',\n passage: 'My name {{be}} Rossi and I {{live}} in Madrid.',\n blanks: [\n { id: 'be', acceptedAnswers: ['is'] },\n { id: 'live', acceptedAnswers: ['live'], hint: 'Present simple, first person.' },\n ],\n scoringStrategy: 'partial',\n};\n\nconst landscape: GapSelectData = {\n schemaVersion: '1.0',\n type: 'gap-select',\n id: 'ai-check-gap',\n title: 'Geography',\n locale: 'es-ES',\n passage: 'El río pasa por un {{g1}} muy profundo, y el agua {{g2}} fría.',\n gaps: [\n {\n id: 'g1',\n choices: [\n { id: 'canon', text: 'cañón' },\n { id: 'campo', text: 'campo' },\n ],\n correctChoiceId: 'canon',\n },\n {\n id: 'g2',\n choices: [\n { id: 'esta', text: 'está' },\n { id: 'es', text: 'es' },\n ],\n correctChoiceId: 'esta',\n },\n ],\n scoringStrategy: 'partial',\n};\n\nconst listening: DictationData = {\n schemaVersion: '1.0',\n type: 'dictation',\n id: 'ai-check-dictation',\n title: 'Listen and type',\n transcript: 'The train leaves at half past nine.',\n};\n\nconst weekend: WrittenResponseData = {\n schemaVersion: '1.0',\n type: 'written-response',\n id: 'ai-check-writing',\n title: 'Your weekend',\n prompt: 'Write a few sentences about what you did last weekend.',\n minWords: 15,\n maxWords: 120,\n languageTarget: 'en-A2',\n rubric: {\n criteria: [\n { name: 'Grammar', description: 'Past tenses, articles, agreement', weight: 2 },\n { name: 'Vocabulary', description: 'Everyday words, used correctly', weight: 1 },\n { name: 'Task', description: 'Says what the learner did, in order', weight: 1 },\n ],\n },\n};\n\n/**\n * One call to make against a host's port, and what a learner was looking at\n * when the SDK would have made it.\n */\nexport interface AiCheckCase {\n /** Stable across releases, so a host can name one in an allow-list or a report. */\n id: string;\n /** Which port the case is for. */\n feature: 'explanation' | 'hint' | 'writing-feedback';\n /** What the learner did, in a few words, for a report a person reads. */\n about: string;\n /** The request, built by the SDK exactly as a component builds it. */\n request: AiExplanationRequest | AiHintRequest | AiWritingFeedbackRequest;\n}\n\nconst chose = (ids: string[]): LearnerResponse => ({\n type: 'multiple-choice',\n selectedOptionIds: ids,\n});\nconst typed = (answers: Record<string, string>): LearnerResponse => ({\n type: 'fill-in-the-blanks',\n answers,\n});\nconst picked = (choices: Record<string, string>): LearnerResponse => ({\n type: 'gap-select',\n selections: choices,\n});\nconst wrote = (text: string): LearnerResponse => ({ type: 'dictation', text });\nconst drafted = (text: string): LearnerResponse => ({\n type: 'written-response',\n text,\n wordCount: 0,\n});\n\n/** Builds a case, failing loudly rather than shipping a case with no request. */\nfunction explanationCase(\n id: string,\n about: string,\n data: Parameters<typeof aiExplanationRequest>[0]['data'],\n response: LearnerResponse,\n): AiCheckCase {\n const request = aiExplanationRequest({ data, response });\n if (request === null) {\n throw new Error(`ai-check: no explanation request for \"${id}\"`);\n }\n return { id, feature: 'explanation', about, request };\n}\n\nfunction hintCase(\n id: string,\n about: string,\n data: Parameters<typeof aiHintRequest>[0]['data'],\n response: LearnerResponse,\n previousHints: string[] = [],\n): AiCheckCase {\n const request = aiHintRequest({ data, response, previousHints });\n if (request === null) {\n throw new Error(`ai-check: no hint request for \"${id}\"`);\n }\n return { id, feature: 'hint', about, request };\n}\n\nfunction writingCase(\n id: string,\n about: string,\n text: string,\n previousFeedback: string[] = [],\n learnerLocale?: string,\n): AiCheckCase {\n const request = aiWritingFeedbackRequest({\n data: weekend,\n response: drafted(text),\n previousFeedback,\n ...(learnerLocale !== undefined ? { learnerLocale } : {}),\n });\n if (request === null) {\n throw new Error(`ai-check: no writing feedback request for \"${id}\"`);\n }\n return { id, feature: 'writing-feedback', about, request };\n}\n\n/**\n * The cases {@link runAiCheck} runs: every type the SDK explains, answered\n * right, wrong and — where a type can be — partly right; every type it hints\n * for, before an answer and after a wrong one; and drafts of an essay, with\n * mistakes, without, and revised.\n *\n * They are ordinary calls. What makes them a test is that the SDK knows the\n * answer to each, so it can check what your model writes about it.\n *\n * A fresh array each call, so a caller may filter, slice or add to it without\n * changing what the next caller gets.\n */\nexport function aiCheckCases(): AiCheckCase[] {\n return [\n explanationCase('mc-correct', 'Chose the right city', capital, chose(['madrid'])),\n explanationCase('mc-wrong', 'Chose Barcelona', capital, chose(['barcelona'])),\n explanationCase('mc-blank', 'Chose nothing and submitted', capital, chose([])),\n explanationCase(\n 'fib-correct',\n 'Filled both blanks correctly',\n introduction,\n typed({ be: 'is', live: 'live' }),\n ),\n explanationCase(\n 'fib-partly',\n 'One blank right, one wrong',\n introduction,\n typed({ be: 'is', live: 'lives' }),\n ),\n explanationCase(\n 'fib-wrong',\n 'Both blanks wrong',\n introduction,\n typed({ be: 'are', live: 'living' }),\n ),\n explanationCase(\n 'gap-partly',\n 'One gap right, one wrong, in Spanish',\n landscape,\n picked({ g1: 'canon', g2: 'es' }),\n ),\n explanationCase(\n 'gap-wrong',\n 'Both gaps wrong, in Spanish',\n landscape,\n picked({ g1: 'campo', g2: 'es' }),\n ),\n explanationCase(\n 'dictation-near',\n 'Typed the sentence with two words wrong',\n listening,\n wrote('The train leaves at half past five'),\n ),\n explanationCase(\n 'dictation-correct',\n 'Typed the sentence correctly',\n listening,\n wrote('The train leaves at half past nine.'),\n ),\n hintCase('mc-hint-1', 'Has not answered yet', capital, chose([])),\n hintCase('mc-hint-2', 'Asked again after choosing Seville', capital, chose(['seville']), [\n 'Think about where the government sits.',\n ]),\n hintCase('fib-hint-1', 'Both blanks empty', introduction, typed({})),\n hintCase(\n 'fib-hint-2',\n 'Asked again with one blank wrong',\n introduction,\n typed({ be: 'are', live: '' }),\n ['Look again at the first blank.'],\n ),\n hintCase('gap-hint-1', 'Neither gap chosen, in Spanish', landscape, picked({})),\n hintCase(\n 'gap-hint-2',\n 'Asked again with the first gap wrong',\n landscape,\n picked({ g1: 'campo' }),\n ['Piensa en la forma del terreno.'],\n ),\n writingCase(\n 'writing-mistakes',\n 'A first draft with tense, article and agreement mistakes',\n \"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.\",\n ),\n writingCase(\n 'writing-clean',\n 'A first draft with no mistakes to correct',\n '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.',\n ),\n writingCase(\n 'writing-revised',\n 'A second draft that fixed some mistakes',\n \"Last weekend I went to the market and bought a apple. My friends was there too, so we didn't go home early.\",\n ['Check your past tenses: \"go\" and \"buyed\" should be past forms.'],\n ),\n writingCase(\n 'writing-feedback-in-spanish',\n 'A first draft, with feedback asked for in Spanish',\n 'Last weekend I visit my grandmother. She cook a big lunch and we eat together in the garden.',\n [],\n 'es',\n ),\n ];\n}\n","/**\n * A test kit for the prompts behind your AI ports.\n *\n * The SDK cannot test your model, and will not try. What it can do is make the\n * calls a learner's questions would make — on items whose answers it knows —\n * and run the same checks it runs before a learner sees anything. What comes\n * back is a count of what would have been shown and what would have been\n * refused, and why.\n *\n * Run it where you change a prompt or a model, in your own CI, with your own\n * key. It is a separate entry point (`@intellectif/lk-core/ai-check`) because\n * it is for your test run, not for a learner's browser: nothing here is\n * imported by anything a page renders.\n *\n * ```ts\n * import { aiCheckCases, formatAiCheckReport, runAiCheck } from '@intellectif/lk-core/ai-check';\n *\n * const report = await runAiCheck({\n * explain: (request) => callMyModel(EXPLAIN_PROMPT, request),\n * hint: (request) => callMyModel(HINT_PROMPT, request),\n * writingFeedback: (request) => callMyModel(FEEDBACK_PROMPT, request),\n * });\n * console.log(formatAiCheckReport(report));\n * if (report.refused > 0 || report.errors > 0) {\n * process.exitCode = 1;\n * }\n * ```\n *\n * A refusal is a real failure, not a warning: it is an answer a learner would\n * have asked for and not received. `reveals-answer` on a hint case is the one\n * to take most seriously — that prompt gives answers away — and\n * `misquotes-answer` on a writing case the next: that prompt corrects words the\n * learner never wrote.\n */\nimport { checkAiExplanation, checkAiHint } from '../ai.js';\nimport { checkAiWritingFeedback } from '../ai-writing.js';\nimport type {\n AiExplanationRequest,\n AiHintRequest,\n AiRefusal,\n AiTextResult,\n AiWritingFeedback,\n AiWritingFeedbackRequest,\n} from '../types/ai.js';\nimport { type AiCheckCase, aiCheckCases } from './cases.js';\n\nexport { type AiCheckCase, aiCheckCases } from './cases.js';\n\n/**\n * Your ports, as this kit calls them. The same functions\n * `<LkAiProvider ai={…}>` takes, minus the `AbortSignal` a browser passes —\n * nothing here abandons a call.\n *\n * Leave one out and its cases are skipped rather than failed.\n */\nexport interface AiCheckPorts {\n explain?(request: AiExplanationRequest): Promise<unknown> | unknown;\n hint?(request: AiHintRequest): Promise<unknown> | unknown;\n writingFeedback?(request: AiWritingFeedbackRequest): Promise<unknown> | unknown;\n}\n\n/** What happened on one case. */\nexport interface AiCheckResult {\n case: AiCheckCase;\n /** Whether a learner would have been shown what came back. */\n ok: boolean;\n /** Why it would not have been shown. */\n refusal?: AiRefusal;\n /** The port threw or rejected. Its message, as a string. */\n error?: string;\n /**\n * What came back, once the SDK had read it — so a refusal can be read beside\n * the text that caused it. Absent when the port failed or answered with\n * nothing the SDK could read.\n */\n result?: AiTextResult;\n /** For a writing case a learner would have been shown: the feedback, as the SDK accepted it. */\n feedback?: AiWritingFeedback;\n /** How long the call took, in milliseconds. */\n ms: number;\n}\n\n/** What a run came to. */\nexport interface AiCheckReport {\n /** Cases run: the ones a port was supplied for. */\n total: number;\n /** Cases whose answer a learner would have been shown. */\n shown: number;\n /** Cases whose answer the SDK refused. */\n refused: number;\n /** Cases where the port itself failed. */\n errors: number;\n /** Cases skipped because no port was supplied for that feature. */\n skipped: number;\n /** How many refusals of each reason. */\n byRefusal: Record<AiRefusal, number>;\n results: AiCheckResult[];\n}\n\nexport interface AiCheckOptions {\n /**\n * The cases to run. Defaults to {@link aiCheckCases}. Pass a filtered list to\n * run one type, or your own cases — built with `aiExplanationRequest` and\n * `aiHintRequest` on your own items, which is how you test a prompt against\n * the content your learners actually see.\n */\n cases?: readonly AiCheckCase[];\n /**\n * How many cases to have in flight at once. Default 1: a run in CI hits a\n * rate limit far more often than it runs out of patience.\n */\n concurrency?: number;\n}\n\nconst REFUSALS: AiRefusal[] = [\n 'malformed',\n 'empty',\n 'too-long',\n 'contradicts-grade',\n 'reveals-answer',\n 'misquotes-answer',\n];\n\n/** The port a case is for. */\nfunction portFor(\n ports: AiCheckPorts,\n one: AiCheckCase,\n): ((request: never) => Promise<unknown> | unknown) | undefined {\n switch (one.request.feature) {\n case 'explanation':\n return ports.explain as never;\n case 'hint':\n return ports.hint as never;\n default:\n return ports.writingFeedback as never;\n }\n}\n\n/** Milliseconds, from whichever clock this runtime has. */\nconst now = (): number => Date.now();\n\n/** Runs one case: calls the port, times it, and checks what came back. */\nasync function runCase(ports: AiCheckPorts, one: AiCheckCase): Promise<AiCheckResult> {\n const started = now();\n const port = portFor(ports, one);\n if (port === undefined) {\n throw new Error(`ai-check: no port for \"${one.id}\"`);\n }\n let raw: unknown;\n try {\n raw = await port(one.request as never);\n } catch (error) {\n return {\n case: one,\n ok: false,\n error: error instanceof Error ? error.message : String(error),\n ms: now() - started,\n };\n }\n const ms = now() - started;\n if (one.request.feature === 'writing-feedback') {\n const checked = checkAiWritingFeedback(raw, one.request);\n if (checked.ok) {\n const { text, provenance, usage } = checked.feedback;\n return {\n case: one,\n ok: true,\n result: {\n text,\n ...(provenance !== undefined ? { provenance } : {}),\n ...(usage !== undefined ? { usage } : {}),\n },\n feedback: checked.feedback,\n ms,\n };\n }\n return refused(one, raw, checked.refusal, ms);\n }\n const checked =\n one.request.feature === 'explanation'\n ? checkAiExplanation(raw, one.request)\n : checkAiHint(raw, one.request);\n if (checked.ok) {\n return { case: one, ok: true, result: checked.result, ms };\n }\n return refused(one, raw, checked.refusal, ms);\n}\n\n/** A case whose answer was refused, with the text that came back when there was one to read. */\nfunction refused(one: AiCheckCase, raw: unknown, refusal: AiRefusal, ms: number): AiCheckResult {\n const text =\n typeof (raw as { text?: unknown })?.text === 'string' ? (raw as AiTextResult) : undefined;\n return {\n case: one,\n ok: false,\n refusal,\n ...(text !== undefined ? { result: text } : {}),\n ms,\n };\n}\n\n/**\n * Calls your ports on every case and reports what a learner would have seen.\n *\n * It never throws for a failing case: a port that rejects is an `error` in the\n * report, so one bad call cannot hide the rest.\n */\nexport async function runAiCheck(\n ports: AiCheckPorts,\n options: AiCheckOptions = {},\n): Promise<AiCheckReport> {\n const all = options.cases ?? aiCheckCases();\n const asked = Math.trunc(options.concurrency ?? 1);\n const lanes = Number.isFinite(asked) && asked >= 1 ? Math.min(asked, 16) : 1;\n const runnable = all.filter((one) => portFor(ports, one) !== undefined);\n const results: AiCheckResult[] = new Array(runnable.length);\n let next = 0;\n const lane = async (): Promise<void> => {\n while (next < runnable.length) {\n const mine = next;\n next += 1;\n const one = runnable[mine];\n if (one === undefined) {\n return;\n }\n results[mine] = await runCase(ports, one);\n }\n };\n await Promise.all(Array.from({ length: Math.min(lanes, runnable.length) }, lane));\n\n const byRefusal = Object.fromEntries(REFUSALS.map((reason) => [reason, 0])) as Record<\n AiRefusal,\n number\n >;\n let shown = 0;\n let refused = 0;\n let errors = 0;\n for (const result of results) {\n if (result.ok) {\n shown += 1;\n } else if (result.refusal !== undefined) {\n refused += 1;\n byRefusal[result.refusal] += 1;\n } else {\n errors += 1;\n }\n }\n return {\n total: results.length,\n shown,\n refused,\n errors,\n skipped: all.length - runnable.length,\n byRefusal,\n results,\n };\n}\n\n/**\n * The report as a few lines for a CI log: the counts, then every case that\n * failed, with what came back.\n *\n * The refused text is printed — this is your own test run, not a learner's\n * screen, and a hint that gives the answer away is only fixable if you can\n * read it.\n */\nexport function formatAiCheckReport(report: AiCheckReport): string {\n const lines: string[] = [];\n const slowest = report.results.reduce((worst, one) => Math.max(worst, one.ms), 0);\n lines.push(\n `ai-check: ${report.shown}/${report.total} shown, ${report.refused} refused, ${report.errors} failed` +\n `${report.skipped > 0 ? `, ${report.skipped} skipped (no port)` : ''} — slowest ${slowest} ms`,\n );\n for (const reason of REFUSALS) {\n const count = report.byRefusal[reason];\n if (count > 0) {\n lines.push(` ${reason}: ${count}`);\n }\n }\n for (const result of report.results) {\n if (result.ok) {\n continue;\n }\n const why = result.refusal ?? `port failed (${result.error ?? 'no message'})`;\n lines.push(` ✗ ${result.case.id} [${result.case.feature}] ${result.case.about}: ${why}`);\n if (result.result !== undefined) {\n lines.push(` ${result.result.text.replace(/\\s+/g, ' ').slice(0, 200)}`);\n }\n }\n return lines.join('\\n');\n}\n"]}
|
package/dist/ai-check.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { k as AiExplanationRequest, q as AiHintRequest, F as AiWritingFeedbackRequest, v as AiRefusal, y as AiTextResult, E as AiWritingFeedback } from './activity-CYc7SD3d.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* One call to make against a host's port, and what a learner was looking at
|
|
@@ -8,16 +8,17 @@ interface AiCheckCase {
|
|
|
8
8
|
/** Stable across releases, so a host can name one in an allow-list or a report. */
|
|
9
9
|
id: string;
|
|
10
10
|
/** Which port the case is for. */
|
|
11
|
-
feature: 'explanation' | 'hint';
|
|
11
|
+
feature: 'explanation' | 'hint' | 'writing-feedback';
|
|
12
12
|
/** What the learner did, in a few words, for a report a person reads. */
|
|
13
13
|
about: string;
|
|
14
14
|
/** The request, built by the SDK exactly as a component builds it. */
|
|
15
|
-
request: AiExplanationRequest | AiHintRequest;
|
|
15
|
+
request: AiExplanationRequest | AiHintRequest | AiWritingFeedbackRequest;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The cases {@link runAiCheck} runs: every type the SDK explains, answered
|
|
19
|
-
* right, wrong and — where a type can be — partly right;
|
|
20
|
-
*
|
|
19
|
+
* right, wrong and — where a type can be — partly right; every type it hints
|
|
20
|
+
* for, before an answer and after a wrong one; and drafts of an essay, with
|
|
21
|
+
* mistakes, without, and revised.
|
|
21
22
|
*
|
|
22
23
|
* They are ordinary calls. What makes them a test is that the SDK knows the
|
|
23
24
|
* answer to each, so it can check what your model writes about it.
|
|
@@ -37,6 +38,7 @@ declare function aiCheckCases(): AiCheckCase[];
|
|
|
37
38
|
interface AiCheckPorts {
|
|
38
39
|
explain?(request: AiExplanationRequest): Promise<unknown> | unknown;
|
|
39
40
|
hint?(request: AiHintRequest): Promise<unknown> | unknown;
|
|
41
|
+
writingFeedback?(request: AiWritingFeedbackRequest): Promise<unknown> | unknown;
|
|
40
42
|
}
|
|
41
43
|
/** What happened on one case. */
|
|
42
44
|
interface AiCheckResult {
|
|
@@ -53,6 +55,8 @@ interface AiCheckResult {
|
|
|
53
55
|
* nothing the SDK could read.
|
|
54
56
|
*/
|
|
55
57
|
result?: AiTextResult;
|
|
58
|
+
/** For a writing case a learner would have been shown: the feedback, as the SDK accepted it. */
|
|
59
|
+
feedback?: AiWritingFeedback;
|
|
56
60
|
/** How long the call took, in milliseconds. */
|
|
57
61
|
ms: number;
|
|
58
62
|
}
|
package/dist/ai-check.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { k as AiExplanationRequest, q as AiHintRequest, F as AiWritingFeedbackRequest, v as AiRefusal, y as AiTextResult, E as AiWritingFeedback } from './activity-CYc7SD3d.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* One call to make against a host's port, and what a learner was looking at
|
|
@@ -8,16 +8,17 @@ interface AiCheckCase {
|
|
|
8
8
|
/** Stable across releases, so a host can name one in an allow-list or a report. */
|
|
9
9
|
id: string;
|
|
10
10
|
/** Which port the case is for. */
|
|
11
|
-
feature: 'explanation' | 'hint';
|
|
11
|
+
feature: 'explanation' | 'hint' | 'writing-feedback';
|
|
12
12
|
/** What the learner did, in a few words, for a report a person reads. */
|
|
13
13
|
about: string;
|
|
14
14
|
/** The request, built by the SDK exactly as a component builds it. */
|
|
15
|
-
request: AiExplanationRequest | AiHintRequest;
|
|
15
|
+
request: AiExplanationRequest | AiHintRequest | AiWritingFeedbackRequest;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The cases {@link runAiCheck} runs: every type the SDK explains, answered
|
|
19
|
-
* right, wrong and — where a type can be — partly right;
|
|
20
|
-
*
|
|
19
|
+
* right, wrong and — where a type can be — partly right; every type it hints
|
|
20
|
+
* for, before an answer and after a wrong one; and drafts of an essay, with
|
|
21
|
+
* mistakes, without, and revised.
|
|
21
22
|
*
|
|
22
23
|
* They are ordinary calls. What makes them a test is that the SDK knows the
|
|
23
24
|
* answer to each, so it can check what your model writes about it.
|
|
@@ -37,6 +38,7 @@ declare function aiCheckCases(): AiCheckCase[];
|
|
|
37
38
|
interface AiCheckPorts {
|
|
38
39
|
explain?(request: AiExplanationRequest): Promise<unknown> | unknown;
|
|
39
40
|
hint?(request: AiHintRequest): Promise<unknown> | unknown;
|
|
41
|
+
writingFeedback?(request: AiWritingFeedbackRequest): Promise<unknown> | unknown;
|
|
40
42
|
}
|
|
41
43
|
/** What happened on one case. */
|
|
42
44
|
interface AiCheckResult {
|
|
@@ -53,6 +55,8 @@ interface AiCheckResult {
|
|
|
53
55
|
* nothing the SDK could read.
|
|
54
56
|
*/
|
|
55
57
|
result?: AiTextResult;
|
|
58
|
+
/** For a writing case a learner would have been shown: the feedback, as the SDK accepted it. */
|
|
59
|
+
feedback?: AiWritingFeedback;
|
|
56
60
|
/** How long the call took, in milliseconds. */
|
|
57
61
|
ms: number;
|
|
58
62
|
}
|
package/dist/ai-check.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
aiExplanationRequest,
|
|
3
3
|
aiHintRequest,
|
|
4
|
+
aiWritingFeedbackRequest,
|
|
4
5
|
checkAiExplanation,
|
|
5
|
-
checkAiHint
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
checkAiHint,
|
|
7
|
+
checkAiWritingFeedback
|
|
8
|
+
} from "./chunk-5UCR4UNR.js";
|
|
9
|
+
import "./chunk-Q7MV3IXJ.js";
|
|
8
10
|
import "./chunk-D3GP5MET.js";
|
|
9
11
|
|
|
10
12
|
// src/ai-check/cases.ts
|
|
@@ -68,6 +70,23 @@ var listening = {
|
|
|
68
70
|
title: "Listen and type",
|
|
69
71
|
transcript: "The train leaves at half past nine."
|
|
70
72
|
};
|
|
73
|
+
var weekend = {
|
|
74
|
+
schemaVersion: "1.0",
|
|
75
|
+
type: "written-response",
|
|
76
|
+
id: "ai-check-writing",
|
|
77
|
+
title: "Your weekend",
|
|
78
|
+
prompt: "Write a few sentences about what you did last weekend.",
|
|
79
|
+
minWords: 15,
|
|
80
|
+
maxWords: 120,
|
|
81
|
+
languageTarget: "en-A2",
|
|
82
|
+
rubric: {
|
|
83
|
+
criteria: [
|
|
84
|
+
{ name: "Grammar", description: "Past tenses, articles, agreement", weight: 2 },
|
|
85
|
+
{ name: "Vocabulary", description: "Everyday words, used correctly", weight: 1 },
|
|
86
|
+
{ name: "Task", description: "Says what the learner did, in order", weight: 1 }
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
};
|
|
71
90
|
var chose = (ids) => ({
|
|
72
91
|
type: "multiple-choice",
|
|
73
92
|
selectedOptionIds: ids
|
|
@@ -81,6 +100,11 @@ var picked = (choices) => ({
|
|
|
81
100
|
selections: choices
|
|
82
101
|
});
|
|
83
102
|
var wrote = (text) => ({ type: "dictation", text });
|
|
103
|
+
var drafted = (text) => ({
|
|
104
|
+
type: "written-response",
|
|
105
|
+
text,
|
|
106
|
+
wordCount: 0
|
|
107
|
+
});
|
|
84
108
|
function explanationCase(id, about, data, response) {
|
|
85
109
|
const request = aiExplanationRequest({ data, response });
|
|
86
110
|
if (request === null) {
|
|
@@ -95,6 +119,18 @@ function hintCase(id, about, data, response, previousHints = []) {
|
|
|
95
119
|
}
|
|
96
120
|
return { id, feature: "hint", about, request };
|
|
97
121
|
}
|
|
122
|
+
function writingCase(id, about, text, previousFeedback = [], learnerLocale) {
|
|
123
|
+
const request = aiWritingFeedbackRequest({
|
|
124
|
+
data: weekend,
|
|
125
|
+
response: drafted(text),
|
|
126
|
+
previousFeedback,
|
|
127
|
+
...learnerLocale !== void 0 ? { learnerLocale } : {}
|
|
128
|
+
});
|
|
129
|
+
if (request === null) {
|
|
130
|
+
throw new Error(`ai-check: no writing feedback request for "${id}"`);
|
|
131
|
+
}
|
|
132
|
+
return { id, feature: "writing-feedback", about, request };
|
|
133
|
+
}
|
|
98
134
|
function aiCheckCases() {
|
|
99
135
|
return [
|
|
100
136
|
explanationCase("mc-correct", "Chose the right city", capital, chose(["madrid"])),
|
|
@@ -161,6 +197,29 @@ function aiCheckCases() {
|
|
|
161
197
|
landscape,
|
|
162
198
|
picked({ g1: "campo" }),
|
|
163
199
|
["Piensa en la forma del terreno."]
|
|
200
|
+
),
|
|
201
|
+
writingCase(
|
|
202
|
+
"writing-mistakes",
|
|
203
|
+
"A first draft with tense, article and agreement mistakes",
|
|
204
|
+
"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."
|
|
205
|
+
),
|
|
206
|
+
writingCase(
|
|
207
|
+
"writing-clean",
|
|
208
|
+
"A first draft with no mistakes to correct",
|
|
209
|
+
"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."
|
|
210
|
+
),
|
|
211
|
+
writingCase(
|
|
212
|
+
"writing-revised",
|
|
213
|
+
"A second draft that fixed some mistakes",
|
|
214
|
+
"Last weekend I went to the market and bought a apple. My friends was there too, so we didn't go home early.",
|
|
215
|
+
['Check your past tenses: "go" and "buyed" should be past forms.']
|
|
216
|
+
),
|
|
217
|
+
writingCase(
|
|
218
|
+
"writing-feedback-in-spanish",
|
|
219
|
+
"A first draft, with feedback asked for in Spanish",
|
|
220
|
+
"Last weekend I visit my grandmother. She cook a big lunch and we eat together in the garden.",
|
|
221
|
+
[],
|
|
222
|
+
"es"
|
|
164
223
|
)
|
|
165
224
|
];
|
|
166
225
|
}
|
|
@@ -171,13 +230,23 @@ var REFUSALS = [
|
|
|
171
230
|
"empty",
|
|
172
231
|
"too-long",
|
|
173
232
|
"contradicts-grade",
|
|
174
|
-
"reveals-answer"
|
|
233
|
+
"reveals-answer",
|
|
234
|
+
"misquotes-answer"
|
|
175
235
|
];
|
|
236
|
+
function portFor(ports, one) {
|
|
237
|
+
switch (one.request.feature) {
|
|
238
|
+
case "explanation":
|
|
239
|
+
return ports.explain;
|
|
240
|
+
case "hint":
|
|
241
|
+
return ports.hint;
|
|
242
|
+
default:
|
|
243
|
+
return ports.writingFeedback;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
176
246
|
var now = () => Date.now();
|
|
177
247
|
async function runCase(ports, one) {
|
|
178
248
|
const started = now();
|
|
179
|
-
const
|
|
180
|
-
const port = explaining ? ports.explain : ports.hint;
|
|
249
|
+
const port = portFor(ports, one);
|
|
181
250
|
if (port === void 0) {
|
|
182
251
|
throw new Error(`ai-check: no port for "${one.id}"`);
|
|
183
252
|
}
|
|
@@ -193,15 +262,36 @@ async function runCase(ports, one) {
|
|
|
193
262
|
};
|
|
194
263
|
}
|
|
195
264
|
const ms = now() - started;
|
|
196
|
-
|
|
265
|
+
if (one.request.feature === "writing-feedback") {
|
|
266
|
+
const checked2 = checkAiWritingFeedback(raw, one.request);
|
|
267
|
+
if (checked2.ok) {
|
|
268
|
+
const { text, provenance, usage } = checked2.feedback;
|
|
269
|
+
return {
|
|
270
|
+
case: one,
|
|
271
|
+
ok: true,
|
|
272
|
+
result: {
|
|
273
|
+
text,
|
|
274
|
+
...provenance !== void 0 ? { provenance } : {},
|
|
275
|
+
...usage !== void 0 ? { usage } : {}
|
|
276
|
+
},
|
|
277
|
+
feedback: checked2.feedback,
|
|
278
|
+
ms
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return refused(one, raw, checked2.refusal, ms);
|
|
282
|
+
}
|
|
283
|
+
const checked = one.request.feature === "explanation" ? checkAiExplanation(raw, one.request) : checkAiHint(raw, one.request);
|
|
197
284
|
if (checked.ok) {
|
|
198
285
|
return { case: one, ok: true, result: checked.result, ms };
|
|
199
286
|
}
|
|
287
|
+
return refused(one, raw, checked.refusal, ms);
|
|
288
|
+
}
|
|
289
|
+
function refused(one, raw, refusal, ms) {
|
|
200
290
|
const text = typeof raw?.text === "string" ? raw : void 0;
|
|
201
291
|
return {
|
|
202
292
|
case: one,
|
|
203
293
|
ok: false,
|
|
204
|
-
refusal
|
|
294
|
+
refusal,
|
|
205
295
|
...text !== void 0 ? { result: text } : {},
|
|
206
296
|
ms
|
|
207
297
|
};
|
|
@@ -210,9 +300,7 @@ async function runAiCheck(ports, options = {}) {
|
|
|
210
300
|
const all = options.cases ?? aiCheckCases();
|
|
211
301
|
const asked = Math.trunc(options.concurrency ?? 1);
|
|
212
302
|
const lanes = Number.isFinite(asked) && asked >= 1 ? Math.min(asked, 16) : 1;
|
|
213
|
-
const runnable = all.filter(
|
|
214
|
-
(one) => one.request.feature === "explanation" ? ports.explain !== void 0 : ports.hint !== void 0
|
|
215
|
-
);
|
|
303
|
+
const runnable = all.filter((one) => portFor(ports, one) !== void 0);
|
|
216
304
|
const results = new Array(runnable.length);
|
|
217
305
|
let next = 0;
|
|
218
306
|
const lane = async () => {
|
|
@@ -229,13 +317,13 @@ async function runAiCheck(ports, options = {}) {
|
|
|
229
317
|
await Promise.all(Array.from({ length: Math.min(lanes, runnable.length) }, lane));
|
|
230
318
|
const byRefusal = Object.fromEntries(REFUSALS.map((reason) => [reason, 0]));
|
|
231
319
|
let shown = 0;
|
|
232
|
-
let
|
|
320
|
+
let refused2 = 0;
|
|
233
321
|
let errors = 0;
|
|
234
322
|
for (const result of results) {
|
|
235
323
|
if (result.ok) {
|
|
236
324
|
shown += 1;
|
|
237
325
|
} else if (result.refusal !== void 0) {
|
|
238
|
-
|
|
326
|
+
refused2 += 1;
|
|
239
327
|
byRefusal[result.refusal] += 1;
|
|
240
328
|
} else {
|
|
241
329
|
errors += 1;
|
|
@@ -244,7 +332,7 @@ async function runAiCheck(ports, options = {}) {
|
|
|
244
332
|
return {
|
|
245
333
|
total: results.length,
|
|
246
334
|
shown,
|
|
247
|
-
refused,
|
|
335
|
+
refused: refused2,
|
|
248
336
|
errors,
|
|
249
337
|
skipped: all.length - runnable.length,
|
|
250
338
|
byRefusal,
|