@learnpack/learnpack 5.0.361 → 5.0.362
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/lib/commands/serve.js +44 -1
- package/lib/creatorDist/assets/{index-CqVEKiJR.js → index-CKg5uuoj.js} +8049 -8007
- package/lib/creatorDist/index.html +1 -1
- package/lib/utils/lessonRecovery.d.ts +18 -0
- package/lib/utils/lessonRecovery.js +31 -0
- package/package.json +1 -1
- package/src/commands/serve.ts +65 -9
- package/src/creatorDist/assets/{index-CqVEKiJR.js → index-CKg5uuoj.js} +8049 -8007
- package/src/creatorDist/index.html +1 -1
- package/src/utils/lessonRecovery.ts +32 -0
package/lib/commands/serve.js
CHANGED
|
@@ -23,6 +23,7 @@ const rigoActions_1 = require("../utils/rigoActions");
|
|
|
23
23
|
const dotenv = require("dotenv");
|
|
24
24
|
// import { v4 as uuidv4 } from "uuid"
|
|
25
25
|
const creatorUtilities_1 = require("../utils/creatorUtilities");
|
|
26
|
+
const lessonRecovery_1 = require("../utils/lessonRecovery");
|
|
26
27
|
// import { handleAssetCreation } from "./publish"
|
|
27
28
|
const axios_1 = require("axios");
|
|
28
29
|
const FormData = require("form-data");
|
|
@@ -407,6 +408,9 @@ async function startInitialContentGeneration(rigoToken, steps, packageContext, e
|
|
|
407
408
|
};
|
|
408
409
|
const res = await (0, rigoActions_1.initialContentGenerator)(rigoToken.trim(), inputs, webhookUrl, endpointSlug);
|
|
409
410
|
console.log("INITIAL CONTENT GENERATOR RES", res);
|
|
411
|
+
if (!res) {
|
|
412
|
+
throw new Error(`Could not start generating lesson ${exSlug}`);
|
|
413
|
+
}
|
|
410
414
|
return res.id;
|
|
411
415
|
}
|
|
412
416
|
async function startInteractivityGeneration(rigoToken, steps, packageContext, exercise, courseSlug, purposeSlug, bucket, lastLesson = "") {
|
|
@@ -620,6 +624,32 @@ async function updateLessonStatusToDone(courseSlug, exerciseSlug, bucket) {
|
|
|
620
624
|
throw error;
|
|
621
625
|
}
|
|
622
626
|
}
|
|
627
|
+
const lessonSlug = (lesson) => (0, creatorUtilities_2.slugify)(lesson.id + "-" + lesson.title);
|
|
628
|
+
async function repairFinishedLessons(courseSlug, syllabus, bucket) {
|
|
629
|
+
var _a;
|
|
630
|
+
const language = syllabus.courseInfo.language || "en";
|
|
631
|
+
try {
|
|
632
|
+
const finished = await (0, lessonRecovery_1.findFinishedLessons)((_a = syllabus.lessons) !== null && _a !== void 0 ? _a : [], async (lesson) => {
|
|
633
|
+
const readme = bucket.file(`courses/${courseSlug}/exercises/${lessonSlug(lesson)}/README${(0, creatorUtilities_1.getReadmeExtension)(language)}`);
|
|
634
|
+
const [exists] = await readme.exists();
|
|
635
|
+
if (!exists)
|
|
636
|
+
return null;
|
|
637
|
+
const [content] = await readme.download();
|
|
638
|
+
return content.toString();
|
|
639
|
+
});
|
|
640
|
+
for (const lesson of finished) {
|
|
641
|
+
// eslint-disable-next-line no-await-in-loop
|
|
642
|
+
await updateLessonStatusToDone(courseSlug, lessonSlug(lesson), bucket);
|
|
643
|
+
lesson.status = "DONE";
|
|
644
|
+
lesson.generated = true;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
catch (error) {
|
|
648
|
+
// Loading the course matters more than repairing it now. The next load
|
|
649
|
+
// tries again.
|
|
650
|
+
console.error(`Error repairing lessons of ${courseSlug}:`, error);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
623
653
|
async function continueWithNextLesson(courseSlug, currentExerciseIndex, rigoToken, finalContent, bucket) {
|
|
624
654
|
const syllabus = await getSyllabus(courseSlug, bucket);
|
|
625
655
|
const nextExercise = syllabus.lessons[currentExerciseIndex + 1] || null;
|
|
@@ -633,7 +663,19 @@ async function continueWithNextLesson(courseSlug, currentExerciseIndex, rigoToke
|
|
|
633
663
|
if (syllabus.feedback) {
|
|
634
664
|
feedback = `\n\nThe user added the following feedback with relation to the previous generations: ${syllabus.feedback}`;
|
|
635
665
|
}
|
|
636
|
-
|
|
666
|
+
try {
|
|
667
|
+
nextCompletionId = await startInitialContentGeneration(rigoToken, syllabus.lessons, syllabus.courseInfo, nextExercise, courseSlug, syllabus.courseInfo.purpose, finalContent + "\n\n" + feedback);
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
// The current lesson is finished either way. The next one stays PENDING,
|
|
671
|
+
// and its screen offers to continue.
|
|
672
|
+
console.error("Error starting the next lesson:", error);
|
|
673
|
+
(0, creatorSocket_1.emitToCourse)(courseSlug, "course-creation", {
|
|
674
|
+
lesson: (0, creatorUtilities_2.slugify)(nextExercise.id + "-" + nextExercise.title),
|
|
675
|
+
status: "error",
|
|
676
|
+
log: `❌ Could not start lesson ${nextExercise.title}`,
|
|
677
|
+
});
|
|
678
|
+
}
|
|
637
679
|
}
|
|
638
680
|
else {
|
|
639
681
|
console.log("Stopping generation process at", currentExerciseIndex, syllabus.lessons[currentExerciseIndex].title, "because it's a multiple of 3");
|
|
@@ -3591,6 +3633,7 @@ class ServeCommand extends SessionCommand_1.default {
|
|
|
3591
3633
|
const [content] = await syllabus.download();
|
|
3592
3634
|
const syllabusJson = JSON.parse(content.toString());
|
|
3593
3635
|
sanitizeSyllabusFromUnknown(syllabusJson);
|
|
3636
|
+
await repairFinishedLessons(courseSlug, syllabusJson, bucket);
|
|
3594
3637
|
res.json(syllabusJson);
|
|
3595
3638
|
}
|
|
3596
3639
|
catch (error) {
|