@celljs/ta-edu 4.28.0 → 4.30.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/web/index.js CHANGED
@@ -173,6 +173,40 @@ var TaAgentSummary;
173
173
  }
174
174
  TaAgentSummary2.strip = strip;
175
175
  })(TaAgentSummary || (TaAgentSummary = {}));
176
+ var TaPictureNote;
177
+ (function(TaPictureNote2) {
178
+ TaPictureNote2.OPEN = "<pictures>";
179
+ TaPictureNote2.CLOSE = "</pictures>";
180
+ const BLOCK = /[ \t]*<pictures>([\s\S]*?)(?:<\/pictures>|$)|<p(?:i(?:c(?:t(?:u(?:r(?:es?)?)?)?)?)?)?$/gi;
181
+ const ROW = /(?:^|\s)[-*]?\s*p(\d+)\s*[::]\s*/gi;
182
+ function take(text) {
183
+ const told = new Map;
184
+ if (!/<p/i.test(text)) {
185
+ return { said: text, told };
186
+ }
187
+ const said = text.replace(BLOCK, (_all, body) => {
188
+ const rows = [...(body !== null && body !== undefined ? body : "").matchAll(ROW)];
189
+ rows.forEach((row, index) => {
190
+ var _a;
191
+ var _b, _c;
192
+ const end = (_b = (_a = rows[index + 1]) === null || _a === undefined ? undefined : _a.index) !== null && _b !== undefined ? _b : body === null || body === undefined ? undefined : body.length;
193
+ const what = body === null || body === undefined ? undefined : body.slice(((_c = row.index) !== null && _c !== undefined ? _c : 0) + row[0].length, end).trim();
194
+ if (what) {
195
+ told.set(Number(row[1]), what);
196
+ }
197
+ });
198
+ return "";
199
+ });
200
+ return { said: said === text ? text : said.replace(/\n{3,}/g, `
201
+
202
+ `).trim(), told };
203
+ }
204
+ TaPictureNote2.take = take;
205
+ function strip(text) {
206
+ return take(text).said;
207
+ }
208
+ TaPictureNote2.strip = strip;
209
+ })(TaPictureNote || (TaPictureNote = {}));
176
210
  var TaSkillUse;
177
211
  (function(TaSkillUse2) {
178
212
  const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
@@ -282,6 +316,7 @@ var PAGE = `${NAME}/home`;
282
316
  var MARK = "[ta:edu]";
283
317
  var QUIZ = "ta-quiz";
284
318
  var LEARNING = "ta-learning";
319
+ var CONSENT = "ta-edu-consent";
285
320
  var GROUP_KIND = "ta-rooms";
286
321
  var DIRECT_KIND = "ta-direct";
287
322
  var STATE = "edu:";
@@ -296,8 +331,75 @@ var Keys;
296
331
  Keys.DAYS = "days";
297
332
  Keys.POSTED = "posted";
298
333
  Keys.TEACHER_KEY = "teacherKey";
334
+ Keys.CONSENT = "consent";
335
+ Keys.REPORTED = "reported";
336
+ Keys.TASKS = "tasks";
299
337
  })(Keys ||= {});
300
338
 
339
+ // web-src/edu-seal.ts
340
+ var CURVE = { name: "ECDH", namedCurve: "P-256" };
341
+ function base64(bytes) {
342
+ let text = "";
343
+ for (const byte of new Uint8Array(bytes)) {
344
+ text += String.fromCharCode(byte);
345
+ }
346
+ return btoa(text);
347
+ }
348
+ function bytes(text) {
349
+ const binary = atob(text);
350
+ const out = new Uint8Array(binary.length);
351
+ for (let i = 0;i < binary.length; i++) {
352
+ out[i] = binary.charCodeAt(i);
353
+ }
354
+ return out;
355
+ }
356
+ async function secret(privateKey, publicKey) {
357
+ const other = await crypto.subtle.importKey("jwk", publicKey, CURVE, false, []);
358
+ return crypto.subtle.deriveKey({ name: "ECDH", public: other }, privateKey, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
359
+ }
360
+ var EduSeal;
361
+ ((EduSeal) => {
362
+ async function keys() {
363
+ const pair = await crypto.subtle.generateKey(CURVE, true, ["deriveKey"]);
364
+ return { publicKey: await crypto.subtle.exportKey("jwk", pair.publicKey), privateKey: await crypto.subtle.exportKey("jwk", pair.privateKey) };
365
+ }
366
+ EduSeal.keys = keys;
367
+ function isKeys(value) {
368
+ const keys2 = value;
369
+ return !!keys2 && typeof keys2.publicKey?.x === "string" && typeof keys2.privateKey?.d === "string";
370
+ }
371
+ EduSeal.isKeys = isKeys;
372
+ function isPublic(value) {
373
+ const key = value;
374
+ return !!key && key.kty === "EC" && typeof key.x === "string" && typeof key.y === "string" && !("d" in key);
375
+ }
376
+ EduSeal.isPublic = isPublic;
377
+ async function seal(value, publicKey) {
378
+ const pair = await crypto.subtle.generateKey(CURVE, true, ["deriveKey"]);
379
+ const key = await secret(pair.privateKey, publicKey);
380
+ const iv = crypto.getRandomValues(new Uint8Array(12));
381
+ const data = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, new TextEncoder().encode(JSON.stringify(value)));
382
+ const e = await crypto.subtle.exportKey("jwk", pair.publicKey);
383
+ return { e: { kty: e.kty, crv: e.crv, x: e.x, y: e.y }, iv: base64(iv), d: base64(data) };
384
+ }
385
+ EduSeal.seal = seal;
386
+ async function open(sealed, keys2) {
387
+ const value = sealed;
388
+ if (!value || !isPublic(value.e) || typeof value.iv !== "string" || typeof value.d !== "string") {
389
+ return;
390
+ }
391
+ try {
392
+ const mine = await crypto.subtle.importKey("jwk", keys2.privateKey, CURVE, false, ["deriveKey"]);
393
+ const key = await secret(mine, value.e);
394
+ const data = await crypto.subtle.decrypt({ name: "AES-GCM", iv: bytes(value.iv) }, key, bytes(value.d));
395
+ return JSON.parse(new TextDecoder().decode(data));
396
+ } catch {
397
+ return;
398
+ }
399
+ }
400
+ EduSeal.open = open;
401
+ })(EduSeal ||= {});
402
+
301
403
  // ../ta-protocol/esm/common/figure-protocol.js
302
404
  var TaFigure;
303
405
  (function(TaFigure2) {
@@ -336,12 +438,10 @@ var EduUtil;
336
438
  stage: STAGES.includes(stored.stage) ? stored.stage : undefined,
337
439
  subject: typeof stored.subject === "string" ? stored.subject : "",
338
440
  textbook: typeof stored.textbook === "string" ? stored.textbook : "",
339
- consent: stored.consent === true,
340
441
  current: IDENTITIES.includes(stored.current) && identities.includes(stored.current) ? stored.current : undefined,
341
442
  classes: Array.isArray(stored.classes) ? stored.classes.filter((one) => typeof one === "string") : [],
342
443
  klass: typeof stored.klass === "string" ? stored.klass : undefined,
343
- reportTo: typeof stored.reportTo === "string" ? stored.reportTo : undefined,
344
- reportAt: typeof stored.reportAt === "number" ? stored.reportAt : undefined
444
+ reportTo: typeof stored.reportTo === "string" ? stored.reportTo : undefined
345
445
  };
346
446
  }
347
447
  EduUtil.settings = settings;
@@ -460,10 +560,23 @@ var EduUtil;
460
560
  return best;
461
561
  }
462
562
  EduUtil.hardest = hardest;
