@thanh01.pmt/curriculum-kit 1.1.0 → 1.2.1
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/dist/ai/index.cjs +48 -4
- package/dist/ai/index.cjs.map +1 -1
- package/dist/ai/index.d.cts +11 -1
- package/dist/ai/index.d.ts +11 -1
- package/dist/ai/index.mjs +47 -5
- package/dist/ai/index.mjs.map +1 -1
- package/dist/{gateSettings-DKXRztJy.d.cts → gateSettings-Buk_MSML.d.cts} +3 -0
- package/dist/{gateSettings-DKXRztJy.d.ts → gateSettings-Buk_MSML.d.ts} +3 -0
- package/dist/index.cjs +588 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -7
- package/dist/index.d.ts +78 -7
- package/dist/index.mjs +578 -185
- package/dist/index.mjs.map +1 -1
- package/dist/media/index.cjs +3 -0
- package/dist/media/index.cjs.map +1 -1
- package/dist/media/index.mjs +3 -0
- package/dist/media/index.mjs.map +1 -1
- package/dist/pipeline/index.cjs +4 -4
- package/dist/pipeline/index.cjs.map +1 -1
- package/dist/pipeline/index.mjs +4 -4
- package/dist/pipeline/index.mjs.map +1 -1
- package/dist/workflow/index.cjs +451 -18
- package/dist/workflow/index.cjs.map +1 -1
- package/dist/workflow/index.d.cts +2 -2
- package/dist/workflow/index.d.ts +2 -2
- package/dist/workflow/index.mjs +451 -18
- package/dist/workflow/index.mjs.map +1 -1
- package/package.json +22 -21
- package/LICENSE +0 -21
package/dist/workflow/index.cjs
CHANGED
|
@@ -77,6 +77,8 @@ function getSuggestedActionForCode(code) {
|
|
|
77
77
|
return "N\u1ED9i dung sinh ra thi\u1EBFu c\xE1c ph\u1EA7n b\u1EAFt bu\u1ED9c [REQUIRED]. H\xE3y k\xEDch ho\u1EA1t ki\u1EC3m th\u1EED ho\u1EB7c b\u1EA5m Rerun.";
|
|
78
78
|
case "ERR_STORAGE_IO_FAILED":
|
|
79
79
|
return "L\u1ED7i \u0111\u1ECDc/ghi t\u1EC7p tin tr\xEAn h\u1EC7 th\u1ED1ng l\u01B0u tr\u1EEF. Ki\u1EC3m tra quy\u1EC1n ghi th\u01B0 m\u1EE5c output/projects.";
|
|
80
|
+
case "ERR_CONTEXT_MISSING":
|
|
81
|
+
return "Thi\u1EBFu ngu\u1ED3n tri th\u1EE9c b\u1EAFt bu\u1ED9c (KNOWLEDGE_EXPOSITION ho\u1EB7c CANONICAL LESSON) theo Dependency Routing Matrix. Vui l\xF2ng t\u1EA1o ho\u1EB7c \u0111\u1ED3ng b\u1ED9 t\xE0i li\u1EC7u ngu\u1ED3n tr\u01B0\u1EDBc.";
|
|
80
82
|
default:
|
|
81
83
|
return "B\u1EA5m Rerun \u0111\u1EC3 th\u1EED l\u1EA1i ho\u1EB7c ki\u1EC3m tra nh\u1EADt k\xFD h\u1EC7 th\u1ED1ng.";
|
|
82
84
|
}
|
|
@@ -94,11 +96,23 @@ function isCodeRetryable(code) {
|
|
|
94
96
|
case "ERR_TASK_GATE_BLOCKED":
|
|
95
97
|
case "ERR_METERED_LIMIT_EXCEEDED":
|
|
96
98
|
case "ERR_SCHEMA_CONTRACT_VIOLATION":
|
|
99
|
+
case "ERR_CONTEXT_MISSING":
|
|
97
100
|
return false;
|
|
98
101
|
default:
|
|
99
102
|
return true;
|
|
100
103
|
}
|
|
101
104
|
}
|
|
105
|
+
function createContextMissingError(params) {
|
|
106
|
+
return new CurriculumError({
|
|
107
|
+
errorCode: "ERR_CONTEXT_MISSING",
|
|
108
|
+
artifactType: params.artifactType,
|
|
109
|
+
lessonId: params.lessonId,
|
|
110
|
+
agent: params.agent,
|
|
111
|
+
message: `Required context source "${params.missingSource}" is missing for artifact "${params.artifactType}"`,
|
|
112
|
+
suggestedAction: `Generate or provide the authoritative "${params.missingSource}" source before producing "${params.artifactType}".`,
|
|
113
|
+
retryable: false
|
|
114
|
+
});
|
|
115
|
+
}
|
|
102
116
|
var CurriculumError;
|
|
103
117
|
var init_errors = __esm({
|
|
104
118
|
"src/errors/index.ts"() {
|
|
@@ -3507,13 +3521,13 @@ Evaluate the candidate artifact across these 6 dimensions:
|
|
|
3507
3521
|
- 0 pts: Missing critical sections.
|
|
3508
3522
|
|
|
3509
3523
|
5. **Technical & Conceptual Accuracy (15 pts):**
|
|
3510
|
-
- 15 pts: Code snippets, logic flows, architectural descriptions, and Mermaid diagrams are conceptually sound
|
|
3524
|
+
- 15 pts: Code snippets, logic flows, architectural descriptions, and Mermaid diagrams are conceptually sound and valid. If \`canonicalExposition\` or \`[KNOWLEDGE_EXPOSITION]\` is provided, content strictly adheres to canonical concepts without contradicting definitions or examples.
|
|
3511
3525
|
- 8 pts: Minor syntax inaccuracies or unidiomatic code that does not break core concepts.
|
|
3512
|
-
- 0 pts: Severe technical hallucinations, broken logic, or
|
|
3526
|
+
- 0 pts: Severe technical hallucinations, broken logic, invalid diagrams, or direct contradiction of canonical exposition knowledge.
|
|
3513
3527
|
|
|
3514
3528
|
6. **Contract Consistency & Zero-Drift (10 pts):**
|
|
3515
|
-
- 10 pts: Satellite artifact strictly adheres to the scope, tech stack, and objectives of Lesson ${lessonId} without introducing unrelated topics.
|
|
3516
|
-
- 0-5 pts: Scope drift
|
|
3529
|
+
- 10 pts: Satellite artifact strictly adheres to the scope, tech stack, and objectives of Lesson ${lessonId} without introducing unrelated topics. If \`canonicalLessonExcerpt\` is present in candidate JSON, all satellite phases/activities strictly operationalize the master Lesson Flow and Activity Sequence without inventing divergent timelines.
|
|
3530
|
+
- 0-5 pts: Scope drift, topic divergence, or disjoint activity sequence detected compared to master lesson.
|
|
3517
3531
|
|
|
3518
3532
|
## VERDICT RULES
|
|
3519
3533
|
- **PASS:** Score >= 80 AND Language Adherence = true AND Standards Alignment >= 12 (when STANDARDS GROUND TRUTH is present).
|
|
@@ -6214,8 +6228,308 @@ var LLMJudgeEngine = class {
|
|
|
6214
6228
|
|
|
6215
6229
|
// src/services/lessonProductionService.ts
|
|
6216
6230
|
init_errors();
|
|
6231
|
+
|
|
6232
|
+
// src/services/contextBuilder.ts
|
|
6233
|
+
var DEFAULT_LESSON_PRIORITIES = [
|
|
6234
|
+
"A. Lesson Design Plan",
|
|
6235
|
+
"B. Lesson Flow",
|
|
6236
|
+
"Learning Objectives & Evidence",
|
|
6237
|
+
"Activity Sequence"
|
|
6238
|
+
];
|
|
6239
|
+
var DEFAULT_KX_PRIORITIES = [
|
|
6240
|
+
"Key Terms",
|
|
6241
|
+
"Concept Narratives",
|
|
6242
|
+
"Worked Micro-Examples"
|
|
6243
|
+
];
|
|
6244
|
+
function buildSectionAwareExcerpt(markdown, opts = {}) {
|
|
6245
|
+
const budget = opts.budget ?? 12e3;
|
|
6246
|
+
const minContentChars = opts.minContentChars ?? 400;
|
|
6247
|
+
const issues = [];
|
|
6248
|
+
const source = (markdown || "").trim();
|
|
6249
|
+
if (!source) {
|
|
6250
|
+
return {
|
|
6251
|
+
excerpt: "",
|
|
6252
|
+
verified: false,
|
|
6253
|
+
sectionAware: false,
|
|
6254
|
+
includedSections: [],
|
|
6255
|
+
issues: ["empty-source"],
|
|
6256
|
+
tokenEstimate: 0
|
|
6257
|
+
};
|
|
6258
|
+
}
|
|
6259
|
+
const slcMap = normalizeSlcContract(opts.sectionLanguageContract);
|
|
6260
|
+
const sections = parseMarkdownSections(source, slcMap, opts.artifactType);
|
|
6261
|
+
if (sections.length === 0) {
|
|
6262
|
+
issues.push("parse:no-sections");
|
|
6263
|
+
const excerpt2 = truncateByBudget(source, budget);
|
|
6264
|
+
const verified2 = excerpt2.length >= minContentChars;
|
|
6265
|
+
if (excerpt2.length < minContentChars) issues.push("content:insufficient");
|
|
6266
|
+
return {
|
|
6267
|
+
excerpt: excerpt2,
|
|
6268
|
+
verified: verified2,
|
|
6269
|
+
sectionAware: false,
|
|
6270
|
+
includedSections: [],
|
|
6271
|
+
issues,
|
|
6272
|
+
tokenEstimate: Math.round(excerpt2.length / 4)
|
|
6273
|
+
};
|
|
6274
|
+
}
|
|
6275
|
+
const byCanonical = /* @__PURE__ */ new Map();
|
|
6276
|
+
const unmatched = [];
|
|
6277
|
+
for (const s of sections) {
|
|
6278
|
+
if (s.canonicalKey && !byCanonical.has(s.canonicalKey)) {
|
|
6279
|
+
byCanonical.set(s.canonicalKey, s);
|
|
6280
|
+
} else {
|
|
6281
|
+
unmatched.push(s);
|
|
6282
|
+
}
|
|
6283
|
+
}
|
|
6284
|
+
const priorities = opts.priorities ?? DEFAULT_LESSON_PRIORITIES;
|
|
6285
|
+
const includedSections = [];
|
|
6286
|
+
const blocks = [];
|
|
6287
|
+
let used = 0;
|
|
6288
|
+
const tryAdd = (heading, body, key) => {
|
|
6289
|
+
const trimmedBody = body.trim();
|
|
6290
|
+
if (!trimmedBody) return false;
|
|
6291
|
+
const block = `## ${heading}
|
|
6292
|
+
|
|
6293
|
+
${trimmedBody}`;
|
|
6294
|
+
if (used + block.length > budget && blocks.length > 0) return false;
|
|
6295
|
+
blocks.push(block);
|
|
6296
|
+
used += block.length;
|
|
6297
|
+
includedSections.push(key);
|
|
6298
|
+
return true;
|
|
6299
|
+
};
|
|
6300
|
+
let sectionAware = false;
|
|
6301
|
+
for (const key of priorities) {
|
|
6302
|
+
const sec = byCanonical.get(key);
|
|
6303
|
+
if (!sec) continue;
|
|
6304
|
+
sectionAware = true;
|
|
6305
|
+
if (!tryAdd(sec.cleanTitle, sec.body, key)) break;
|
|
6306
|
+
}
|
|
6307
|
+
for (const [key, sec] of byCanonical) {
|
|
6308
|
+
if (includedSections.includes(key)) continue;
|
|
6309
|
+
if (used >= budget) break;
|
|
6310
|
+
if (!tryAdd(sec.cleanTitle, sec.body, key)) break;
|
|
6311
|
+
}
|
|
6312
|
+
for (const sec of unmatched) {
|
|
6313
|
+
if (used >= budget) break;
|
|
6314
|
+
if (!tryAdd(sec.cleanTitle, sec.body, sec.cleanTitle)) break;
|
|
6315
|
+
}
|
|
6316
|
+
if (priorities.length > 0 && !priorities.some((k) => includedSections.includes(k))) {
|
|
6317
|
+
issues.push("parse:no-priority-resolution");
|
|
6318
|
+
}
|
|
6319
|
+
let excerpt = blocks.join("\n\n");
|
|
6320
|
+
if (excerpt.length > budget) {
|
|
6321
|
+
excerpt = truncateByBudget(excerpt, budget);
|
|
6322
|
+
}
|
|
6323
|
+
const effectiveMinChars = Math.min(minContentChars, source.length);
|
|
6324
|
+
if (excerpt.length < effectiveMinChars) {
|
|
6325
|
+
issues.push("content:insufficient");
|
|
6326
|
+
}
|
|
6327
|
+
const verified = !issues.includes("parse:no-priority-resolution") && excerpt.length >= effectiveMinChars;
|
|
6328
|
+
return {
|
|
6329
|
+
excerpt,
|
|
6330
|
+
verified,
|
|
6331
|
+
sectionAware: sectionAware || priorities.length === 0 && sections.length > 0,
|
|
6332
|
+
includedSections,
|
|
6333
|
+
issues,
|
|
6334
|
+
tokenEstimate: Math.round(excerpt.length / 4)
|
|
6335
|
+
};
|
|
6336
|
+
}
|
|
6337
|
+
function buildExpositionExcerpt(markdown, opts = {}) {
|
|
6338
|
+
return buildSectionAwareExcerpt(markdown, {
|
|
6339
|
+
...opts,
|
|
6340
|
+
priorities: DEFAULT_KX_PRIORITIES
|
|
6341
|
+
});
|
|
6342
|
+
}
|
|
6343
|
+
function buildLessonExcerpt(markdown, opts = {}) {
|
|
6344
|
+
return buildSectionAwareExcerpt(markdown, {
|
|
6345
|
+
...opts,
|
|
6346
|
+
priorities: DEFAULT_LESSON_PRIORITIES
|
|
6347
|
+
});
|
|
6348
|
+
}
|
|
6349
|
+
function normalizeSlcContract(slc) {
|
|
6350
|
+
if (!slc) return void 0;
|
|
6351
|
+
if (typeof slc !== "string") return slc;
|
|
6352
|
+
const out = {};
|
|
6353
|
+
const blocks = slc.split(/\n(?=#{2,3}\s+[A-Z0-9_]+)/g);
|
|
6354
|
+
for (const block of blocks) {
|
|
6355
|
+
const header = block.match(/^#{2,3}\s+([A-Z0-9_]+)/);
|
|
6356
|
+
if (!header?.[1]) continue;
|
|
6357
|
+
const mapping = {};
|
|
6358
|
+
for (const line of block.split("\n")) {
|
|
6359
|
+
const t = line.trim();
|
|
6360
|
+
if (!t.startsWith("|") || t.includes("---")) continue;
|
|
6361
|
+
const cells = t.split("|").map((c) => c.trim()).filter((_, i, a) => i > 0 && i < a.length - 1);
|
|
6362
|
+
const [c0, c1] = cells;
|
|
6363
|
+
if (c0 && c1 && !c0.toLowerCase().includes("canonical") && !c1.toLowerCase().includes("localized")) {
|
|
6364
|
+
mapping[c0] = c1;
|
|
6365
|
+
}
|
|
6366
|
+
}
|
|
6367
|
+
if (Object.keys(mapping).length > 0) out[header[1]] = mapping;
|
|
6368
|
+
}
|
|
6369
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
6370
|
+
}
|
|
6371
|
+
function parseMarkdownSections(markdown, slcMap, artifactType) {
|
|
6372
|
+
const sections = [];
|
|
6373
|
+
const lines = markdown.split("\n");
|
|
6374
|
+
let currentHeading = "";
|
|
6375
|
+
let currentBody = [];
|
|
6376
|
+
const reverseMap = /* @__PURE__ */ new Map();
|
|
6377
|
+
if (slcMap) {
|
|
6378
|
+
const maps = artifactType && slcMap[artifactType] ? [slcMap[artifactType]] : Object.values(slcMap);
|
|
6379
|
+
for (const m of maps) {
|
|
6380
|
+
for (const [canonical, localized] of Object.entries(m)) {
|
|
6381
|
+
reverseMap.set(normalizeHeading(localized), canonical);
|
|
6382
|
+
reverseMap.set(normalizeHeading(canonical), canonical);
|
|
6383
|
+
}
|
|
6384
|
+
}
|
|
6385
|
+
}
|
|
6386
|
+
const flush = () => {
|
|
6387
|
+
if (!currentHeading && currentBody.length === 0) return;
|
|
6388
|
+
const cleanTitle = currentHeading.replace(/^#{1,4}\s+/, "").trim();
|
|
6389
|
+
const norm = normalizeHeading(cleanTitle);
|
|
6390
|
+
const canonicalKey = reverseMap.get(norm) || findCanonicalFuzzy(norm);
|
|
6391
|
+
sections.push({
|
|
6392
|
+
rawHeading: currentHeading,
|
|
6393
|
+
cleanTitle,
|
|
6394
|
+
canonicalKey,
|
|
6395
|
+
body: currentBody.join("\n")
|
|
6396
|
+
});
|
|
6397
|
+
currentBody = [];
|
|
6398
|
+
};
|
|
6399
|
+
const hasH2 = lines.some((l) => /^##\s+/.test(l));
|
|
6400
|
+
const headingRegex = hasH2 ? /^##\s+(.*)$/ : /^#{2,3}\s+(.*)$/;
|
|
6401
|
+
for (const line of lines) {
|
|
6402
|
+
const headingMatch = line.match(headingRegex);
|
|
6403
|
+
if (headingMatch) {
|
|
6404
|
+
flush();
|
|
6405
|
+
currentHeading = line.trim();
|
|
6406
|
+
} else {
|
|
6407
|
+
currentBody.push(line);
|
|
6408
|
+
}
|
|
6409
|
+
}
|
|
6410
|
+
flush();
|
|
6411
|
+
return sections;
|
|
6412
|
+
}
|
|
6413
|
+
function normalizeHeading(str) {
|
|
6414
|
+
return str.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[^\w\s]/g, " ").replace(/\s+/g, " ").trim();
|
|
6415
|
+
}
|
|
6416
|
+
function findCanonicalFuzzy(norm) {
|
|
6417
|
+
if (norm.includes("lesson design plan") || norm.includes("ke hoach thiet ke")) {
|
|
6418
|
+
return "A. Lesson Design Plan";
|
|
6419
|
+
}
|
|
6420
|
+
if (norm.includes("lesson flow") || norm.includes("tien trinh giang day")) {
|
|
6421
|
+
return "B. Lesson Flow";
|
|
6422
|
+
}
|
|
6423
|
+
if (norm.includes("learning objective") || norm.includes("muc tieu bai hoc")) {
|
|
6424
|
+
return "Learning Objectives & Evidence";
|
|
6425
|
+
}
|
|
6426
|
+
if (norm.includes("activity sequence") || norm.includes("chuoi hoat dong")) {
|
|
6427
|
+
return "Activity Sequence";
|
|
6428
|
+
}
|
|
6429
|
+
if (norm.includes("key term") || norm.includes("thuat ngu")) {
|
|
6430
|
+
return "Key Terms";
|
|
6431
|
+
}
|
|
6432
|
+
if (norm.includes("concept narrative") || norm.includes("dien giai khai niem")) {
|
|
6433
|
+
return "Concept Narratives";
|
|
6434
|
+
}
|
|
6435
|
+
if (norm.includes("worked example") || norm.includes("vi du")) {
|
|
6436
|
+
return "Worked Micro-Examples";
|
|
6437
|
+
}
|
|
6438
|
+
return void 0;
|
|
6439
|
+
}
|
|
6440
|
+
function truncateByBudget(source, budget) {
|
|
6441
|
+
if (source.length <= budget) return source;
|
|
6442
|
+
let cut = source.slice(0, budget);
|
|
6443
|
+
const fenceCount = (cut.match(/^```/gm) || []).length;
|
|
6444
|
+
if (fenceCount % 2 === 1) cut += "\n```";
|
|
6445
|
+
return cut;
|
|
6446
|
+
}
|
|
6217
6447
|
init_errors();
|
|
6218
6448
|
|
|
6449
|
+
// src/services/languageDirective.ts
|
|
6450
|
+
function resolveTargetLanguageCode(language) {
|
|
6451
|
+
const raw = String(language || "vi").trim().toLowerCase();
|
|
6452
|
+
if (raw.startsWith("vi")) return "vi";
|
|
6453
|
+
if (raw.startsWith("en")) return "en";
|
|
6454
|
+
return raw || "vi";
|
|
6455
|
+
}
|
|
6456
|
+
function targetLanguageDisplayName(code) {
|
|
6457
|
+
const map = {
|
|
6458
|
+
vi: "Vietnamese (Ti\u1EBFng Vi\u1EC7t)",
|
|
6459
|
+
en: "English (US)"
|
|
6460
|
+
};
|
|
6461
|
+
return map[code] || code;
|
|
6462
|
+
}
|
|
6463
|
+
function buildLanguageDirective(targetLanguage) {
|
|
6464
|
+
const code = resolveTargetLanguageCode(targetLanguage);
|
|
6465
|
+
const name = targetLanguageDisplayName(code);
|
|
6466
|
+
const perLanguageExamples = {
|
|
6467
|
+
vi: `- V\xED d\u1EE5 ti\xEAu \u0111\u1EC1 b\xE0i h\u1ECDc \u0111\xFAng chu\u1EA9n: "B\xE0i 1: Kh\xE1m ph\xE1 m\u1EA1ch \u0111i\u1EC7n c\u01A1 b\u1EA3n", "B\xE0i 2: \u0110i\u1EC1u khi\u1EC3n \u0111\xE8n LED nh\u1EA5p nh\xE1y" \u2014 KH\xD4NG d\xF9ng ti\xEAu \u0111\u1EC1 ti\u1EBFng Anh.`,
|
|
6468
|
+
en: `- Example compliant lesson title: "Lesson 1: Exploring Basic Circuits" \u2014 natural, idiomatic English throughout.`
|
|
6469
|
+
};
|
|
6470
|
+
const exampleLine = perLanguageExamples[code] || "";
|
|
6471
|
+
return `MANDATORY LANGUAGE DIRECTIVE (TARGET OUTPUT LANGUAGE: ${name}):
|
|
6472
|
+
- The TARGET OUTPUT LANGUAGE for this course is ${name}. You MUST author the ENTIRE document in ${name}.
|
|
6473
|
+
- All section titles, table headers, table cells, lesson names, learning objectives, pedagogical narratives, and cognitive analyses MUST be written in natural, fluent, academic ${name}.
|
|
6474
|
+
- Technical identifiers, code keywords (e.g. setup(), loop(), pinMode()), standard protocols (I2C, SPI, UART, GPIO), and component model numbers (ESP32, Arduino Uno) remain in standard technical notation, but all surrounding explanations MUST be in ${name}.
|
|
6475
|
+
- DO NOT mix in paragraphs, tables, or titles written in any other language. Strict adherence is required.${exampleLine ? `
|
|
6476
|
+
${exampleLine}` : ""}`;
|
|
6477
|
+
}
|
|
6478
|
+
function extractSectionHeadingsFromSLC(slcInput, artifactType) {
|
|
6479
|
+
if (!slcInput) return {};
|
|
6480
|
+
const upperType = artifactType.trim().toUpperCase();
|
|
6481
|
+
if (typeof slcInput === "object") {
|
|
6482
|
+
if (slcInput[upperType]) return slcInput[upperType];
|
|
6483
|
+
for (const [key, mapping] of Object.entries(slcInput)) {
|
|
6484
|
+
if (key.toUpperCase() === upperType || upperType.startsWith("LESSON") && key.toUpperCase().startsWith("LESSON")) {
|
|
6485
|
+
return mapping;
|
|
6486
|
+
}
|
|
6487
|
+
}
|
|
6488
|
+
return {};
|
|
6489
|
+
}
|
|
6490
|
+
const slcMarkdown = slcInput;
|
|
6491
|
+
const blocks = slcMarkdown.split(/\n(?=#{2,3}\s+[A-Z0-9_]+)/g);
|
|
6492
|
+
for (const block of blocks) {
|
|
6493
|
+
const headerMatch = block.match(/^#{2,3}\s+([A-Z0-9_]+)/);
|
|
6494
|
+
if (!headerMatch) continue;
|
|
6495
|
+
const blockType = headerMatch[1].trim().toUpperCase();
|
|
6496
|
+
if (blockType === upperType || upperType.startsWith("LESSON") && blockType.startsWith("LESSON")) {
|
|
6497
|
+
const mapping = {};
|
|
6498
|
+
const lines = block.split("\n");
|
|
6499
|
+
for (const line of lines) {
|
|
6500
|
+
const trimmed = line.trim();
|
|
6501
|
+
if (trimmed.startsWith("|") && !trimmed.includes("---")) {
|
|
6502
|
+
const cells = trimmed.split("|").map((c) => c.trim()).filter((_, idx, arr) => idx > 0 && idx < arr.length - 1);
|
|
6503
|
+
if (cells.length >= 2 && !cells[0].toLowerCase().includes("canonical") && !cells[1].toLowerCase().includes("localized")) {
|
|
6504
|
+
mapping[cells[0]] = cells[1];
|
|
6505
|
+
}
|
|
6506
|
+
} else {
|
|
6507
|
+
const bullet = line.match(/^[-*]\s+([^:]+):\s+(.+)$/);
|
|
6508
|
+
if (bullet) {
|
|
6509
|
+
mapping[bullet[1].trim()] = bullet[2].trim();
|
|
6510
|
+
}
|
|
6511
|
+
}
|
|
6512
|
+
}
|
|
6513
|
+
if (Object.keys(mapping).length > 0) return mapping;
|
|
6514
|
+
}
|
|
6515
|
+
}
|
|
6516
|
+
return {};
|
|
6517
|
+
}
|
|
6518
|
+
function buildHeadingDirective(artifactType, slcMarkdown, targetLanguage = "vi") {
|
|
6519
|
+
const headings = extractSectionHeadingsFromSLC(slcMarkdown, artifactType);
|
|
6520
|
+
if (Object.keys(headings).length === 0) {
|
|
6521
|
+
return "";
|
|
6522
|
+
}
|
|
6523
|
+
const lines = Object.entries(headings).map(
|
|
6524
|
+
([canonical, localized]) => ` - "${canonical}" -> Use Display Heading: "${localized}"`
|
|
6525
|
+
);
|
|
6526
|
+
return `MANDATORY SECTION HEADINGS FROM SECTION_LANGUAGE_CONTRACT:
|
|
6527
|
+
- The YAML frontmatter \`template_required_sections\` MUST preserve the exact English canonical keys.
|
|
6528
|
+
- In the markdown body, section headers MUST use the EXACT Localized Display Labels below (do NOT translate or paraphrase):
|
|
6529
|
+
${lines.join("\n")}
|
|
6530
|
+
- For example: if canonical section is "Computational Thinking Focus", your heading must be "## [REQUIRED] ${headings["Computational Thinking Focus"] || "Computational Thinking Focus"}".`;
|
|
6531
|
+
}
|
|
6532
|
+
|
|
6219
6533
|
// src/services/lessonProductionService.ts
|
|
6220
6534
|
var __filename$1 = typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) === "string" ? url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))) : "";
|
|
6221
6535
|
var _resolvedDir = __filename$1 ? path4__default.default.dirname(__filename$1) : typeof __dirname !== "undefined" ? __dirname : process.cwd();
|
|
@@ -6245,6 +6559,87 @@ function loadCurriculumTemplate(templateName) {
|
|
|
6245
6559
|
|
|
6246
6560
|
// src/services/singleArtifactService.ts
|
|
6247
6561
|
init_errors();
|
|
6562
|
+
|
|
6563
|
+
// src/services/contextRouting.ts
|
|
6564
|
+
init_errors();
|
|
6565
|
+
var ARTIFACT_DEPENDENCY_ROUTING = {
|
|
6566
|
+
LESSON: {
|
|
6567
|
+
required: ["KNOWLEDGE_EXPOSITION", "SESSION_SLICE", "FRAMEWORK_EXCERPT"],
|
|
6568
|
+
optional: ["STYLE_GUIDE", "REFERENCE_PACK"],
|
|
6569
|
+
rationale: "D\u1EA1y theo ki\u1EBFn th\u1EE9c chu\u1EA9n c\u1EE7a plan, ph\xE2n b\u1ED5 m\u1EE5c ti\xEAu v\xE0 khung ch\u01B0\u01A1ng tr\xECnh"
|
|
6570
|
+
},
|
|
6571
|
+
HANDOUT: {
|
|
6572
|
+
required: ["KNOWLEDGE_EXPOSITION"],
|
|
6573
|
+
optional: ["SESSION_SLICE"],
|
|
6574
|
+
rationale: "T\xE0i li\u1EC7u t\u1EF1 h\u1ECDc \u2014 b\xE1m kh\xE1i ni\u1EC7m chu\u1EA9n, kh\xF4ng c\u1EA7n activity timeline"
|
|
6575
|
+
},
|
|
6576
|
+
EXT: {
|
|
6577
|
+
required: ["KNOWLEDGE_EXPOSITION"],
|
|
6578
|
+
optional: ["SESSION_SLICE"],
|
|
6579
|
+
rationale: "Th\u1EED th\xE1ch m\u1EDF r\u1ED9ng chuy\xEAn s\xE2u b\xE1m kh\xE1i ni\u1EC7m"
|
|
6580
|
+
},
|
|
6581
|
+
CODE: {
|
|
6582
|
+
required: ["KNOWLEDGE_EXPOSITION"],
|
|
6583
|
+
optional: ["LESSON_OBJECTIVES"],
|
|
6584
|
+
rationale: "Code lab th\u1EF1c h\xE0nh b\xE1m kh\xE1i ni\u1EC7m k\u1EF9 thu\u1EADt v\xE0 v\xED d\u1EE5 worked examples"
|
|
6585
|
+
},
|
|
6586
|
+
ACT: {
|
|
6587
|
+
required: ["CANONICAL_LESSON"],
|
|
6588
|
+
optional: ["KNOWLEDGE_EXPOSITION", "SESSION_SLICE"],
|
|
6589
|
+
rationale: "STEM Activity Lab b\u1EAFt bu\u1ED9c ph\u1EA3i kh\u1EDBp 100% Activity Sequence v\xE0 Lesson Flow c\u1EE7a LESSON"
|
|
6590
|
+
},
|
|
6591
|
+
WKS: {
|
|
6592
|
+
required: ["CANONICAL_LESSON"],
|
|
6593
|
+
optional: ["KNOWLEDGE_EXPOSITION"],
|
|
6594
|
+
rationale: "Phi\u1EBFu h\u1ECDc t\u1EADp (Worksheet) luy\u1EC7n t\u1EADp theo c\xE1c ch\u1EB7ng ho\u1EA1t \u0111\u1ED9ng c\u1EE7a gi\xE1o \xE1n"
|
|
6595
|
+
},
|
|
6596
|
+
GUIDE: {
|
|
6597
|
+
required: ["CANONICAL_LESSON"],
|
|
6598
|
+
optional: ["SESSION_SLICE"],
|
|
6599
|
+
rationale: "K\u1ECBch b\u1EA3n s\u01B0 ph\u1EA1m gi\xE1o vi\xEAn (Teacher Guide) b\xE1m s\xE1t timeline t\u1EEBng ph\xFAt c\u1EE7a LESSON"
|
|
6600
|
+
},
|
|
6601
|
+
SLIDE: {
|
|
6602
|
+
required: ["CANONICAL_LESSON"],
|
|
6603
|
+
optional: ["KNOWLEDGE_EXPOSITION"],
|
|
6604
|
+
rationale: "Slide b\xE0i gi\u1EA3ng tr\xECnh chi\u1EBFu theo c\u1EA5u tr\xFAc ph\xE2n ph\u1ED1i n\u1ED9i dung c\u1EE7a gi\xE1o \xE1n"
|
|
6605
|
+
},
|
|
6606
|
+
QUIZ: {
|
|
6607
|
+
required: ["KNOWLEDGE_EXPOSITION", "CANONICAL_LESSON"],
|
|
6608
|
+
optional: ["SESSION_SLICE"],
|
|
6609
|
+
rationale: "Ng\xE2n h\xE0ng c\xE2u h\u1ECFi \u0111\xE1nh gi\xE1 c\u1EA3 ki\u1EBFn th\u1EE9c chu\u1EA9n m\u1EF1c (KX) l\u1EABn m\u1EE5c ti\xEAu b\xE0i d\u1EA1y (LESSON)"
|
|
6610
|
+
}
|
|
6611
|
+
};
|
|
6612
|
+
function validateArtifactDependencies(artifactType, availableSources, opts = {}) {
|
|
6613
|
+
const normType = (artifactType || "").toUpperCase().trim();
|
|
6614
|
+
const rule = ARTIFACT_DEPENDENCY_ROUTING[normType];
|
|
6615
|
+
const failClosed = opts.failClosed ?? true;
|
|
6616
|
+
if (!rule) {
|
|
6617
|
+
return { valid: true, missing: [] };
|
|
6618
|
+
}
|
|
6619
|
+
const missing = [];
|
|
6620
|
+
for (const req of rule.required) {
|
|
6621
|
+
const val = availableSources[req];
|
|
6622
|
+
const isPresent = val !== void 0 && val !== null && (typeof val === "string" ? val.trim().length > 0 : true);
|
|
6623
|
+
if (!isPresent) {
|
|
6624
|
+
missing.push(req);
|
|
6625
|
+
}
|
|
6626
|
+
}
|
|
6627
|
+
if (missing.length > 0) {
|
|
6628
|
+
const err = createContextMissingError({
|
|
6629
|
+
artifactType: normType,
|
|
6630
|
+
missingSource: missing[0],
|
|
6631
|
+
lessonId: opts.lessonId,
|
|
6632
|
+
agent: opts.agent
|
|
6633
|
+
});
|
|
6634
|
+
if (failClosed) {
|
|
6635
|
+
throw err;
|
|
6636
|
+
}
|
|
6637
|
+
return { valid: false, missing, error: err };
|
|
6638
|
+
}
|
|
6639
|
+
return { valid: true, missing: [] };
|
|
6640
|
+
}
|
|
6641
|
+
|
|
6642
|
+
// src/services/singleArtifactService.ts
|
|
6248
6643
|
function getArtifactMetadata(type, lessonId, pedagogy) {
|
|
6249
6644
|
const id = lessonId || "ON_DEMAND";
|
|
6250
6645
|
switch (type) {
|
|
@@ -6324,9 +6719,24 @@ async function generateSingleArtifact(req) {
|
|
|
6324
6719
|
const templateContent = loadedTemplate || getDefaultFallbackTemplate(artifactType, displayTitle, lessonId || "ON_DEMAND");
|
|
6325
6720
|
const hwStr = hardwarePlatform.join(", ");
|
|
6326
6721
|
const selectedDevices = (config?.devices || (hardwarePlatform[0]?.toLowerCase().includes("paper") ? "paper-only" : "laptop")).toLowerCase();
|
|
6327
|
-
|
|
6328
|
-
const
|
|
6329
|
-
const
|
|
6722
|
+
language.toLowerCase().includes("bilingual") || language.toLowerCase().includes("song");
|
|
6723
|
+
const targetLang = resolveTargetLanguageCode(language);
|
|
6724
|
+
const langDirective = buildLanguageDirective(language);
|
|
6725
|
+
const headingDirective = buildHeadingDirective(
|
|
6726
|
+
artifactType.toUpperCase(),
|
|
6727
|
+
req.sectionLanguageContract,
|
|
6728
|
+
targetLang
|
|
6729
|
+
);
|
|
6730
|
+
const availableSources = {
|
|
6731
|
+
KNOWLEDGE_EXPOSITION: contextSot.exposition || researchContext,
|
|
6732
|
+
CANONICAL_LESSON: contextSot.lessonPlan,
|
|
6733
|
+
FRAMEWORK_EXCERPT: contextSot.framework
|
|
6734
|
+
};
|
|
6735
|
+
validateArtifactDependencies(artifactType.toUpperCase(), availableSources, {
|
|
6736
|
+
lessonId,
|
|
6737
|
+
agent: meta.persona,
|
|
6738
|
+
failClosed: req.failClosedContext ?? false
|
|
6739
|
+
});
|
|
6330
6740
|
const isPaperOnly = selectedDevices === "paper-only" || hwStr.toLowerCase().includes("paper") || hwStr.toLowerCase().includes("print-ready");
|
|
6331
6741
|
const deviceRule = isPaperOnly ? `
|
|
6332
6742
|
- \u{1F4C4} PAPER-ONLY / NO-DEVICE ENVIRONMENT: The learning space has NO computers or screens. All exercises, worksheets, task cards, exit tickets, and code analyses MUST be 100% printable. Provide write-in blank boxes, printed code snippets with line numbers, tracing tables, and physical manipulative instructions.` : selectedDevices === "tablet" || selectedDevices === "smartphone" ? `
|
|
@@ -6347,7 +6757,8 @@ async function generateSingleArtifact(req) {
|
|
|
6347
6757
|
Your task is to author a canonical, publication-grade learning artifact of type "${artifactType.toUpperCase()}".
|
|
6348
6758
|
|
|
6349
6759
|
### CORE OPERATIONAL INVARIANTS:
|
|
6350
|
-
${
|
|
6760
|
+
${langDirective}
|
|
6761
|
+
${headingDirective}
|
|
6351
6762
|
2. NON-MOCK CODE INVARIANT: Any code snippet provided MUST be 100% syntactically valid, idiomatic, and executable without placeholders or fake functions.
|
|
6352
6763
|
3. PEDAGOGICAL GROUNDING: Strictly align with the ${pedagogy.toUpperCase()} model, Bloom's Revised Taxonomy, and IEEE/ACM CS2023 guidelines.
|
|
6353
6764
|
4. SCAFFOLDING LEVEL: "${scaffoldingLevel.toUpperCase()}".${scaffoldingRule}
|
|
@@ -6356,6 +6767,11 @@ ${langRule}
|
|
|
6356
6767
|
|
|
6357
6768
|
IMAGE PLANNING (media ledger) \u2014 QUOTA GEN: t\u1ED1i \u0111a ${mediaPolicy.maxGenImagesPerArtifact} \u1EA3nh AI cho artifact n\xE0y (\u1EA3nh search kho kh\xF4ng gi\u1EDBi h\u1EA1n).
|
|
6358
6769
|
Khi n\u1ED9i dung c\u1EA7n minh h\u1ECDa (diagram quy tr\xECnh, s\u01A1 \u0111\u1ED3 kh\xE1i ni\u1EC7m, step-by-step visual), ch\xE8n placeholder \u0111\xFAng format [IMAGE: slug] (slug ch\u1EEF th\u01B0\u1EDDng-g\u1EA1ch ngang, unique trong b\xE0i, vd img-for-loop-diagram) T\u1EA0I \u0110\xDANG CH\u1ED6 c\u1EA7n \u1EA3nh, tr\xEAn d\xF2ng ri\xEAng. KH\xD4NG t\u1EF1 sinh \u1EA3nh, KH\xD4NG d\xF9ng markdown image \u2014 placeholder s\u1EBD \u0111\u01B0\u1EE3c thay b\u1EB1ng \u1EA3nh th\u1EADt sau khi Media Curator duy\u1EC7t. Ch\u1EC9 \u0111\u1EB7t cho \u1EA3nh TH\u1EF0C S\u1EF0 c\u1EA7n thi\u1EBFt.` : ""}`;
|
|
6770
|
+
const slcContract = req.sectionLanguageContract;
|
|
6771
|
+
const frameworkExcerpt = contextSot.framework ? buildSectionAwareExcerpt(contextSot.framework, { budget: 2500, sectionLanguageContract: slcContract }).excerpt : "";
|
|
6772
|
+
const lessonPlanExcerpt = contextSot.lessonPlan ? buildLessonExcerpt(contextSot.lessonPlan, { budget: 8e3, sectionLanguageContract: slcContract, artifactType: "LESSON" }).excerpt : "";
|
|
6773
|
+
const handoutExcerpt = contextSot.handout ? buildSectionAwareExcerpt(contextSot.handout, { budget: 2e3, sectionLanguageContract: slcContract }).excerpt : "";
|
|
6774
|
+
const expositionExcerpt = contextSot.exposition ? buildExpositionExcerpt(contextSot.exposition, { budget: 6e3, sectionLanguageContract: slcContract }).excerpt : "";
|
|
6359
6775
|
const userPrompt = `### CONTEXT GROUND TRUTH:
|
|
6360
6776
|
- Topic / Concept Domain: "${topic}"
|
|
6361
6777
|
- Lesson ID: "${lessonId || "ON_DEMAND"}"
|
|
@@ -6373,14 +6789,17 @@ ${selectedDevices ? `- Device Mode: "${selectedDevices}"
|
|
|
6373
6789
|
${researchContext ? `### RESEARCH GROUND TRUTH (fact-checked context \u2014 \u01B0u ti\xEAn d\xF9ng, KH\xD4NG b\u1ECBa s\u1ED1 li\u1EC7u):
|
|
6374
6790
|
${researchContext.slice(0, 4e3)}
|
|
6375
6791
|
` : ""}
|
|
6376
|
-
${
|
|
6377
|
-
${
|
|
6792
|
+
${expositionExcerpt ? `### SOT KNOWLEDGE EXPOSITION (CANONICAL KNOWLEDGE \u2014 teach from this, do not contradict):
|
|
6793
|
+
${expositionExcerpt}
|
|
6794
|
+
` : ""}
|
|
6795
|
+
${frameworkExcerpt ? `### SOT CURRICULUM FRAMEWORK:
|
|
6796
|
+
${frameworkExcerpt}
|
|
6378
6797
|
` : ""}
|
|
6379
|
-
${
|
|
6380
|
-
${
|
|
6798
|
+
${lessonPlanExcerpt ? `### SOT CANONICAL LESSON PLAN:
|
|
6799
|
+
${lessonPlanExcerpt}
|
|
6381
6800
|
` : ""}
|
|
6382
|
-
${
|
|
6383
|
-
${
|
|
6801
|
+
${handoutExcerpt ? `### SOT STUDENT HANDOUT:
|
|
6802
|
+
${handoutExcerpt}
|
|
6384
6803
|
` : ""}
|
|
6385
6804
|
|
|
6386
6805
|
### MANDATORY CANONICAL TEMPLATE CONTRACT:
|
|
@@ -6469,9 +6888,16 @@ ${yaml.trim()}
|
|
|
6469
6888
|
const verdict = await LLMJudgeEngine.evaluateArtifactWithLLM({
|
|
6470
6889
|
targetArtifactType: artifactType.toUpperCase(),
|
|
6471
6890
|
lessonId: lessonId || "ON_DEMAND",
|
|
6472
|
-
expectedLanguage:
|
|
6891
|
+
expectedLanguage: targetLang || "en",
|
|
6473
6892
|
targetObjectives: judgeObjectives,
|
|
6474
|
-
generatedContentJson: JSON.stringify({
|
|
6893
|
+
generatedContentJson: JSON.stringify({
|
|
6894
|
+
content: finalContent,
|
|
6895
|
+
artifactType,
|
|
6896
|
+
lessonId: lessonId || "ON_DEMAND",
|
|
6897
|
+
title: displayTitle,
|
|
6898
|
+
canonicalLessonExcerpt: lessonPlanExcerpt || void 0,
|
|
6899
|
+
canonicalExposition: expositionExcerpt || void 0
|
|
6900
|
+
})
|
|
6475
6901
|
});
|
|
6476
6902
|
const passed = Boolean(verdict.passed) && verdict.score >= 85;
|
|
6477
6903
|
if (passed) {
|
|
@@ -6513,9 +6939,16 @@ ${finalContent}` }
|
|
|
6513
6939
|
const reVerdict = await LLMJudgeEngine.evaluateArtifactWithLLM({
|
|
6514
6940
|
targetArtifactType: artifactType.toUpperCase(),
|
|
6515
6941
|
lessonId: lessonId || "ON_DEMAND",
|
|
6516
|
-
expectedLanguage:
|
|
6942
|
+
expectedLanguage: targetLang || "en",
|
|
6517
6943
|
targetObjectives: judgeObjectives,
|
|
6518
|
-
generatedContentJson: JSON.stringify({
|
|
6944
|
+
generatedContentJson: JSON.stringify({
|
|
6945
|
+
content: repaired,
|
|
6946
|
+
artifactType,
|
|
6947
|
+
lessonId: lessonId || "ON_DEMAND",
|
|
6948
|
+
title: displayTitle,
|
|
6949
|
+
canonicalLessonExcerpt: lessonPlanExcerpt || void 0,
|
|
6950
|
+
canonicalExposition: expositionExcerpt || void 0
|
|
6951
|
+
})
|
|
6519
6952
|
});
|
|
6520
6953
|
if (reVerdict.passed && reVerdict.score >= 85) {
|
|
6521
6954
|
return {
|