@learnpack/learnpack 5.0.231 → 5.0.238
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.d.ts +1 -2
- package/lib/commands/serve.js +8 -109
- package/lib/creatorDist/assets/{index-BjBYI-9r.js → index-x_kA-1DY.js} +8168 -8115
- package/lib/creatorDist/index.html +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/serve.ts +8 -165
- package/src/creator/src/App.tsx +72 -65
- package/src/creator/src/components/LessonItem.tsx +9 -3
- package/src/creator/src/components/NotificationListener.tsx +32 -0
- package/src/creator/src/components/syllabus/SyllabusEditor.tsx +42 -44
- package/src/creator/src/utils/creatorUtils.ts +2 -2
- package/src/creator/src/utils/rigo.ts +9 -2
- package/src/creator/src/utils/store.ts +13 -2
- package/src/creatorDist/assets/{index-BjBYI-9r.js → index-x_kA-1DY.js} +8168 -8115
- package/src/creatorDist/index.html +1 -1
- package/src/ui/_app/app.css +1 -1
- package/src/ui/_app/app.js +1 -1
- package/src/ui/app.tar.gz +0 -0
- package/src/utils/configBuilder.ts +1 -2
package/lib/commands/serve.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import SessionCommand from "../utils/SessionCommand";
|
2
2
|
import { Bucket } from "@google-cloud/storage";
|
3
|
-
import { FormState
|
3
|
+
import { FormState } from "../models/creator";
|
4
4
|
export declare const createLearnJson: (courseInfo: FormState) => {
|
5
5
|
slug: string;
|
6
6
|
title: {
|
@@ -21,7 +21,6 @@ export declare const createLearnJson: (courseInfo: FormState) => {
|
|
21
21
|
preview: string;
|
22
22
|
};
|
23
23
|
export declare const processImage: (bucket: Bucket, tutorialDir: string, url: string, description: string, rigoToken: string) => Promise<boolean>;
|
24
|
-
export declare function processExercise(bucket: Bucket, rigoToken: string, steps: Lesson[], packageContext: FormState, exercise: Lesson, tutorialDir: string, courseSlug: string, purposeSlug: string, lastLesson?: string): Promise<string>;
|
25
24
|
export default class ServeCommand extends SessionCommand {
|
26
25
|
static description: string;
|
27
26
|
static flags: any;
|
package/lib/commands/serve.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.processImage = exports.createLearnJson = void 0;
|
4
|
-
exports.processExercise = processExercise;
|
5
4
|
const tslib_1 = require("tslib");
|
6
5
|
const command_1 = require("@oclif/command");
|
7
6
|
// import { readDocument } from "../utils/readDocuments"
|
@@ -95,7 +94,9 @@ const PARAMS = {
|
|
95
94
|
};
|
96
95
|
const processImage = async (bucket, tutorialDir, url, description, rigoToken) => {
|
97
96
|
try {
|
97
|
+
// TODO: MAKE THIS ASYNC
|
98
98
|
const filename = (0, creatorUtilities_1.getFilenameFromUrl)(url);
|
99
|
+
console.log("🖼️ IMAGE FILENAME", filename);
|
99
100
|
const imagePath = `${tutorialDir}/.learn/assets/${filename}`;
|
100
101
|
console.log("🖼️ Generating image", imagePath);
|
101
102
|
const res = await (0, rigoActions_1.generateImage)(rigoToken, { prompt: description });
|
@@ -148,83 +149,6 @@ async function startExerciseGeneration(bucket, rigoToken, steps, packageContext,
|
|
148
149
|
kind: exercise.type.toLowerCase(),
|
149
150
|
last_lesson: lastLesson,
|
150
151
|
}, purposeSlug, webhookUrl);
|
151
|
-
// console.log("res processing in background", res)
|
152
|
-
}
|
153
|
-
async function processExercise(bucket, rigoToken, steps, packageContext, exercise, tutorialDir, courseSlug, purposeSlug, lastLesson = "") {
|
154
|
-
const exercisesDir = `${tutorialDir}/exercises`;
|
155
|
-
// const tid = toast.loading("Generating lesson...")
|
156
|
-
const exSlug = (0, creatorUtilities_2.slugify)(exercise.id + "-" + exercise.title);
|
157
|
-
console.log("exSlug", exSlug);
|
158
|
-
const readmeFilename = `README.${packageContext.language && packageContext.language !== "en" ?
|
159
|
-
`${packageContext.language}.` :
|
160
|
-
""}md`;
|
161
|
-
const targetDir = `${exercisesDir}/${exSlug}`;
|
162
|
-
console.log("✍🏻 Generating lesson", exercise.id, exercise.title);
|
163
|
-
const readme = await (0, rigoActions_1.readmeCreator)(rigoToken, {
|
164
|
-
title: `${exercise.id} - ${exercise.title}`,
|
165
|
-
output_lang: packageContext.language || "en",
|
166
|
-
list_of_exercises: JSON.stringify(steps.map(step => step.id + "-" + step.title)),
|
167
|
-
tutorial_description: JSON.stringify(cleanFormState(packageContext)),
|
168
|
-
lesson_description: exercise.description,
|
169
|
-
kind: exercise.type.toLowerCase(),
|
170
|
-
last_lesson: lastLesson,
|
171
|
-
}, purposeSlug);
|
172
|
-
const duration = exercise.duration;
|
173
|
-
// let attempts = 0
|
174
|
-
const readability = (0, creatorUtilities_2.checkReadability)(readme.parsed.content, PARAMS.max_words, duration || 3);
|
175
|
-
(0, creatorSocket_1.emitToCourse)(courseSlug, "course-creation", {
|
176
|
-
lesson: exSlug,
|
177
|
-
status: "generating",
|
178
|
-
log: `🔄 The lesson ${exercise.id} - ${exercise.title} has a readability score of ${readability.fkglResult.fkgl}`,
|
179
|
-
});
|
180
|
-
// while (
|
181
|
-
// readability.fkglResult.fkgl > PARAMS.max_fkgl &&
|
182
|
-
// attempts < PARAMS.max_rewrite_attempts
|
183
|
-
// ) {
|
184
|
-
// // eslint-disable-next-line
|
185
|
-
// const reducedReadme = await makeReadmeReadable(
|
186
|
-
// rigoToken,
|
187
|
-
// {
|
188
|
-
// lesson: readability.body,
|
189
|
-
// number_of_words: readability.minutes.toString(),
|
190
|
-
// expected_number_words: PARAMS.max_words.toString(),
|
191
|
-
// fkgl_results: JSON.stringify(readability.fkglResult),
|
192
|
-
// expected_grade_level: PARAMS.expected_grade_level,
|
193
|
-
// },
|
194
|
-
// purposeSlug
|
195
|
-
// )
|
196
|
-
// if (!reducedReadme) break
|
197
|
-
// readability = checkReadability(
|
198
|
-
// reducedReadme.parsed.content,
|
199
|
-
// PARAMS.max_words,
|
200
|
-
// duration || 3
|
201
|
-
// )
|
202
|
-
// attempts++
|
203
|
-
// }
|
204
|
-
await uploadFileToBucket(bucket, readability.newMarkdown, `${targetDir}/${readmeFilename}`);
|
205
|
-
if (exercise.type.toLowerCase() === "code" &&
|
206
|
-
readme.parsed.codefile_content) {
|
207
|
-
console.log("🔍 Creating code file for", exercise.title);
|
208
|
-
await uploadFileToBucket(bucket, readme.parsed.codefile_content, `${targetDir}/${readme.parsed.codefile_name.toLowerCase().trim()}`);
|
209
|
-
}
|
210
|
-
const imagesArray = (0, creatorUtilities_1.extractImagesFromMarkdown)(readability.newMarkdown);
|
211
|
-
if (imagesArray.length > 0) {
|
212
|
-
(0, creatorSocket_1.emitToCourse)(courseSlug, "course-creation", {
|
213
|
-
lesson: exSlug,
|
214
|
-
status: "done",
|
215
|
-
log: `🔄 Generating images for ${exercise.title}`,
|
216
|
-
});
|
217
|
-
for (const image of imagesArray) {
|
218
|
-
// eslint-disable-next-line no-await-in-loop
|
219
|
-
await (0, exports.processImage)(bucket, tutorialDir, image.url, image.alt, rigoToken);
|
220
|
-
}
|
221
|
-
}
|
222
|
-
(0, creatorSocket_1.emitToCourse)(courseSlug, "course-creation", {
|
223
|
-
lesson: exSlug,
|
224
|
-
status: "done",
|
225
|
-
log: `✅ The lesson ${exercise.id} - ${exercise.title} has been generated successfully!`,
|
226
|
-
});
|
227
|
-
return readability.newMarkdown;
|
228
152
|
}
|
229
153
|
const fixPreviewUrl = (slug, previewUrl) => {
|
230
154
|
if (!previewUrl) {
|
@@ -459,13 +383,17 @@ class ServeCommand extends SessionCommand_1.default {
|
|
459
383
|
log: `🔄 Creating code file for ${exercise.title}`,
|
460
384
|
});
|
461
385
|
await uploadFileToBucket(bucket, readme.parsed.codefile_content, `${targetDir}/${readme.parsed.codefile_name.toLowerCase().trim()}`);
|
386
|
+
(0, creatorSocket_1.emitToCourse)(courseSlug, "course-creation", {
|
387
|
+
lesson: exSlug,
|
388
|
+
status: "done",
|
389
|
+
log: `✅ Code file created for ${exercise.title}`,
|
390
|
+
});
|
462
391
|
}
|
463
392
|
if (nextExercise) {
|
464
393
|
startExerciseGeneration(bucket, rigoToken, syllabusJson.lessons, syllabusJson.courseInfo, nextExercise, `courses/${courseSlug}`, courseSlug, syllabusJson.courseInfo.purpose, readme.parsed.content);
|
465
394
|
}
|
466
395
|
const imagesArray = (0, creatorUtilities_1.extractImagesFromMarkdown)(readability.newMarkdown);
|
467
396
|
if (imagesArray.length > 0) {
|
468
|
-
console.log("This course requires images and I don't have the token :)");
|
469
397
|
(0, creatorSocket_1.emitToCourse)(courseSlug, "course-creation", {
|
470
398
|
lesson: exSlug,
|
471
399
|
status: "pending",
|
@@ -826,41 +754,12 @@ class ServeCommand extends SessionCommand_1.default {
|
|
826
754
|
await uploadFileToBucket(bucket, JSON.stringify(sidebar), `${tutorialDir}/.learn/sidebar.json`);
|
827
755
|
const firstLesson = syllabus.lessons[0];
|
828
756
|
const lastResult = "Nothing";
|
829
|
-
startExerciseGeneration(bucket, rigoToken, syllabus.lessons, syllabus.courseInfo, firstLesson, tutorialDir, courseSlug, syllabus.courseInfo.purpose, lastResult);
|
757
|
+
await startExerciseGeneration(bucket, rigoToken, syllabus.lessons, syllabus.courseInfo, firstLesson, tutorialDir, courseSlug, syllabus.courseInfo.purpose, lastResult);
|
830
758
|
return res.json({
|
831
759
|
message: "Course created",
|
832
760
|
slug: (0, creatorUtilities_2.slugify)(syllabus.courseInfo.title),
|
833
761
|
});
|
834
762
|
});
|
835
|
-
// app.post(
|
836
|
-
// "/check-latex/:courseSlug/:exerciseSlug/:lang",
|
837
|
-
// async (req, res) => {
|
838
|
-
// const { courseSlug, exerciseSlug, lang } = req.params
|
839
|
-
// const rigoToken = req.header("x-rigo-token")
|
840
|
-
// if (!rigoToken) {
|
841
|
-
// return res.status(400).json({ error: "Missing tokens" })
|
842
|
-
// }
|
843
|
-
// const exercise = await bucket.file(
|
844
|
-
// `courses/${courseSlug}/exercises/${exerciseSlug}/README.${lang}.md`
|
845
|
-
// )
|
846
|
-
// const [content] = await exercise.download()
|
847
|
-
// const headers = {
|
848
|
-
// Authorization: `Token ${rigoToken}`,
|
849
|
-
// }
|
850
|
-
// const response = await axios.get(
|
851
|
-
// `${RIGOBOT_HOST}/v1/prompting/completion/60865/`,
|
852
|
-
// {
|
853
|
-
// headers,
|
854
|
-
// }
|
855
|
-
// )
|
856
|
-
// console.log(response.data.parsed.content, "RESPONSE from Rigobot")
|
857
|
-
// res.json({
|
858
|
-
// message: "Exercise downloaded",
|
859
|
-
// completion: response.data,
|
860
|
-
// exercise: content.toString(),
|
861
|
-
// })
|
862
|
-
// }
|
863
|
-
// )
|
864
763
|
app.get("/courses/:courseSlug/syllabus", async (req, res) => {
|
865
764
|
try {
|
866
765
|
console.log("GET /courses/:courseSlug/syllabus");
|