463
- function locked(settings2, identity) {
464
- return identity === "student" && settings2.stage === "primary" && !settings2.consent;
563
+ function locked(settings2, identity, consent2) {
564
+ return identity === "student" && settings2.stage === "primary" && !consent2?.granted;
465
565
  }
466
566
  EduUtil.locked = locked;
567
+ function reportedAt(value) {
568
+ const at = value?.at;
569
+ return typeof at === "number" ? at : undefined;
570
+ }
571
+ EduUtil.reportedAt = reportedAt;
572
+ function consent(value) {
573
+ const raw = value && typeof value === "object" ? value : {};
574
+ const one = (part, id) => part && typeof part[id] === "string" && typeof part.name === "string" && typeof part.at === "number" ? { [id]: part[id], name: part.name, at: part.at } : undefined;
575
+ const granted = one(raw.granted, "by");
576
+ const asked = one(raw.asked, "to");
577
+ return { ...granted ? { granted } : {}, ...asked ? { asked } : {} };
578
+ }
579
+ EduUtil.consent = consent;
467
580
  function hash(text2) {
468
581
  let h = 2166136261;
469
582
  for (let i = 0;i < text2.length; i++) {
@@ -613,89 +726,6 @@ ${question2.figure}` : question2.q),
613
726
  }
614
727
  })(EduUtil ||= {});
615
728
 
616
- // web-src/edu-roles.ts
617
- var QUIZ_FORMAT = `To give questions to answer, write a fenced block of language ${QUIZ} holding JSON, which Ta draws as a card the user answers in, checked at once: {"title"?: string, "reveal"?: boolean, "questions": [{"q": string, "options"?: [string] (a choice question; "answer" the letter), "answer": "B" | true | false (true or false question) | ["answers", "taken as right"] (fill in the blank), "explain": string, "subject": the school subject, "topic": the point it tests, "review"?: id of the mistake it reviews, "figure"?: its figure (geometry, a graph), drawn right under its text: {"ta-plot": the JSON of a ta-plot block} | {"ta-3d": that of a ta-3d block} | "![](image)"}]}. A figure goes in the question it belongs to, never as a block before the card; its text says "如图", not "如图 3". Mistakes the user makes in it are kept for review. To show how someone is learning, a ${LEARNING} block: {"title"?: string, "items": [{"label": topic, "value": 0-100 mastery, "note"?: string}], "weak"?: [string], "next"?: [what to do next]}.`;
618
- var ROLES = {
619
- student: {
620
- assistant: "assistantStudent",
621
- tagline: "taglineStudent",
622
- icon: "BookOpen",
623
- skills: ["edu-tutor", "edu-quiz"],
624
- actions: [
625
- { key: "explain", icon: "Image" },
626
- { key: "quizMe", icon: "ListChecks", send: true },
627
- { key: "review", icon: "RotateCcw", send: true },
628
- { key: "recite", icon: "Mic" }
629
- ],
630
- rules: "You tutor a student. Never give the final answer or a whole solution before the student has tried: ask what they know, give one hint at a time, let them do each step, and show the full solution only once they reached it or asked twice after trying. Check understanding with a question in another form. Never write their essays or homework for them: outlines, questions and comments on what they wrote. Encourage effort, not talent. If they speak of distress, listen, and tell them to talk to a parent or a teacher they trust."
631
- },
632
- parent: {
633
- assistant: "assistantParent",
634
- tagline: "taglineParent",
635
- icon: "House",
636
- skills: ["edu-parent", "edu-quiz"],
637
- actions: [
638
- { key: "check", icon: "Image" },
639
- { key: "talk", icon: "MessageCircle" },
640
- { key: "toTeacher", icon: "Send" },
641
- { key: "plan", icon: "Calendar" }
642
- ],
643
- rules: "You help a parent help their child. Tell the parent where and why the child went wrong, the words to explain it to the child at their age, and one practice question; do not do the homework for the child. Help them keep calm and kind; on messages to teachers, help them be clear, specific and respectful. Their child is theirs to judge: no labels, no diagnosis."
644
- },
645
- teacher: {
646
- assistant: "assistantTeacher",
647
- tagline: "taglineTeacher",
648
- icon: "Pencil",
649
- skills: ["edu-grading", "edu-quiz", "edu-lesson"],
650
- actions: [
651
- { key: "grade", icon: "ListChecks" },
652
- { key: "makeQuiz", icon: "FilePlus" },
653
- { key: "lesson", icon: "FileText" },
654
- { key: "exam", icon: "ChartSpline" },
655
- { key: "weekly", icon: "Calendar", send: true }
656
- ],
657
- rules: 'You assist a teacher. Marking: right or wrong for each question, the causes of the mistakes grouped, what the class shares, and an outline to go over it; what you are unsure of you say. Questions: in three levels (basic, better, stretch) with answers and explanations, "reveal": true. Score sheets and records in the working directory you read yourself; you count, the teacher decides. Names of students stay on this computer.'
658
- },
659
- homeroom: {
660
- assistant: "assistantHomeroom",
661
- tagline: "taglineHomeroom",
662
- icon: "Users",
663
- skills: ["edu-homeroom"],
664
- actions: [
665
- { key: "reply", icon: "MessageCircle" },
666
- { key: "comments", icon: "Pencil" },
667
- { key: "meeting", icon: "Users" },
668
- { key: "notice", icon: "Megaphone" }
669
- ],
670
- rules: "You assist a class teacher. Replies to parents are drafts the teacher sends: warm, clear, within what the school decides, never promising what is not theirs. Report comments come from what the teacher told of each student, specific and kind, no stock phrases. A student at risk (self-harm, abuse, bullying): tell the teacher to bring in the school counsellor, the school leaders and the parents at once; do not handle it alone."
671
- }
672
- };
673
- var STAGE_NAMES = { primary: "primary school", junior: "middle school", senior: "high school" };
674
- var EduRoles;
675
- ((EduRoles) => {
676
- function prompt(identity, settings) {
677
- const role = ROLES[identity];
678
- const about = [
679
- settings.stage && `stage: ${STAGE_NAMES[settings.stage]}`,
680
- settings.subject && `subjects: ${settings.subject}`,
681
- settings.textbook && `textbooks: ${settings.textbook}`
682
- ].filter(Boolean);
683
- return [
684
- `${MARK} You are Ta for a ${identity === "homeroom" ? "class teacher" : identity} in school education in China${about.length ? ` (${about.join("; ")})` : ""}.`,
685
- role.rules,
686
- `Skills for this: ${role.skills.join(", ")}.`,
687
- "What students, scores and families are is private: keep it on this computer, and leave names out of what is shared unless the user asks.",
688
- QUIZ_FORMAT
689
- ].join(`
690
- `);
691
- }
692
- EduRoles.prompt = prompt;
693
- function action(words, key) {
694
- return words[key];
695
- }
696
- EduRoles.action = action;
697
- })(EduRoles ||= {});
698
-
699
729
  // ../ta-protocol/esm/common/language.js
700
730
  var TaLanguageUtil;
701
731
  (function(TaLanguageUtil2) {
@@ -735,423 +765,8 @@ var TaLanguageUtil;
735
765
  TaLanguageUtil2.list = list;
736
766
  })(TaLanguageUtil || (TaLanguageUtil = {}));
737
767
 
738
- // web-src/i18n.ts
768
+ // web-src/i18n-home.ts
739
769
  var EN = {
740
- student: "Student",
741
- parent: "Parent",
742
- teacher: "Teacher",
743
- homeroom: "Class teacher",
744
- assistantStudent: "Study buddy",
745
- assistantParent: "Homework coach",
746
- assistantTeacher: "Teaching assistant",
747
- assistantHomeroom: "Class assistant",
748
- taglineStudent: "Works it out with you, not for you",
749
- taglineParent: "See where your child went wrong, and how to explain it",
750
- taglineTeacher: "Marking, questions, lesson plans, test analysis",
751
- taglineHomeroom: "Parents, report comments, class meetings, notices",
752
- due: "{count} mistakes to review today",
753
- locked: "A parent or teacher turns this on for primary school",
754
- primary: "Primary",
755
- junior: "Middle school",
756
- senior: "High school",
757
- consentTitle: "Let the child use the study buddy?",
758
- consentMessage: "Under the guidelines for generative AI in primary and secondary schools, primary pupils do not use open-ended AI on their own. Turn it on as a parent or teacher, and stay with them when you can.",
759
- consentConfirm: "I am a parent or teacher, turn it on",
760
- explain: { label: "Explain a problem", text: "I can't do this one. Don't tell me the answer yet, help me think it through:" },
761
- quizMe: { label: "Quiz me", text: "Give me a few questions on what I learned lately" },
762
- review: { label: "Review mistakes", text: "Review the {count} mistakes due today" },
763
- recite: { label: "Recite", text: "Help me learn this passage by heart: let me try first, then tell me what I got wrong:" },
764
- check: { label: "Check homework", text: "Look at my child’s homework: what is wrong, and how do I explain it to them?" },
765
- talk: { label: "What to say", text: "My child is in this situation. How should I talk to them about it?" },
766
- toTeacher: { label: "Message the teacher", text: "Help me write to the teacher, clearly and politely:" },
767
- plan: { label: "Plan the week", text: "Plan my child’s study for this week. How things are:" },
768
- grade: {
769
- label: "Mark homework",
770
- text: "Mark these (photos below): right or wrong for each question, the causes of the mistakes grouped, and an outline for going over them in class:"
771
- },
772
- makeQuiz: { label: "Set questions", text: "Set questions in three levels (basic, better, stretch) on:" },
773
- lesson: { label: "Lesson plan", text: "Write a lesson plan for:" },
774
- exam: { label: "Analyse a test", text: "Analyse this score sheet (file below): the weak points the class shares, and the students to look after:" },
775
- weekly: {
776
- label: "Weekly summary",
777
- text: "Every Friday at 4 pm, read this week’s scores and homework records in this folder and write me a summary of how the class is learning"
778
- },
779
- reply: { label: "Reply to a parent", text: `A parent wrote:
780
-
781
- Draft me a reply; I will read it before I send it:` },
782
- comments: { label: "Report comments", text: `Write report comments from how each student did, below, with no stock phrases:
783
- ` },
784
- meeting: { label: "Class meeting", text: "Plan a class meeting on:" },
785
- notice: { label: "Notice to parents", text: "Write a notice to parents about:" },
786
- settingsTitle: "Education",
787
- identitiesLabel: "Who you are",
788
- identitiesHint: "Each one you pick has its assistant in your list",
789
- stageLabel: "Stage",
790
- subjectLabel: "Subjects",
791
- subjectHint: "Such as maths, English",
792
- textbookLabel: "Textbooks",
793
- textbookHint: "The edition your school uses",
794
- consentLabel: "Primary pupils may use the study buddy",
795
- consentHint: "Turned on by a parent or teacher",
796
- quiz: "Practice",
797
- submit: "Check",
798
- right: "Right",
799
- wrongAnswer: "The answer: {answer}",
800
- score: "{right} of {total} right",
801
- explainWrong: "Go over my mistakes",
802
- explainWrongText: "Go over the questions I got wrong",
803
- judgeTrue: "True",
804
- judgeFalse: "False",
805
- blank: "Your answer",
806
- revealAnswer: "Answer: {answer}",
807
- learning: "How it is going",
808
- weak: "Weak points",
809
- next: "Next"
810
- };
811
- var ZH = {
812
- student: "学生",
813
- parent: "家长",
814
- teacher: "老师",
815
- homeroom: "班主任",
816
- assistantStudent: "学习伙伴",
817
- assistantParent: "辅导助手",
818
- assistantTeacher: "教学助手",
819
- assistantHomeroom: "班级助手",
820
- taglineStudent: "不直接给答案,带你自己做出来",
821
- taglineParent: "看懂孩子错在哪,知道怎么讲",
822
- taglineTeacher: "批改、出题、备课、试卷分析",
823
- taglineHomeroom: "家长沟通、评语、班会、通知",
824
- due: "{count} 道错题今天该复习",
825
- locked: "小学生需要家长或老师开启",
826
- primary: "小学",
827
- junior: "初中",
828
- senior: "高中",
829
- consentTitle: "让孩子使用学习伙伴?",
830
- consentMessage: "按《中小学生成式人工智能使用指南》,小学生不独自使用开放式生成。请家长或老师确认后开启,平时尽量陪着用。",
831
- consentConfirm: "我是家长或老师,开启",
832
- explain: { label: "拍题讲解", text: "这道题我不会,先别告诉我答案,带我一步步想:" },
833
- quizMe: { label: "考考我", text: "按我最近学的内容出几道题考考我" },
834
- review: { label: "复习错题", text: "复习今天该复习的 {count} 道错题" },
835
- recite: { label: "背诵默写", text: "帮我背这一段,先让我自己背,再告诉我哪里错了:" },
836
- check: { label: "看作业对错", text: "帮我看看孩子这份作业哪里错了,告诉我怎么讲给孩子听:" },
837
- talk: { label: "怎么跟孩子讲", text: "孩子遇到这个情况,我该怎么跟他说:" },
838
- toTeacher: { label: "给老师写消息", text: "帮我写一段给老师的话,说清楚、有分寸:" },
839
- plan: { label: "安排学习计划", text: "帮孩子安排这周的学习计划,情况是:" },
840
- grade: { label: "批改作业", text: "批改这些作业(照片在下面),逐题判对错,归类错因,最后给讲评提纲:" },
841
- makeQuiz: { label: "出一套题", text: "出一套题,分基础、提升、拓展三层,主题是:" },
842
- lesson: { label: "写教学设计", text: "写一份教学设计,课题是:" },
843
- exam: { label: "试卷分析", text: "分析这份成绩表(文件在下面),找出共性薄弱点和需要关注的学生:" },
844
- weekly: { label: "每周学情小结", text: "每周五下午 4 点,读本目录里这一周的成绩和作业记录,写一份学情小结给我" },
845
- reply: { label: "回家长消息", text: `家长发来:
846
-
847
- 帮我拟一段回复,我看过再发:` },
848
- comments: { label: "写评语", text: `按下面每个学生的表现写评语,不写套话:
849
- ` },
850
- meeting: { label: "班会方案", text: "设计一次班会,主题是:" },
851
- notice: { label: "写通知", text: "写一则给家长的通知,内容是:" },
852
- settingsTitle: "教育",
853
- identitiesLabel: "身份",
854
- identitiesHint: "选了哪个,列表里就有对应的助手",
855
- stageLabel: "学段",
856
- subjectLabel: "学科",
857
- subjectHint: "如 数学、英语",
858
- textbookLabel: "教材版本",
859
- textbookHint: "学校用的教材版本",
860
- consentLabel: "允许小学生使用学习伙伴",
861
- consentHint: "由家长或老师开启",
862
- quiz: "练习",
863
- submit: "提交",
864
- right: "答对了",
865
- wrongAnswer: "正确答案:{answer}",
866
- score: "答对 {right}/{total}",
867
- explainWrong: "讲讲我错的",
868
- explainWrongText: "讲讲这几道我做错的题",
869
- judgeTrue: "对",
870
- judgeFalse: "错",
871
- blank: "写下答案",
872
- revealAnswer: "答案:{answer}",
873
- learning: "学情",
874
- weak: "薄弱点",
875
- next: "接下来"
876
- };
877
- var ZH_TW = {
878
- student: "學生",
879
- parent: "家長",
880
- teacher: "老師",
881
- homeroom: "班導師",
882
- assistantStudent: "學習夥伴",
883
- assistantParent: "輔導助手",
884
- assistantTeacher: "教學助手",
885
- assistantHomeroom: "班級助手",
886
- taglineStudent: "不直接給答案,帶你自己做出來",
887
- taglineParent: "看懂孩子錯在哪,知道怎麼講",
888
- taglineTeacher: "批改、出題、備課、試卷分析",
889
- taglineHomeroom: "家長溝通、評語、班會、通知",
890
- due: "{count} 道錯題今天該複習",
891
- locked: "小學生需要家長或老師開啟",
892
- primary: "小學",
893
- junior: "國中",
894
- senior: "高中",
895
- consentTitle: "讓孩子使用學習夥伴?",
896
- consentMessage: "依照中小學生成式人工智慧使用指南,小學生不獨自使用開放式生成。請家長或老師確認後開啟,平時盡量陪著用。",
897
- consentConfirm: "我是家長或老師,開啟",
898
- explain: { label: "拍題講解", text: "這道題我不會,先別告訴我答案,帶我一步步想:" },
899
- quizMe: { label: "考考我", text: "依我最近學的內容出幾道題考考我" },
900
- review: { label: "複習錯題", text: "複習今天該複習的 {count} 道錯題" },
901
- recite: { label: "背誦默寫", text: "幫我背這一段,先讓我自己背,再告訴我哪裡錯了:" },
902
- check: { label: "看作業對錯", text: "幫我看看孩子這份作業哪裡錯了,告訴我怎麼講給孩子聽:" },
903
- talk: { label: "怎麼跟孩子講", text: "孩子遇到這個情況,我該怎麼跟他說:" },
904
- toTeacher: { label: "給老師寫訊息", text: "幫我寫一段給老師的話,說清楚、有分寸:" },
905
- plan: { label: "安排學習計畫", text: "幫孩子安排這週的學習計畫,情況是:" },
906
- grade: { label: "批改作業", text: "批改這些作業(照片在下面),逐題判對錯,歸類錯因,最後給講評提綱:" },
907
- makeQuiz: { label: "出一套題", text: "出一套題,分基礎、提升、拓展三層,主題是:" },
908
- lesson: { label: "寫教學設計", text: "寫一份教學設計,課題是:" },
909
- exam: { label: "試卷分析", text: "分析這份成績表(檔案在下面),找出共同的薄弱點和需要關注的學生:" },
910
- weekly: { label: "每週學習小結", text: "每週五下午 4 點,讀本目錄裡這一週的成績和作業紀錄,寫一份學習小結給我" },
911
- reply: { label: "回家長訊息", text: `家長傳來:
912
-
913
- 幫我擬一段回覆,我看過再傳:` },
914
- comments: { label: "寫評語", text: `依下面每個學生的表現寫評語,不寫套話:
915
- ` },
916
- meeting: { label: "班會方案", text: "設計一次班會,主題是:" },
917
- notice: { label: "寫通知", text: "寫一則給家長的通知,內容是:" },
918
- settingsTitle: "教育",
919
- identitiesLabel: "身分",
920
- identitiesHint: "選了哪個,列表裡就有對應的助手",
921
- stageLabel: "學段",
922
- subjectLabel: "學科",
923
- subjectHint: "如 數學、英語",
924
- textbookLabel: "教材版本",
925
- textbookHint: "學校用的教材版本",
926
- consentLabel: "允許小學生使用學習夥伴",
927
- consentHint: "由家長或老師開啟",
928
- quiz: "練習",
929
- submit: "送出",
930
- right: "答對了",
931
- wrongAnswer: "正確答案:{answer}",
932
- score: "答對 {right}/{total}",
933
- explainWrong: "講講我錯的",
934
- explainWrongText: "講講這幾道我做錯的題",
935
- judgeTrue: "對",
936
- judgeFalse: "錯",
937
- blank: "寫下答案",
938
- revealAnswer: "答案:{answer}",
939
- learning: "學習情況",
940
- weak: "薄弱點",
941
- next: "接下來"
942
- };
943
- var JA = {
944
- student: "生徒",
945
- parent: "保護者",
946
- teacher: "先生",
947
- homeroom: "担任",
948
- assistantStudent: "学習パートナー",
949
- assistantParent: "家庭学習サポート",
950
- assistantTeacher: "授業アシスタント",
951
- assistantHomeroom: "クラスアシスタント",
952
- taglineStudent: "答えを教えず、自分で解けるまで一緒に考えます",
953
- taglineParent: "どこで間違えたか、どう伝えればいいかが分かります",
954
- taglineTeacher: "採点、出題、授業準備、テスト分析",
955
- taglineHomeroom: "保護者対応、所見、学級活動、お知らせ",
956
- due: "今日復習する間違いが {count} 問",
957
- locked: "小学生は保護者か先生がオンにします",
958
- primary: "小学校",
959
- junior: "中学校",
960
- senior: "高校",
961
- consentTitle: "お子さんに学習パートナーを使わせますか?",
962
- consentMessage: "小中学校の生成 AI 利用指針では、小学生は自由に生成する AI を一人で使いません。保護者か先生が確認してオンにし、できるだけそばで見守ってください。",
963
- consentConfirm: "保護者・先生としてオンにする",
964
- explain: { label: "問題を解説", text: "この問題が分かりません。答えはまだ言わずに、一歩ずつ考えさせてください:" },
965
- quizMe: { label: "問題を出して", text: "最近習ったところから何問か出してください" },
966
- review: { label: "間違いを復習", text: "今日復習する {count} 問の間違いを復習する" },
967
- recite: { label: "暗記・暗唱", text: "この部分を覚えたいです。まず自分で言ってみるので、違うところを教えてください:" },
968
- check: { label: "宿題を確認", text: "子どもの宿題のどこが間違っているか、どう説明すればいいか教えてください:" },
969
- talk: { label: "どう話すか", text: "子どもがこういう状況です。どう話せばいいでしょうか:" },
970
- toTeacher: { label: "先生への連絡", text: "先生への連絡を、分かりやすく失礼のないように書いてください:" },
971
- plan: { label: "学習計画", text: "子どもの今週の学習計画を立ててください。状況は:" },
972
- grade: { label: "宿題を採点", text: "この宿題(写真は下)を採点してください。一問ずつ正誤、間違いの原因の分類、最後に解説授業の要点を:" },
973
- makeQuiz: { label: "問題を作る", text: "基礎・応用・発展の三段階で問題を作ってください。テーマは:" },
974
- lesson: { label: "指導案", text: "指導案を書いてください。単元は:" },
975
- exam: { label: "テスト分析", text: "この成績表(ファイルは下)を分析して、クラス共通の弱点と気にかけるべき生徒を挙げてください:" },
976
- weekly: { label: "毎週のまとめ", text: "毎週金曜の午後 4 時に、このフォルダの今週の成績と宿題の記録を読んで、学習状況のまとめを書いてください" },
977
- reply: { label: "保護者に返信", text: `保護者からの連絡:
978
-
979
- 返信の下書きをお願いします。読んでから送ります:` },
980
- comments: { label: "所見を書く", text: `下の各生徒の様子をもとに、決まり文句なしで所見を書いてください:
981
- ` },
982
- meeting: { label: "学級活動", text: "学級活動の案を作ってください。テーマは:" },
983
- notice: { label: "お知らせ", text: "保護者へのお知らせを書いてください。内容は:" },
984
- settingsTitle: "教育",
985
- identitiesLabel: "あなたの立場",
986
- identitiesHint: "選んだ立場ごとに、リストにアシスタントが出ます",
987
- stageLabel: "学校段階",
988
- subjectLabel: "教科",
989
- subjectHint: "例:数学、英語",
990
- textbookLabel: "教科書",
991
- textbookHint: "学校で使っている教科書",
992
- consentLabel: "小学生が学習パートナーを使える",
993
- consentHint: "保護者か先生がオンにします",
994
- quiz: "練習",
995
- submit: "答え合わせ",
996
- right: "正解",
997
- wrongAnswer: "正解:{answer}",
998
- score: "{total} 問中 {right} 問正解",
999
- explainWrong: "間違いを解説",
1000
- explainWrongText: "間違えた問題を解説して",
1001
- judgeTrue: "正しい",
1002
- judgeFalse: "誤り",
1003
- blank: "答えを書く",
1004
- revealAnswer: "答え:{answer}",
1005
- learning: "学習状況",
1006
- weak: "弱点",
1007
- next: "次に"
1008
- };
1009
- var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
1010
- var EduWords;
1011
- ((EduWords) => {
1012
- function of(language) {
1013
- return TaLanguageUtil.pick(language, WORDS);
1014
- }
1015
- EduWords.of = of;
1016
- function format(text, values) {
1017
- return text.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
1018
- }
1019
- EduWords.format = format;
1020
- })(EduWords ||= {});
1021
-
1022
- // web-src/edu-chats.ts
1023
- var EduChats;
1024
- ((EduChats) => {
1025
- function identityOf(store, sessionFile) {
1026
- const { chats } = store.state;
1027
- return sessionFile ? Object.keys(chats).find((one) => chats[one] === sessionFile) : undefined;
1028
- }
1029
- EduChats.identityOf = identityOf;
1030
- async function open(pi, store, identity) {
1031
- const words = EduWords.of(pi.ui.language);
1032
- const { settings, chats } = store.state;
1033
- if (EduUtil.locked(settings, identity)) {
1034
- const yes = await pi.ui.confirm(words.consentTitle, words.consentMessage, { confirmLabel: words.consentConfirm });
1035
- if (!yes) {
1036
- return;
1037
- }
1038
- await store.setSettings({ consent: true });
1039
- }
1040
- const role = EduRoles.prompt(identity, store.state.settings);
1041
- const title = words[ROLES[identity].assistant];
1042
- const file = chats[identity];
1043
- if (file) {
1044
- const open2 = (await pi.server.listSessions()).find((session) => session.sessionFile === file);
1045
- if (open2) {
1046
- await pi.switchSession(open2.sessionId);
1047
- pi.ui.showView("");
1048
- return open2.sessionId;
1049
- }
1050
- const saved = (await pi.server.listSavedSessions()).find((session) => session.sessionFile === file);
1051
- if (saved) {
1052
- const opened2 = pi.server.openSession({ cwd: saved.cwd, sessionFile: file, group: NAME, appendSystemPrompt: role });
1053
- const id2 = opened2.then((session) => session.sessionId);
1054
- await pi.switchSession(id2, { title, cwd: saved.cwd, sessionFile: file });
1055
- pi.ui.showView("");
1056
- return id2;
1057
- }
1058
- }
1059
- const { cwd } = await pi.server.getServerInfo();
1060
- const opened = pi.server.openSession({ cwd, group: NAME, appendSystemPrompt: role });
1061
- const named = opened.then(async (session) => {
1062
- if (session.sessionFile) {
1063
- await store.setChat(identity, session.sessionFile);
1064
- }
1065
- await pi.server.setSessionName(session.sessionId, title);
1066
- });
1067
- const id = opened.then((session) => session.sessionId);
1068
- await pi.switchSession(id, { title, cwd });
1069
- pi.ui.showView("");
1070
- await named;
1071
- return id;
1072
- }
1073
- EduChats.open = open;
1074
- async function say(pi, store, identity, message, images) {
1075
- const id = await open(pi, store, identity);
1076
- if (id) {
1077
- await send(pi, id, message, images);
1078
- }
1079
- }
1080
- EduChats.say = say;
1081
- async function send(pi, sessionId, message, images) {
1082
- await pi.server.prompt(sessionId, { message, ...images?.length ? { images } : {}, clientMessageId: crypto.randomUUID() });
1083
- }
1084
- EduChats.send = send;
1085
- })(EduChats ||= {});
1086
- var EduPhotos;
1087
- ((EduPhotos) => {
1088
- function pick() {
1089
- return new Promise((resolve) => {
1090
- const input = document.createElement("input");
1091
- input.type = "file";
1092
- input.accept = "image/*";
1093
- input.multiple = true;
1094
- input.style.display = "none";
1095
- input.addEventListener("change", () => {
1096
- const files = [...input.files ?? []].slice(0, 6);
1097
- input.remove();
1098
- Promise.all(files.map(shrink)).then(resolve, () => resolve([]));
1099
- });
1100
- input.addEventListener("cancel", () => {
1101
- input.remove();
1102
- resolve([]);
1103
- });
1104
- document.body.appendChild(input);
1105
- input.click();
1106
- });
1107
- }
1108
- EduPhotos.pick = pick;
1109
- async function shrink(file) {
1110
- const bitmap = await createImageBitmap(file);
1111
- const scale = Math.min(1, 1600 / Math.max(bitmap.width, bitmap.height));
1112
- const canvas = document.createElement("canvas");
1113
- canvas.width = Math.round(bitmap.width * scale);
1114
- canvas.height = Math.round(bitmap.height * scale);
1115
- canvas.getContext("2d")?.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
1116
- bitmap.close();
1117
- const url = canvas.toDataURL("image/jpeg", 0.85);
1118
- return { type: "image", data: url.slice(url.indexOf(",") + 1), mimeType: "image/jpeg" };
1119
- }
1120
- function upload(pi, accept) {
1121
- return new Promise((resolve) => {
1122
- const input = document.createElement("input");
1123
- input.type = "file";
1124
- input.accept = accept;
1125
- input.style.display = "none";
1126
- input.addEventListener("change", () => {
1127
- const file = input.files?.[0];
1128
- input.remove();
1129
- if (!file) {
1130
- resolve(undefined);
1131
- return;
1132
- }
1133
- const reader = new FileReader;
1134
- reader.onload = () => {
1135
- const url = String(reader.result);
1136
- const path = `edu/${file.name.replace(/[\\/]/g, "_")}`;
1137
- pi.workspace.uploadFile(path, url.slice(url.indexOf(",") + 1)).then(() => resolve(path), () => resolve(undefined));
1138
- };
1139
- reader.onerror = () => resolve(undefined);
1140
- reader.readAsDataURL(file);
1141
- });
1142
- input.addEventListener("cancel", () => {
1143
- input.remove();
1144
- resolve(undefined);
1145
- });
1146
- document.body.appendChild(input);
1147
- input.click();
1148
- });
1149
- }
1150
- EduPhotos.upload = upload;
1151
- })(EduPhotos ||= {});
1152
-
1153
- // web-src/i18n-home.ts
1154
- var EN2 = {
1155
770
  eduTitle: "Education",
1156
771
  pickTitle: "I am…",
1157
772
  pickHint: "Pick all that fit; switch between them at the top",
@@ -1182,7 +797,7 @@ var EN2 = {
1182
797
  statDays: "days studied",
1183
798
  weekdays: "MTWTFSS",
1184
799
  toParent: "Send my week to a parent",
1185
- toParentOn: "Each week to {name}",
800
+ toParentOn: "Sundays to {name}",
1186
801
  pickParent: "Send it to",
1187
802
  noFriends: "Add your parent as a friend in Ta first",
1188
803
  reportPrivacy: "Only counts, how many were right and weak points go, never what you said",
@@ -1275,11 +890,37 @@ var EN2 = {
1275
890
  followUpText: 'Set more practice on question {no} of "{title}" for those who got it wrong',
1276
891
  noticeHelp: "A notice from the teacher: what do I need to do, and when?",
1277
892
  askHelp: "A parent wrote to me in the class group. Draft me a reply; I will read it before I send it",
893
+ consentNeeded: "Ask a parent first",
894
+ consentNeededHint: "At primary school the study buddy is used with a parent’s yes, given in their own Ta",
895
+ consentAsk: "Ask a parent",
896
+ consentAsked: "Asked {name} · waiting for their yes",
897
+ consentAskOther: "Ask again or ask someone else",
898
+ consentAskIntro: "{name} would like to use the study buddy of Ta. Say yes under Education → Parent in your Ta",
899
+ consentGrantIntro: "Yes, you may use the study buddy",
900
+ consentRevokeIntro: "Not the study buddy for now",
901
+ consentAskTitle: "{name} would like to use the study buddy",
902
+ consentAskBody: "It guides them to work things out and never writes their homework. Best used with you around.",
903
+ consentYes: "Say yes",
904
+ consentNo: "Not now",
905
+ consentTakeBack: "Take it back",
906
+ consentYouGranted: "You said yes to {name}",
907
+ consentYouRevoked: "You said not now to {name}",
908
+ consentGrantedChild: "{name} said yes: the study buddy is yours",
909
+ consentRevokedChild: "{name} said not now",
910
+ consentWaitingChild: "Asked for a yes",
911
+ consentAsks: "Your child asks",
912
+ consentLocked: "Ask a parent first: they say yes in their own Ta",
913
+ consentBy: "{name} said yes on {date}",
914
+ consentNone: "No parent said yes yet",
915
+ taskStudent: "Mistakes to review tonight",
916
+ taskParent: "Your child’s week",
917
+ taskTeacher: "The week of practice",
918
+ taskHomeroom: "Parents’ messages today",
1278
919
  failed: "It did not work: {error}",
1279
920
  today: "Today",
1280
921
  yesterday: "Yesterday"
1281
922
  };
1282
- var ZH2 = {
923
+ var ZH = {
1283
924
  eduTitle: "教育",
1284
925
  pickTitle: "我是…",
1285
926
  pickHint: "可以多选,在顶上切换",
@@ -1310,7 +951,7 @@ var ZH2 = {
1310
951
  statDays: "天在学",
1311
952
  weekdays: "一二三四五六日",
1312
953
  toParent: "每周把学情发给家长",
1313
- toParentOn: "每周发给 {name}",
954
+ toParentOn: "每周日发给 {name}",
1314
955
  pickParent: "发给谁",
1315
956
  noFriends: "先在 Ta 里加家长为好友",
1316
957
  reportPrivacy: "只发做题数、正确率和薄弱点,不发对话内容",
@@ -1403,11 +1044,37 @@ var ZH2 = {
1403
1044
  followUpText: "给做错练习「{title}」第 {no} 题的同学补一套同类题",
1404
1045
  noticeHelp: "这是老师发的通知:我需要做什么、什么时候做?",
1405
1046
  askHelp: "家长在班级群里找我,帮我拟一段回复,我看过再发",
1047
+ consentNeeded: "先请家长同意",
1048
+ consentNeededHint: "小学段要家长在他自己的 Ta 里同意,才能用学习伙伴",
1049
+ consentAsk: "请家长同意",
1050
+ consentAsked: "已请 {name} 同意,等他回复",
1051
+ consentAskOther: "再请一次或换个人",
1052
+ consentAskIntro: "{name}想用 Ta 的学习伙伴,请在你的 Ta「教育 · 家长」里同意",
1053
+ consentGrantIntro: "我同意你用学习伙伴",
1054
+ consentRevokeIntro: "学习伙伴先不用了",
1055
+ consentAskTitle: "{name}想用学习伙伴",
1056
+ consentAskBody: "它只引导孩子自己想出来,不给答案、不代写作业。平时尽量陪着用。",
1057
+ consentYes: "同意",
1058
+ consentNo: "先不",
1059
+ consentTakeBack: "收回同意",
1060
+ consentYouGranted: "你已同意{name}用学习伙伴",
1061
+ consentYouRevoked: "你暂不让{name}用学习伙伴",
1062
+ consentGrantedChild: "{name}同意了,可以用学习伙伴了",
1063
+ consentRevokedChild: "{name}说先不用",
1064
+ consentWaitingChild: "已请家长同意",
1065
+ consentAsks: "孩子请你同意",
1066
+ consentLocked: "先请家长同意:家长在他自己的 Ta 里点同意",
1067
+ consentBy: "{name} 于 {date} 同意",
1068
+ consentNone: "还没有家长同意",
1069
+ taskStudent: "今晚错题复习",
1070
+ taskParent: "孩子这周学习简报",
1071
+ taskTeacher: "本周学情小结",
1072
+ taskHomeroom: "今天的家长消息",
1406
1073
  failed: "没做成:{error}",
1407
1074
  today: "今天",
1408
1075
  yesterday: "昨天"
1409
1076
  };
1410
- var ZH_TW2 = {
1077
+ var ZH_TW = {
1411
1078
  eduTitle: "教育",
1412
1079
  pickTitle: "我是…",
1413
1080
  pickHint: "可以複選,在頂端切換",
@@ -1438,7 +1105,7 @@ var ZH_TW2 = {
1438
1105
  statDays: "天在學",
1439
1106
  weekdays: "一二三四五六日",
1440
1107
  toParent: "每週把學習狀況傳給家長",
1441
- toParentOn: "每週傳給 {name}",
1108
+ toParentOn: "每週日傳給 {name}",
1442
1109
  pickParent: "傳給誰",
1443
1110
  noFriends: "先在 Ta 裡加家長為好友",
1444
1111
  reportPrivacy: "只傳做題數、正確率和弱點,不傳對話內容",
@@ -1531,11 +1198,37 @@ var ZH_TW2 = {
1531
1198
  followUpText: "給做錯練習「{title}」第 {no} 題的同學補一套同類題",
1532
1199
  noticeHelp: "這是老師傳的通知:我需要做什麼、什麼時候做?",
1533
1200
  askHelp: "家長在班級群組裡找我,幫我擬一段回覆,我看過再傳",
1201
+ consentNeeded: "先請家長同意",
1202
+ consentNeededHint: "小學階段要家長在他自己的 Ta 裡同意,才能用學習夥伴",
1203
+ consentAsk: "請家長同意",
1204
+ consentAsked: "已請 {name} 同意,等他回覆",
1205
+ consentAskOther: "再請一次或換個人",
1206
+ consentAskIntro: "{name}想用 Ta 的學習夥伴,請在你的 Ta「教育 · 家長」裡同意",
1207
+ consentGrantIntro: "我同意你用學習夥伴",
1208
+ consentRevokeIntro: "學習夥伴先不用了",
1209
+ consentAskTitle: "{name}想用學習夥伴",
1210
+ consentAskBody: "它只引導孩子自己想出來,不給答案、不代寫作業。平時盡量陪著用。",
1211
+ consentYes: "同意",
1212
+ consentNo: "先不",
1213
+ consentTakeBack: "收回同意",
1214
+ consentYouGranted: "你已同意{name}用學習夥伴",
1215
+ consentYouRevoked: "你暫不讓{name}用學習夥伴",
1216
+ consentGrantedChild: "{name}同意了,可以用學習夥伴了",
1217
+ consentRevokedChild: "{name}說先不用",
1218
+ consentWaitingChild: "已請家長同意",
1219
+ consentAsks: "孩子請你同意",
1220
+ consentLocked: "先請家長同意:家長在他自己的 Ta 裡點同意",
1221
+ consentBy: "{name} 於 {date} 同意",
1222
+ consentNone: "還沒有家長同意",
1223
+ taskStudent: "今晚錯題複習",
1224
+ taskParent: "孩子這週學習簡報",
1225
+ taskTeacher: "本週學情小結",
1226
+ taskHomeroom: "今天的家長訊息",
1534
1227
  failed: "沒做成:{error}",
1535
1228
  today: "今天",
1536
1229
  yesterday: "昨天"
1537
1230
  };
1538
- var JA2 = {
1231
+ var JA = {
1539
1232
  eduTitle: "教育",
1540
1233
  pickTitle: "わたしは…",
1541
1234
  pickHint: "複数選べます。上で切り替えます",
@@ -1566,7 +1259,7 @@ var JA2 = {
1566
1259
  statDays: "日学習",
1567
1260
  weekdays: "月火水木金土日",
1568
1261
  toParent: "毎週の学習状況を保護者に送る",
1569
- toParentOn: "毎週 {name} に送信",
1262
+ toParentOn: "毎週日曜に {name} へ",
1570
1263
  pickParent: "送り先",
1571
1264
  noFriends: "先に Ta で保護者を友だちに追加してください",
1572
1265
  reportPrivacy: "送るのは問題数・正答率・弱点だけで、会話の内容は送りません",
@@ -1659,11 +1352,37 @@ var JA2 = {
1659
1352
  followUpText: "練習「{title}」の第 {no} 問を間違えた生徒に、同じような問題を作ってください",
1660
1353
  noticeHelp: "先生からのお知らせです。何をいつまでにすればいいですか",
1661
1354
  askHelp: "保護者がクラスのグループで連絡をくれました。返信の下書きをお願いします。読んでから送ります",
1355
+ consentNeeded: "まず保護者の同意を",
1356
+ consentNeededHint: "小学生は、保護者が自分の Ta で同意してから学習パートナーを使います",
1357
+ consentAsk: "保護者に頼む",
1358
+ consentAsked: "{name} に頼みました · 返事待ち",
1359
+ consentAskOther: "もう一度、または別の人に",
1360
+ consentAskIntro: "{name} が Ta の学習パートナーを使いたがっています。あなたの Ta の「教育 · 保護者」で同意してください",
1361
+ consentGrantIntro: "学習パートナーを使っていいよ",
1362
+ consentRevokeIntro: "学習パートナーはしばらくお休み",
1363
+ consentAskTitle: "{name} が学習パートナーを使いたがっています",
1364
+ consentAskBody: "答えを教えず、自分で考えられるように導きます。宿題の代筆はしません。できるだけそばで使ってください。",
1365
+ consentYes: "同意する",
1366
+ consentNo: "今はやめる",
1367
+ consentTakeBack: "同意を取り消す",
1368
+ consentYouGranted: "{name} に同意しました",
1369
+ consentYouRevoked: "{name} にはまだ使わせません",
1370
+ consentGrantedChild: "{name} が同意しました。学習パートナーを使えます",
1371
+ consentRevokedChild: "{name}:今はやめておこう",
1372
+ consentWaitingChild: "保護者に同意を頼みました",
1373
+ consentAsks: "お子さんからのお願い",
1374
+ consentLocked: "まず保護者の同意を:保護者が自分の Ta で同意します",
1375
+ consentBy: "{name} が {date} に同意",
1376
+ consentNone: "まだ保護者の同意がありません",
1377
+ taskStudent: "今夜の間違い直し",
1378
+ taskParent: "お子さんの今週",
1379
+ taskTeacher: "今週の学習まとめ",
1380
+ taskHomeroom: "今日の保護者メッセージ",
1662
1381
  failed: "うまくいきませんでした:{error}",
1663
1382
  today: "今日",
1664
1383
  yesterday: "昨日"
1665
1384
  };
1666
- var HOME_WORDS = { "zh-CN": ZH2, "zh-TW": ZH_TW2, "en-US": EN2, "ja-JP": JA2 };
1385
+ var HOME_WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
1667
1386
  var NOTICE_PREFIXES = [...new Set(Object.values(HOME_WORDS).map((words) => words.noticePrefix))];
1668
1387
  var HomeWordsUtil;
1669
1388
  ((HomeWordsUtil) => {
@@ -1673,1333 +1392,1942 @@ var HomeWordsUtil;
1673
1392
  HomeWordsUtil.of = of;
1674
1393
  })(HomeWordsUtil ||= {});
1675
1394
 
1676
- // web-src/react.ts
1677
- var React;
1678
- function bind(react) {
1679
- React = react;
1680
- }
1395
+ // web-src/edu-rooms.ts
1396
+ var DAY2 = 86400000;
1397
+ var EduRoomUtil;
1398
+ ((EduRoomUtil) => {
1399
+ function keyOf(member) {
1400
+ return `${STATE}key:${member}`;
1401
+ }
1402
+ EduRoomUtil.keyOf = keyOf;
1403
+ function submissionOf(quiz, member) {
1404
+ return `${STATE}sub:${quiz}:${member}`;
1405
+ }
1406
+ EduRoomUtil.submissionOf = submissionOf;
1407
+ function notice(text) {
1408
+ const prefix = NOTICE_PREFIXES.find((one) => text.startsWith(one));
1409
+ return prefix ? text.slice(prefix.length).trim() : undefined;
1410
+ }
1411
+ EduRoomUtil.notice = notice;
1412
+ function report(text) {
1413
+ const match = new RegExp(`\`\`\`${LEARNING}\\n([\\s\\S]*?)\\n\`\`\``).exec(text);
1414
+ const learning = match ? EduUtil.learning(match[1]) : undefined;
1415
+ return learning?.report ? learning : undefined;
1416
+ }
1417
+ EduRoomUtil.report = report;
1418
+ function asks(lines, me, since) {
1419
+ const answered = new Set(lines.filter((line) => line.from === me && line.re).map((line) => line.re));
1420
+ const after = (line) => lines.some((other) => other.from === me && other.at > line.at);
1421
+ return lines.filter((line) => line.from !== me && line.at >= since && line.person && line.to?.includes(me) && !answered.has(line.id) && !after(line));
1422
+ }
1423
+ EduRoomUtil.asks = asks;
1424
+ function quizText(quiz, intro) {
1425
+ const body = {
1426
+ id: quiz.id,
1427
+ room: quiz.room,
1428
+ teacher: quiz.teacher,
1429
+ title: quiz.title,
1430
+ questions: quiz.questions.map((question) => ({
1431
+ q: question.q,
1432
+ ...question.kind === "choice" ? { options: question.options } : {},
1433
+ answer: question.kind === "choice" ? EduUtil.letter(question.answer) : question.answer,
1434
+ ...question.explain ? { explain: question.explain } : {},
1435
+ ...question.figure ? { figure: question.figure } : {},
1436
+ ...question.subject ? { subject: question.subject } : {},
1437
+ ...question.topic ? { topic: question.topic } : {}
1438
+ }))
1439
+ };
1440
+ return `${intro}
1681
1441
 
1682
- // web-src/ui.tsx
1683
- var TONES = { student: "0", parent: "4", teacher: "3", homeroom: "5" };
1684
- var TINTS = { student: "edu", parent: "book", teacher: "class", homeroom: "learn" };
1685
- function tone(n) {
1686
- return { "--ted-ink": `var(--ta-tint-ink-${n})`, "--ted-tile": `var(--ta-tint-${n})` };
1687
- }
1688
- function format(text, values) {
1689
- return EduWords.format(text, values);
1690
- }
1691
- function useStore(store) {
1692
- const [, tick] = React.useReducer((n) => n + 1, 0);
1693
- React.useEffect(() => store.subscribe(tick), [store]);
1694
- return store.state;
1695
- }
1696
- function useRooms(rooms) {
1697
- const [, tick] = React.useReducer((n) => n + 1, 0);
1698
- React.useEffect(() => rooms.subscribe(tick), [rooms]);
1699
- return rooms.version;
1700
- }
1701
- function useAsync(read, keys) {
1702
- const [value, setValue] = React.useState();
1703
- React.useEffect(() => {
1704
- let live = true;
1705
- read().then((got) => live && setValue(got), () => {
1442
+ \`\`\`${QUIZ}
1443
+ ${JSON.stringify(body)}
1444
+ \`\`\``;
1445
+ }
1446
+ EduRoomUtil.quizText = quizText;
1447
+ function reportText(learning, intro) {
1448
+ return `${intro}
1449
+
1450
+ \`\`\`${LEARNING}
1451
+ ${JSON.stringify(learning)}
1452
+ \`\`\``;
1453
+ }
1454
+ EduRoomUtil.reportText = reportText;
1455
+ function consentText(line, intro) {
1456
+ return `${intro}
1457
+
1458
+ \`\`\`${CONSENT}
1459
+ ${JSON.stringify(line)}
1460
+ \`\`\``;
1461
+ }
1462
+ EduRoomUtil.consentText = consentText;
1463
+ function consent(text) {
1464
+ const match = new RegExp(`\`\`\`${CONSENT}\\n([\\s\\S]*?)\\n\`\`\``).exec(text);
1465
+ let raw;
1466
+ try {
1467
+ raw = JSON.parse(match ? match[1] : text);
1468
+ } catch {
1706
1469
  return;
1707
- });
1470
+ }
1471
+ return raw && (raw.kind === "ask" || raw.kind === "grant" || raw.kind === "revoke") && typeof raw.room === "string" && typeof raw.child === "string" && typeof raw.name === "string" ? { kind: raw.kind, room: raw.room, child: raw.child, name: raw.name, ...typeof raw.from === "string" ? { from: raw.from } : {} } : undefined;
1472
+ }
1473
+ EduRoomUtil.consent = consent;
1474
+ })(EduRoomUtil ||= {});
1475
+
1476
+ class EduRooms {
1477
+ side;
1478
+ store;
1479
+ list = [];
1480
+ friendList = [];
1481
+ listeners = new Set;
1482
+ loading;
1483
+ stop;
1484
+ me;
1485
+ version = 0;
1486
+ constructor(side, store) {
1487
+ this.side = side;
1488
+ this.store = store;
1489
+ }
1490
+ get server() {
1491
+ return this.side.rooms;
1492
+ }
1493
+ identity() {
1494
+ this.me ??= this.server ? this.server.getIdentity().catch(() => {
1495
+ return;
1496
+ }) : Promise.resolve(undefined);
1497
+ return this.me;
1498
+ }
1499
+ get rooms() {
1500
+ return this.list;
1501
+ }
1502
+ get friends() {
1503
+ return this.friendList;
1504
+ }
1505
+ subscribe = (listener) => {
1506
+ this.listeners.add(listener);
1507
+ if (!this.stop && this.side.onRoomEvent) {
1508
+ this.stop = this.side.onRoomEvent((event) => {
1509
+ if (event.type === "rooms" || event.type === "state" && event.key.startsWith(STATE)) {
1510
+ this.load();
1511
+ }
1512
+ }, { messages: false, state: [STATE] });
1513
+ this.load();
1514
+ }
1708
1515
  return () => {
1709
- live = false;
1516
+ this.listeners.delete(listener);
1517
+ if (!this.listeners.size) {
1518
+ this.stop?.();
1519
+ this.stop = undefined;
1520
+ }
1710
1521
  };
1711
- }, keys);
1712
- return value;
1713
- }
1714
- function iconOf(pi, name, fallback = "BookOpen") {
1715
- return pi.ui.icons[name] ?? pi.ui.icons[fallback] ?? pi.ui.icons.BookOpen;
1716
- }
1717
- function when(at, language, words) {
1718
- const date = new Date(at);
1719
- const now = new Date;
1720
- const time = date.toLocaleTimeString(language, { hour: "2-digit", minute: "2-digit", hour12: false });
1721
- if (EduUtil.dayOf(at) === EduUtil.dayOf(now.getTime())) {
1722
- return time;
1522
+ };
1523
+ load() {
1524
+ const server = this.server;
1525
+ if (!server) {
1526
+ return Promise.resolve();
1527
+ }
1528
+ this.loading ??= Promise.all([server.listRooms().catch(() => this.list), server.listFriends().catch(() => this.friendList)]).then(([rooms, friends]) => {
1529
+ this.list = rooms.filter((room) => room.status === "member");
1530
+ this.friendList = friends.filter((friend) => friend.status === "friend");
1531
+ this.version++;
1532
+ for (const listener of this.listeners) {
1533
+ listener();
1534
+ }
1535
+ }).finally(() => {
1536
+ this.loading = undefined;
1537
+ });
1538
+ return this.loading;
1539
+ }
1540
+ groups() {
1541
+ return this.list.filter((room) => room.kind === GROUP_KIND);
1542
+ }
1543
+ classes() {
1544
+ const { classes } = this.store.state.settings;
1545
+ return classes.flatMap((id) => this.list.find((room) => room.id === id) ?? []);
1546
+ }
1547
+ memberOf(room) {
1548
+ return room.members.find((member) => member.self)?.member;
1549
+ }
1550
+ async publishKey(room) {
1551
+ const me = this.memberOf(room);
1552
+ const server = this.server;
1553
+ if (!me || !server) {
1554
+ return;
1555
+ }
1556
+ const keys = await this.store.teacherKeys();
1557
+ const key = EduRoomUtil.keyOf(me);
1558
+ const state = await server.getState(room.id, key);
1559
+ if (state[key]?.value && JSON.stringify(state[key].value) === JSON.stringify(keys.publicKey)) {
1560
+ return;
1561
+ }
1562
+ await server.setState(room.id, key, keys.publicKey);
1723
1563
  }
1724
- if (EduUtil.dayOf(at) === EduUtil.dayOf(now.getTime() - 86400000)) {
1725
- return `${words.yesterday} ${time}`;
1564
+ async postQuiz(room, quiz, intro) {
1565
+ const me = this.memberOf(room);
1566
+ const server = this.server;
1567
+ if (!me || !server) {
1568
+ throw new Error("Not in the class.");
1569
+ }
1570
+ await this.publishKey(room);
1571
+ const id = `q${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
1572
+ const sent = { ...quiz, reveal: false, id, room: room.id, teacher: me };
1573
+ await server.say(room.id, EduRoomUtil.quizText(sent, intro));
1574
+ const gone = await this.store.addPosted({ id, room: room.id, title: quiz.title ?? "", at: Date.now(), questions: quiz.questions });
1575
+ for (const old of gone) {
1576
+ const state = await server.getState(old.room, `${STATE}sub:${old.id}:`).catch(() => ({}));
1577
+ for (const key of Object.keys(state)) {
1578
+ await server.setState(old.room, key, null).catch(() => {
1579
+ return;
1580
+ });
1581
+ }
1582
+ }
1726
1583
  }
1727
- return date.toLocaleDateString(language, now.getTime() - at < 6 * 86400000 ? { weekday: "short" } : { month: "numeric", day: "numeric" });
1728
- }
1729
- function failed(pi, words) {
1730
- return (error) => pi.ui.notify(format(words.failed, { error: error instanceof Error ? error.message : String(error) }), "error");
1731
- }
1732
- function Tile({ icon: Icon, tone: hue, size = "row" }) {
1733
- return /* @__PURE__ */ React.createElement("span", {
1734
- className: `ted-tile ted-tile-${size}`,
1735
- style: tone(hue)
1736
- }, /* @__PURE__ */ React.createElement(Icon, {
1737
- size: size === "big" ? 22 : 18,
1738
- strokeWidth: 1.8
1739
- }));
1740
- }
1741
- function Actions({ context, actions }) {
1742
- const { pi } = context;
1743
- const [busy, setBusy] = React.useState();
1744
- const home = HomeWordsUtil.of(pi.ui.language);
1745
- return /* @__PURE__ */ React.createElement("div", {
1746
- className: "ted-actions"
1747
- }, actions.map((action) => /* @__PURE__ */ React.createElement("button", {
1748
- key: action.key,
1749
- type: "button",
1750
- className: "ted-action",
1751
- disabled: busy === action.key,
1752
- onClick: () => {
1753
- setBusy(action.key);
1754
- Promise.resolve().then(action.run).catch(failed(pi, home)).finally(() => setBusy(undefined));
1584
+ async submit(quiz, submission) {
1585
+ const server = this.server;
1586
+ if (!quiz.id || !quiz.room || !quiz.teacher || !server) {
1587
+ return "not-in";
1755
1588
  }
1756
- }, /* @__PURE__ */ React.createElement(Tile, {
1757
- icon: iconOf(pi, action.icon, action.fallback),
1758
- tone: action.tone,
1759
- size: "big"
1760
- }), /* @__PURE__ */ React.createElement("span", null, action.label))));
1761
- }
1762
- function Assistant({ context, identity }) {
1763
- const { pi, store } = context;
1764
- const words = EduWords.of(pi.ui.language);
1765
- const home = HomeWordsUtil.of(pi.ui.language);
1766
- const role = ROLES[identity];
1767
- return /* @__PURE__ */ React.createElement("div", {
1768
- className: "ted-panel ted-list ted-assistant"
1769
- }, /* @__PURE__ */ React.createElement("button", {
1770
- type: "button",
1771
- className: "ted-row",
1772
- onClick: () => void EduChats.open(pi, store, identity).catch(failed(pi, home))
1773
- }, /* @__PURE__ */ React.createElement(Tile, {
1774
- icon: iconOf(pi, role.icon),
1775
- tone: TONES[identity]
1776
- }), /* @__PURE__ */ React.createElement("span", {
1777
- className: "ted-row-main"
1778
- }, /* @__PURE__ */ React.createElement("span", {
1779
- className: "ted-row-title"
1780
- }, words[role.assistant]), /* @__PURE__ */ React.createElement("span", {
1781
- className: "ted-row-sub"
1782
- }, words[role.tagline])), /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronRight, {
1783
- size: 16
1784
- })));
1785
- }
1786
- function Section({ title, aside, children }) {
1787
- return /* @__PURE__ */ React.createElement("section", {
1788
- className: "ted-section"
1789
- }, /* @__PURE__ */ React.createElement("div", {
1790
- className: "ted-section-head"
1791
- }, /* @__PURE__ */ React.createElement("h3", null, title), aside !== undefined && /* @__PURE__ */ React.createElement("span", {
1792
- className: "ted-section-aside"
1793
- }, aside)), children);
1794
- }
1795
- async function ask(context, identity, title, hint, prefix, many = false) {
1796
- const { pi, store } = context;
1797
- const text = many ? await pi.ui.editor(title, hint) : await pi.ui.input(title, hint);
1798
- if (text?.trim()) {
1799
- await EduChats.say(pi, store, identity, `${prefix}${text.trim()}`);
1589
+ if (!this.list.length) {
1590
+ await this.load();
1591
+ }
1592
+ const room = this.list.find((one) => one.id === quiz.room);
1593
+ const me = room && this.memberOf(room);
1594
+ if (!room || !me) {
1595
+ return "not-in";
1596
+ }
1597
+ const key = (await server.getState(room.id, EduRoomUtil.keyOf(quiz.teacher)))[EduRoomUtil.keyOf(quiz.teacher)]?.value;
1598
+ if (!EduSeal.isPublic(key)) {
1599
+ return "no-key";
1600
+ }
1601
+ await server.setState(room.id, EduRoomUtil.submissionOf(quiz.id, me), await EduSeal.seal(submission, key));
1602
+ return "sent";
1800
1603
  }
1801
- }
1802
- async function photo(context, identity, text) {
1803
- const images = await EduPhotos.pick();
1804
- if (images.length) {
1805
- await EduChats.say(context.pi, context.store, identity, text, images);
1604
+ async submitted(quiz) {
1605
+ const room = quiz.room ? this.list.find((one) => one.id === quiz.room) : undefined;
1606
+ const me = room && this.memberOf(room);
1607
+ if (!room || !me || !quiz.id || !this.server) {
1608
+ return false;
1609
+ }
1610
+ const key = EduRoomUtil.submissionOf(quiz.id, me);
1611
+ return !!(await this.server.getState(room.id, key))[key]?.value;
1806
1612
  }
1807
- }
1808
- function reviewContext(mistakes) {
1809
- const lines = mistakes.slice(0, 10).map((one) => JSON.stringify({ id: one.id, q: one.question, answer: one.answer, given: one.given, subject: one.subject, topic: one.topic }));
1810
- return `[${NAME}:review]
1811
- The mistakes the user is due to review. For each, ask a new question on the same point in another form (other numbers, words or setting), with "review" its id and "subject" its subject, in one quiz card; then go over what they still get wrong.
1812
- ${lines.join(`
1813
- `)}`;
1814
- }
1815
- function review(context, mistakes) {
1816
- const { pi, store } = context;
1817
- const words = EduWords.of(pi.ui.language);
1818
- return EduChats.say(pi, store, "student", TaMessageContext.wrap(reviewContext(mistakes), format(words.review.text, { count: mistakes.length })));
1819
- }
1820
- function toneOf(text) {
1821
- return String(Number.parseInt(EduUtil.hash(text), 36) % 9);
1822
- }
1823
- function Stats({ items }) {
1824
- return /* @__PURE__ */ React.createElement("div", {
1825
- className: "ted-stats"
1826
- }, items.map(([value, label, unit]) => /* @__PURE__ */ React.createElement("div", {
1827
- key: label,
1828
- className: "ted-stat"
1829
- }, /* @__PURE__ */ React.createElement("b", null, value, unit && /* @__PURE__ */ React.createElement("small", null, unit)), /* @__PURE__ */ React.createElement("span", null, label))));
1830
- }
1831
- function Count({ text, count, tone: tone2 }) {
1832
- const [before, after = ""] = text.split("{count}");
1833
- return /* @__PURE__ */ React.createElement(React.Fragment, null, before, /* @__PURE__ */ React.createElement("em", {
1834
- className: "ted-count",
1835
- style: { color: `var(--ta-tint-ink-${tone2})` }
1836
- }, count), after);
1837
- }
1838
- function homeDetail(store, words, home) {
1839
- const { settings, mistakes } = store.state;
1840
- const identity = EduUtil.current(settings);
1841
- if (!identity) {
1842
- return { detail: home.homeDetailPick, unseen: false };
1613
+ async submissions(posted) {
1614
+ const server = this.server;
1615
+ if (!server) {
1616
+ return [];
1617
+ }
1618
+ const keys = await this.store.teacherKeys();
1619
+ const state = await server.getState(posted.room, `${STATE}sub:${posted.id}:`).catch(() => ({}));
1620
+ const opened = await Promise.all(Object.values(state).map((value) => EduSeal.open(value.value, keys)));
1621
+ return opened.filter((one) => !!one && typeof one.name === "string" && Array.isArray(one.right));
1843
1622
  }
1844
- const due = EduUtil.due(mistakes, Date.now()).length;
1845
- if (identity === "student" && due) {
1846
- return { detail: `${format(home.dueHead, { count: due })} · ${words.student}`, unseen: true };
1623
+ async lines(room, limit = 80) {
1624
+ return (await this.server?.readChat?.(room, { limit }).catch(() => {
1625
+ return;
1626
+ }))?.lines ?? [];
1847
1627
  }
1848
- return { detail: `${words[ROLES[identity].tagline]} · ${words[identity]}`, unseen: false };
1849
- }
1850
-
1851
- // web-src/family.tsx
1852
- function ParentHome({ context }) {
1853
- const { pi, store, rooms } = context;
1854
- const version = useRooms(rooms);
1855
- const home = HomeWordsUtil.of(pi.ui.language);
1856
- const reports = useAsync(() => rooms.reports(), [version]);
1857
- const notices = useAsync(() => rooms.notices(), [version, store.state.settings.classes.join()]);
1858
- const [child, setChild] = React.useState();
1859
- const children = [...new Map((reports ?? []).map((report2) => [report2.child, report2])).values()];
1860
- const report = children.find((one) => one.child === child) ?? children[0];
1861
- const Lock = iconOf(pi, "Lock");
1862
- return /* @__PURE__ */ React.createElement(React.Fragment, null, children.length > 1 && /* @__PURE__ */ React.createElement("div", {
1863
- className: "ted-chips"
1864
- }, children.map((one) => /* @__PURE__ */ React.createElement("button", {
1865
- key: one.child,
1866
- type: "button",
1867
- className: "ted-chip",
1868
- "aria-pressed": one === report,
1869
- onClick: () => setChild(one.child)
1870
- }, one.child))), report ? /* @__PURE__ */ React.createElement(ReportCard, {
1871
- context,
1872
- report
1873
- }) : /* @__PURE__ */ React.createElement("div", {
1874
- className: "ted-panel ted-empty"
1875
- }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
1876
- compact: true,
1877
- title: reports ? home.noReport : " ",
1878
- hint: home.noReportHint
1879
- })), /* @__PURE__ */ React.createElement(Actions, {
1880
- context,
1881
- actions: [
1882
- {
1883
- key: "check",
1884
- label: home.tileCheck,
1885
- icon: "Camera",
1886
- fallback: "Image",
1887
- tone: "4",
1888
- run: () => photo(context, "parent", home.photoParent)
1889
- },
1890
- {
1891
- key: "talk",
1892
- label: home.tileTalk,
1893
- icon: "MessageCircle",
1894
- tone: "5",
1895
- run: () => ask(context, "parent", home.tileTalk, "", EduWords.of(pi.ui.language).talk.text, true)
1896
- },
1897
- {
1898
- key: "teacher",
1899
- label: home.tileTeacher,
1900
- icon: "Send",
1901
- tone: "3",
1902
- run: () => ask(context, "parent", home.tileTeacher, "", EduWords.of(pi.ui.language).toTeacher.text, true)
1903
- },
1904
- {
1905
- key: "plan",
1906
- label: home.tilePlan,
1907
- icon: "Calendar",
1908
- tone: "0",
1909
- run: () => ask(context, "parent", home.tilePlan, "", EduWords.of(pi.ui.language).plan.text, true)
1628
+ async notices() {
1629
+ const since = Date.now() - 30 * DAY2;
1630
+ const all = await Promise.all(this.classes().map(async (room) => (await this.lines(room.id)).flatMap((line) => {
1631
+ const text = !line.failed && line.at >= since ? EduRoomUtil.notice(line.text) : undefined;
1632
+ return text ? [{ id: line.id, room: room.id, klass: room.title, from: line.name, text, at: line.at }] : [];
1633
+ })));
1634
+ return all.flat().sort((a, b) => b.at - a.at);
1635
+ }
1636
+ async postNotice(room, text, prefix) {
1637
+ await this.server?.say(room, `${prefix}${text.trim()}`);
1638
+ }
1639
+ async asks() {
1640
+ const since = Date.now() - 7 * DAY2;
1641
+ const all = await Promise.all(this.classes().map(async (room) => {
1642
+ const me = this.memberOf(room);
1643
+ return me ? EduRoomUtil.asks(await this.lines(room.id), me, since).map((line) => ({
1644
+ id: line.id,
1645
+ room: room.id,
1646
+ klass: room.title,
1647
+ from: line.name,
1648
+ text: line.text,
1649
+ at: line.at
1650
+ })) : [];
1651
+ }));
1652
+ return all.flat().sort((a, b) => b.at - a.at);
1653
+ }
1654
+ async reports() {
1655
+ const directs = this.list.filter((room) => room.kind === DIRECT_KIND);
1656
+ const found = await Promise.all(directs.map(async (room) => {
1657
+ const lines = await this.lines(room.id, 60);
1658
+ for (const line of [...lines].reverse()) {
1659
+ const learning = room.members.find((member) => member.member === line.from)?.self ? undefined : EduRoomUtil.report(line.text);
1660
+ if (learning) {
1661
+ return [{ room: room.id, child: line.name, at: line.at, learning }];
1662
+ }
1910
1663
  }
1911
- ]
1912
- }), /* @__PURE__ */ React.createElement(Assistant, {
1913
- context,
1914
- identity: "parent"
1915
- }), /* @__PURE__ */ React.createElement(Notices, {
1916
- context,
1917
- notices,
1918
- identity: "parent"
1919
- }), /* @__PURE__ */ React.createElement("p", {
1920
- className: "ted-privacy"
1921
- }, /* @__PURE__ */ React.createElement(Lock, {
1922
- size: 12
1923
- }), home.parentPrivacy));
1924
- }
1925
- function ReportCard({ context, report }) {
1926
- const { pi, store } = context;
1927
- const home = HomeWordsUtil.of(pi.ui.language);
1928
- const { learning } = report;
1929
- const about = `[${NAME}:report]
1930
- The week of the user's child, as the child's Ta sent it:
1931
- ${JSON.stringify(learning)}`;
1932
- const say = (text) => void EduChats.say(pi, store, "parent", TaMessageContext.wrap(about, text)).catch(failed(pi, home));
1933
- return /* @__PURE__ */ React.createElement("div", {
1934
- className: "ted-panel ted-report"
1935
- }, /* @__PURE__ */ React.createElement("div", {
1936
- className: "ted-panel-head"
1937
- }, /* @__PURE__ */ React.createElement("span", {
1938
- className: "ted-panel-title"
1939
- }, format(home.childWeek, { name: report.child })), /* @__PURE__ */ React.createElement("span", {
1940
- className: "ted-panel-aside"
1941
- }, format(home.fromChild, { name: report.child, time: when(report.at, pi.ui.language, home) }))), learning.stats.length > 0 && /* @__PURE__ */ React.createElement(Stats, {
1942
- items: learning.stats.map((one) => [one.value, one.label])
1943
- }), (learning.weak.length > 0 || learning.items.length > 0) && /* @__PURE__ */ React.createElement("div", {
1944
- className: "ted-report-rows"
1945
- }, learning.items.map((item) => /* @__PURE__ */ React.createElement("div", {
1946
- key: item.label,
1947
- className: "ted-report-row"
1948
- }, /* @__PURE__ */ React.createElement("span", {
1949
- className: "ted-tone",
1950
- "data-level": item.value >= 70 ? "good" : item.value >= 40 ? "warn" : "bad"
1951
- }), /* @__PURE__ */ React.createElement("b", null, item.label), /* @__PURE__ */ React.createElement("small", null, item.note ? `${item.note} · ${item.value}%` : `${item.value}%`))), learning.weak.length > 0 && /* @__PURE__ */ React.createElement("div", {
1952
- className: "ted-tags"
1953
- }, learning.weak.map((one) => /* @__PURE__ */ React.createElement("span", {
1954
- key: one,
1955
- className: "ted-tag"
1956
- }, one)))), /* @__PURE__ */ React.createElement("div", {
1957
- className: "ted-panel-acts"
1958
- }, /* @__PURE__ */ React.createElement("button", {
1959
- type: "button",
1960
- className: "ta-button ta-primary ted-pill",
1961
- onClick: () => say(home.howToHelp)
1962
- }, home.howToHelp), /* @__PURE__ */ React.createElement("button", {
1963
- type: "button",
1964
- className: "ta-button ted-pill",
1965
- onClick: () => say(EduWords.of(pi.ui.language).toTeacher.text)
1966
- }, home.askTeacher)));
1664
+ return [];
1665
+ }));
1666
+ return found.flat().sort((a, b) => b.at - a.at);
1667
+ }
1668
+ async sendReport(friend, learning, intro, make = true) {
1669
+ return !!await this.sendTo(friend, () => EduRoomUtil.reportText(learning, intro), make);
1670
+ }
1671
+ async sendTo(friend, text, make = true) {
1672
+ const server = this.server;
1673
+ if (!server) {
1674
+ return;
1675
+ }
1676
+ let room = await this.direct(friend);
1677
+ if (!room && make && this.side.openFriend && await this.side.openFriend(friend)) {
1678
+ for (let tries = 0;tries < 20 && !room; tries++) {
1679
+ await new Promise((resolve) => setTimeout(resolve, 500));
1680
+ room = await this.direct(friend, true);
1681
+ }
1682
+ }
1683
+ if (!room) {
1684
+ return;
1685
+ }
1686
+ await server.say(room.id, text(room.id));
1687
+ return room.id;
1688
+ }
1689
+ async consentOf() {
1690
+ const me = (await this.identity())?.id;
1691
+ const said = (await this.consents()).filter((one) => !one.self && one.by && one.consent.child === me && one.consent.kind !== "ask");
1692
+ const last = said.sort((a, b) => a.line.at - b.line.at).at(-1);
1693
+ if (!last) {
1694
+ return;
1695
+ }
1696
+ return last.consent.kind === "grant" && last.by ? { by: last.by, name: last.line.name, at: last.line.at } : null;
1697
+ }
1698
+ async consentAsks() {
1699
+ const said = await this.consents();
1700
+ const asks = new Map;
1701
+ for (const one of said) {
1702
+ if (!one.self && one.consent.kind === "ask" && one.by === one.consent.child) {
1703
+ asks.set(one.consent.child, { room: one.consent.room, child: one.consent.child, name: one.line.name, at: one.line.at });
1704
+ }
1705
+ }
1706
+ return [...asks.values()].filter((ask) => !said.some((one) => one.self && one.consent.kind !== "ask" && one.consent.child === ask.child && one.line.at > ask.at)).sort((a, b) => b.at - a.at);
1707
+ }
1708
+ async consentAnswer(room, child) {
1709
+ const said = (await this.consents(room)).filter((one) => one.self && one.consent.kind !== "ask" && one.consent.child === child);
1710
+ return said.sort((a, b) => a.line.at - b.line.at).at(-1)?.consent.kind;
1711
+ }
1712
+ async answerConsent(ask, yes, words) {
1713
+ const me = await this.identity();
1714
+ const line = { kind: yes ? "grant" : "revoke", room: ask.room, child: ask.child, name: ask.name, ...me ? { from: me.name } : {} };
1715
+ await this.server?.say(ask.room, EduRoomUtil.consentText(line, yes ? words.consentGrantIntro : words.consentRevokeIntro));
1716
+ }
1717
+ async consents(only) {
1718
+ if (!this.list.length) {
1719
+ await this.load();
1720
+ }
1721
+ const directs = this.list.filter((room) => room.kind === DIRECT_KIND && (!only || room.id === only));
1722
+ const all = await Promise.all(directs.map(async (room) => (await this.lines(room.id, 200)).flatMap((line) => {
1723
+ const consent = !line.failed && line.text.includes(CONSENT) ? EduRoomUtil.consent(line.text) : undefined;
1724
+ const member = room.members.find((one) => one.member === line.from);
1725
+ return consent && consent.room === room.id ? [{ line, consent, by: member?.id, self: !!member?.self }] : [];
1726
+ })));
1727
+ return all.flat();
1728
+ }
1729
+ async direct(friend, again = false) {
1730
+ if (again || !this.list.length) {
1731
+ await this.load();
1732
+ }
1733
+ return this.list.filter((room) => room.kind === DIRECT_KIND && room.members.some((member) => !member.self && member.id === friend)).sort((a, b) => a.createdAt - b.createdAt)[0];
1734
+ }
1967
1735
  }
1968
- function Notices({ context, notices, identity }) {
1969
- const { pi, store, rooms } = context;
1970
- const home = HomeWordsUtil.of(pi.ui.language);
1971
- const Megaphone = iconOf(pi, "Megaphone");
1972
- const School = iconOf(pi, "Users");
1973
- if (!pi.rooms) {
1974
- return null;
1736
+
1737
+ // web-src/edu-roles.ts
1738
+ var PLAY_HINT = "What is learned playing sticks: when practice, review or a point that needs many tries would be better played (the user asks to play, is bored or tired, or a mistake keeps coming back), make it a ta-play game, made for this learner from their mistakes, level and interests; a game for a class is for several, sent to its group chat by Play together on its card, all playing at once. A result a game sends back: say in a line how it went and make the next round from it.";
1739
+ var QUIZ_FORMAT = `To give questions to answer, write a fenced block of language ${QUIZ} holding JSON, which Ta draws as a card the user answers in, checked at once: {"title"?: string, "reveal"?: boolean, "questions": [{"q": string, "options"?: [string] (a choice question; "answer" the letter), "answer": "B" | true | false (true or false question) | ["answers", "taken as right"] (fill in the blank), "explain": string, "subject": the school subject, "topic": the point it tests, "review"?: id of the mistake it reviews, "figure"?: its figure (geometry, a graph), drawn right under its text: {"ta-plot": the JSON of a ta-plot block} | {"ta-3d": that of a ta-3d block} | "![](image)"}]}. A figure goes in the question it belongs to, never as a block before the card; its text says "如图", not "如图 3". Mistakes the user makes in it are kept for review. To show how someone is learning, a ${LEARNING} block: {"title"?: string, "items": [{"label": topic, "value": 0-100 mastery, "note"?: string}], "weak"?: [string], "next"?: [what to do next]}.`;
1740
+ var ROLES = {
1741
+ student: {
1742
+ assistant: "assistantStudent",
1743
+ tagline: "taglineStudent",
1744
+ icon: "BookOpen",
1745
+ skills: ["edu-tutor", "edu-quiz"],
1746
+ actions: [
1747
+ { key: "explain", icon: "Image" },
1748
+ { key: "play", icon: "Gamepad2", send: true },
1749
+ { key: "quizMe", icon: "ListChecks", send: true },
1750
+ { key: "review", icon: "RotateCcw", send: true },
1751
+ { key: "recite", icon: "Mic" }
1752
+ ],
1753
+ rules: "You tutor a student. Never give the final answer or a whole solution before the student has tried: ask what they know, give one hint at a time, let them do each step, and show the full solution only once they reached it or asked twice after trying. Check understanding with a question in another form. Never write their essays or homework for them: outlines, questions and comments on what they wrote. Encourage effort, not talent. If they speak of distress, listen, and tell them to talk to a parent or a teacher they trust."
1754
+ },
1755
+ parent: {
1756
+ assistant: "assistantParent",
1757
+ tagline: "taglineParent",
1758
+ icon: "House",
1759
+ skills: ["edu-parent", "edu-quiz"],
1760
+ actions: [
1761
+ { key: "check", icon: "Image" },
1762
+ { key: "talk", icon: "MessageCircle" },
1763
+ { key: "toTeacher", icon: "Send" },
1764
+ { key: "plan", icon: "Calendar" }
1765
+ ],
1766
+ rules: "You help a parent help their child. Tell the parent where and why the child went wrong, the words to explain it to the child at their age, and one practice question; do not do the homework for the child. Help them keep calm and kind; on messages to teachers, help them be clear, specific and respectful. Their child is theirs to judge: no labels, no diagnosis."
1767
+ },
1768
+ teacher: {
1769
+ assistant: "assistantTeacher",
1770
+ tagline: "taglineTeacher",
1771
+ icon: "Pencil",
1772
+ skills: ["edu-grading", "edu-quiz", "edu-lesson"],
1773
+ actions: [
1774
+ { key: "grade", icon: "ListChecks" },
1775
+ { key: "makeQuiz", icon: "FilePlus" },
1776
+ { key: "lesson", icon: "FileText" },
1777
+ { key: "exam", icon: "ChartSpline" },
1778
+ { key: "weekly", icon: "Calendar", send: true },
1779
+ { key: "classGame", icon: "Gamepad2" }
1780
+ ],
1781
+ rules: 'You assist a teacher. Marking: right or wrong for each question, the causes of the mistakes grouped, what the class shares, and an outline to go over it; what you are unsure of you say. Questions: in three levels (basic, better, stretch) with answers and explanations, "reveal": true. Score sheets and records in the working directory you read yourself; you count, the teacher decides. Names of students stay on this computer.'
1782
+ },
1783
+ homeroom: {
1784
+ assistant: "assistantHomeroom",
1785
+ tagline: "taglineHomeroom",
1786
+ icon: "Users",
1787
+ skills: ["edu-homeroom"],
1788
+ actions: [
1789
+ { key: "reply", icon: "MessageCircle" },
1790
+ { key: "comments", icon: "Pencil" },
1791
+ { key: "meeting", icon: "Users" },
1792
+ { key: "notice", icon: "Megaphone" }
1793
+ ],
1794
+ rules: "You assist a class teacher. Replies to parents are drafts the teacher sends: warm, clear, within what the school decides, never promising what is not theirs. Report comments come from what the teacher told of each student, specific and kind, no stock phrases. A student at risk (self-harm, abuse, bullying): tell the teacher to bring in the school counsellor, the school leaders and the parents at once; do not handle it alone."
1975
1795
  }
1976
- if (!rooms.classes().length) {
1977
- return /* @__PURE__ */ React.createElement(Section, {
1978
- title: home.notices
1979
- }, /* @__PURE__ */ React.createElement("div", {
1980
- className: "ted-panel ted-list"
1981
- }, /* @__PURE__ */ React.createElement("button", {
1982
- type: "button",
1983
- className: "ted-row",
1984
- onClick: () => openClasses(context)
1985
- }, /* @__PURE__ */ React.createElement(Tile, {
1986
- icon: School,
1987
- tone: TONES.homeroom
1988
- }), /* @__PURE__ */ React.createElement("span", {
1989
- className: "ted-row-main"
1990
- }, /* @__PURE__ */ React.createElement("span", {
1991
- className: "ted-row-title"
1992
- }, home.linkClass), /* @__PURE__ */ React.createElement("span", {
1993
- className: "ted-row-sub ted-wrap"
1994
- }, home.linkClassHint)), /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronRight, {
1995
- size: 16
1996
- }))));
1796
+ };
1797
+ var STAGE_NAMES = { primary: "primary school", junior: "middle school", senior: "high school" };
1798
+ var EduRoles;
1799
+ ((EduRoles) => {
1800
+ function prompt(identity, settings) {
1801
+ const role = ROLES[identity];
1802
+ const about = [
1803
+ settings.stage && `stage: ${STAGE_NAMES[settings.stage]}`,
1804
+ settings.subject && `subjects: ${settings.subject}`,
1805
+ settings.textbook && `textbooks: ${settings.textbook}`
1806
+ ].filter(Boolean);
1807
+ return [
1808
+ `${MARK} You are Ta for a ${identity === "homeroom" ? "class teacher" : identity} in school education in China${about.length ? ` (${about.join("; ")})` : ""}.`,
1809
+ role.rules,
1810
+ `Skills for this: ${role.skills.join(", ")}.`,
1811
+ "What students, scores and families are is private: keep it on this computer, and leave names out of what is shared unless the user asks.",
1812
+ QUIZ_FORMAT,
1813
+ PLAY_HINT
1814
+ ].join(`
1815
+ `);
1997
1816
  }
1998
- const list = (notices ?? []).slice(0, 5);
1999
- return /* @__PURE__ */ React.createElement(Section, {
2000
- title: identity === "parent" ? home.notices : home.recentNotices,
2001
- aside: list.length ? format(home.count, { count: list.length }) : undefined
2002
- }, /* @__PURE__ */ React.createElement("div", {
2003
- className: "ted-panel ted-list"
2004
- }, list.length ? list.map((notice) => /* @__PURE__ */ React.createElement("button", {
2005
- key: notice.id,
2006
- type: "button",
2007
- className: "ted-row",
2008
- onClick: () => void EduChats.say(pi, store, identity, `${home.noticeHelp}
1817
+ EduRoles.prompt = prompt;
1818
+ function action(words, key) {
1819
+ return words[key];
1820
+ }
1821
+ EduRoles.action = action;
1822
+ })(EduRoles ||= {});
1823
+
1824
+ // web-src/i18n.ts
1825
+ var EN2 = {
1826
+ student: "Student",
1827
+ parent: "Parent",
1828
+ teacher: "Teacher",
1829
+ homeroom: "Class teacher",
1830
+ assistantStudent: "Study buddy",
1831
+ assistantParent: "Homework coach",
1832
+ assistantTeacher: "Teaching assistant",
1833
+ assistantHomeroom: "Class assistant",
1834
+ taglineStudent: "Works it out with you, not for you",
1835
+ taglineParent: "See where your child went wrong, and how to explain it",
1836
+ taglineTeacher: "Marking, questions, lesson plans, test analysis",
1837
+ taglineHomeroom: "Parents, report comments, class meetings, notices",
1838
+ due: "{count} mistakes to review today",
1839
+ locked: "A parent or teacher turns this on for primary school",
1840
+ primary: "Primary",
1841
+ junior: "Middle school",
1842
+ senior: "High school",
1843
+ explain: { label: "Explain a problem", text: "I can't do this one. Don't tell me the answer yet, help me think it through:" },
1844
+ quizMe: { label: "Quiz me", text: "Give me a few questions on what I learned lately" },
1845
+ play: { label: "Play a round", text: "Make me a little game on what I learned lately and the mistakes I made, and let me play a round" },
1846
+ review: { label: "Review mistakes", text: "Review the {count} mistakes due today" },
1847
+ recite: { label: "Recite", text: "Help me learn this passage by heart: let me try first, then tell me what I got wrong:" },
1848
+ check: { label: "Check homework", text: "Look at my child’s homework: what is wrong, and how do I explain it to them?" },
1849
+ talk: { label: "What to say", text: "My child is in this situation. How should I talk to them about it?" },
1850
+ toTeacher: { label: "Message the teacher", text: "Help me write to the teacher, clearly and politely:" },
1851
+ plan: { label: "Plan the week", text: "Plan my child’s study for this week. How things are:" },
1852
+ grade: {
1853
+ label: "Mark homework",
1854
+ text: "Mark these (photos below): right or wrong for each question, the causes of the mistakes grouped, and an outline for going over them in class:"
1855
+ },
1856
+ makeQuiz: { label: "Set questions", text: "Set questions in three levels (basic, better, stretch) on:" },
1857
+ classGame: { label: "Class game", text: "Make a game the whole class plays together in our group chat, on: " },
1858
+ lesson: { label: "Lesson plan", text: "Write a lesson plan for:" },
1859
+ exam: { label: "Analyse a test", text: "Analyse this score sheet (file below): the weak points the class shares, and the students to look after:" },
1860
+ weekly: {
1861
+ label: "Weekly summary",
1862
+ text: "Every Friday at 4 pm, read this week’s scores and homework records in this folder and write me a summary of how the class is learning"
1863
+ },
1864
+ reply: { label: "Reply to a parent", text: `A parent wrote:
2009
1865
 
2010
- > ${notice.text.replace(/\n/g, `
2011
- > `)}`).catch(failed(pi, home))
2012
- }, /* @__PURE__ */ React.createElement(Tile, {
2013
- icon: Megaphone,
2014
- tone: TONES.homeroom
2015
- }), /* @__PURE__ */ React.createElement("span", {
2016
- className: "ted-row-main"
2017
- }, /* @__PURE__ */ React.createElement("span", {
2018
- className: "ted-row-title ted-clamp"
2019
- }, notice.text), /* @__PURE__ */ React.createElement("span", {
2020
- className: "ted-row-sub"
2021
- }, `${notice.klass} · ${notice.from} · ${when(notice.at, pi.ui.language, home)}`)))) : /* @__PURE__ */ React.createElement("div", {
2022
- className: "ted-quiet"
2023
- }, notices ? home.linkClassHint : " ")));
2024
- }
2025
- function openClasses(context) {
2026
- const { pi } = context;
2027
- const home = HomeWordsUtil.of(pi.ui.language);
2028
- pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
2029
- title: home.classesTitle,
2030
- onClose: close
2031
- }, /* @__PURE__ */ React.createElement(ClassPicker, {
2032
- context,
2033
- close
2034
- })));
2035
- }
2036
- function ClassPicker({ context, close }) {
2037
- const { pi, store, rooms } = context;
2038
- useRooms(rooms);
2039
- const state = useStore(store);
2040
- const home = HomeWordsUtil.of(pi.ui.language);
2041
- const { classes } = state.settings;
2042
- const groups = rooms.groups();
2043
- const teacher = state.settings.identities.some((one) => one === "teacher" || one === "homeroom");
2044
- const toggle = (room) => {
2045
- const on = classes.includes(room.id);
2046
- store.setSettings({ classes: on ? classes.filter((one) => one !== room.id) : [...classes, room.id], ...on ? {} : { klass: room.id } });
2047
- if (!on && teacher) {
2048
- rooms.publishKey(room).catch(() => {
2049
- return;
2050
- });
2051
- }
2052
- };
2053
- return /* @__PURE__ */ React.createElement("div", {
2054
- className: "ted-picker"
2055
- }, /* @__PURE__ */ React.createElement("div", {
2056
- className: "ted-picker-hint ted-picker-hint-alone"
2057
- }, home.classesHint), groups.length ? /* @__PURE__ */ React.createElement("div", {
2058
- className: "ted-list"
2059
- }, groups.map((room) => {
2060
- const on = classes.includes(room.id);
2061
- return /* @__PURE__ */ React.createElement("button", {
2062
- key: room.id,
2063
- type: "button",
2064
- className: "ted-row",
2065
- "aria-pressed": on,
2066
- onClick: () => toggle(room)
2067
- }, /* @__PURE__ */ React.createElement(Tile, {
2068
- icon: pi.ui.icons.Users,
2069
- tone: toneOf(room.id)
2070
- }), /* @__PURE__ */ React.createElement("span", {
2071
- className: "ted-row-main"
2072
- }, /* @__PURE__ */ React.createElement("span", {
2073
- className: "ted-row-title"
2074
- }, room.title), /* @__PURE__ */ React.createElement("span", {
2075
- className: "ted-row-sub"
2076
- }, room.members.length)), /* @__PURE__ */ React.createElement("span", {
2077
- className: "ted-check",
2078
- "data-on": on || undefined
2079
- }, on && /* @__PURE__ */ React.createElement(pi.ui.icons.Check, {
2080
- size: 13,
2081
- strokeWidth: 3
2082
- })));
2083
- })) : /* @__PURE__ */ React.createElement(pi.ui.Empty, {
2084
- compact: true,
2085
- title: home.noGroups
2086
- }), /* @__PURE__ */ React.createElement("div", {
2087
- className: "ted-picker-foot"
2088
- }, /* @__PURE__ */ React.createElement("button", {
2089
- type: "button",
2090
- className: "ta-button ta-primary",
2091
- onClick: close
2092
- }, home.done)));
2093
- }
1866
+ Draft me a reply; I will read it before I send it:` },
1867
+ comments: { label: "Report comments", text: `Write report comments from how each student did, below, with no stock phrases:
1868
+ ` },
1869
+ meeting: { label: "Class meeting", text: "Plan a class meeting on:" },
1870
+ notice: { label: "Notice to parents", text: "Write a notice to parents about:" },
1871
+ settingsTitle: "Education",
1872
+ identitiesLabel: "Who you are",
1873
+ identitiesHint: "Each one you pick has its assistant in your list",
1874
+ stageLabel: "Stage",
1875
+ subjectLabel: "Subjects",
1876
+ subjectHint: "Such as maths, English",
1877
+ textbookLabel: "Textbooks",
1878
+ textbookHint: "The edition your school uses",
1879
+ consentLabel: "Study buddy at primary school",
1880
+ consentHint: "A parent says yes in their own Ta; it is not changed here",
1881
+ quiz: "Practice",
1882
+ submit: "Check",
1883
+ right: "Right",
1884
+ wrongAnswer: "The answer: {answer}",
1885
+ score: "{right} of {total} right",
1886
+ explainWrong: "Go over my mistakes",
1887
+ explainWrongText: "Go over the questions I got wrong",
1888
+ judgeTrue: "True",
1889
+ judgeFalse: "False",
1890
+ blank: "Your answer",
1891
+ revealAnswer: "Answer: {answer}",
1892
+ learning: "How it is going",
1893
+ weak: "Weak points",
1894
+ next: "Next"
1895
+ };
1896
+ var ZH2 = {
1897
+ student: "学生",
1898
+ parent: "家长",
1899
+ teacher: "老师",
1900
+ homeroom: "班主任",
1901
+ assistantStudent: "学习伙伴",
1902
+ assistantParent: "辅导助手",
1903
+ assistantTeacher: "教学助手",
1904
+ assistantHomeroom: "班级助手",
1905
+ taglineStudent: "不直接给答案,带你自己做出来",
1906
+ taglineParent: "看懂孩子错在哪,知道怎么讲",
1907
+ taglineTeacher: "批改、出题、备课、试卷分析",
1908
+ taglineHomeroom: "家长沟通、评语、班会、通知",
1909
+ due: "{count} 道错题今天该复习",
1910
+ locked: "小学生需要家长或老师开启",
1911
+ primary: "小学",
1912
+ junior: "初中",
1913
+ senior: "高中",
1914
+ explain: { label: "拍题讲解", text: "这道题我不会,先别告诉我答案,带我一步步想:" },
1915
+ quizMe: { label: "考考我", text: "按我最近学的内容出几道题考考我" },
1916
+ play: { label: "玩一局", text: "按我最近学的和错过的,做个小游戏让我玩一局" },
1917
+ review: { label: "复习错题", text: "复习今天该复习的 {count} 道错题" },
1918
+ recite: { label: "背诵默写", text: "帮我背这一段,先让我自己背,再告诉我哪里错了:" },
1919
+ check: { label: "看作业对错", text: "帮我看看孩子这份作业哪里错了,告诉我怎么讲给孩子听:" },
1920
+ talk: { label: "怎么跟孩子讲", text: "孩子遇到这个情况,我该怎么跟他说:" },
1921
+ toTeacher: { label: "给老师写消息", text: "帮我写一段给老师的话,说清楚、有分寸:" },
1922
+ plan: { label: "安排学习计划", text: "帮孩子安排这周的学习计划,情况是:" },
1923
+ grade: { label: "批改作业", text: "批改这些作业(照片在下面),逐题判对错,归类错因,最后给讲评提纲:" },
1924
+ makeQuiz: { label: "出一套题", text: "出一套题,分基础、提升、拓展三层,主题是:" },
1925
+ classGame: { label: "课堂游戏", text: "做一个全班在班级群里一起玩的课堂小游戏,知识点是:" },
1926
+ lesson: { label: "写教学设计", text: "写一份教学设计,课题是:" },
1927
+ exam: { label: "试卷分析", text: "分析这份成绩表(文件在下面),找出共性薄弱点和需要关注的学生:" },
1928
+ weekly: { label: "每周学情小结", text: "每周五下午 4 点,读本目录里这一周的成绩和作业记录,写一份学情小结给我" },
1929
+ reply: { label: "回家长消息", text: `家长发来:
1930
+
1931
+ 帮我拟一段回复,我看过再发:` },
1932
+ comments: { label: "写评语", text: `按下面每个学生的表现写评语,不写套话:
1933
+ ` },
1934
+ meeting: { label: "班会方案", text: "设计一次班会,主题是:" },
1935
+ notice: { label: "写通知", text: "写一则给家长的通知,内容是:" },
1936
+ settingsTitle: "教育",
1937
+ identitiesLabel: "身份",
1938
+ identitiesHint: "选了哪个,列表里就有对应的助手",
1939
+ stageLabel: "学段",
1940
+ subjectLabel: "学科",
1941
+ subjectHint: "如 数学、英语",
1942
+ textbookLabel: "教材版本",
1943
+ textbookHint: "学校用的教材版本",
1944
+ consentLabel: "小学段使用学习伙伴",
1945
+ consentHint: "由家长在他自己的 Ta 里同意,这里改不了",
1946
+ quiz: "练习",
1947
+ submit: "提交",
1948
+ right: "答对了",
1949
+ wrongAnswer: "正确答案:{answer}",
1950
+ score: "答对 {right}/{total}",
1951
+ explainWrong: "讲讲我错的",
1952
+ explainWrongText: "讲讲这几道我做错的题",
1953
+ judgeTrue: "对",
1954
+ judgeFalse: "错",
1955
+ blank: "写下答案",
1956
+ revealAnswer: "答案:{answer}",
1957
+ learning: "学情",
1958
+ weak: "薄弱点",
1959
+ next: "接下来"
1960
+ };
1961
+ var ZH_TW2 = {
1962
+ student: "學生",
1963
+ parent: "家長",
1964
+ teacher: "老師",
1965
+ homeroom: "班導師",
1966
+ assistantStudent: "學習夥伴",
1967
+ assistantParent: "輔導助手",
1968
+ assistantTeacher: "教學助手",
1969
+ assistantHomeroom: "班級助手",
1970
+ taglineStudent: "不直接給答案,帶你自己做出來",
1971
+ taglineParent: "看懂孩子錯在哪,知道怎麼講",
1972
+ taglineTeacher: "批改、出題、備課、試卷分析",
1973
+ taglineHomeroom: "家長溝通、評語、班會、通知",
1974
+ due: "{count} 道錯題今天該複習",
1975
+ locked: "小學生需要家長或老師開啟",
1976
+ primary: "小學",
1977
+ junior: "國中",
1978
+ senior: "高中",
1979
+ explain: { label: "拍題講解", text: "這道題我不會,先別告訴我答案,帶我一步步想:" },
1980
+ quizMe: { label: "考考我", text: "依我最近學的內容出幾道題考考我" },
1981
+ play: { label: "玩一局", text: "依我最近學的和錯過的,做個小遊戲讓我玩一局" },
1982
+ review: { label: "複習錯題", text: "複習今天該複習的 {count} 道錯題" },
1983
+ recite: { label: "背誦默寫", text: "幫我背這一段,先讓我自己背,再告訴我哪裡錯了:" },
1984
+ check: { label: "看作業對錯", text: "幫我看看孩子這份作業哪裡錯了,告訴我怎麼講給孩子聽:" },
1985
+ talk: { label: "怎麼跟孩子講", text: "孩子遇到這個情況,我該怎麼跟他說:" },
1986
+ toTeacher: { label: "給老師寫訊息", text: "幫我寫一段給老師的話,說清楚、有分寸:" },
1987
+ plan: { label: "安排學習計畫", text: "幫孩子安排這週的學習計畫,情況是:" },
1988
+ grade: { label: "批改作業", text: "批改這些作業(照片在下面),逐題判對錯,歸類錯因,最後給講評提綱:" },
1989
+ makeQuiz: { label: "出一套題", text: "出一套題,分基礎、提升、拓展三層,主題是:" },
1990
+ classGame: { label: "課堂遊戲", text: "做一個全班在班級群裡一起玩的課堂小遊戲,知識點是:" },
1991
+ lesson: { label: "寫教學設計", text: "寫一份教學設計,課題是:" },
1992
+ exam: { label: "試卷分析", text: "分析這份成績表(檔案在下面),找出共同的薄弱點和需要關注的學生:" },
1993
+ weekly: { label: "每週學習小結", text: "每週五下午 4 點,讀本目錄裡這一週的成績和作業紀錄,寫一份學習小結給我" },
1994
+ reply: { label: "回家長訊息", text: `家長傳來:
1995
+
1996
+ 幫我擬一段回覆,我看過再傳:` },
1997
+ comments: { label: "寫評語", text: `依下面每個學生的表現寫評語,不寫套話:
1998
+ ` },
1999
+ meeting: { label: "班會方案", text: "設計一次班會,主題是:" },
2000
+ notice: { label: "寫通知", text: "寫一則給家長的通知,內容是:" },
2001
+ settingsTitle: "教育",
2002
+ identitiesLabel: "身分",
2003
+ identitiesHint: "選了哪個,列表裡就有對應的助手",
2004
+ stageLabel: "學段",
2005
+ subjectLabel: "學科",
2006
+ subjectHint: "如 數學、英語",
2007
+ textbookLabel: "教材版本",
2008
+ textbookHint: "學校用的教材版本",
2009
+ consentLabel: "小學階段使用學習夥伴",
2010
+ consentHint: "由家長在他自己的 Ta 裡同意,這裡改不了",
2011
+ quiz: "練習",
2012
+ submit: "送出",
2013
+ right: "答對了",
2014
+ wrongAnswer: "正確答案:{answer}",
2015
+ score: "答對 {right}/{total}",
2016
+ explainWrong: "講講我錯的",
2017
+ explainWrongText: "講講這幾道我做錯的題",
2018
+ judgeTrue: "對",
2019
+ judgeFalse: "錯",
2020
+ blank: "寫下答案",
2021
+ revealAnswer: "答案:{answer}",
2022
+ learning: "學習情況",
2023
+ weak: "薄弱點",
2024
+ next: "接下來"
2025
+ };
2026
+ var JA2 = {
2027
+ student: "生徒",
2028
+ parent: "保護者",
2029
+ teacher: "先生",
2030
+ homeroom: "担任",
2031
+ assistantStudent: "学習パートナー",
2032
+ assistantParent: "家庭学習サポート",
2033
+ assistantTeacher: "授業アシスタント",
2034
+ assistantHomeroom: "クラスアシスタント",
2035
+ taglineStudent: "答えを教えず、自分で解けるまで一緒に考えます",
2036
+ taglineParent: "どこで間違えたか、どう伝えればいいかが分かります",
2037
+ taglineTeacher: "採点、出題、授業準備、テスト分析",
2038
+ taglineHomeroom: "保護者対応、所見、学級活動、お知らせ",
2039
+ due: "今日復習する間違いが {count} 問",
2040
+ locked: "小学生は保護者か先生がオンにします",
2041
+ primary: "小学校",
2042
+ junior: "中学校",
2043
+ senior: "高校",
2044
+ explain: { label: "問題を解説", text: "この問題が分かりません。答えはまだ言わずに、一歩ずつ考えさせてください:" },
2045
+ quizMe: { label: "問題を出して", text: "最近習ったところから何問か出してください" },
2046
+ play: { label: "ゲームで練習", text: "最近習ったところと間違えたところで、小さなゲームを作って遊ばせてください" },
2047
+ review: { label: "間違いを復習", text: "今日復習する {count} 問の間違いを復習する" },
2048
+ recite: { label: "暗記・暗唱", text: "この部分を覚えたいです。まず自分で言ってみるので、違うところを教えてください:" },
2049
+ check: { label: "宿題を確認", text: "子どもの宿題のどこが間違っているか、どう説明すればいいか教えてください:" },
2050
+ talk: { label: "どう話すか", text: "子どもがこういう状況です。どう話せばいいでしょうか:" },
2051
+ toTeacher: { label: "先生への連絡", text: "先生への連絡を、分かりやすく失礼のないように書いてください:" },
2052
+ plan: { label: "学習計画", text: "子どもの今週の学習計画を立ててください。状況は:" },
2053
+ grade: { label: "宿題を採点", text: "この宿題(写真は下)を採点してください。一問ずつ正誤、間違いの原因の分類、最後に解説授業の要点を:" },
2054
+ makeQuiz: { label: "問題を作る", text: "基礎・応用・発展の三段階で問題を作ってください。テーマは:" },
2055
+ classGame: { label: "クラスでゲーム", text: "クラス全員がグループチャットで一緒に遊べるゲームを作ってください。テーマは:" },
2056
+ lesson: { label: "指導案", text: "指導案を書いてください。単元は:" },
2057
+ exam: { label: "テスト分析", text: "この成績表(ファイルは下)を分析して、クラス共通の弱点と気にかけるべき生徒を挙げてください:" },
2058
+ weekly: { label: "毎週のまとめ", text: "毎週金曜の午後 4 時に、このフォルダの今週の成績と宿題の記録を読んで、学習状況のまとめを書いてください" },
2059
+ reply: { label: "保護者に返信", text: `保護者からの連絡:
2094
2060
 
