@tansy/lms 0.0.0-stage → 0.1.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.
@@ -0,0 +1,187 @@
1
+ /** What learners read: course and lesson pages, quizzes, certificates and emails, as `t("lms.<key>")`. Themes and owners can word any of it differently. */
2
+ export const siteMessages = {
3
+ en: {
4
+ lms: {
5
+ noLessons: "No lessons yet.",
6
+ outline: "Course outline",
7
+ preview: "Preview",
8
+ completedMark: "(completed)",
9
+ minutes: "{count} min",
10
+ levels: { beginner: "Beginner", intermediate: "Intermediate", advanced: "Advanced" },
11
+ courseCompleted: "You completed this course.",
12
+ start: "Start: {title}",
13
+ continue: "Continue: {title}",
14
+ staffEnroll: "Staff enroll learners in this course.",
15
+ taughtBy: "Taught by {name}",
16
+ lessonsDone: "{done} of {total} lessons",
17
+ done: "{done} of {total}",
18
+ progress: "Course progress",
19
+ previewNotice: "This is a preview.",
20
+ enrollToTrack: "Enroll in the course to track your progress.",
21
+ lessons: "Lessons",
22
+ video: "Video",
23
+ transcript: "Transcript",
24
+ download: "Download",
25
+ enroll: "Enroll for free",
26
+ enrolling: "Enrolling…",
27
+ enrollFailed: "You couldn't be enrolled. Try again.",
28
+ enrollOffline: "You couldn't be enrolled. Check your connection and try again.",
29
+ buyFor: "Buy for {price}",
30
+ opening: "Opening checkout…",
31
+ checkoutFailed: "The checkout couldn't start. Try again.",
32
+ checkoutOffline: "The checkout couldn't start. Check your connection and try again.",
33
+ paymentSlow: "Your payment went through, and your enrollment is taking longer than usual. Refresh this page in a minute.",
34
+ paymentReceived: "Payment received. Setting up your enrollment…",
35
+ boughtNotEnrolled: "You bought this course, but you aren't enrolled in it. Contact the site if you think that's wrong.",
36
+ notForSale: "This course isn't on sale yet.",
37
+ includedIn: "Included in {plans}",
38
+ orPlan: "Or take it with a plan",
39
+ withPlan: "With a plan",
40
+ startWithPlan: "Start with your plan",
41
+ subscribeTo: "Subscribe to {plan}",
42
+ perMonth: "{price} a month",
43
+ perYear: "{price} a year",
44
+ subscribeFailed: "We couldn't open the checkout. Try again in a moment.",
45
+ subscribed: "Thanks for subscribing. Once your payment is confirmed, the courses in your plan open here.",
46
+ markComplete: "Mark as complete",
47
+ saving: "Saving…",
48
+ saveFailed: "Your progress couldn't be saved. Try again.",
49
+ finishedCourse: "You completed the course. Your certificate is on its way to your inbox.",
50
+ completed: "Completed",
51
+ nextLesson: "Next lesson",
52
+ quizSignIn: "Sign in to take this quiz.",
53
+ quizLocked: "This quiz opens once you're enrolled in the course.",
54
+ quizFailed: "The quiz couldn't load.",
55
+ quizLoading: "Loading quiz…",
56
+ passWith: "Pass with {score}%.",
57
+ attemptsLeft: "{count, plural, one {# attempt left.} other {# attempts left.}}",
58
+ passedQuiz: "You've passed this quiz.",
59
+ bestScore: "Best score: {score}%.",
60
+ result: "{correct} of {total} right: {score}%.",
61
+ passed: "Passed.",
62
+ notPassed: "Not passed yet.",
63
+ yourAnswer: "Your answer",
64
+ grading: "Grading…",
65
+ tryAgain: "Try again",
66
+ submit: "Submit answers",
67
+ sendFailed: "Your answers couldn't be sent. Try again.",
68
+ noAttempts: "You have used every attempt at this quiz.",
69
+ loadingCourses: "Loading your courses…",
70
+ signIn: "Sign in",
71
+ signInToSee: "Sign in to see your courses.",
72
+ coursesFailed: "Your courses couldn't load. Try again later.",
73
+ noCourses: "You aren't enrolled in any courses yet.",
74
+ course: "Course",
75
+ certificateCode: "Certificate code",
76
+ check: "Check",
77
+ noCertificate: "No certificate has this code.",
78
+ checkFailed: "The certificate couldn't be checked. Try again later.",
79
+ genuine: "Genuine certificate",
80
+ certified: "{name} completed {course}.",
81
+ certifiedOn: "{name} completed {course} on {date}.",
82
+ code: "Code {code}",
83
+ mail: {
84
+ enrolledSubject: "You're enrolled in {title}",
85
+ enrolledBody: "Hello {name},\n\nYou're now enrolled in {title}. Your courses are on the site's My courses page.",
86
+ completedSubject: "You completed {title}",
87
+ completedBody: "Congratulations, {name}. You have completed {title}.\n\nYour certificate code is {code}. Anyone can check it on the site's certificate page.",
88
+ someone: "there",
89
+ learner: "learner",
90
+ aCourse: "a course",
91
+ yourCourse: "your course",
92
+ },
93
+ },
94
+ },
95
+ ar: {
96
+ lms: {
97
+ noLessons: "لا توجد دروس بعد.",
98
+ outline: "محتوى الدورة",
99
+ preview: "معاينة",
100
+ completedMark: "(مكتمل)",
101
+ minutes: "{count} د",
102
+ levels: { beginner: "مبتدئ", intermediate: "متوسط", advanced: "متقدم" },
103
+ courseCompleted: "أكملت هذه الدورة.",
104
+ start: "ابدأ: {title}",
105
+ continue: "تابع: {title}",
106
+ staffEnroll: "يسجّل الفريق المتعلمين في هذه الدورة.",
107
+ taughtBy: "يقدّمها {name}",
108
+ lessonsDone: "{done} من {total} دروس",
109
+ done: "{done} من {total}",
110
+ progress: "التقدم في الدورة",
111
+ previewNotice: "هذه معاينة.",
112
+ enrollToTrack: "سجّل في الدورة لتتابع تقدمك.",
113
+ lessons: "الدروس",
114
+ video: "فيديو",
115
+ transcript: "النص المكتوب",
116
+ download: "تنزيل",
117
+ enroll: "سجّل مجانًا",
118
+ enrolling: "جارٍ التسجيل…",
119
+ enrollFailed: "تعذّر تسجيلك. حاول مجددًا.",
120
+ enrollOffline: "تعذّر تسجيلك. تحقق من اتصالك وحاول مجددًا.",
121
+ buyFor: "اشترِ بـ {price}",
122
+ opening: "جارٍ فتح صفحة الدفع…",
123
+ checkoutFailed: "تعذّر بدء الدفع. حاول مجددًا.",
124
+ checkoutOffline: "تعذّر بدء الدفع. تحقق من اتصالك وحاول مجددًا.",
125
+ paymentSlow: "تمّ الدفع، ويستغرق تسجيلك وقتًا أطول من المعتاد. حدّث هذه الصفحة بعد دقيقة.",
126
+ paymentReceived: "استلمنا الدفع. جارٍ تسجيلك…",
127
+ boughtNotEnrolled: "اشتريت هذه الدورة لكنك غير مسجّل فيها. تواصل مع الموقع إن كنت ترى أن هذا خطأ.",
128
+ notForSale: "هذه الدورة غير معروضة للبيع بعد.",
129
+ includedIn: "مشمولة في {plans}",
130
+ orPlan: "أو خذها ضمن خطة",
131
+ withPlan: "ضمن خطة",
132
+ startWithPlan: "ابدأ بخطتك",
133
+ subscribeTo: "اشترك في {plan}",
134
+ perMonth: "{price} شهريًا",
135
+ perYear: "{price} سنويًا",
136
+ subscribeFailed: "تعذّر فتح صفحة الدفع. حاول مرة أخرى بعد قليل.",
137
+ subscribed: "شكرًا لاشتراكك. حين يتأكد الدفع تُفتح هنا الدورات المشمولة في خطتك.",
138
+ markComplete: "حدّده مكتملًا",
139
+ saving: "جارٍ الحفظ…",
140
+ saveFailed: "تعذّر حفظ تقدمك. حاول مجددًا.",
141
+ finishedCourse: "أكملت الدورة. شهادتك في طريقها إلى بريدك.",
142
+ completed: "مكتمل",
143
+ nextLesson: "الدرس التالي",
144
+ quizSignIn: "سجّل الدخول لتخوض هذا الاختبار.",
145
+ quizLocked: "يُفتح هذا الاختبار بعد تسجيلك في الدورة.",
146
+ quizFailed: "تعذّر تحميل الاختبار.",
147
+ quizLoading: "جارٍ تحميل الاختبار…",
148
+ passWith: "تنجح بنسبة {score}%.",
149
+ attemptsLeft: "{count, plural, zero {لم تبق محاولات.} one {بقيت محاولة واحدة.} two {بقيت محاولتان.} few {بقيت # محاولات.} many {بقيت # محاولة.} other {بقيت # محاولة.}}",
150
+ passedQuiz: "نجحت في هذا الاختبار.",
151
+ bestScore: "أفضل نتيجة: {score}%.",
152
+ result: "{correct} من {total} صحيحة: {score}%.",
153
+ passed: "ناجح.",
154
+ notPassed: "لم تنجح بعد.",
155
+ yourAnswer: "إجابتك",
156
+ grading: "جارٍ التصحيح…",
157
+ tryAgain: "حاول مجددًا",
158
+ submit: "أرسل الإجابات",
159
+ sendFailed: "تعذّر إرسال إجاباتك. حاول مجددًا.",
160
+ noAttempts: "استنفدت كل محاولات هذا الاختبار.",
161
+ loadingCourses: "جارٍ تحميل دوراتك…",
162
+ signIn: "تسجيل الدخول",
163
+ signInToSee: "سجّل الدخول لترى دوراتك.",
164
+ coursesFailed: "تعذّر تحميل دوراتك. حاول لاحقًا.",
165
+ noCourses: "لست مسجّلًا في أي دورة بعد.",
166
+ course: "دورة",
167
+ certificateCode: "رمز الشهادة",
168
+ check: "تحقق",
169
+ noCertificate: "لا توجد شهادة بهذا الرمز.",
170
+ checkFailed: "تعذّر التحقق من الشهادة. حاول لاحقًا.",
171
+ genuine: "شهادة أصلية",
172
+ certified: "أكمل {name} دورة {course}.",
173
+ certifiedOn: "أكمل {name} دورة {course} في {date}.",
174
+ code: "الرمز {code}",
175
+ mail: {
176
+ enrolledSubject: "سُجّلت في {title}",
177
+ enrolledBody: "مرحبًا {name}،\n\nأنت الآن مسجّل في {title}. دوراتك في صفحة «دوراتي» على الموقع.",
178
+ completedSubject: "أكملت {title}",
179
+ completedBody: "تهانينا يا {name}. لقد أكملت {title}.\n\nرمز شهادتك هو {code}. يمكن لأي أحد التحقق منه في صفحة الشهادات على الموقع.",
180
+ someone: "بك",
181
+ learner: "أيها المتعلم",
182
+ aCourse: "دورة",
183
+ yourCourse: "دورتك",
184
+ },
185
+ },
186
+ },
187
+ };
package/tools.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ /** What an AI agent can do with courses, as whoever asked: instructors only in their own courses. */
3
+ export declare const lmsTools: import("tansy/plugin").AgentTool<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>[];
package/tools.js ADDED
@@ -0,0 +1,74 @@
1
+ import { z } from "zod";
2
+ import { defineTool } from "tansy/plugin";
3
+ import { idOf, listAll } from "./service";
4
+ const markdown = (what) => z.string().max(100_000).describe(`${what}, in Markdown`);
5
+ const lesson = z.object({
6
+ title: z.string().min(1).max(200),
7
+ content: markdown("The lesson's text").optional(),
8
+ durationMinutes: z.number().int().min(0).max(10_000).optional(),
9
+ preview: z.boolean().optional().describe("Open to everyone, enrolled or not"),
10
+ });
11
+ const courseInput = z.object({
12
+ title: z.string().min(1).max(200),
13
+ summary: z.string().max(500).optional().describe("One or two sentences for course lists"),
14
+ description: markdown("What the course covers, for its page").optional(),
15
+ level: z.enum(["beginner", "intermediate", "advanced"]).optional(),
16
+ access: z.enum(["free", "enrollment"]).optional().describe("free: anyone signed in can enroll. enrollment: staff enroll learners. Selling a course is set up in the dashboard"),
17
+ estimatedMinutes: z.number().int().min(0).max(100_000).optional(),
18
+ sections: z.array(z.object({ title: z.string().min(1).max(200), lessons: z.array(lesson).max(100) })).max(50),
19
+ });
20
+ /** Owners can remove fields, so only the ones the collection still has are written. */
21
+ async function keep(context, slug, values) {
22
+ const names = new Set((await context.schema.describe(slug))?.fields.map((field) => field.name) ?? []);
23
+ return Object.fromEntries(Object.entries(values).filter(([name, value]) => value !== undefined && names.has(name)));
24
+ }
25
+ /** A stream of one text block. create_record turns the Markdown into rich text and fills in the block's id and version. */
26
+ const textStream = (text) => (text?.trim() ? [{ type: "lms_text", value: { body: text } }] : undefined);
27
+ const create = async (context, slug, values) => (await context.tools.call("create_record", { collection: slug, data: await keep(context, slug, values) }));
28
+ /** What an AI agent can do with courses, as whoever asked: instructors only in their own courses. */
29
+ export const lmsTools = [
30
+ defineTool({
31
+ name: "lms_create_course",
32
+ description: "Create a whole course in one step: the course, its sections in order and each section's lessons with their text. Everything is saved as a draft for a person to review and publish. Covers, videos, downloads and quizzes are added afterwards in the course builder.",
33
+ input: courseInput,
34
+ access: { access: "authenticated" },
35
+ write: true,
36
+ audit: "lms.create_course",
37
+ handler: async (context) => {
38
+ const { sections, description, ...course } = context.input;
39
+ const created = await create(context, "lms-courses", { ...course, description: textStream(description), status: "draft" });
40
+ const courseId = idOf(created.id);
41
+ if (courseId === null)
42
+ throw new Error("The course was created without an id.");
43
+ let lessons = 0;
44
+ for (const [position, section] of sections.entries()) {
45
+ const made = await create(context, "lms-sections", { title: section.title, course: courseId, position, status: "draft" });
46
+ for (const [index, item] of section.lessons.entries()) {
47
+ await create(context, "lms-lessons", { title: item.title, course: courseId, section: idOf(made.id), position: index, preview: item.preview, durationMinutes: item.durationMinutes, content: textStream(item.content), status: "draft" });
48
+ lessons++;
49
+ }
50
+ }
51
+ return { course: { id: courseId, title: created.title, slug: created.slug }, sections: sections.length, lessons };
52
+ },
53
+ }),
54
+ defineTool({
55
+ name: "lms_outline",
56
+ description: "A course's sections and lessons in order, with their ids, as you can see them. Use it before adding to or reorganising a course.",
57
+ input: z.object({ course: z.number().int().positive().describe("The course's record id") }),
58
+ access: { access: "authenticated" },
59
+ write: false,
60
+ handler: async ({ records, input }) => {
61
+ const course = await records.get("lms-courses", input.course, { fields: "id,title,slug,status" });
62
+ const filter = `course = ${input.course}`;
63
+ const [sections, lessons] = await Promise.all([
64
+ listAll(records, "lms-sections", { filter, sort: "position,id", fields: "id,title,position,status" }),
65
+ listAll(records, "lms-lessons", { filter, sort: "position,id", fields: "id,title,section,position,preview,status" }),
66
+ ]);
67
+ return {
68
+ course,
69
+ sections: sections.map((section) => ({ ...section, lessons: lessons.filter((item) => item.section === section.id) })),
70
+ withoutSection: lessons.filter((item) => !sections.some((section) => section.id === item.section)),
71
+ };
72
+ },
73
+ }),
74
+ ];
package/words.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { type SiteWords } from "tansy/react";
2
+ /** The LMS's words in the page's language, or in English where a theme passes none. */
3
+ export declare const lmsWords: (words: SiteWords | null | undefined) => import("tansy/plugin").Formatters;
package/words.js ADDED
@@ -0,0 +1,5 @@
1
+ import { siteWords } from "tansy/react";
2
+ import { siteMessages } from "./site-messages";
3
+ const ENGLISH = { locale: "en", messages: siteMessages.en };
4
+ /** The LMS's words in the page's language, or in English where a theme passes none. */
5
+ export const lmsWords = (words) => siteWords(words ?? ENGLISH);