2095
- // web-src/cards.tsx
2096
- function useStore2(store) {
2097
- const [, tick] = React.useReducer((n) => n + 1, 0);
2098
- React.useEffect(() => store.subscribe(tick), [store]);
2099
- return store.state;
2100
- }
2101
- function rightOf(question, given) {
2102
- const { answer } = question;
2103
- if (typeof answer === "number") {
2104
- return given === String(answer);
2061
+ 返信の下書きをお願いします。読んでから送ります:` },
2062
+ comments: { label: "所見を書く", text: `下の各生徒の様子をもとに、決まり文句なしで所見を書いてください:
2063
+ ` },
2064
+ meeting: { label: "学級活動", text: "学級活動の案を作ってください。テーマは:" },
2065
+ notice: { label: "お知らせ", text: "保護者へのお知らせを書いてください。内容は:" },
2066
+ settingsTitle: "教育",
2067
+ identitiesLabel: "あなたの立場",
2068
+ identitiesHint: "選んだ立場ごとに、リストにアシスタントが出ます",
2069
+ stageLabel: "学校段階",
2070
+ subjectLabel: "教科",
2071
+ subjectHint: "例:数学、英語",
2072
+ textbookLabel: "教科書",
2073
+ textbookHint: "学校で使っている教科書",
2074
+ consentLabel: "小学生の学習パートナー",
2075
+ consentHint: "保護者が自分の Ta で同意します。ここでは変えられません",
2076
+ quiz: "練習",
2077
+ submit: "答え合わせ",
2078
+ right: "正解",
2079
+ wrongAnswer: "正解:{answer}",
2080
+ score: "{total} 問中 {right} 問正解",
2081
+ explainWrong: "間違いを解説",
2082
+ explainWrongText: "間違えた問題を解説して",
2083
+ judgeTrue: "正しい",
2084
+ judgeFalse: "誤り",
2085
+ blank: "答えを書く",
2086
+ revealAnswer: "答え:{answer}",
2087
+ learning: "学習状況",
2088
+ weak: "弱点",
2089
+ next: "次に"
2090
+ };
2091
+ var WORDS = { "zh-CN": ZH2, "zh-TW": ZH_TW2, "en-US": EN2, "ja-JP": JA2 };
2092
+ var EduWords;
2093
+ ((EduWords) => {
2094
+ function of(language) {
2095
+ return TaLanguageUtil.pick(language, WORDS);
2105
2096
  }
2106
- if (typeof answer === "boolean") {
2107
- return given === String(answer);
2097
+ EduWords.of = of;
2098
+ function format(text, values) {
2099
+ return text.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
2108
2100
  }
2109
- return EduUtil.blankRight(answer, given);
2110
- }
2111
- function givenText(question, given) {
2112
- if (question.kind === "choice") {
2113
- const index = Number(given);
2114
- return `${EduUtil.letter(index)}. ${question.options[index] ?? ""}`.trim();
2101
+ EduWords.format = format;
2102
+ })(EduWords ||= {});
2103
+
2104
+ // web-src/edu-chats.ts
2105
+ var EduChats;
2106
+ ((EduChats) => {
2107
+ function identityOf(store, sessionFile) {
2108
+ const { chats } = store.state;
2109
+ return sessionFile ? Object.keys(chats).find((one) => chats[one] === sessionFile) : undefined;
2115
2110
  }
2116
- return question.kind === "judge" ? given === "true" ? "✓" : "✗" : given;
2117
- }
2118
- function Question(props) {
2119
- const { pi, words, question, index, given, reveal } = props;
2120
- const [typed, setTyped] = React.useState("");
2121
- const done = given !== undefined;
2122
- const shown = done || reveal;
2123
- const right = done && rightOf(question, given);
2124
- const Markdown = pi.ui.Markdown;
2125
- const choice = (value, label, key) => {
2126
- const isAnswer = shown && rightOf(question, value) && question.kind !== "blank";
2127
- const state = isAnswer ? "right" : done && given === value ? "wrong" : undefined;
2128
- return /* @__PURE__ */ React.createElement("button", {
2129
- key,
2130
- type: "button",
2131
- className: "ted-option",
2132
- "data-state": state,
2133
- disabled: shown,
2134
- onClick: () => props.answer(value)
2135
- }, label);
2136
- };
2137
- return /* @__PURE__ */ React.createElement("li", {
2138
- className: "ted-q",
2139
- "data-state": done ? right ? "right" : "wrong" : undefined
2140
- }, /* @__PURE__ */ React.createElement("div", {
2141
- className: "ted-q-head"
2142
- }, /* @__PURE__ */ React.createElement("span", {
2143
- className: "ted-q-no"
2144
- }, index + 1), /* @__PURE__ */ React.createElement("div", {
2145
- className: "ted-q-text"
2146
- }, /* @__PURE__ */ React.createElement(Markdown, {
2147
- text: question.q
2148
- }))), question.figure && /* @__PURE__ */ React.createElement("div", {
2149
- className: "ted-figure"
2150
- }, /* @__PURE__ */ React.createElement(Markdown, {
2151
- text: question.figure
2152
- })), question.kind === "choice" && /* @__PURE__ */ React.createElement("div", {
2153
- className: "ted-options"
2154
- }, question.options.map((option, at) => choice(String(at), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("b", null, EduUtil.letter(at)), /* @__PURE__ */ React.createElement(Markdown, {
2155
- inline: true,
2156
- text: option
2157
- })), String(at)))), question.kind === "judge" && /* @__PURE__ */ React.createElement("div", {
2158
- className: "ted-options ted-judge"
2159
- }, choice("true", words.judgeTrue, "true"), choice("false", words.judgeFalse, "false")), question.kind === "blank" && !shown && /* @__PURE__ */ React.createElement("form", {
2160
- className: "ted-blank",
2161
- onSubmit: (event) => {
2162
- event.preventDefault();
2163
- if (typed.trim()) {
2164
- props.answer(typed.trim());
2111
+ EduChats.identityOf = identityOf;
2112
+ async function open(pi, store, identity) {
2113
+ const words = EduWords.of(pi.ui.language);
2114
+ const { settings, chats, consent } = store.state;
2115
+ if (EduUtil.locked(settings, identity, consent)) {
2116
+ pi.ui.notify(HomeWordsUtil.of(pi.ui.language).consentLocked, "warning");
2117
+ await pi.ui.showView(PAGE);
2118
+ return;
2119
+ }
2120
+ const role = EduRoles.prompt(identity, store.state.settings);
2121
+ const title = words[ROLES[identity].assistant];
2122
+ const file = chats[identity];
2123
+ if (file) {
2124
+ const open2 = (await pi.server.listSessions()).find((session) => session.sessionFile === file);
2125
+ if (open2) {
2126
+ await pi.switchSession(open2.sessionId);
2127
+ pi.ui.showView("");
2128
+ return open2.sessionId;
2129
+ }
2130
+ const saved = (await pi.server.listSavedSessions()).find((session) => session.sessionFile === file);
2131
+ if (saved) {
2132
+ const opened2 = pi.server.openSession({ cwd: saved.cwd, sessionFile: file, group: NAME, appendSystemPrompt: role });
2133
+ const id2 = opened2.then((session) => session.sessionId);
2134
+ await pi.switchSession(id2, { title, cwd: saved.cwd, sessionFile: file });
2135
+ pi.ui.showView("");
2136
+ return id2;
2165
2137
  }
2166
2138
  }
2167
- }, /* @__PURE__ */ React.createElement("input", {
2168
- className: "ta-input",
2169
- value: typed,
2170
- placeholder: words.blank,
2171
- onChange: (event) => setTyped(event.target.value)
2172
- }), /* @__PURE__ */ React.createElement("button", {
2173
- type: "submit",
2174
- className: "ta-button",
2175
- disabled: !typed.trim()
2176
- }, words.submit)), shown && /* @__PURE__ */ React.createElement("div", {
2177
- className: "ted-result"
2178
- }, done && question.kind === "blank" && /* @__PURE__ */ React.createElement("div", {
2179
- className: "ted-given"
2180
- }, /* @__PURE__ */ React.createElement(Markdown, {
2181
- inline: true,
2182
- text: given
2183
- })), /* @__PURE__ */ React.createElement("div", {
2184
- className: "ted-verdict"
2185
- }, done && right ? words.right : /* @__PURE__ */ React.createElement(Markdown, {
2186
- inline: true,
2187
- text: EduWords.format(done ? words.wrongAnswer : words.revealAnswer, { answer: EduUtil.answerText(question) })
2188
- })), question.explain && /* @__PURE__ */ React.createElement("div", {
2189
- className: "ted-explain"
2190
- }, /* @__PURE__ */ React.createElement(Markdown, {
2191
- text: question.explain
2192
- }))));
2139
+ const { cwd } = await pi.server.getServerInfo();
2140
+ const opened = pi.server.openSession({ cwd, group: NAME, appendSystemPrompt: role });
2141
+ const named = opened.then(async (session) => {
2142
+ if (session.sessionFile) {
2143
+ await store.setChat(identity, session.sessionFile);
2144
+ }
2145
+ await pi.server.setSessionName(session.sessionId, title);
2146
+ });
2147
+ const id = opened.then((session) => session.sessionId);
2148
+ await pi.switchSession(id, { title, cwd });
2149
+ pi.ui.showView("");
2150
+ await named;
2151
+ return id;
2152
+ }
2153
+ EduChats.open = open;
2154
+ async function say(pi, store, identity, message, images) {
2155
+ const id = await open(pi, store, identity);
2156
+ if (id) {
2157
+ await send(pi, id, message, images);
2158
+ }
2159
+ }
2160
+ EduChats.say = say;
2161
+ async function send(pi, sessionId, message, images) {
2162
+ await pi.server.prompt(sessionId, { message, ...images?.length ? { images } : {}, clientMessageId: crypto.randomUUID() });
2163
+ }
2164
+ EduChats.send = send;
2165
+ })(EduChats ||= {});
2166
+ var EduPhotos;
2167
+ ((EduPhotos) => {
2168
+ function pick() {
2169
+ return new Promise((resolve) => {
2170
+ const input = document.createElement("input");
2171
+ input.type = "file";
2172
+ input.accept = "image/*";
2173
+ input.multiple = true;
2174
+ input.style.display = "none";
2175
+ input.addEventListener("change", () => {
2176
+ const files = [...input.files ?? []].slice(0, 6);
2177
+ input.remove();
2178
+ Promise.all(files.map(shrink)).then(resolve, () => resolve([]));
2179
+ });
2180
+ input.addEventListener("cancel", () => {
2181
+ input.remove();
2182
+ resolve([]);
2183
+ });
2184
+ document.body.appendChild(input);
2185
+ input.click();
2186
+ });
2187
+ }
2188
+ EduPhotos.pick = pick;
2189
+ async function shrink(file) {
2190
+ const bitmap = await createImageBitmap(file);
2191
+ const scale = Math.min(1, 1600 / Math.max(bitmap.width, bitmap.height));
2192
+ const canvas = document.createElement("canvas");
2193
+ canvas.width = Math.round(bitmap.width * scale);
2194
+ canvas.height = Math.round(bitmap.height * scale);
2195
+ canvas.getContext("2d")?.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
2196
+ bitmap.close();
2197
+ const url = canvas.toDataURL("image/jpeg", 0.85);
2198
+ return { type: "image", data: url.slice(url.indexOf(",") + 1), mimeType: "image/jpeg" };
2199
+ }
2200
+ function upload(pi, accept) {
2201
+ return new Promise((resolve) => {
2202
+ const input = document.createElement("input");
2203
+ input.type = "file";
2204
+ input.accept = accept;
2205
+ input.style.display = "none";
2206
+ input.addEventListener("change", () => {
2207
+ const file = input.files?.[0];
2208
+ input.remove();
2209
+ if (!file) {
2210
+ resolve(undefined);
2211
+ return;
2212
+ }
2213
+ const reader = new FileReader;
2214
+ reader.onload = () => {
2215
+ const url = String(reader.result);
2216
+ const path = `edu/${file.name.replace(/[\\/]/g, "_")}`;
2217
+ pi.workspace.uploadFile(path, url.slice(url.indexOf(",") + 1)).then(() => resolve(path), () => resolve(undefined));
2218
+ };
2219
+ reader.onerror = () => resolve(undefined);
2220
+ reader.readAsDataURL(file);
2221
+ });
2222
+ input.addEventListener("cancel", () => {
2223
+ input.remove();
2224
+ resolve(undefined);
2225
+ });
2226
+ document.body.appendChild(input);
2227
+ input.click();
2228
+ });
2229
+ }
2230
+ EduPhotos.upload = upload;
2231
+ })(EduPhotos ||= {});
2232
+
2233
+ // web-src/react.ts
2234
+ var React;
2235
+ function bind(react) {
2236
+ React = react;
2193
2237
  }
2194
- function quizCard(pi, store, rooms) {
2195
- return function QuizCard({ code, closed, send }) {
2196
- const state = useStore2(store);
2197
- const [, tick] = React.useReducer((n) => n + 1, 0);
2198
- React.useEffect(() => rooms.subscribe(tick), []);
2199
- const words = EduWords.of(pi.ui.language);
2200
- const quiz = closed ? EduUtil.quiz(code) : undefined;
2201
- if (!closed) {
2202
- return /* @__PURE__ */ React.createElement("div", {
2203
- className: "ted-card"
2204
- }, /* @__PURE__ */ React.createElement(pi.ui.Loading, {
2205
- label: words.quiz,
2206
- compact: true
2207
- }));
2208
- }
2209
- if (!quiz) {
2210
- throw new Error("Not a quiz");
2211
- }
2212
- const card = EduUtil.hash(code);
2213
- const room = quiz.room ? rooms.rooms.find((one) => one.id === quiz.room) : undefined;
2214
- const mine = !!room && !!quiz.teacher && rooms.me(room) === quiz.teacher;
2215
- const reveal = quiz.reveal || mine;
2216
- const given = state.answers[card] ?? {};
2217
- const answered = quiz.questions.filter((_, at) => given[at] !== undefined);
2218
- const wrong = quiz.questions.flatMap((question, at) => given[at] !== undefined && !rightOf(question, given[at]) ? [{ question, at }] : []);
2219
- const all = answered.length === quiz.questions.length;
2220
- const explain = () => {
2221
- const lines = wrong.map(({ question, at }) => JSON.stringify({ no: at + 1, q: question.q, answer: EduUtil.answerText(question), given: givenText(question, given[at]) }));
2222
- const context = `[${NAME}:mistakes]
2223
- The questions of the quiz above the user got wrong. Go over why, step by step, and give one more question on each point.
2224
- ${lines.join(`
2225
- `)}`;
2226
- (send ?? pi.sendUserMessage)(TaMessageContext.wrap(context, words.explainWrongText));
2238
+
2239
+ // web-src/ui.tsx
2240
+ var TONES = { student: "0", parent: "4", teacher: "3", homeroom: "5" };
2241
+ var TINTS = { student: "edu", parent: "book", teacher: "class", homeroom: "learn" };
2242
+ function tone(n) {
2243
+ return { "--ted-ink": `var(--ta-tint-ink-${n})`, "--ted-tile": `var(--ta-tint-${n})` };
2244
+ }
2245
+ function format(text, values) {
2246
+ return EduWords.format(text, values);
2247
+ }
2248
+ function useStore(store) {
2249
+ const [, tick] = React.useReducer((n) => n + 1, 0);
2250
+ React.useEffect(() => store.subscribe(tick), [store]);
2251
+ return store.state;
2252
+ }
2253
+ function useRooms(rooms) {
2254
+ const [, tick] = React.useReducer((n) => n + 1, 0);
2255
+ React.useEffect(() => rooms.subscribe(tick), [rooms]);
2256
+ return rooms.version;
2257
+ }
2258
+ function useAsync(read, keys) {
2259
+ const [value, setValue] = React.useState();
2260
+ React.useEffect(() => {
2261
+ let live = true;
2262
+ read().then((got) => live && setValue(got), () => {
2263
+ return;
2264
+ });
2265
+ return () => {
2266
+ live = false;
2227
2267
  };
2228
- return /* @__PURE__ */ React.createElement("div", {
2229
- className: "ted-card"
2230
- }, /* @__PURE__ */ React.createElement("div", {
2231
- className: "ted-head"
2232
- }, /* @__PURE__ */ React.createElement("span", {
2233
- className: "ted-mark"
2234
- }, /* @__PURE__ */ React.createElement(pi.ui.icons.ListChecks, {
2235
- size: 15
2236
- })), /* @__PURE__ */ React.createElement("span", {
2237
- className: "ted-title"
2238
- }, quiz.title ? /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
2239
- inline: true,
2240
- text: quiz.title
2241
- }) : words.quiz), answered.length > 0 && !reveal && /* @__PURE__ */ React.createElement("span", {
2242
- className: "ted-score"
2243
- }, EduWords.format(words.score, { right: answered.length - wrong.length, total: quiz.questions.length }))), /* @__PURE__ */ React.createElement("ol", {
2244
- className: "ted-qs"
2245
- }, quiz.questions.map((question, at) => /* @__PURE__ */ React.createElement(Question, {
2246
- key: at,
2247
- pi,
2248
- words,
2249
- question,
2250
- index: at,
2251
- given: given[at],
2252
- reveal,
2253
- answer: (value) => void store.answer(card, at, question, value, givenText(question, value), rightOf(question, value))
2254
- }))), mine && room && /* @__PURE__ */ React.createElement(Handed, {
2255
- pi,
2256
- rooms,
2257
- quiz,
2258
- room
2259
- }), !mine && quiz.id && all && /* @__PURE__ */ React.createElement(HandIn, {
2260
- pi,
2261
- rooms,
2262
- quiz,
2263
- name: () => rooms.server?.getIdentity().then((one) => one.name),
2264
- given
2265
- }), all && wrong.length > 0 && !reveal && /* @__PURE__ */ React.createElement("div", {
2266
- className: "ted-foot"
2267
- }, /* @__PURE__ */ React.createElement("button", {
2268
- type: "button",
2269
- className: "ta-button ta-primary",
2270
- onClick: explain
2271
- }, words.explainWrong)), quiz.reveal && !quiz.id && state.settings.identities.includes("teacher") && rooms.server && /* @__PURE__ */ React.createElement(SendToClass, {
2272
- pi,
2273
- store,
2274
- rooms,
2275
- quiz
2276
- }));
2277
- };
2268
+ }, keys);
2269
+ return value;
2278
2270
  }
2279
- function HandIn(props) {
2280
- const { pi, rooms, quiz, given } = props;
2271
+ function iconOf(pi, name, fallback = "BookOpen") {
2272
+ return pi.ui.icons[name] ?? pi.ui.icons[fallback] ?? pi.ui.icons.BookOpen;
2273
+ }
2274
+ function when(at, language, words) {
2275
+ const date = new Date(at);
2276
+ const now = new Date;
2277
+ const time = date.toLocaleTimeString(language, { hour: "2-digit", minute: "2-digit", hour12: false });
2278
+ if (EduUtil.dayOf(at) === EduUtil.dayOf(now.getTime())) {
2279
+ return time;
2280
+ }
2281
+ if (EduUtil.dayOf(at) === EduUtil.dayOf(now.getTime() - 86400000)) {
2282
+ return `${words.yesterday} ${time}`;
2283
+ }
2284
+ return date.toLocaleDateString(language, now.getTime() - at < 6 * 86400000 ? { weekday: "short" } : { month: "numeric", day: "numeric" });
2285
+ }
2286
+ function failed(pi, words) {
2287
+ return (error) => pi.ui.notify(format(words.failed, { error: error instanceof Error ? error.message : String(error) }), "error");
2288
+ }
2289
+ function Tile({ icon: Icon, tone: hue, size = "row" }) {
2290
+ return /* @__PURE__ */ React.createElement("span", {
2291
+ className: `ted-tile ted-tile-${size}`,
2292
+ style: tone(hue)
2293
+ }, /* @__PURE__ */ React.createElement(Icon, {
2294
+ size: size === "big" ? 22 : 18,
2295
+ strokeWidth: 1.8
2296
+ }));
2297
+ }
2298
+ function Actions({ context, actions }) {
2299
+ const { pi } = context;
2300
+ const [busy, setBusy] = React.useState();
2281
2301
  const home = HomeWordsUtil.of(pi.ui.language);
2282
- const [status, setStatus] = React.useState("checking");
2283
- const handIn = React.useCallback(async () => {
2284
- setStatus("sending");
2285
- try {
2286
- const name = await props.name() ?? "";
2287
- const submission = {
2288
- name,
2289
- given: quiz.questions.map((question, at) => givenText(question, given[at] ?? "")),
2290
- right: quiz.questions.map((question, at) => given[at] !== undefined && rightOf(question, given[at])),
2291
- at: Date.now()
2292
- };
2293
- const result = await rooms.submit(quiz, submission);
2294
- setStatus(result === "sent" ? "sent" : result === "no-key" ? "no-key" : "failed");
2295
- } catch {
2296
- setStatus("failed");
2302
+ return /* @__PURE__ */ React.createElement("div", {
2303
+ className: "ted-actions"
2304
+ }, actions.map((action) => /* @__PURE__ */ React.createElement("button", {
2305
+ key: action.key,
2306
+ type: "button",
2307
+ className: "ted-action",
2308
+ disabled: busy === action.key,
2309
+ onClick: () => {
2310
+ setBusy(action.key);
2311
+ Promise.resolve().then(action.run).catch(failed(pi, home)).finally(() => setBusy(undefined));
2297
2312
  }
2298
- }, [quiz, given, rooms]);
2299
- React.useEffect(() => {
2300
- rooms.submitted(quiz).then((done) => done ? setStatus("sent") : handIn(), () => handIn());
2301
- }, []);
2302
- const Check = pi.ui.icons.Check;
2313
+ }, /* @__PURE__ */ React.createElement(Tile, {
2314
+ icon: iconOf(pi, action.icon, action.fallback),
2315
+ tone: action.tone,
2316
+ size: "big"
2317
+ }), /* @__PURE__ */ React.createElement("span", null, action.label))));
2318
+ }
2319
+ function Assistant({ context, identity }) {
2320
+ const { pi, store } = context;
2321
+ const words = EduWords.of(pi.ui.language);
2322
+ const home = HomeWordsUtil.of(pi.ui.language);
2323
+ const role = ROLES[identity];
2303
2324
  return /* @__PURE__ */ React.createElement("div", {
2304
- className: "ted-foot ted-handin",
2305
- "data-status": status
2306
- }, status === "sent" ? /* @__PURE__ */ React.createElement("span", {
2307
- className: "ted-handed"
2308
- }, /* @__PURE__ */ React.createElement(Check, {
2309
- size: 14,
2310
- strokeWidth: 2.6
2311
- }), home.handedIn) : status === "checking" || status === "sending" ? /* @__PURE__ */ React.createElement(pi.ui.Loading, {
2312
- compact: true
2313
- }) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
2314
- className: "ted-handin-note"
2315
- }, status === "no-key" ? home.noTeacherKey : ""), /* @__PURE__ */ React.createElement("button", {
2325
+ className: "ted-panel ted-list ted-assistant"
2326
+ }, /* @__PURE__ */ React.createElement("button", {
2316
2327
  type: "button",
2317
- className: "ta-button",
2318
- onClick: () => void handIn()
2319
- }, home.handIn)));
2328
+ className: "ted-row",
2329
+ onClick: () => void EduChats.open(pi, store, identity).catch(failed(pi, home))
2330
+ }, /* @__PURE__ */ React.createElement(Tile, {
2331
+ icon: iconOf(pi, role.icon),
2332
+ tone: TONES[identity]
2333
+ }), /* @__PURE__ */ React.createElement("span", {
2334
+ className: "ted-row-main"
2335
+ }, /* @__PURE__ */ React.createElement("span", {
2336
+ className: "ted-row-title"
2337
+ }, words[role.assistant]), /* @__PURE__ */ React.createElement("span", {
2338
+ className: "ted-row-sub"
2339
+ }, words[role.tagline])), /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronRight, {
2340
+ size: 16
2341
+ })));
2342
+ }
2343
+ function Section({ title, aside, children }) {
2344
+ return /* @__PURE__ */ React.createElement("section", {
2345
+ className: "ted-section"
2346
+ }, /* @__PURE__ */ React.createElement("div", {
2347
+ className: "ted-section-head"
2348
+ }, /* @__PURE__ */ React.createElement("h3", null, title), aside !== undefined && /* @__PURE__ */ React.createElement("span", {
2349
+ className: "ted-section-aside"
2350
+ }, aside)), children);
2351
+ }
2352
+ async function ask(context, identity, title, hint, prefix, many = false) {
2353
+ const { pi, store } = context;
2354
+ const text = many ? await pi.ui.editor(title, hint) : await pi.ui.input(title, hint);
2355
+ if (text?.trim()) {
2356
+ await EduChats.say(pi, store, identity, `${prefix}${text.trim()}`);
2357
+ }
2358
+ }
2359
+ async function photo(context, identity, text) {
2360
+ const images = await EduPhotos.pick();
2361
+ if (images.length) {
2362
+ await EduChats.say(context.pi, context.store, identity, text, images);
2363
+ }
2320
2364
  }
2321
- function Handed({ pi, rooms, quiz, room }) {
2322
- const home = HomeWordsUtil.of(pi.ui.language);
2323
- const [count, setCount] = React.useState();
2324
- React.useEffect(() => {
2325
- rooms.server?.getState(room.id, `edu:sub:${quiz.id}:`).then((state) => setCount(Object.keys(state).length), () => {
2326
- return;
2327
- });
2328
- }, [room.id, quiz.id, rooms.version]);
2365
+ function reviewContext(mistakes) {
2366
+ const lines = mistakes.slice(0, 10).map((one) => JSON.stringify({ id: one.id, q: one.question, answer: one.answer, given: one.given, subject: one.subject, topic: one.topic }));
2367
+ return `[${NAME}:review]
2368
+ The mistakes the user is due to review. For each, ask a new question on the same point in another form (other numbers, words or setting), with "review" its id and "subject" its subject, in one quiz card; then go over what they still get wrong.
2369
+ ${lines.join(`
2370
+ `)}`;
2371
+ }
2372
+ function review(context, mistakes) {
2373
+ const { pi, store } = context;
2374
+ const words = EduWords.of(pi.ui.language);
2375
+ return EduChats.say(pi, store, "student", TaMessageContext.wrap(reviewContext(mistakes), format(words.review.text, { count: mistakes.length })));
2376
+ }
2377
+ function toneOf(text) {
2378
+ return String(Number.parseInt(EduUtil.hash(text), 36) % 9);
2379
+ }
2380
+ function Stats({ items }) {
2329
2381
  return /* @__PURE__ */ React.createElement("div", {
2330
- className: "ted-foot ted-handin"
2331
- }, /* @__PURE__ */ React.createElement("span", {
2332
- className: "ted-handin-note"
2333
- }, count === undefined ? "" : EduWords.format(home.handedCount, { count })), /* @__PURE__ */ React.createElement("button", {
2334
- type: "button",
2335
- className: "ta-button",
2336
- onClick: () => void pi.ui.showView(PAGE)
2337
- }, home.results));
2382
+ className: "ted-stats"
2383
+ }, items.map(([value, label, unit]) => /* @__PURE__ */ React.createElement("div", {
2384
+ key: label,
2385
+ className: "ted-stat"
2386
+ }, /* @__PURE__ */ React.createElement("b", null, value, unit && /* @__PURE__ */ React.createElement("small", null, unit)), /* @__PURE__ */ React.createElement("span", null, label))));
2338
2387
  }
2339
- function SendToClass({ pi, store, rooms, quiz }) {
2388
+ function Count({ text, count, tone: tone2 }) {
2389
+ const [before, after = ""] = text.split("{count}");
2390
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, before, /* @__PURE__ */ React.createElement("em", {
2391
+ className: "ted-count",
2392
+ style: { color: `var(--ta-tint-ink-${tone2})` }
2393
+ }, count), after);
2394
+ }
2395
+ function homeDetail(store, words, home) {
2396
+ const { settings, mistakes } = store.state;
2397
+ const identity = EduUtil.current(settings);
2398
+ if (!identity) {
2399
+ return { detail: home.homeDetailPick, unseen: false };
2400
+ }
2401
+ const due = EduUtil.due(mistakes, Date.now()).length;
2402
+ if (identity === "student" && due) {
2403
+ return { detail: `${format(home.dueHead, { count: due })} · ${words.student}`, unseen: true };
2404
+ }
2405
+ return { detail: `${words[ROLES[identity].tagline]} · ${words[identity]}`, unseen: false };
2406
+ }
2407
+
2408
+ // web-src/family.tsx
2409
+ function ParentHome({ context }) {
2410
+ const { pi, store, rooms } = context;
2411
+ const version = useRooms(rooms);
2340
2412
  const home = HomeWordsUtil.of(pi.ui.language);
2341
- const [sent, setSent] = React.useState();
2342
- const [busy, setBusy] = React.useState(false);
2343
- const context = { pi, store, rooms };
2344
- const post = async (room) => {
2345
- setBusy(true);
2346
- try {
2347
- const intro = EduWords.format(home.quizIntro, { title: quiz.title ?? EduWords.of(pi.ui.language).quiz, count: quiz.questions.length });
2348
- await rooms.postQuiz(room, quiz, intro);
2349
- await store.setSettings({ klass: room.id });
2350
- setSent(room.title);
2351
- pi.ui.notify(EduWords.format(home.sentToClass, { klass: room.title }));
2352
- } catch (error) {
2353
- pi.ui.notify(EduWords.format(home.failed, { error: error instanceof Error ? error.message : String(error) }), "error");
2354
- } finally {
2355
- setBusy(false);
2356
- }
2357
- };
2358
- const pick = async () => {
2359
- await rooms.load();
2360
- const classes = rooms.classes();
2361
- if (!classes.length) {
2362
- openClasses(context);
2363
- return;
2364
- }
2365
- if (classes.length === 1) {
2366
- if (await pi.ui.confirm(home.sendToClass, classes[0].title, { confirmLabel: home.sendToClass })) {
2367
- await post(classes[0]);
2368
- }
2369
- return;
2370
- }
2371
- pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
2372
- title: home.pickClass,
2373
- onClose: close
2374
- }, /* @__PURE__ */ React.createElement("div", {
2375
- className: "ted-list"
2376
- }, classes.map((room) => /* @__PURE__ */ React.createElement("button", {
2377
- key: room.id,
2378
- type: "button",
2379
- className: "ted-row",
2380
- onClick: () => {
2381
- close();
2382
- post(room);
2383
- }
2384
- }, /* @__PURE__ */ React.createElement("span", {
2385
- className: "ted-row-main"
2386
- }, /* @__PURE__ */ React.createElement("span", {
2387
- className: "ted-row-title"
2388
- }, room.title)))))));
2389
- };
2390
- const Send = pi.ui.icons.Send;
2391
- return /* @__PURE__ */ React.createElement("div", {
2392
- className: "ted-foot ted-handin"
2393
- }, /* @__PURE__ */ React.createElement("span", {
2394
- className: "ted-handin-note"
2395
- }, sent ? EduWords.format(home.sentToClass, { klass: sent }) : ""), /* @__PURE__ */ React.createElement("button", {
2413
+ const reports = useAsync(() => rooms.reports(), [version]);
2414
+ const notices = useAsync(() => rooms.notices(), [version, store.state.settings.classes.join()]);
2415
+ const [answered, setAnswered] = React.useState(0);
2416
+ const asks = useAsync(() => rooms.consentAsks(), [version, answered]);
2417
+ const [child, setChild] = React.useState();
2418
+ const children = [...new Map((reports ?? []).map((report2) => [report2.child, report2])).values()];
2419
+ const report = children.find((one) => one.child === child) ?? children[0];
2420
+ const Lock = iconOf(pi, "Lock");
2421
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, asks && asks.length > 0 && /* @__PURE__ */ React.createElement(ConsentAsks, {
2422
+ context,
2423
+ asks,
2424
+ answered: () => setAnswered((n) => n + 1)
2425
+ }), children.length > 1 && /* @__PURE__ */ React.createElement("div", {
2426
+ className: "ted-chips"
2427
+ }, children.map((one) => /* @__PURE__ */ React.createElement("button", {
2428
+ key: one.child,
2396
2429
  type: "button",
2397
- className: "ta-button",
2398
- disabled: busy,
2399
- onClick: () => void pick()
2400
- }, /* @__PURE__ */ React.createElement(Send, {
2401
- size: 14
2402
- }), home.sendToClass));
2403
- }
2404
- function learningCard(pi) {
2405
- return function LearningCard({ code, closed, send }) {
2406
- const words = EduWords.of(pi.ui.language);
2407
- const learning = closed ? EduUtil.learning(code) : undefined;
2408
- if (!closed) {
2409
- return /* @__PURE__ */ React.createElement("div", {
2410
- className: "ted-card"
2411
- }, /* @__PURE__ */ React.createElement(pi.ui.Loading, {
2412
- label: words.learning,
2413
- compact: true
2414
- }));
2415
- }
2416
- if (!learning) {
2417
- throw new Error("Not a learning card");
2418
- }
2419
- return /* @__PURE__ */ React.createElement("div", {
2420
- className: "ted-card"
2421
- }, /* @__PURE__ */ React.createElement("div", {
2422
- className: "ted-head"
2423
- }, /* @__PURE__ */ React.createElement("span", {
2424
- className: "ted-mark"
2425
- }, /* @__PURE__ */ React.createElement(pi.ui.icons.TrendingUp, {
2426
- size: 15
2427
- })), /* @__PURE__ */ React.createElement("span", {
2428
- className: "ted-title"
2429
- }, learning.title ? /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
2430
- inline: true,
2431
- text: learning.title
2432
- }) : words.learning)), learning.stats.length > 0 && /* @__PURE__ */ React.createElement("div", {
2433
- className: "ted-stats ted-stats-card"
2434
- }, learning.stats.map((one) => /* @__PURE__ */ React.createElement("div", {
2435
- key: one.label,
2436
- className: "ted-stat"
2437
- }, /* @__PURE__ */ React.createElement("b", null, one.value), /* @__PURE__ */ React.createElement("span", null, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
2438
- inline: true,
2439
- text: one.label
2440
- }))))), learning.items.length > 0 && /* @__PURE__ */ React.createElement("ul", {
2441
- className: "ted-bars"
2442
- }, learning.items.map((item) => /* @__PURE__ */ React.createElement("li", {
2443
- key: item.label,
2444
- className: "ted-bar",
2445
- "data-level": item.value >= 85 ? "good" : item.value >= 60 ? "warn" : "bad"
2446
- }, /* @__PURE__ */ React.createElement("span", {
2447
- className: "ted-bar-label"
2448
- }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
2449
- inline: true,
2450
- text: item.label
2451
- })), /* @__PURE__ */ React.createElement("span", {
2452
- className: "ted-bar-track"
2453
- }, /* @__PURE__ */ React.createElement("i", {
2454
- style: { width: `${item.value}%` }
2455
- })), /* @__PURE__ */ React.createElement("span", {
2456
- className: "ted-bar-value"
2457
- }, item.value, "%"), item.note && /* @__PURE__ */ React.createElement("span", {
2458
- className: "ted-bar-note"
2459
- }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
2460
- inline: true,
2461
- text: item.note
2462
- }))))), learning.weak.length > 0 && /* @__PURE__ */ React.createElement("div", {
2463
- className: "ted-part"
2464
- }, /* @__PURE__ */ React.createElement("div", {
2465
- className: "ted-part-title"
2466
- }, words.weak), /* @__PURE__ */ React.createElement("div", {
2467
- className: "ted-tags"
2468
- }, learning.weak.map((one) => /* @__PURE__ */ React.createElement("span", {
2469
- key: one,
2470
- className: "ted-tag"
2471
- }, one)))), learning.next.length > 0 && /* @__PURE__ */ React.createElement("div", {
2472
- className: "ted-part"
2473
- }, /* @__PURE__ */ React.createElement("div", {
2474
- className: "ted-part-title"
2475
- }, words.next), /* @__PURE__ */ React.createElement("div", {
2476
- className: "ted-next"
2477
- }, learning.next.map((one) => /* @__PURE__ */ React.createElement("button", {
2478
- key: one,
2479
- type: "button",
2480
- className: "ted-chip",
2481
- onClick: () => void (send ?? pi.sendUserMessage)(one)
2482
- }, one)))));
2483
- };
2430
+ className: "ted-chip",
2431
+ "aria-pressed": one === report,
2432
+ onClick: () => setChild(one.child)
2433
+ }, one.child))), report ? /* @__PURE__ */ React.createElement(ReportCard, {
2434
+ context,
2435
+ report
2436
+ }) : /* @__PURE__ */ React.createElement("div", {
2437
+ className: "ted-panel ted-empty"
2438
+ }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
2439
+ compact: true,
2440
+ title: reports ? home.noReport : " ",
2441
+ hint: home.noReportHint
2442
+ })), /* @__PURE__ */ React.createElement(Actions, {
2443
+ context,
2444
+ actions: [
2445
+ {
2446
+ key: "check",
2447
+ label: home.tileCheck,
2448
+ icon: "Camera",
2449
+ fallback: "Image",
2450
+ tone: "4",
2451
+ run: () => photo(context, "parent", home.photoParent)
2452
+ },
2453
+ {
2454
+ key: "talk",
2455
+ label: home.tileTalk,
2456
+ icon: "MessageCircle",
2457
+ tone: "5",
2458
+ run: () => ask(context, "parent", home.tileTalk, "", EduWords.of(pi.ui.language).talk.text, true)
2459
+ },
2460
+ {
2461
+ key: "teacher",
2462
+ label: home.tileTeacher,
2463
+ icon: "Send",
2464
+ tone: "3",
2465
+ run: () => ask(context, "parent", home.tileTeacher, "", EduWords.of(pi.ui.language).toTeacher.text, true)
2466
+ },
2467
+ {
2468
+ key: "plan",
2469
+ label: home.tilePlan,
2470
+ icon: "Calendar",
2471
+ tone: "0",
2472
+ run: () => ask(context, "parent", home.tilePlan, "", EduWords.of(pi.ui.language).plan.text, true)
2473
+ }
2474
+ ]
2475
+ }), /* @__PURE__ */ React.createElement(Assistant, {
2476
+ context,
2477
+ identity: "parent"
2478
+ }), /* @__PURE__ */ React.createElement(Notices, {
2479
+ context,
2480
+ notices,
2481
+ identity: "parent"
2482
+ }), /* @__PURE__ */ React.createElement("p", {
2483
+ className: "ted-privacy"
2484
+ }, /* @__PURE__ */ React.createElement(Lock, {
2485
+ size: 12
2486
+ }), home.parentPrivacy));
2484
2487
  }
2485
-
2486
- // web-src/composer.tsx
2487
- var TONES2 = { student: "0", parent: "4", teacher: "3", homeroom: "5" };
2488
- function photoText(identity, pi) {
2488
+ function ConsentAsks({ context, asks, answered }) {
2489
+ const { pi, rooms } = context;
2489
2490
  const home = HomeWordsUtil.of(pi.ui.language);
2490
- return identity === "student" ? home.photoStudent : identity === "parent" ? home.photoParent : home.photoTeacher;
2491
- }
2492
- async function run(pi, store, conversation, identity, key) {
2493
- const words = EduWords.of(pi.ui.language);
2494
- const action = ROLES[identity].actions.find((one) => one.key === key);
2495
- if (!action) {
2496
- return;
2497
- }
2498
- const { label, text } = EduRoles.action(words, action.key);
2499
- if (action.key === "review") {
2500
- const due = EduUtil.due(store.state.mistakes, Date.now());
2501
- await EduChats.send(pi, conversation.sessionId, TaMessageContext.wrap(reviewContext(due), EduWords.format(text, { count: due.length })));
2502
- return;
2503
- }
2504
- if (action.icon === "Image") {
2505
- const images = await EduPhotos.pick();
2506
- if (images.length) {
2507
- await EduChats.send(pi, conversation.sessionId, photoText(identity, pi), images);
2508
- }
2509
- return;
2510
- }
2511
- const message = action.send ? text : await pi.ui.editor(label, text);
2512
- if (message?.trim()) {
2513
- await EduChats.send(pi, conversation.sessionId, message.trim());
2514
- }
2515
- }
2516
- function Empty({ pi, store, conversation, identity }) {
2517
- useStore(store);
2518
- const words = EduWords.of(pi.ui.language);
2519
- const role = ROLES[identity];
2520
- const Icon = iconOf(pi, role.icon);
2521
- const due = EduUtil.due(store.state.mistakes, Date.now()).length;
2522
- const actions = role.actions.filter((action) => action.key !== "review" || due > 0).slice(0, 4);
2491
+ const [busy, setBusy] = React.useState();
2492
+ const say = (ask2, yes) => {
2493
+ setBusy(ask2.child);
2494
+ rooms.answerConsent(ask2, yes, home).then(answered, failed(pi, home)).finally(() => setBusy(undefined));
2495
+ };
2523
2496
  return /* @__PURE__ */ React.createElement("div", {
2524
- className: "ted-hero"
2497
+ className: "ted-consent-asks"
2498
+ }, /* @__PURE__ */ React.createElement(Section, {
2499
+ title: home.consentAsks
2500
+ }, /* @__PURE__ */ React.createElement("div", {
2501
+ className: "ted-panel ted-list"
2502
+ }, asks.map((ask2) => /* @__PURE__ */ React.createElement("div", {
2503
+ key: ask2.child,
2504
+ className: "ted-consent-ask"
2505
+ }, /* @__PURE__ */ React.createElement("div", {
2506
+ className: "ted-row ted-row-static"
2507
+ }, /* @__PURE__ */ React.createElement(pi.ui.Face, {
2508
+ seed: ask2.child,
2509
+ size: 36
2510
+ }), /* @__PURE__ */ React.createElement("span", {
2511
+ className: "ted-row-main"
2525
2512
  }, /* @__PURE__ */ React.createElement("span", {
2526
- className: "ted-hero-face",
2527
- style: tone(TONES2[identity])
2528
- }, /* @__PURE__ */ React.createElement(Icon, {
2529
- size: 30,
2530
- strokeWidth: 1.8
2531
- })), /* @__PURE__ */ React.createElement("h1", {
2532
- className: "ted-hero-title"
2533
- }, words[role.assistant]), /* @__PURE__ */ React.createElement("p", {
2534
- className: "ted-hero-hint"
2535
- }, words[role.tagline]), /* @__PURE__ */ React.createElement("div", {
2536
- className: "ted-hero-starts"
2537
- }, actions.map((action) => {
2538
- const { label } = EduRoles.action(words, action.key);
2539
- const ActionIcon = iconOf(pi, action.icon === "Image" ? "Camera" : action.icon, action.icon);
2540
- return /* @__PURE__ */ React.createElement("button", {
2541
- key: action.key,
2542
- type: "button",
2543
- className: "ted-start",
2544
- onClick: () => void run(pi, store, conversation, identity, action.key)
2545
- }, /* @__PURE__ */ React.createElement(ActionIcon, {
2546
- size: 16,
2547
- strokeWidth: 1.9
2548
- }), /* @__PURE__ */ React.createElement("span", null, action.key === "review" ? `${label} · ${due}` : label));
2549
- })));
2513
+ className: "ted-row-title"
2514
+ }, format(home.consentAskTitle, { name: ask2.name })), /* @__PURE__ */ React.createElement("span", {
2515
+ className: "ted-row-sub ted-wrap"
2516
+ }, home.consentAskBody))), /* @__PURE__ */ React.createElement("div", {
2517
+ className: "ted-consent-acts"
2518
+ }, /* @__PURE__ */ React.createElement("button", {
2519
+ type: "button",
2520
+ className: "ta-button ted-pill",
2521
+ disabled: busy === ask2.child,
2522
+ onClick: () => say(ask2, false)
2523
+ }, home.consentNo), /* @__PURE__ */ React.createElement("button", {
2524
+ type: "button",
2525
+ className: "ta-button ta-primary ted-pill",
2526
+ disabled: busy === ask2.child,
2527
+ onClick: () => say(ask2, true)
2528
+ }, home.consentYes)))))));
2550
2529
  }
2551
- function Chips({ pi, conversation }) {
2530
+ function ReportCard({ context, report }) {
2531
+ const { pi, store } = context;
2552
2532
  const home = HomeWordsUtil.of(pi.ui.language);
2553
- const chips = [
2554
- {
2555
- key: "photo",
2556
- label: home.chipPhoto,
2557
- icon: "Camera",
2558
- fallback: "Image",
2559
- run: async () => {
2560
- const images = await EduPhotos.pick();
2561
- if (images.length) {
2562
- await EduChats.send(pi, conversation.sessionId, home.photoStudent, images);
2563
- }
2564
- }
2565
- },
2566
- { key: "hint", label: home.chipHint, icon: "Lightbulb", run: () => EduChats.send(pi, conversation.sessionId, home.chipHintText) },
2567
- {
2568
- key: "again",
2569
- label: home.chipAgain,
2570
- icon: "Shuffle",
2571
- fallback: "RotateCcw",
2572
- run: () => EduChats.send(pi, conversation.sessionId, home.chipAgainText)
2573
- },
2574
- { key: "got", label: home.chipGot, icon: "Check", run: () => EduChats.send(pi, conversation.sessionId, home.chipGotText) }
2575
- ];
2533
+ const { learning } = report;
2534
+ const about = `[${NAME}:report]
2535
+ The week of the user's child, as the child's Ta sent it:
2536
+ ${JSON.stringify(learning)}`;
2537
+ const say = (text) => void EduChats.say(pi, store, "parent", TaMessageContext.wrap(about, text)).catch(failed(pi, home));
2576
2538
  return /* @__PURE__ */ React.createElement("div", {
2577
- className: "ted-chiprow"
2578
- }, chips.map((chip) => {
2579
- const Icon = chip.key === "photo" ? iconOf(pi, chip.icon, chip.fallback) : undefined;
2580
- return /* @__PURE__ */ React.createElement("button", {
2581
- key: chip.key,
2582
- type: "button",
2583
- className: "ted-chip ted-chip-icon",
2584
- onClick: () => void chip.run().catch(() => {
2585
- return;
2586
- })
2587
- }, Icon && /* @__PURE__ */ React.createElement(Icon, {
2588
- size: 14,
2589
- strokeWidth: 2
2590
- }), chip.label);
2591
- }));
2592
- }
2593
- function eduComposer(pi, store) {
2594
- const identityOf = (conversation) => conversation.group === NAME ? EduChats.identityOf(store, conversation.sessionFile) : undefined;
2595
- return {
2596
- actions: (conversation) => {
2597
- const identity = identityOf(conversation);
2598
- if (!identity) {
2599
- return [];
2600
- }
2601
- const words = EduWords.of(pi.ui.language);
2602
- const due = EduUtil.due(store.state.mistakes, Date.now()).length;
2603
- return ROLES[identity].actions.map((action) => {
2604
- const { label, text } = EduRoles.action(words, action.key);
2605
- const icon = pi.ui.icons[action.icon];
2606
- if (action.key === "review") {
2607
- return {
2608
- key: action.key,
2609
- label,
2610
- icon,
2611
- detail: due ? String(due) : undefined,
2612
- disabled: due === 0,
2613
- run: () => void run(pi, store, conversation, identity, action.key)
2614
- };
2615
- }
2616
- return action.send || action.icon === "Image" ? { key: action.key, label, icon, run: () => void run(pi, store, conversation, identity, action.key) } : { key: action.key, label, icon, insert: text };
2617
- });
2618
- },
2619
- subscribe: (listener) => store.subscribe(listener),
2620
- above: ({ conversation }) => identityOf(conversation) === "student" ? /* @__PURE__ */ React.createElement(Chips, {
2621
- pi,
2622
- conversation
2623
- }) : null,
2624
- empty: (conversation) => {
2625
- const identity = identityOf(conversation);
2626
- return identity ? /* @__PURE__ */ React.createElement(Empty, {
2627
- pi,
2628
- store,
2629
- conversation,
2630
- identity
2631
- }) : undefined;
2632
- }
2633
- };
2539
+ className: "ted-panel ted-report"
2540
+ }, /* @__PURE__ */ React.createElement("div", {
2541
+ className: "ted-panel-head"
2542
+ }, /* @__PURE__ */ React.createElement("span", {
2543
+ className: "ted-panel-title"
2544
+ }, format(home.childWeek, { name: report.child })), /* @__PURE__ */ React.createElement("span", {
2545
+ className: "ted-panel-aside"
2546
+ }, format(home.fromChild, { name: report.child, time: when(report.at, pi.ui.language, home) }))), learning.stats.length > 0 && /* @__PURE__ */ React.createElement(Stats, {
2547
+ items: learning.stats.map((one) => [one.value, one.label])
2548
+ }), (learning.weak.length > 0 || learning.items.length > 0) && /* @__PURE__ */ React.createElement("div", {
2549
+ className: "ted-report-rows"
2550
+ }, learning.items.map((item) => /* @__PURE__ */ React.createElement("div", {
2551
+ key: item.label,
2552
+ className: "ted-report-row"
2553
+ }, /* @__PURE__ */ React.createElement("span", {
2554
+ className: "ted-tone",
2555
+ "data-level": item.value >= 70 ? "good" : item.value >= 40 ? "warn" : "bad"
2556
+ }), /* @__PURE__ */ React.createElement("b", null, item.label), /* @__PURE__ */ React.createElement("small", null, item.note ? `${item.note} · ${item.value}%` : `${item.value}%`))), learning.weak.length > 0 && /* @__PURE__ */ React.createElement("div", {
2557
+ className: "ted-tags"
2558
+ }, learning.weak.map((one) => /* @__PURE__ */ React.createElement("span", {
2559
+ key: one,
2560
+ className: "ted-tag"
2561
+ }, one)))), /* @__PURE__ */ React.createElement("div", {
2562
+ className: "ted-panel-acts"
2563
+ }, /* @__PURE__ */ React.createElement("button", {
2564
+ type: "button",
2565
+ className: "ta-button ta-primary ted-pill",
2566
+ onClick: () => say(home.howToHelp)
2567
+ }, home.howToHelp), /* @__PURE__ */ React.createElement("button", {
2568
+ type: "button",
2569
+ className: "ta-button ted-pill",
2570
+ onClick: () => say(EduWords.of(pi.ui.language).toTeacher.text)
2571
+ }, home.askTeacher)));
2634
2572
  }
2635
-
2636
- // web-src/edu-report.ts
2637
- var WEEK = 7 * 86400000;
2638
- var EduReport;
2639
- ((EduReport) => {
2640
- function of(days, mistakes, name, words, now) {
2641
- const week = EduUtil.lastWeek(days, now);
2642
- const books = EduUtil.books(mistakes, now, words.otherSubject);
2643
- const format2 = (text, values) => text.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
2644
- return {
2645
- title: format2(words.reportTitle, { name }),
2646
- stats: [
2647
- { label: words.statQuestions, value: String(week.n) },
2648
- { label: words.statRight, value: week.n ? `${Math.round(week.right / week.n * 100)}%` : "—" },
2649
- { label: words.statDays, value: String(week.days) }
2650
- ],
2651
- items: books.slice(0, 5).map((book) => ({ label: book.subject, value: book.progress, note: format2(words.reportNote, { count: book.mistakes.length }) })),
2652
- weak: EduUtil.weak(mistakes),
2653
- next: [],
2654
- report: true
2655
- };
2656
- }
2657
- EduReport.of = of;
2658
- function due(reportTo, reportAt, now) {
2659
- return !!reportTo && (!reportAt || now - reportAt >= WEEK);
2660
- }
2661
- EduReport.due = due;
2662
- })(EduReport ||= {});
2663
-
2664
- // web-src/edu-seal.ts
2665
- var CURVE = { name: "ECDH", namedCurve: "P-256" };
2666
- function base64(bytes) {
2667
- let text = "";
2668
- for (const byte of new Uint8Array(bytes)) {
2669
- text += String.fromCharCode(byte);
2573
+ function Notices({ context, notices, identity }) {
2574
+ const { pi, store, rooms } = context;
2575
+ const home = HomeWordsUtil.of(pi.ui.language);
2576
+ const Megaphone = iconOf(pi, "Megaphone");
2577
+ const School = iconOf(pi, "Users");
2578
+ if (!pi.rooms) {
2579
+ return null;
2670
2580
  }
2671
- return btoa(text);
2672
- }
2673
- function bytes(text) {
2674
- const binary = atob(text);
2675
- const out = new Uint8Array(binary.length);
2676
- for (let i = 0;i < binary.length; i++) {
2677
- out[i] = binary.charCodeAt(i);
2581
+ if (!rooms.classes().length) {
2582
+ return /* @__PURE__ */ React.createElement(Section, {
2583
+ title: home.notices
2584
+ }, /* @__PURE__ */ React.createElement("div", {
2585
+ className: "ted-panel ted-list"
2586
+ }, /* @__PURE__ */ React.createElement("button", {
2587
+ type: "button",
2588
+ className: "ted-row",
2589
+ onClick: () => openClasses(context)
2590
+ }, /* @__PURE__ */ React.createElement(Tile, {
2591
+ icon: School,
2592
+ tone: TONES.homeroom
2593
+ }), /* @__PURE__ */ React.createElement("span", {
2594
+ className: "ted-row-main"
2595
+ }, /* @__PURE__ */ React.createElement("span", {
2596
+ className: "ted-row-title"
2597
+ }, home.linkClass), /* @__PURE__ */ React.createElement("span", {
2598
+ className: "ted-row-sub ted-wrap"
2599
+ }, home.linkClassHint)), /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronRight, {
2600
+ size: 16
2601
+ }))));
2678
2602
  }
2679
- return out;
2603
+ const list = (notices ?? []).slice(0, 5);
2604
+ return /* @__PURE__ */ React.createElement(Section, {
2605
+ title: identity === "parent" ? home.notices : home.recentNotices,
2606
+ aside: list.length ? format(home.count, { count: list.length }) : undefined
2607
+ }, /* @__PURE__ */ React.createElement("div", {
2608
+ className: "ted-panel ted-list"
2609
+ }, list.length ? list.map((notice) => /* @__PURE__ */ React.createElement("button", {
2610
+ key: notice.id,
2611
+ type: "button",
2612
+ className: "ted-row",
2613
+ onClick: () => void EduChats.say(pi, store, identity, `${home.noticeHelp}
2614
+
2615
+ > ${notice.text.replace(/\n/g, `
2616
+ > `)}`).catch(failed(pi, home))
2617
+ }, /* @__PURE__ */ React.createElement(Tile, {
2618
+ icon: Megaphone,
2619
+ tone: TONES.homeroom
2620
+ }), /* @__PURE__ */ React.createElement("span", {
2621
+ className: "ted-row-main"
2622
+ }, /* @__PURE__ */ React.createElement("span", {
2623
+ className: "ted-row-title ted-clamp"
2624
+ }, notice.text), /* @__PURE__ */ React.createElement("span", {
2625
+ className: "ted-row-sub"
2626
+ }, `${notice.klass} · ${notice.from} · ${when(notice.at, pi.ui.language, home)}`)))) : /* @__PURE__ */ React.createElement("div", {
2627
+ className: "ted-quiet"
2628
+ }, notices ? home.linkClassHint : " ")));
2680
2629
  }
2681
- async function secret(privateKey, publicKey) {
2682
- const other = await crypto.subtle.importKey("jwk", publicKey, CURVE, false, []);
2683
- return crypto.subtle.deriveKey({ name: "ECDH", public: other }, privateKey, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
2630
+ function openClasses(context) {
2631
+ const { pi } = context;
2632
+ const home = HomeWordsUtil.of(pi.ui.language);
2633
+ pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
2634
+ title: home.classesTitle,
2635
+ onClose: close
2636
+ }, /* @__PURE__ */ React.createElement(ClassPicker, {
2637
+ context,
2638
+ close
2639
+ })));
2684
2640
  }
2685
- var EduSeal;
2686
- ((EduSeal) => {
2687
- async function keys() {
2688
- const pair = await crypto.subtle.generateKey(CURVE, true, ["deriveKey"]);
2689
- return { publicKey: await crypto.subtle.exportKey("jwk", pair.publicKey), privateKey: await crypto.subtle.exportKey("jwk", pair.privateKey) };
2690
- }
2691
- EduSeal.keys = keys;
2692
- function isKeys(value) {
2693
- const keys2 = value;
2694
- return !!keys2 && typeof keys2.publicKey?.x === "string" && typeof keys2.privateKey?.d === "string";
2695
- }
2696
- EduSeal.isKeys = isKeys;
2697
- function isPublic(value) {
2698
- const key = value;
2699
- return !!key && key.kty === "EC" && typeof key.x === "string" && typeof key.y === "string" && !("d" in key);
2700
- }
2701
- EduSeal.isPublic = isPublic;
2702
- async function seal(value, publicKey) {
2703
- const pair = await crypto.subtle.generateKey(CURVE, true, ["deriveKey"]);
2704
- const key = await secret(pair.privateKey, publicKey);
2705
- const iv = crypto.getRandomValues(new Uint8Array(12));
2706
- const data = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, new TextEncoder().encode(JSON.stringify(value)));
2707
- const e = await crypto.subtle.exportKey("jwk", pair.publicKey);
2708
- return { e: { kty: e.kty, crv: e.crv, x: e.x, y: e.y }, iv: base64(iv), d: base64(data) };
2709
- }
2710
- EduSeal.seal = seal;
2711
- async function open(sealed, keys2) {
2712
- const value = sealed;
2713
- if (!value || !isPublic(value.e) || typeof value.iv !== "string" || typeof value.d !== "string") {
2714
- return;
2715
- }
2716
- try {
2717
- const mine = await crypto.subtle.importKey("jwk", keys2.privateKey, CURVE, false, ["deriveKey"]);
2718
- const key = await secret(mine, value.e);
2719
- const data = await crypto.subtle.decrypt({ name: "AES-GCM", iv: bytes(value.iv) }, key, bytes(value.d));
2720
- return JSON.parse(new TextDecoder().decode(data));
2721
- } catch {
2722
- return;
2641
+ function ClassPicker({ context, close }) {
2642
+ const { pi, store, rooms } = context;
2643
+ useRooms(rooms);
2644
+ const state = useStore(store);
2645
+ const home = HomeWordsUtil.of(pi.ui.language);
2646
+ const { classes } = state.settings;
2647
+ const groups = rooms.groups();
2648
+ const teacher = state.settings.identities.some((one) => one === "teacher" || one === "homeroom");
2649
+ const toggle = (room) => {
2650
+ const on = classes.includes(room.id);
2651
+ store.setSettings({ classes: on ? classes.filter((one) => one !== room.id) : [...classes, room.id], ...on ? {} : { klass: room.id } });
2652
+ if (!on && teacher) {
2653
+ rooms.publishKey(room).catch(() => {
2654
+ return;
2655
+ });
2723
2656
  }
2724
- }
2725
- EduSeal.open = open;
2726
- })(EduSeal ||= {});
2727
-
2728
- // web-src/edu-rooms.ts
2729
- var DAY2 = 86400000;
2730
- var EduRoomUtil;
2731
- ((EduRoomUtil) => {
2732
- function keyOf(member) {
2733
- return `${STATE}key:${member}`;
2734
- }
2735
- EduRoomUtil.keyOf = keyOf;
2736
- function submissionOf(quiz, member) {
2737
- return `${STATE}sub:${quiz}:${member}`;
2738
- }
2739
- EduRoomUtil.submissionOf = submissionOf;
2740
- function notice(text) {
2741
- const prefix = NOTICE_PREFIXES.find((one) => text.startsWith(one));
2742
- return prefix ? text.slice(prefix.length).trim() : undefined;
2743
- }
2744
- EduRoomUtil.notice = notice;
2745
- function report(text) {
2746
- const match = new RegExp(`\`\`\`${LEARNING}\\n([\\s\\S]*?)\\n\`\`\``).exec(text);
2747
- const learning = match ? EduUtil.learning(match[1]) : undefined;
2748
- return learning?.report ? learning : undefined;
2749
- }
2750
- EduRoomUtil.report = report;
2751
- function asks(lines, me, since) {
2752
- const answered = new Set(lines.filter((line) => line.from === me && line.re).map((line) => line.re));
2753
- const after = (line) => lines.some((other) => other.from === me && other.at > line.at);
2754
- return lines.filter((line) => line.from !== me && line.at >= since && line.person && line.to?.includes(me) && !answered.has(line.id) && !after(line));
2755
- }
2756
- EduRoomUtil.asks = asks;
2757
- function quizText(quiz, intro) {
2758
- const body = {
2759
- id: quiz.id,
2760
- room: quiz.room,
2761
- teacher: quiz.teacher,
2762
- title: quiz.title,
2763
- questions: quiz.questions.map((question) => ({
2764
- q: question.q,
2765
- ...question.kind === "choice" ? { options: question.options } : {},
2766
- answer: question.kind === "choice" ? EduUtil.letter(question.answer) : question.answer,
2767
- ...question.explain ? { explain: question.explain } : {},
2768
- ...question.figure ? { figure: question.figure } : {},
2769
- ...question.subject ? { subject: question.subject } : {},
2770
- ...question.topic ? { topic: question.topic } : {}
2771
- }))
2772
- };
2773
- return `${intro}
2774
-
2775
- \`\`\`${QUIZ}
2776
- ${JSON.stringify(body)}
2777
- \`\`\``;
2778
- }
2779
- EduRoomUtil.quizText = quizText;
2780
- function reportText(learning, intro) {
2781
- return `${intro}
2782
-
2783
- \`\`\`${LEARNING}
2784
- ${JSON.stringify(learning)}
2785
- \`\`\``;
2786
- }
2787
- EduRoomUtil.reportText = reportText;
2788
- })(EduRoomUtil ||= {});
2657
+ };
2658
+ return /* @__PURE__ */ React.createElement("div", {
2659
+ className: "ted-picker"
2660
+ }, /* @__PURE__ */ React.createElement("div", {
2661
+ className: "ted-picker-hint ted-picker-hint-alone"
2662
+ }, home.classesHint), groups.length ? /* @__PURE__ */ React.createElement("div", {
2663
+ className: "ted-list"
2664
+ }, groups.map((room) => {
2665
+ const on = classes.includes(room.id);
2666
+ return /* @__PURE__ */ React.createElement("button", {
2667
+ key: room.id,
2668
+ type: "button",
2669
+ className: "ted-row",
2670
+ "aria-pressed": on,
2671
+ onClick: () => toggle(room)
2672
+ }, /* @__PURE__ */ React.createElement(Tile, {
2673
+ icon: pi.ui.icons.Users,
2674
+ tone: toneOf(room.id)
2675
+ }), /* @__PURE__ */ React.createElement("span", {
2676
+ className: "ted-row-main"
2677
+ }, /* @__PURE__ */ React.createElement("span", {
2678
+ className: "ted-row-title"
2679
+ }, room.title), /* @__PURE__ */ React.createElement("span", {
2680
+ className: "ted-row-sub"
2681
+ }, room.members.length)), /* @__PURE__ */ React.createElement("span", {
2682
+ className: "ted-check",
2683
+ "data-on": on || undefined
2684
+ }, on && /* @__PURE__ */ React.createElement(pi.ui.icons.Check, {
2685
+ size: 13,
2686
+ strokeWidth: 3
2687
+ })));
2688
+ })) : /* @__PURE__ */ React.createElement(pi.ui.Empty, {
2689
+ compact: true,
2690
+ title: home.noGroups
2691
+ }), /* @__PURE__ */ React.createElement("div", {
2692
+ className: "ted-picker-foot"
2693
+ }, /* @__PURE__ */ React.createElement("button", {
2694
+ type: "button",
2695
+ className: "ta-button ta-primary",
2696
+ onClick: close
2697
+ }, home.done)));
2698
+ }
2789
2699
 
2790
- class EduRooms {
2791
- pi;
2792
- store;
2793
- list = [];
2794
- friendList = [];
2795
- listeners = new Set;
2796
- loading;
2797
- stop;
2798
- version = 0;
2799
- constructor(pi, store) {
2800
- this.pi = pi;
2801
- this.store = store;
2802
- }
2803
- get server() {
2804
- return this.pi.rooms;
2700
+ // web-src/cards.tsx
2701
+ function useStore2(store) {
2702
+ const [, tick] = React.useReducer((n) => n + 1, 0);
2703
+ React.useEffect(() => store.subscribe(tick), [store]);
2704
+ return store.state;
2705
+ }
2706
+ function rightOf(question, given) {
2707
+ const { answer } = question;
2708
+ if (typeof answer === "number") {
2709
+ return given === String(answer);
2805
2710
  }
2806
- get rooms() {
2807
- return this.list;
2711
+ if (typeof answer === "boolean") {
2712
+ return given === String(answer);
2808
2713
  }
2809
- get friends() {
2810
- return this.friendList;
2714
+ return EduUtil.blankRight(answer, given);
2715
+ }
2716
+ function givenText(question, given) {
2717
+ if (question.kind === "choice") {
2718
+ const index = Number(given);
2719
+ return `${EduUtil.letter(index)}. ${question.options[index] ?? ""}`.trim();
2811
2720
  }
2812
- subscribe = (listener) => {
2813
- this.listeners.add(listener);
2814
- if (!this.stop && this.pi.onRoomEvent) {
2815
- this.stop = this.pi.onRoomEvent((event) => {
2816
- if (event.type === "rooms" || event.type === "state" && event.key.startsWith(STATE)) {
2817
- this.load();
2818
- }
2819
- }, { messages: false, state: [STATE] });
2820
- this.load();
2821
- }
2822
- return () => {
2823
- this.listeners.delete(listener);
2824
- if (!this.listeners.size) {
2825
- this.stop?.();
2826
- this.stop = undefined;
2721
+ return question.kind === "judge" ? given === "true" ? "✓" : "✗" : given;
2722
+ }
2723
+ function Question(props) {
2724
+ const { pi, words, question, index, given, reveal } = props;
2725
+ const [typed, setTyped] = React.useState("");
2726
+ const done = given !== undefined;
2727
+ const shown = done || reveal;
2728
+ const right = done && rightOf(question, given);
2729
+ const Markdown = pi.ui.Markdown;
2730
+ const choice = (value, label, key) => {
2731
+ const isAnswer = shown && rightOf(question, value) && question.kind !== "blank";
2732
+ const state = isAnswer ? "right" : done && given === value ? "wrong" : undefined;
2733
+ return /* @__PURE__ */ React.createElement("button", {
2734
+ key,
2735
+ type: "button",
2736
+ className: "ted-option",
2737
+ "data-state": state,
2738
+ disabled: shown,
2739
+ onClick: () => props.answer(value)
2740
+ }, label);
2741
+ };
2742
+ return /* @__PURE__ */ React.createElement("li", {
2743
+ className: "ted-q",
2744
+ "data-state": done ? right ? "right" : "wrong" : undefined
2745
+ }, /* @__PURE__ */ React.createElement("div", {
2746
+ className: "ted-q-head"
2747
+ }, /* @__PURE__ */ React.createElement("span", {
2748
+ className: "ted-q-no"
2749
+ }, index + 1), /* @__PURE__ */ React.createElement("div", {
2750
+ className: "ted-q-text"
2751
+ }, /* @__PURE__ */ React.createElement(Markdown, {
2752
+ text: question.q
2753
+ }))), question.figure && /* @__PURE__ */ React.createElement("div", {
2754
+ className: "ted-figure"
2755
+ }, /* @__PURE__ */ React.createElement(Markdown, {
2756
+ text: question.figure
2757
+ })), question.kind === "choice" && /* @__PURE__ */ React.createElement("div", {
2758
+ className: "ted-options"
2759
+ }, question.options.map((option, at) => choice(String(at), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("b", null, EduUtil.letter(at)), /* @__PURE__ */ React.createElement(Markdown, {
2760
+ inline: true,
2761
+ text: option
2762
+ })), String(at)))), question.kind === "judge" && /* @__PURE__ */ React.createElement("div", {
2763
+ className: "ted-options ted-judge"
2764
+ }, choice("true", words.judgeTrue, "true"), choice("false", words.judgeFalse, "false")), question.kind === "blank" && !shown && /* @__PURE__ */ React.createElement("form", {
2765
+ className: "ted-blank",
2766
+ onSubmit: (event) => {
2767
+ event.preventDefault();
2768
+ if (typed.trim()) {
2769
+ props.answer(typed.trim());
2827
2770
  }
2771
+ }
2772
+ }, /* @__PURE__ */ React.createElement("input", {
2773
+ className: "ta-input",
2774
+ value: typed,
2775
+ placeholder: words.blank,
2776
+ onChange: (event) => setTyped(event.target.value)
2777
+ }), /* @__PURE__ */ React.createElement("button", {
2778
+ type: "submit",
2779
+ className: "ta-button",
2780
+ disabled: !typed.trim()
2781
+ }, words.submit)), shown && /* @__PURE__ */ React.createElement("div", {
2782
+ className: "ted-result"
2783
+ }, done && question.kind === "blank" && /* @__PURE__ */ React.createElement("div", {
2784
+ className: "ted-given"
2785
+ }, /* @__PURE__ */ React.createElement(Markdown, {
2786
+ inline: true,
2787
+ text: given
2788
+ })), /* @__PURE__ */ React.createElement("div", {
2789
+ className: "ted-verdict"
2790
+ }, done && right ? words.right : /* @__PURE__ */ React.createElement(Markdown, {
2791
+ inline: true,
2792
+ text: EduWords.format(done ? words.wrongAnswer : words.revealAnswer, { answer: EduUtil.answerText(question) })
2793
+ })), question.explain && /* @__PURE__ */ React.createElement("div", {
2794
+ className: "ted-explain"
2795
+ }, /* @__PURE__ */ React.createElement(Markdown, {
2796
+ text: question.explain
2797
+ }))));
2798
+ }
2799
+ function quizCard(pi, store, rooms) {
2800
+ return function QuizCard({ code, closed, send }) {
2801
+ const state = useStore2(store);
2802
+ const [, tick] = React.useReducer((n) => n + 1, 0);
2803
+ React.useEffect(() => rooms.subscribe(tick), []);
2804
+ const words = EduWords.of(pi.ui.language);
2805
+ const quiz = closed ? EduUtil.quiz(code) : undefined;
2806
+ if (!closed) {
2807
+ return /* @__PURE__ */ React.createElement("div", {
2808
+ className: "ted-card"
2809
+ }, /* @__PURE__ */ React.createElement(pi.ui.Loading, {
2810
+ label: words.quiz,
2811
+ compact: true
2812
+ }));
2813
+ }
2814
+ if (!quiz) {
2815
+ throw new Error("Not a quiz");
2816
+ }
2817
+ const card = EduUtil.hash(code);
2818
+ const room = quiz.room ? rooms.rooms.find((one) => one.id === quiz.room) : undefined;
2819
+ const mine = !!room && !!quiz.teacher && rooms.memberOf(room) === quiz.teacher;
2820
+ const reveal = quiz.reveal || mine;
2821
+ const given = state.answers[card] ?? {};
2822
+ const answered = quiz.questions.filter((_, at) => given[at] !== undefined);
2823
+ const wrong = quiz.questions.flatMap((question, at) => given[at] !== undefined && !rightOf(question, given[at]) ? [{ question, at }] : []);
2824
+ const all = answered.length === quiz.questions.length;
2825
+ const explain = () => {
2826
+ const lines = wrong.map(({ question, at }) => JSON.stringify({ no: at + 1, q: question.q, answer: EduUtil.answerText(question), given: givenText(question, given[at]) }));
2827
+ const context = `[${NAME}:mistakes]
2828
+ The questions of the quiz above the user got wrong. Go over why, step by step, and give one more question on each point.
2829
+ ${lines.join(`
2830
+ `)}`;
2831
+ (send ?? pi.sendUserMessage)(TaMessageContext.wrap(context, words.explainWrongText));
2828
2832
  };
2833
+ return /* @__PURE__ */ React.createElement("div", {
2834
+ className: "ted-card"
2835
+ }, /* @__PURE__ */ React.createElement("div", {
2836
+ className: "ted-head"
2837
+ }, /* @__PURE__ */ React.createElement("span", {
2838
+ className: "ted-mark"
2839
+ }, /* @__PURE__ */ React.createElement(pi.ui.icons.ListChecks, {
2840
+ size: 15
2841
+ })), /* @__PURE__ */ React.createElement("span", {
2842
+ className: "ted-title"
2843
+ }, quiz.title ? /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
2844
+ inline: true,
2845
+ text: quiz.title
2846
+ }) : words.quiz), answered.length > 0 && !reveal && /* @__PURE__ */ React.createElement("span", {
2847
+ className: "ted-score"
2848
+ }, EduWords.format(words.score, { right: answered.length - wrong.length, total: quiz.questions.length }))), /* @__PURE__ */ React.createElement("ol", {
2849
+ className: "ted-qs"
2850
+ }, quiz.questions.map((question, at) => /* @__PURE__ */ React.createElement(Question, {
2851
+ key: at,
2852
+ pi,
2853
+ words,
2854
+ question,
2855
+ index: at,
2856
+ given: given[at],
2857
+ reveal,
2858
+ answer: (value) => void store.answer(card, at, question, value, givenText(question, value), rightOf(question, value))
2859
+ }))), mine && room && /* @__PURE__ */ React.createElement(Handed, {
2860
+ pi,
2861
+ rooms,
2862
+ quiz,
2863
+ room
2864
+ }), !mine && quiz.id && all && /* @__PURE__ */ React.createElement(HandIn, {
2865
+ pi,
2866
+ rooms,
2867
+ quiz,
2868
+ name: () => rooms.server?.getIdentity().then((one) => one.name),
2869
+ given
2870
+ }), all && wrong.length > 0 && !reveal && /* @__PURE__ */ React.createElement("div", {
2871
+ className: "ted-foot"
2872
+ }, /* @__PURE__ */ React.createElement("button", {
2873
+ type: "button",
2874
+ className: "ta-button ta-primary",
2875
+ onClick: explain
2876
+ }, words.explainWrong)), quiz.reveal && !quiz.id && state.settings.identities.includes("teacher") && rooms.server && /* @__PURE__ */ React.createElement(SendToClass, {
2877
+ pi,
2878
+ store,
2879
+ rooms,
2880
+ quiz
2881
+ }));
2882
+ };
2883
+ }
2884
+ function HandIn(props) {
2885
+ const { pi, rooms, quiz, given } = props;
2886
+ const home = HomeWordsUtil.of(pi.ui.language);
2887
+ const [status, setStatus] = React.useState("checking");
2888
+ const handIn = React.useCallback(async () => {
2889
+ setStatus("sending");
2890
+ try {
2891
+ const name = await props.name() ?? "";
2892
+ const submission = {
2893
+ name,
2894
+ given: quiz.questions.map((question, at) => givenText(question, given[at] ?? "")),
2895
+ right: quiz.questions.map((question, at) => given[at] !== undefined && rightOf(question, given[at])),
2896
+ at: Date.now()
2897
+ };
2898
+ const result = await rooms.submit(quiz, submission);
2899
+ setStatus(result === "sent" ? "sent" : result === "no-key" ? "no-key" : "failed");
2900
+ } catch {
2901
+ setStatus("failed");
2902
+ }
2903
+ }, [quiz, given, rooms]);
2904
+ React.useEffect(() => {
2905
+ rooms.submitted(quiz).then((done) => done ? setStatus("sent") : handIn(), () => handIn());
2906
+ }, []);
2907
+ const Check = pi.ui.icons.Check;
2908
+ return /* @__PURE__ */ React.createElement("div", {
2909
+ className: "ted-foot ted-handin",
2910
+ "data-status": status
2911
+ }, status === "sent" ? /* @__PURE__ */ React.createElement("span", {
2912
+ className: "ted-handed"
2913
+ }, /* @__PURE__ */ React.createElement(Check, {
2914
+ size: 14,
2915
+ strokeWidth: 2.6
2916
+ }), home.handedIn) : status === "checking" || status === "sending" ? /* @__PURE__ */ React.createElement(pi.ui.Loading, {
2917
+ compact: true
2918
+ }) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
2919
+ className: "ted-handin-note"
2920
+ }, status === "no-key" ? home.noTeacherKey : ""), /* @__PURE__ */ React.createElement("button", {
2921
+ type: "button",
2922
+ className: "ta-button",
2923
+ onClick: () => void handIn()
2924
+ }, home.handIn)));
2925
+ }
2926
+ function Handed({ pi, rooms, quiz, room }) {
2927
+ const home = HomeWordsUtil.of(pi.ui.language);
2928
+ const [count, setCount] = React.useState();
2929
+ React.useEffect(() => {
2930
+ rooms.server?.getState(room.id, `edu:sub:${quiz.id}:`).then((state) => setCount(Object.keys(state).length), () => {
2931
+ return;
2932
+ });
2933
+ }, [room.id, quiz.id, rooms.version]);
2934
+ return /* @__PURE__ */ React.createElement("div", {
2935
+ className: "ted-foot ted-handin"
2936
+ }, /* @__PURE__ */ React.createElement("span", {
2937
+ className: "ted-handin-note"
2938
+ }, count === undefined ? "" : EduWords.format(home.handedCount, { count })), /* @__PURE__ */ React.createElement("button", {
2939
+ type: "button",
2940
+ className: "ta-button",
2941
+ onClick: () => void pi.ui.showView(PAGE)
2942
+ }, home.results));
2943
+ }
2944
+ function SendToClass({ pi, store, rooms, quiz }) {
2945
+ const home = HomeWordsUtil.of(pi.ui.language);
2946
+ const [sent, setSent] = React.useState();
2947
+ const [busy, setBusy] = React.useState(false);
2948
+ const context = { pi, store, rooms };
2949
+ const post = async (room) => {
2950
+ setBusy(true);
2951
+ try {
2952
+ const intro = EduWords.format(home.quizIntro, { title: quiz.title ?? EduWords.of(pi.ui.language).quiz, count: quiz.questions.length });
2953
+ await rooms.postQuiz(room, quiz, intro);
2954
+ await store.setSettings({ klass: room.id });
2955
+ setSent(room.title);
2956
+ pi.ui.notify(EduWords.format(home.sentToClass, { klass: room.title }));
2957
+ } catch (error) {
2958
+ pi.ui.notify(EduWords.format(home.failed, { error: error instanceof Error ? error.message : String(error) }), "error");
2959
+ } finally {
2960
+ setBusy(false);
2961
+ }
2829
2962
  };
2830
- load() {
2831
- const server = this.server;
2832
- if (!server) {
2833
- return Promise.resolve();
2963
+ const pick = async () => {
2964
+ await rooms.load();
2965
+ const classes = rooms.classes();
2966
+ if (!classes.length) {
2967
+ openClasses(context);
2968
+ return;
2834
2969
  }
2835
- this.loading ??= Promise.all([server.listRooms().catch(() => this.list), server.listFriends().catch(() => this.friendList)]).then(([rooms, friends]) => {
2836
- this.list = rooms.filter((room) => room.status === "member");
2837
- this.friendList = friends.filter((friend) => friend.status === "friend");
2838
- this.version++;
2839
- for (const listener of this.listeners) {
2840
- listener();
2970
+ if (classes.length === 1) {
2971
+ if (await pi.ui.confirm(home.sendToClass, classes[0].title, { confirmLabel: home.sendToClass })) {
2972
+ await post(classes[0]);
2841
2973
  }
2842
- }).finally(() => {
2843
- this.loading = undefined;
2844
- });
2845
- return this.loading;
2846
- }
2847
- groups() {
2848
- return this.list.filter((room) => room.kind === GROUP_KIND);
2849
- }
2850
- classes() {
2851
- const { classes } = this.store.state.settings;
2852
- return classes.flatMap((id) => this.list.find((room) => room.id === id) ?? []);
2853
- }
2854
- me(room) {
2855
- return room.members.find((member) => member.self)?.member;
2856
- }
2857
- async publishKey(room) {
2858
- const me = this.me(room);
2859
- const server = this.server;
2860
- if (!me || !server) {
2861
2974
  return;
2862
2975
  }
2863
- const keys = await this.store.teacherKeys();
2864
- const key = EduRoomUtil.keyOf(me);
2865
- const state = await server.getState(room.id, key);
2866
- if (state[key]?.value && JSON.stringify(state[key].value) === JSON.stringify(keys.publicKey)) {
2867
- return;
2976
+ pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
2977
+ title: home.pickClass,
2978
+ onClose: close
2979
+ }, /* @__PURE__ */ React.createElement("div", {
2980
+ className: "ted-list"
2981
+ }, classes.map((room) => /* @__PURE__ */ React.createElement("button", {
2982
+ key: room.id,
2983
+ type: "button",
2984
+ className: "ted-row",
2985
+ onClick: () => {
2986
+ close();
2987
+ post(room);
2988
+ }
2989
+ }, /* @__PURE__ */ React.createElement("span", {
2990
+ className: "ted-row-main"
2991
+ }, /* @__PURE__ */ React.createElement("span", {
2992
+ className: "ted-row-title"
2993
+ }, room.title)))))));
2994
+ };
2995
+ const Send = pi.ui.icons.Send;
2996
+ return /* @__PURE__ */ React.createElement("div", {
2997
+ className: "ted-foot ted-handin"
2998
+ }, /* @__PURE__ */ React.createElement("span", {
2999
+ className: "ted-handin-note"
3000
+ }, sent ? EduWords.format(home.sentToClass, { klass: sent }) : ""), /* @__PURE__ */ React.createElement("button", {
3001
+ type: "button",
3002
+ className: "ta-button",
3003
+ disabled: busy,
3004
+ onClick: () => void pick()
3005
+ }, /* @__PURE__ */ React.createElement(Send, {
3006
+ size: 14
3007
+ }), home.sendToClass));
3008
+ }
3009
+ function learningCard(pi) {
3010
+ return function LearningCard({ code, closed, send }) {
3011
+ const words = EduWords.of(pi.ui.language);
3012
+ const learning = closed ? EduUtil.learning(code) : undefined;
3013
+ if (!closed) {
3014
+ return /* @__PURE__ */ React.createElement("div", {
3015
+ className: "ted-card"
3016
+ }, /* @__PURE__ */ React.createElement(pi.ui.Loading, {
3017
+ label: words.learning,
3018
+ compact: true
3019
+ }));
2868
3020
  }
2869
- await server.setState(room.id, key, keys.publicKey);
2870
- }
2871
- async postQuiz(room, quiz, intro) {
2872
- const me = this.me(room);
2873
- const server = this.server;
2874
- if (!me || !server) {
2875
- throw new Error("Not in the class.");
3021
+ if (!learning) {
3022
+ throw new Error("Not a learning card");
2876
3023
  }
2877
- await this.publishKey(room);
2878
- const id = `q${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
2879
- const sent = { ...quiz, reveal: false, id, room: room.id, teacher: me };
2880
- await server.say(room.id, EduRoomUtil.quizText(sent, intro));
2881
- const gone = await this.store.addPosted({ id, room: room.id, title: quiz.title ?? "", at: Date.now(), questions: quiz.questions });
2882
- for (const old of gone) {
2883
- const state = await server.getState(old.room, `${STATE}sub:${old.id}:`).catch(() => ({}));
2884
- for (const key of Object.keys(state)) {
2885
- await server.setState(old.room, key, null).catch(() => {
3024
+ return /* @__PURE__ */ React.createElement("div", {
3025
+ className: "ted-card"
3026
+ }, /* @__PURE__ */ React.createElement("div", {
3027
+ className: "ted-head"
3028
+ }, /* @__PURE__ */ React.createElement("span", {
3029
+ className: "ted-mark"
3030
+ }, /* @__PURE__ */ React.createElement(pi.ui.icons.TrendingUp, {
3031
+ size: 15
3032
+ })), /* @__PURE__ */ React.createElement("span", {
3033
+ className: "ted-title"
3034
+ }, learning.title ? /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
3035
+ inline: true,
3036
+ text: learning.title
3037
+ }) : words.learning)), learning.stats.length > 0 && /* @__PURE__ */ React.createElement("div", {
3038
+ className: "ted-stats ted-stats-card"
3039
+ }, learning.stats.map((one) => /* @__PURE__ */ React.createElement("div", {
3040
+ key: one.label,
3041
+ className: "ted-stat"
3042
+ }, /* @__PURE__ */ React.createElement("b", null, one.value), /* @__PURE__ */ React.createElement("span", null, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
3043
+ inline: true,
3044
+ text: one.label
3045
+ }))))), learning.items.length > 0 && /* @__PURE__ */ React.createElement("ul", {
3046
+ className: "ted-bars"
3047
+ }, learning.items.map((item) => /* @__PURE__ */ React.createElement("li", {
3048
+ key: item.label,
3049
+ className: "ted-bar",
3050
+ "data-level": item.value >= 85 ? "good" : item.value >= 60 ? "warn" : "bad"
3051
+ }, /* @__PURE__ */ React.createElement("span", {
3052
+ className: "ted-bar-label"
3053
+ }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
3054
+ inline: true,
3055
+ text: item.label
3056
+ })), /* @__PURE__ */ React.createElement("span", {
3057
+ className: "ted-bar-track"
3058
+ }, /* @__PURE__ */ React.createElement("i", {
3059
+ style: { width: `${item.value}%` }
3060
+ })), /* @__PURE__ */ React.createElement("span", {
3061
+ className: "ted-bar-value"
3062
+ }, item.value, "%"), item.note && /* @__PURE__ */ React.createElement("span", {
3063
+ className: "ted-bar-note"
3064
+ }, /* @__PURE__ */ React.createElement(pi.ui.Markdown, {
3065
+ inline: true,
3066
+ text: item.note
3067
+ }))))), learning.weak.length > 0 && /* @__PURE__ */ React.createElement("div", {
3068
+ className: "ted-part"
3069
+ }, /* @__PURE__ */ React.createElement("div", {
3070
+ className: "ted-part-title"
3071
+ }, words.weak), /* @__PURE__ */ React.createElement("div", {
3072
+ className: "ted-tags"
3073
+ }, learning.weak.map((one) => /* @__PURE__ */ React.createElement("span", {
3074
+ key: one,
3075
+ className: "ted-tag"
3076
+ }, one)))), learning.next.length > 0 && /* @__PURE__ */ React.createElement("div", {
3077
+ className: "ted-part"
3078
+ }, /* @__PURE__ */ React.createElement("div", {
3079
+ className: "ted-part-title"
3080
+ }, words.next), /* @__PURE__ */ React.createElement("div", {
3081
+ className: "ted-next"
3082
+ }, learning.next.map((one) => /* @__PURE__ */ React.createElement("button", {
3083
+ key: one,
3084
+ type: "button",
3085
+ className: "ted-chip",
3086
+ onClick: () => void (send ?? pi.sendUserMessage)(one)
3087
+ }, one)))));
3088
+ };
3089
+ }
3090
+ function consentCard(pi, rooms) {
3091
+ return function ConsentCard({ code, closed }) {
3092
+ const home = HomeWordsUtil.of(pi.ui.language);
3093
+ const line = closed ? EduRoomUtil.consent(code) : undefined;
3094
+ const [me, setMe] = React.useState();
3095
+ const [answer, setAnswer] = React.useState();
3096
+ const [pending, setPending] = React.useState(false);
3097
+ const [busy, setBusy] = React.useState(false);
3098
+ const [round, setRound] = React.useState(0);
3099
+ React.useEffect(() => {
3100
+ let live = true;
3101
+ rooms.identity().then((identity) => live && setMe(identity?.id));
3102
+ return () => {
3103
+ live = false;
3104
+ };
3105
+ }, []);
3106
+ const parent = !!line && !!me && me !== line.child;
3107
+ React.useEffect(() => {
3108
+ let live = true;
3109
+ if (line && parent) {
3110
+ Promise.all([rooms.consentAnswer(line.room, line.child), rooms.consentAsks()]).then(([kind, asks]) => {
3111
+ if (live) {
3112
+ setAnswer(kind);
3113
+ setPending(asks.some((one) => one.room === line.room && one.child === line.child));
3114
+ }
3115
+ }, () => {
2886
3116
  return;
2887
3117
  });
2888
3118
  }
3119
+ return () => {
3120
+ live = false;
3121
+ };
3122
+ }, [code, parent, round]);
3123
+ if (!closed) {
3124
+ return /* @__PURE__ */ React.createElement("div", {
3125
+ className: "ted-card"
3126
+ }, /* @__PURE__ */ React.createElement(pi.ui.Loading, {
3127
+ label: home.consentAsk,
3128
+ compact: true
3129
+ }));
2889
3130
  }
2890
- }
2891
- async submit(quiz, submission) {
2892
- const server = this.server;
2893
- if (!quiz.id || !quiz.room || !quiz.teacher || !server) {
2894
- return "not-in";
2895
- }
2896
- if (!this.list.length) {
2897
- await this.load();
2898
- }
2899
- const room = this.list.find((one) => one.id === quiz.room);
2900
- const me = room && this.me(room);
2901
- if (!room || !me) {
2902
- return "not-in";
2903
- }
2904
- const key = (await server.getState(room.id, EduRoomUtil.keyOf(quiz.teacher)))[EduRoomUtil.keyOf(quiz.teacher)]?.value;
2905
- if (!EduSeal.isPublic(key)) {
2906
- return "no-key";
2907
- }
2908
- await server.setState(room.id, EduRoomUtil.submissionOf(quiz.id, me), await EduSeal.seal(submission, key));
2909
- return "sent";
2910
- }
2911
- async submitted(quiz) {
2912
- const room = quiz.room ? this.list.find((one) => one.id === quiz.room) : undefined;
2913
- const me = room && this.me(room);
2914
- if (!room || !me || !quiz.id || !this.server) {
2915
- return false;
2916
- }
2917
- const key = EduRoomUtil.submissionOf(quiz.id, me);
2918
- return !!(await this.server.getState(room.id, key))[key]?.value;
2919
- }
2920
- async submissions(posted) {
2921
- const server = this.server;
2922
- if (!server) {
2923
- return [];
3131
+ if (!line) {
3132
+ throw new Error("Not a consent");
2924
3133
  }
2925
- const keys = await this.store.teacherKeys();
2926
- const state = await server.getState(posted.room, `${STATE}sub:${posted.id}:`).catch(() => ({}));
2927
- const opened = await Promise.all(Object.values(state).map((value) => EduSeal.open(value.value, keys)));
2928
- return opened.filter((one) => !!one && typeof one.name === "string" && Array.isArray(one.right));
2929
- }
2930
- async lines(room, limit = 80) {
2931
- return (await this.server?.readChat?.(room, { limit }).catch(() => {
2932
- return;
2933
- }))?.lines ?? [];
2934
- }
2935
- async notices() {
2936
- const since = Date.now() - 30 * DAY2;
2937
- const all = await Promise.all(this.classes().map(async (room) => (await this.lines(room.id)).flatMap((line) => {
2938
- const text = !line.failed && line.at >= since ? EduRoomUtil.notice(line.text) : undefined;
2939
- return text ? [{ id: line.id, room: room.id, klass: room.title, from: line.name, text, at: line.at }] : [];
2940
- })));
2941
- return all.flat().sort((a, b) => b.at - a.at);
3134
+ const say = (yes) => {
3135
+ setBusy(true);
3136
+ rooms.answerConsent(line, yes, home).then(() => setRound((n) => n + 1)).catch((error) => pi.ui.notify(EduWords.format(home.failed, { error: error instanceof Error ? error.message : String(error) }), "error")).finally(() => setBusy(false));
3137
+ };
3138
+ const from = line.from ?? "";
3139
+ const [title, sub] = line.kind === "ask" ? parent ? [EduWords.format(home.consentAskTitle, { name: line.name }), home.consentAskBody] : [home.consentWaitingChild, home.consentNeededHint] : line.kind === "grant" ? [parent ? EduWords.format(home.consentYouGranted, { name: line.name }) : EduWords.format(home.consentGrantedChild, { name: from }), ""] : [parent ? EduWords.format(home.consentYouRevoked, { name: line.name }) : EduWords.format(home.consentRevokedChild, { name: from }), ""];
3140
+ const Icon = line.kind === "grant" ? pi.ui.icons.Check : pi.ui.icons.Lock ?? pi.ui.icons.BookOpen;
3141
+ const ask2 = parent && line.kind === "ask" && pending;
3142
+ const takeBack = parent && line.kind === "grant" && answer === "grant";
3143
+ return /* @__PURE__ */ React.createElement("div", {
3144
+ className: "ted-card ted-consent-card",
3145
+ "data-kind": line.kind
3146
+ }, /* @__PURE__ */ React.createElement("div", {
3147
+ className: "ted-head"
3148
+ }, /* @__PURE__ */ React.createElement("span", {
3149
+ className: "ted-mark"
3150
+ }, /* @__PURE__ */ React.createElement(Icon, {
3151
+ size: 15
3152
+ })), /* @__PURE__ */ React.createElement("span", {
3153
+ className: "ted-title"
3154
+ }, title)), sub && /* @__PURE__ */ React.createElement("div", {
3155
+ className: "ted-consent-body"
3156
+ }, sub), parent && line.kind === "ask" && !pending && answer && /* @__PURE__ */ React.createElement("div", {
3157
+ className: "ted-consent-body ted-consent-said"
3158
+ }, EduWords.format(answer === "grant" ? home.consentYouGranted : home.consentYouRevoked, { name: line.name })), (ask2 || takeBack) && /* @__PURE__ */ React.createElement("div", {
3159
+ className: "ted-foot"
3160
+ }, ask2 ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("button", {
3161
+ type: "button",
3162
+ className: "ta-button",
3163
+ disabled: busy,
3164
+ onClick: () => say(false)
3165
+ }, home.consentNo), /* @__PURE__ */ React.createElement("button", {
3166
+ type: "button",
3167
+ className: "ta-button ta-primary",
3168
+ disabled: busy,
3169
+ onClick: () => say(true)
3170
+ }, home.consentYes)) : /* @__PURE__ */ React.createElement("button", {
3171
+ type: "button",
3172
+ className: "ta-button",
3173
+ disabled: busy,
3174
+ onClick: () => say(false)
3175
+ }, home.consentTakeBack)));
3176
+ };
3177
+ }
3178
+
3179
+ // web-src/composer.tsx
3180
+ var TONES2 = { student: "0", parent: "4", teacher: "3", homeroom: "5" };
3181
+ function photoText(identity, pi) {
3182
+ const home = HomeWordsUtil.of(pi.ui.language);
3183
+ return identity === "student" ? home.photoStudent : identity === "parent" ? home.photoParent : home.photoTeacher;
3184
+ }
3185
+ async function run(pi, store, conversation, identity, key) {
3186
+ const words = EduWords.of(pi.ui.language);
3187
+ const action = ROLES[identity].actions.find((one) => one.key === key);
3188
+ if (!action) {
3189
+ return;
2942
3190
  }
2943
- async postNotice(room, text, prefix) {
2944
- await this.server?.say(room, `${prefix}${text.trim()}`);
3191
+ const { label, text } = EduRoles.action(words, action.key);
3192
+ if (action.key === "review") {
3193
+ const due = EduUtil.due(store.state.mistakes, Date.now());
3194
+ await EduChats.send(pi, conversation.sessionId, TaMessageContext.wrap(reviewContext(due), EduWords.format(text, { count: due.length })));
3195
+ return;
2945
3196
  }
2946
- async asks() {
2947
- const since = Date.now() - 7 * DAY2;
2948
- const all = await Promise.all(this.classes().map(async (room) => {
2949
- const me = this.me(room);
2950
- return me ? EduRoomUtil.asks(await this.lines(room.id), me, since).map((line) => ({
2951
- id: line.id,
2952
- room: room.id,
2953
- klass: room.title,
2954
- from: line.name,
2955
- text: line.text,
2956
- at: line.at
2957
- })) : [];
2958
- }));
2959
- return all.flat().sort((a, b) => b.at - a.at);
3197
+ if (action.icon === "Image") {
3198
+ const images = await EduPhotos.pick();
3199
+ if (images.length) {
3200
+ await EduChats.send(pi, conversation.sessionId, photoText(identity, pi), images);
3201
+ }
3202
+ return;
2960
3203
  }
2961
- async reports() {
2962
- const directs = this.list.filter((room) => room.kind === DIRECT_KIND);
2963
- const found = await Promise.all(directs.map(async (room) => {
2964
- const lines = await this.lines(room.id, 60);
2965
- for (const line of [...lines].reverse()) {
2966
- const learning = room.members.find((member) => member.member === line.from)?.self ? undefined : EduRoomUtil.report(line.text);
2967
- if (learning) {
2968
- return [{ room: room.id, child: line.name, at: line.at, learning }];
3204
+ const message = action.send ? text : await pi.ui.editor(label, text);
3205
+ if (message?.trim()) {
3206
+ await EduChats.send(pi, conversation.sessionId, message.trim());
3207
+ }
3208
+ }
3209
+ function Empty({ pi, store, conversation, identity }) {
3210
+ useStore(store);
3211
+ const words = EduWords.of(pi.ui.language);
3212
+ const role = ROLES[identity];
3213
+ const Icon = iconOf(pi, role.icon);
3214
+ const due = EduUtil.due(store.state.mistakes, Date.now()).length;
3215
+ const actions = role.actions.filter((action) => action.key !== "review" || due > 0).slice(0, 4);
3216
+ return /* @__PURE__ */ React.createElement("div", {
3217
+ className: "ted-hero"
3218
+ }, /* @__PURE__ */ React.createElement("span", {
3219
+ className: "ted-hero-face",
3220
+ style: tone(TONES2[identity])
3221
+ }, /* @__PURE__ */ React.createElement(Icon, {
3222
+ size: 30,
3223
+ strokeWidth: 1.8
3224
+ })), /* @__PURE__ */ React.createElement("h1", {
3225
+ className: "ted-hero-title"
3226
+ }, words[role.assistant]), /* @__PURE__ */ React.createElement("p", {
3227
+ className: "ted-hero-hint"
3228
+ }, words[role.tagline]), /* @__PURE__ */ React.createElement("div", {
3229
+ className: "ted-hero-starts"
3230
+ }, actions.map((action) => {
3231
+ const { label } = EduRoles.action(words, action.key);
3232
+ const ActionIcon = iconOf(pi, action.icon === "Image" ? "Camera" : action.icon, action.icon);
3233
+ return /* @__PURE__ */ React.createElement("button", {
3234
+ key: action.key,
3235
+ type: "button",
3236
+ className: "ted-start",
3237
+ onClick: () => void run(pi, store, conversation, identity, action.key)
3238
+ }, /* @__PURE__ */ React.createElement(ActionIcon, {
3239
+ size: 16,
3240
+ strokeWidth: 1.9
3241
+ }), /* @__PURE__ */ React.createElement("span", null, action.key === "review" ? `${label} · ${due}` : label));
3242
+ })));
3243
+ }
3244
+ function Chips({ pi, conversation }) {
3245
+ const home = HomeWordsUtil.of(pi.ui.language);
3246
+ const chips = [
3247
+ {
3248
+ key: "photo",
3249
+ label: home.chipPhoto,
3250
+ icon: "Camera",
3251
+ fallback: "Image",
3252
+ run: async () => {
3253
+ const images = await EduPhotos.pick();
3254
+ if (images.length) {
3255
+ await EduChats.send(pi, conversation.sessionId, home.photoStudent, images);
2969
3256
  }
2970
3257
  }
2971
- return [];
2972
- }));
2973
- return found.flat().sort((a, b) => b.at - a.at);
2974
- }
2975
- async sendReport(friend, learning, intro, make = true) {
2976
- const server = this.server;
2977
- if (!server) {
2978
- return false;
2979
- }
2980
- let room = await this.direct(friend);
2981
- if (!room && make && this.pi.ui.openPartner && await this.pi.ui.openPartner(friend, "friend")) {
2982
- for (let tries = 0;tries < 20 && !room; tries++) {
2983
- await new Promise((resolve) => setTimeout(resolve, 500));
2984
- room = await this.direct(friend, true);
3258
+ },
3259
+ { key: "hint", label: home.chipHint, icon: "Lightbulb", run: () => EduChats.send(pi, conversation.sessionId, home.chipHintText) },
3260
+ {
3261
+ key: "again",
3262
+ label: home.chipAgain,
3263
+ icon: "Shuffle",
3264
+ fallback: "RotateCcw",
3265
+ run: () => EduChats.send(pi, conversation.sessionId, home.chipAgainText)
3266
+ },
3267
+ { key: "got", label: home.chipGot, icon: "Check", run: () => EduChats.send(pi, conversation.sessionId, home.chipGotText) }
3268
+ ];
3269
+ return /* @__PURE__ */ React.createElement("div", {
3270
+ className: "ted-chiprow"
3271
+ }, chips.map((chip) => {
3272
+ const Icon = chip.key === "photo" ? iconOf(pi, chip.icon, chip.fallback) : undefined;
3273
+ return /* @__PURE__ */ React.createElement("button", {
3274
+ key: chip.key,
3275
+ type: "button",
3276
+ className: "ted-chip ted-chip-icon",
3277
+ onClick: () => void chip.run().catch(() => {
3278
+ return;
3279
+ })
3280
+ }, Icon && /* @__PURE__ */ React.createElement(Icon, {
3281
+ size: 14,
3282
+ strokeWidth: 2
3283
+ }), chip.label);
3284
+ }));
3285
+ }
3286
+ function eduComposer(pi, store) {
3287
+ const identityOf = (conversation) => conversation.group === NAME ? EduChats.identityOf(store, conversation.sessionFile) : undefined;
3288
+ return {
3289
+ actions: (conversation) => {
3290
+ const identity = identityOf(conversation);
3291
+ if (!identity) {
3292
+ return [];
2985
3293
  }
3294
+ const words = EduWords.of(pi.ui.language);
3295
+ const due = EduUtil.due(store.state.mistakes, Date.now()).length;
3296
+ return ROLES[identity].actions.map((action) => {
3297
+ const { label, text } = EduRoles.action(words, action.key);
3298
+ const icon = pi.ui.icons[action.icon];
3299
+ if (action.key === "review") {
3300
+ return {
3301
+ key: action.key,
3302
+ label,
3303
+ icon,
3304
+ detail: due ? String(due) : undefined,
3305
+ disabled: due === 0,
3306
+ run: () => void run(pi, store, conversation, identity, action.key)
3307
+ };
3308
+ }
3309
+ return action.send || action.icon === "Image" ? { key: action.key, label, icon, run: () => void run(pi, store, conversation, identity, action.key) } : { key: action.key, label, icon, insert: text };
3310
+ });
3311
+ },
3312
+ subscribe: (listener) => store.subscribe(listener),
3313
+ above: ({ conversation }) => identityOf(conversation) === "student" ? /* @__PURE__ */ React.createElement(Chips, {
3314
+ pi,
3315
+ conversation
3316
+ }) : null,
3317
+ empty: (conversation) => {
3318
+ const identity = identityOf(conversation);
3319
+ return identity ? /* @__PURE__ */ React.createElement(Empty, {
3320
+ pi,
3321
+ store,
3322
+ conversation,
3323
+ identity
3324
+ }) : undefined;
2986
3325
  }
2987
- if (!room) {
2988
- return false;
2989
- }
2990
- await server.say(room.id, EduRoomUtil.reportText(learning, intro));
2991
- return true;
2992
- }
2993
- async direct(friend, again = false) {
2994
- if (again || !this.list.length) {
2995
- await this.load();
2996
- }
2997
- return this.list.filter((room) => room.kind === DIRECT_KIND && room.members.some((member) => !member.self && member.id === friend)).sort((a, b) => a.createdAt - b.createdAt)[0];
2998
- }
3326
+ };
2999
3327
  }
3000
3328
 
3001
3329
  // web-src/edu-store.ts
3002
- var KEYS = [Keys.SETTINGS, Keys.MISTAKES, Keys.CHATS, Keys.ANSWERS, Keys.DAYS, Keys.POSTED];
3330
+ var KEYS = [Keys.SETTINGS, Keys.MISTAKES, Keys.CHATS, Keys.ANSWERS, Keys.DAYS, Keys.POSTED, Keys.CONSENT, Keys.REPORTED];
3003
3331
  var MAX_POSTED = 30;
3004
3332
 
3005
3333
  class EduStore {
@@ -3011,7 +3339,8 @@ class EduStore {
3011
3339
  chats: {},
3012
3340
  answers: {},
3013
3341
  days: {},
3014
- posted: []
3342
+ posted: [],
3343
+ consent: {}
3015
3344
  };
3016
3345
  listeners = new Set;
3017
3346
  keys;
@@ -3032,6 +3361,15 @@ class EduStore {
3032
3361
  this.set({ ...this.current, settings });
3033
3362
  return this.write(Keys.SETTINGS, settings);
3034
3363
  }
3364
+ setAsked(asked) {
3365
+ const consent = { ...this.current.consent, asked };
3366
+ this.set({ ...this.current, consent });
3367
+ return this.write(Keys.CONSENT, consent);
3368
+ }
3369
+ setReported(at) {
3370
+ this.set({ ...this.current, reportedAt: at });
3371
+ return this.write(Keys.REPORTED, { at });
3372
+ }
3035
3373
  setChat(identity, sessionFile) {
3036
3374
  const chats = { ...this.current.chats, [identity]: sessionFile };
3037
3375
  this.set({ ...this.current, chats });
@@ -3069,14 +3407,16 @@ class EduStore {
3069
3407
  return this.pi.storage.set(key, value).catch((error) => this.pi.ui.notify(error instanceof Error ? error.message : String(error), "error"));
3070
3408
  }
3071
3409
  read() {
3072
- Promise.all(KEYS.map((key) => this.pi.storage.get(key))).then(([settings, mistakes, chats, answers, days, posted]) => this.update({
3410
+ Promise.all(KEYS.map((key) => this.pi.storage.get(key))).then(([settings, mistakes, chats, answers, days, posted, consent, reported]) => this.update({
3073
3411
  loaded: true,
3074
3412
  settings: EduUtil.settings(settings),
3075
3413
  mistakes: EduUtil.mistakes(mistakes),
3076
3414
  chats: chats && typeof chats === "object" ? chats : {},
3077
3415
  answers: EduUtil.answers(answers),
3078
3416
  days: EduUtil.days(days),
3079
- posted: Array.isArray(posted) ? posted.filter((one) => typeof one?.id === "string" && typeof one.room === "string" && Array.isArray(one.questions)) : []
3417
+ posted: Array.isArray(posted) ? posted.filter((one) => typeof one?.id === "string" && typeof one.room === "string" && Array.isArray(one.questions)) : [],
3418
+ consent: EduUtil.consent(consent),
3419
+ reportedAt: EduUtil.reportedAt(reported)
3080
3420
  }), () => this.set({ ...this.current, loaded: true }));
3081
3421
  }
3082
3422
  update(state) {
@@ -3408,6 +3748,43 @@ ${one.from}(${one.klass}):
3408
3748
  }, asks ? home.noAsks : " ")));
3409
3749
  }
3410
3750
 
3751
+ // web-src/edu-report.ts
3752
+ var WEEK = 7 * 86400000;
3753
+ var EduReport;
3754
+ ((EduReport) => {
3755
+ function of(days, mistakes, name, words, now) {
3756
+ const week = EduUtil.lastWeek(days, now);
3757
+ const books = EduUtil.books(mistakes, now, words.otherSubject);
3758
+ const format2 = (text, values) => text.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
3759
+ return {
3760
+ title: format2(words.reportTitle, { name }),
3761
+ stats: [
3762
+ { label: words.statQuestions, value: String(week.n) },
3763
+ { label: words.statRight, value: week.n ? `${Math.round(week.right / week.n * 100)}%` : "—" },
3764
+ { label: words.statDays, value: String(week.days) }
3765
+ ],
3766
+ items: books.slice(0, 5).map((book) => ({ label: book.subject, value: book.progress, note: format2(words.reportNote, { count: book.mistakes.length }) })),
3767
+ weak: EduUtil.weak(mistakes),
3768
+ next: [],
3769
+ report: true
3770
+ };
3771
+ }
3772
+ EduReport.of = of;
3773
+ EduReport.DAY = 0;
3774
+ EduReport.HOUR = 18;
3775
+ function slot(now) {
3776
+ const date = new Date(now);
3777
+ date.setHours(EduReport.HOUR, 0, 0, 0);
3778
+ date.setDate(date.getDate() - (date.getDay() - EduReport.DAY + 7) % 7);
3779
+ return date.getTime() > now ? date.getTime() - WEEK : date.getTime();
3780
+ }
3781
+ EduReport.slot = slot;
3782
+ function due(reportTo, reportedAt, now) {
3783
+ return !!reportTo && (reportedAt === undefined || reportedAt < slot(now));
3784
+ }
3785
+ EduReport.due = due;
3786
+ })(EduReport ||= {});
3787
+
3411
3788
  // web-src/student.tsx
3412
3789
  function WeekDots({ context }) {
3413
3790
  const { pi, store } = context;
@@ -3446,7 +3823,9 @@ function StudentHome({ context, books, openBook }) {
3446
3823
  text: home.dueHead,
3447
3824
  count: due.length,
3448
3825
  tone: TONES.student
3449
- }) : home.dueNone)), /* @__PURE__ */ React.createElement("div", {
3826
+ }) : home.dueNone)), EduUtil.locked(state.settings, "student", state.consent) ? /* @__PURE__ */ React.createElement(ConsentPanel, {
3827
+ context
3828
+ }) : /* @__PURE__ */ React.createElement("div", {
3450
3829
  className: "ted-panel ted-today"
3451
3830
  }, first ? /* @__PURE__ */ React.createElement("div", {
3452
3831
  className: "ted-today-q"
@@ -3561,6 +3940,53 @@ function StudentHome({ context, books, openBook }) {
3561
3940
  context
3562
3941
  }))));
3563
3942
  }
3943
+ function ConsentPanel({ context }) {
3944
+ const { pi, store, rooms } = context;
3945
+ const home = HomeWordsUtil.of(pi.ui.language);
3946
+ const { asked } = store.state.consent;
3947
+ const Lock = iconOf(pi, "Lock");
3948
+ const ask2 = async (id, name) => {
3949
+ const me = await rooms.identity();
3950
+ const room = me && await rooms.sendTo(id, (room2) => EduRoomUtil.consentText({ kind: "ask", room: room2, child: me.id, name: me.name }, format(home.consentAskIntro, { name: me.name })));
3951
+ if (!room) {
3952
+ pi.ui.notify(home.reportFailed, "warning");
3953
+ return false;
3954
+ }
3955
+ await store.setAsked({ to: id, name, at: Date.now() });
3956
+ pi.ui.notify(format(home.consentAsked, { name }));
3957
+ return true;
3958
+ };
3959
+ const open = () => pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
3960
+ title: home.consentAsk,
3961
+ onClose: close
3962
+ }, /* @__PURE__ */ React.createElement(FriendPicker, {
3963
+ context,
3964
+ close,
3965
+ hint: home.consentNeededHint,
3966
+ chosen: asked?.to,
3967
+ pick: ask2
3968
+ })));
3969
+ return /* @__PURE__ */ React.createElement("div", {
3970
+ className: "ted-panel ted-consent"
3971
+ }, /* @__PURE__ */ React.createElement("div", {
3972
+ className: "ted-consent-main"
3973
+ }, /* @__PURE__ */ React.createElement(Tile, {
3974
+ icon: Lock,
3975
+ tone: TONES.parent
3976
+ }), /* @__PURE__ */ React.createElement("span", {
3977
+ className: "ted-row-main"
3978
+ }, /* @__PURE__ */ React.createElement("span", {
3979
+ className: "ted-row-title"
3980
+ }, home.consentNeeded), /* @__PURE__ */ React.createElement("span", {
3981
+ className: "ted-row-sub ted-wrap"
3982
+ }, asked ? format(home.consentAsked, { name: asked.name }) : home.consentNeededHint))), /* @__PURE__ */ React.createElement("div", {
3983
+ className: "ted-today-foot"
3984
+ }, /* @__PURE__ */ React.createElement("span", null), pi.rooms && /* @__PURE__ */ React.createElement("button", {
3985
+ type: "button",
3986
+ className: `ta-button ted-pill${asked ? "" : " ta-primary"}`,
3987
+ onClick: open
3988
+ }, asked ? home.consentAskOther : home.consentAsk)));
3989
+ }
3564
3990
  function ToParent({ context }) {
3565
3991
  const { pi, store, rooms } = context;
3566
3992
  const home = HomeWordsUtil.of(pi.ui.language);
@@ -3570,12 +3996,32 @@ function ToParent({ context }) {
3570
3996
  if (!pi.rooms) {
3571
3997
  return null;
3572
3998
  }
3999
+ const send = async (id, name) => {
4000
+ const me = await pi.rooms.getIdentity();
4001
+ const learning = EduReport.of(store.state.days, store.state.mistakes, me.name, home, Date.now());
4002
+ if (!await rooms.sendReport(id, learning, format(home.reportIntro, { name: me.name }))) {
4003
+ pi.ui.notify(home.reportFailed, "warning");
4004
+ return false;
4005
+ }
4006
+ await store.setSettings({ reportTo: id });
4007
+ await store.setReported(Date.now());
4008
+ pi.ui.notify(format(home.reportSent, { name }));
4009
+ return true;
4010
+ };
3573
4011
  const menu = () => pi.ui.custom(({ close }) => /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
3574
4012
  title: home.pickParent,
3575
4013
  onClose: close
3576
4014
  }, /* @__PURE__ */ React.createElement(FriendPicker, {
3577
4015
  context,
3578
- close
4016
+ close,
4017
+ hint: home.reportPrivacy,
4018
+ chosen: store.state.settings.reportTo,
4019
+ pick: send,
4020
+ foot: store.state.settings.reportTo && /* @__PURE__ */ React.createElement("button", {
4021
+ type: "button",
4022
+ className: "ta-button",
4023
+ onClick: () => void store.setSettings({ reportTo: undefined }).then(close)
4024
+ }, home.stopSending)
3579
4025
  })));
3580
4026
  return /* @__PURE__ */ React.createElement("div", {
3581
4027
  className: "ted-panel ted-list ted-toparent"
@@ -3597,23 +4043,23 @@ function ToParent({ context }) {
3597
4043
  "data-on": friend ? true : undefined
3598
4044
  })));
3599
4045
  }
3600
- function FriendPicker({ context, close }) {
3601
- const { pi, store, rooms } = context;
4046
+ function FriendPicker({
4047
+ context,
4048
+ close,
4049
+ hint,
4050
+ chosen,
4051
+ pick,
4052
+ foot
4053
+ }) {
4054
+ const { pi, rooms } = context;
3602
4055
  useRooms(rooms);
3603
4056
  const home = HomeWordsUtil.of(pi.ui.language);
3604
- const { settings } = store.state;
3605
4057
  const [busy, setBusy] = React.useState(false);
3606
- const send = async (id, name) => {
4058
+ const choose = async (id, name) => {
3607
4059
  setBusy(true);
3608
4060
  try {
3609
- const learning = EduReport.of(store.state.days, store.state.mistakes, (await pi.rooms.getIdentity()).name, home, Date.now());
3610
- const sent = await rooms.sendReport(id, learning, format(home.reportIntro, { name: (await pi.rooms.getIdentity()).name }));
3611
- if (sent) {
3612
- await store.setSettings({ reportTo: id, reportAt: Date.now() });
3613
- pi.ui.notify(format(home.reportSent, { name }));
4061
+ if (await pick(id, name)) {
3614
4062
  close();
3615
- } else {
3616
- pi.ui.notify(home.reportFailed, "warning");
3617
4063
  }
3618
4064
  } catch (error) {
3619
4065
  failed(pi, home)(error);
@@ -3625,14 +4071,14 @@ function FriendPicker({ context, close }) {
3625
4071
  className: "ted-picker"
3626
4072
  }, /* @__PURE__ */ React.createElement("div", {
3627
4073
  className: "ted-picker-hint ted-picker-hint-alone"
3628
- }, home.reportPrivacy), rooms.friends.length ? /* @__PURE__ */ React.createElement("div", {
4074
+ }, hint), rooms.friends.length ? /* @__PURE__ */ React.createElement("div", {
3629
4075
  className: "ted-list"
3630
4076
  }, rooms.friends.map((friend) => /* @__PURE__ */ React.createElement("button", {
3631
4077
  key: friend.id,
3632
4078
  type: "button",
3633
4079
  className: "ted-row",
3634
4080
  disabled: busy,
3635
- onClick: () => void send(friend.id, friend.name)
4081
+ onClick: () => void choose(friend.id, friend.name)
3636
4082
  }, /* @__PURE__ */ React.createElement(pi.ui.Face, {
3637
4083
  seed: friend.id,
3638
4084
  look: friend.look,
@@ -3643,20 +4089,16 @@ function FriendPicker({ context, close }) {
3643
4089
  className: "ted-row-title"
3644
4090
  }, friend.name)), /* @__PURE__ */ React.createElement("span", {
3645
4091
  className: "ted-check",
3646
- "data-on": friend.id === settings.reportTo || undefined
3647
- }, friend.id === settings.reportTo && /* @__PURE__ */ React.createElement(pi.ui.icons.Check, {
4092
+ "data-on": friend.id === chosen || undefined
4093
+ }, friend.id === chosen && /* @__PURE__ */ React.createElement(pi.ui.icons.Check, {
3648
4094
  size: 13,
3649
4095
  strokeWidth: 3
3650
4096
  }))))) : /* @__PURE__ */ React.createElement(pi.ui.Empty, {
3651
4097
  compact: true,
3652
4098
  title: home.noFriends
3653
- }), settings.reportTo && /* @__PURE__ */ React.createElement("div", {
4099
+ }), foot && /* @__PURE__ */ React.createElement("div", {
3654
4100
  className: "ted-picker-foot"
3655
- }, /* @__PURE__ */ React.createElement("button", {
3656
- type: "button",
3657
- className: "ta-button",
3658
- onClick: () => void store.setSettings({ reportTo: undefined }).then(close)
3659
- }, home.stopSending)));
4101
+ }, foot));
3660
4102
  }
3661
4103
  function MistakeBook({ context, book }) {
3662
4104
  const { pi } = context;
@@ -3946,6 +4388,7 @@ function Picker({ context, first, close }) {
3946
4388
  }
3947
4389
 
3948
4390
  // web-src/settings.tsx
4391
+ var format2 = EduWords.format;
3949
4392
  function useSettings(store) {
3950
4393
  const [, tick] = React.useReducer((n) => n + 1, 0);
3951
4394
  React.useEffect(() => store.subscribe(tick), [store]);
@@ -4000,17 +4443,16 @@ function eduSettings(pi, store) {
4000
4443
  });
4001
4444
  }
4002
4445
  function Consent() {
4003
- const settings = useSettings(store);
4004
- return /* @__PURE__ */ React.createElement(pi.ui.Switch, {
4005
- checked: settings.consent,
4006
- label: words().consentLabel,
4007
- onChange: (consent) => store.setSettings({ consent })
4008
- });
4446
+ useSettings(store);
4447
+ const home = HomeWordsUtil.of(pi.ui.language);
4448
+ const { granted } = store.state.consent;
4449
+ return /* @__PURE__ */ React.createElement("span", {
4450
+ className: "ted-setting-note"
4451
+ }, granted ? format2(home.consentBy, { name: granted.name, date: new Date(granted.at).toLocaleDateString(pi.ui.language) }) : home.consentNone);
4009
4452
  }
4010
4453
  return {
4011
4454
  title: label("settingsTitle"),
4012
4455
  icon: pi.ui.icons.BookOpen,
4013
- group: "ta",
4014
4456
  rows: [
4015
4457
  { key: "identities", label: label("identitiesLabel"), description: label("identitiesHint"), render: Identities },
4016
4458
  { key: "stage", label: label("stageLabel"), render: Stage },
@@ -4122,6 +4564,18 @@ button.ted-row:hover:not(:disabled) { background: var(--ta-hover); }
4122
4564
  .ted-switchmark[data-on] { background: var(--ta-green); }
4123
4565
  .ted-switchmark[data-on]::after { transform: translateX(14px); }
4124
4566
  .ted-toparent { margin-top: 12px; }
4567
+ .ted-consent { padding: 14px 14px 12px; }
4568
+ .ted-consent-main { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--ta-border-muted); }
4569
+ .ted-consent-asks { margin-bottom: 16px; }
4570
+ .ted-consent-asks .ted-section { margin-top: 0; }
4571
+ .ted-consent-ask + .ted-consent-ask { border-top: 1px solid var(--ta-border-muted); }
4572
+ .ted-row.ted-row-static { cursor: default; align-items: flex-start; }
4573
+ .ted-consent-acts { display: flex; justify-content: flex-end; gap: 8px; padding: 0 14px 12px; }
4574
+ .ted-consent-body { padding: 10px 14px; color: var(--ta-secondary); font-size: calc(13px * var(--ted-s)); }
4575
+ .ted-consent-said { color: var(--ta-muted); }
4576
+ .ted-consent-card[data-kind='grant'] .ted-mark { color: var(--ta-green); background: color-mix(in srgb, var(--ta-green) 12%, transparent); }
4577
+ .ted-consent-card .ted-foot { gap: 8px; }
4578
+ .ted-setting-note { color: var(--ta-secondary); font-size: calc(13px * var(--ted-s)); }
4125
4579
  .ted-toparent .ted-row-sub { white-space: normal; }
4126
4580
  .ted-quiet { padding: 14px; color: var(--ta-muted); font-size: calc(13px * var(--ted-s)); }
4127
4581
  .ted-week { padding: 14px; }
@@ -4286,7 +4740,13 @@ function activate(pi) {
4286
4740
  bind(pi.React);
4287
4741
  const removeStyle = injectStyle();
4288
4742
  const store = new EduStore(pi);
4289
- const rooms = new EduRooms(pi, store);
4743
+ const rooms = new EduRooms({
4744
+ get rooms() {
4745
+ return pi.rooms;
4746
+ },
4747
+ onRoomEvent: pi.onRoomEvent ? (listener, options) => pi.onRoomEvent(listener, options) : undefined,
4748
+ openFriend: pi.ui.openPartner ? (id) => pi.ui.openPartner?.(id, "friend") ?? Promise.resolve(false) : undefined
4749
+ }, store);
4290
4750
  const context = { pi, store, rooms };
4291
4751
  pi.registerView("home", {
4292
4752
  title: () => HomeWordsUtil.of(pi.ui.language).eduTitle,
@@ -4316,24 +4776,8 @@ function activate(pi) {
4316
4776
  pi.registerSettings(eduSettings(pi, store));
4317
4777
  pi.registerCodeRenderer?.(QUIZ, quizCard(pi, store, rooms), { spoken: (code) => EduUtil.quiz(code)?.title });
4318
4778
  pi.registerCodeRenderer?.(LEARNING, learningCard(pi), { spoken: (code) => EduUtil.learning(code)?.title });
4319
- const weekly = store.subscribe(() => {
4320
- const { loaded, settings, days, mistakes } = store.state;
4321
- if (!loaded || !settings.reportTo || !EduReport.due(settings.reportTo, settings.reportAt, Date.now()) || !pi.rooms) {
4322
- return;
4323
- }
4324
- const to = settings.reportTo;
4325
- store.setSettings({ reportAt: Date.now() });
4326
- pi.rooms.getIdentity().then((me) => {
4327
- const home = HomeWordsUtil.of(pi.ui.language);
4328
- return rooms.sendReport(to, EduReport.of(days, mistakes, me.name, home, Date.now()), EduWords.format(home.reportIntro, { name: me.name }), false);
4329
- }).catch(() => {
4330
- return;
4331
- });
4332
- });
4333
- return () => {
4334
- weekly();
4335
- removeStyle();
4336
- };
4779
+ pi.registerCodeRenderer?.(CONSENT, consentCard(pi, rooms), { spoken: (code) => EduRoomUtil.consent(code)?.name });
4780
+ return removeStyle;
4337
4781
  }
4338
4782
  export {
4339
4783
  activate as default