cotutor 0.2.0 → 0.4.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/LICENSE +249 -21
- package/NOTICE +42 -0
- package/README.md +115 -20
- package/avatars/chinese.webp +0 -0
- package/avatars/english.webp +0 -0
- package/avatars/math.webp +0 -0
- package/bin/cotutor.js +15 -5
- package/cards/canvas/card.css +8 -0
- package/cards/canvas/card.md +68 -0
- package/cards/choice/card.css +18 -0
- package/cards/choice/card.md +55 -0
- package/cards/code/card.css +5 -0
- package/cards/code/card.md +46 -0
- package/cards/dictation/card.css +10 -0
- package/cards/dictation/card.md +97 -0
- package/cards/image/card.css +10 -0
- package/cards/image/card.md +52 -0
- package/cards/lecture/card.css +9 -0
- package/cards/lecture/card.md +69 -0
- package/cards/paint/card.css +20 -0
- package/cards/paint/card.md +77 -0
- package/cards/photo/card.css +22 -0
- package/cards/photo/card.md +61 -0
- package/cards/read/card.css +6 -0
- package/cards/read/card.md +51 -0
- package/cards/text/card.css +3 -0
- package/cards/text/card.md +69 -0
- package/cards/tianzige/card.css +17 -0
- package/cards/tianzige/card.md +78 -0
- package/cards/tutor/card.css +79 -0
- package/cards/tutor/card.md +149 -0
- package/cards/word/card.css +24 -0
- package/cards/word/card.md +91 -0
- package/cards//346/235/277/344/271/246/346/200/216/344/271/210/345/206/231.md +159 -0
- package/dist/app/activity-eval-rules.d.ts +62 -0
- package/dist/app/activity-eval-rules.js +276 -0
- package/dist/app/activity-eval.d.ts +65 -0
- package/dist/app/activity-eval.js +159 -0
- package/dist/app/build.d.ts +11 -0
- package/dist/app/build.js +45 -0
- package/dist/app/cli/activities.d.ts +70 -0
- package/dist/app/cli/activities.js +196 -0
- package/dist/app/cli/cert.d.ts +12 -0
- package/dist/app/cli/cert.js +49 -0
- package/dist/app/cli/chalk/bake.d.ts +10 -0
- package/dist/app/cli/chalk/bake.js +58 -0
- package/dist/app/cli/chalk/browser.d.ts +16 -0
- package/dist/app/cli/chalk/browser.js +157 -0
- package/dist/app/cli/chalk/build.d.ts +14 -0
- package/dist/app/cli/chalk/build.js +100 -0
- package/dist/app/cli/chalk/dub.d.ts +51 -0
- package/dist/app/cli/chalk/dub.js +106 -0
- package/dist/app/cli/chalk/load-scene.d.ts +34 -0
- package/dist/app/cli/chalk/load-scene.js +117 -0
- package/dist/app/cli/chalk/main.d.ts +7 -0
- package/dist/app/cli/chalk/main.js +199 -0
- package/dist/app/cli/chalk/serve.d.ts +4 -0
- package/dist/app/cli/chalk/serve.js +28 -0
- package/dist/app/cli/chalk/snap.d.ts +65 -0
- package/dist/app/cli/chalk/snap.js +103 -0
- package/dist/app/cli/chalk/typecheck.d.ts +7 -0
- package/dist/app/cli/chalk/typecheck.js +51 -0
- package/dist/app/cli/doctor.d.ts +24 -0
- package/dist/app/cli/doctor.js +553 -0
- package/dist/app/cli/firewall.d.ts +24 -0
- package/dist/app/cli/firewall.js +79 -0
- package/dist/app/cli/grades.d.ts +14 -0
- package/dist/app/cli/grades.js +44 -0
- package/dist/{cli → app/cli}/init.d.ts +3 -1
- package/dist/app/cli/init.js +158 -0
- package/dist/app/cli/main.js +1038 -0
- package/dist/app/cli/migrate.d.ts +49 -0
- package/dist/app/cli/migrate.js +195 -0
- package/dist/app/cli/port-holder.d.ts +16 -0
- package/dist/app/cli/port-holder.js +34 -0
- package/dist/app/cli/port.d.ts +37 -0
- package/dist/app/cli/port.js +116 -0
- package/dist/app/cli/sandbox.d.ts +25 -0
- package/dist/app/cli/sandbox.js +166 -0
- package/dist/app/cli/serve-log.d.ts +13 -0
- package/dist/app/cli/serve-log.js +90 -0
- package/dist/app/cli/serve.d.ts +51 -0
- package/dist/app/cli/serve.js +168 -0
- package/dist/app/cli/service-windows.d.ts +50 -0
- package/dist/app/cli/service-windows.js +117 -0
- package/dist/app/cli/service.d.ts +138 -0
- package/dist/app/cli/service.js +429 -0
- package/dist/app/cli/shipped.d.ts +30 -0
- package/dist/app/cli/shipped.js +47 -0
- package/dist/app/cli/skeleton.d.ts +38 -0
- package/dist/app/cli/skeleton.js +161 -0
- package/dist/app/cli/skills.d.ts +59 -0
- package/dist/app/cli/skills.js +199 -0
- package/dist/app/cli/themes.d.ts +52 -0
- package/dist/app/cli/themes.js +148 -0
- package/dist/app/cli/tray-icons.d.ts +11 -0
- package/dist/app/cli/tray-icons.js +87 -0
- package/dist/app/cli/tray-ids.d.ts +6 -0
- package/dist/app/cli/tray-ids.js +6 -0
- package/dist/app/cli/tray-mac.d.ts +8 -0
- package/dist/app/cli/tray-mac.js +140 -0
- package/dist/app/cli/tray-run.d.ts +1 -0
- package/dist/app/cli/tray-run.js +33 -0
- package/dist/app/cli/tray-windows.d.ts +5 -0
- package/dist/app/cli/tray-windows.js +166 -0
- package/dist/app/cli/tray.d.ts +205 -0
- package/dist/app/cli/tray.js +618 -0
- package/dist/{cli → app/cli}/tutors.d.ts +15 -26
- package/dist/{cli → app/cli}/tutors.js +86 -110
- package/dist/app/cli/usage.d.ts +2 -0
- package/dist/app/cli/usage.js +35 -0
- package/dist/app/dictation/recognize.d.ts +18 -0
- package/dist/app/dictation/recognize.js +6 -0
- package/dist/app/dictation/route.d.ts +52 -0
- package/dist/app/dictation/route.js +511 -0
- package/dist/app/diff.d.ts +11 -0
- package/dist/app/diff.js +71 -0
- package/dist/app/http/access.d.ts +62 -0
- package/dist/app/http/access.js +180 -0
- package/dist/app/http/app.d.ts +241 -0
- package/dist/app/http/app.js +1159 -0
- package/dist/app/http/avatars.d.ts +17 -0
- package/dist/app/http/avatars.js +35 -0
- package/dist/app/http/dev-activities.d.ts +115 -0
- package/dist/app/http/dev-activities.js +193 -0
- package/dist/app/http/dev-overview.d.ts +108 -0
- package/dist/app/http/dev-overview.js +209 -0
- package/dist/app/http/dev-tutor-files.d.ts +80 -0
- package/dist/app/http/dev-tutor-files.js +151 -0
- package/dist/app/http/parent-home.d.ts +51 -0
- package/dist/app/http/parent-home.js +266 -0
- package/dist/app/http/parent-look.d.ts +2 -0
- package/dist/app/http/parent-look.js +151 -0
- package/dist/app/http/range.d.ts +9 -0
- package/dist/app/http/range.js +19 -0
- package/dist/app/http/raw-view.d.ts +117 -0
- package/dist/app/http/raw-view.js +149 -0
- package/dist/app/http/send-file.d.ts +7 -0
- package/dist/app/http/send-file.js +29 -0
- package/dist/{server → app/http}/stage.d.ts +9 -0
- package/dist/{server → app/http}/stage.js +34 -6
- package/dist/app/http/theme.d.ts +13 -0
- package/dist/app/http/theme.js +41 -0
- package/dist/app/http/voice-preview.d.ts +4 -0
- package/dist/app/http/voice-preview.js +34 -0
- package/dist/app/machine/bailian.d.ts +26 -0
- package/dist/app/machine/bailian.js +87 -0
- package/dist/app/mock/mock-live.d.ts +16 -0
- package/dist/app/mock/mock-live.js +140 -0
- package/dist/{server → app/mock}/mock.d.ts +38 -5
- package/dist/app/mock/mock.js +1125 -0
- package/dist/app/replay.d.ts +94 -0
- package/dist/app/replay.js +170 -0
- package/dist/app/skills/analyze-doc.d.ts +3 -0
- package/dist/app/skills/analyze-doc.js +47 -0
- package/dist/app/skills/home-doc.d.ts +5 -0
- package/dist/app/skills/home-doc.js +112 -0
- package/dist/app/skills/tune-doc.d.ts +3 -0
- package/dist/app/skills/tune-doc.js +80 -0
- package/dist/app/talk/list.d.ts +11 -0
- package/dist/app/talk/list.js +9 -0
- package/dist/app/talk/route.d.ts +16 -0
- package/dist/app/talk/route.js +142 -0
- package/dist/app/workspace.d.ts +63 -0
- package/dist/{cli → app}/workspace.js +100 -52
- package/dist/app/ws/route.d.ts +31 -0
- package/dist/app/ws/route.js +33 -0
- package/dist/app/ws/ws.d.ts +31 -0
- package/dist/app/ws/ws.js +169 -0
- package/dist/board/canvas-chat.d.ts +97 -0
- package/dist/board/canvas-chat.js +175 -0
- package/dist/board/card-guards.d.ts +15 -0
- package/dist/board/card-guards.js +38 -0
- package/dist/board/cards/canvas.d.ts +41 -0
- package/dist/board/cards/canvas.js +83 -0
- package/dist/{cards → board/cards}/choice.js +0 -12
- package/dist/{cards → board/cards}/code.js +0 -3
- package/dist/board/cards/dictation.d.ts +42 -0
- package/dist/board/cards/dictation.js +105 -0
- package/dist/board/cards/docs.d.ts +47 -0
- package/dist/board/cards/docs.js +152 -0
- package/dist/{cards → board/cards}/image.js +1 -10
- package/dist/board/cards/index.d.ts +62 -0
- package/dist/board/cards/index.js +144 -0
- package/dist/{cards → board/cards}/kind.d.ts +10 -4
- package/dist/board/cards/kind.js +9 -0
- package/dist/board/cards/lecture.d.ts +26 -0
- package/dist/board/cards/lecture.js +62 -0
- package/dist/board/cards/paint.d.ts +38 -0
- package/dist/board/cards/paint.js +85 -0
- package/dist/board/cards/photo.d.ts +15 -0
- package/dist/board/cards/photo.js +29 -0
- package/dist/{cards → board/cards}/read.js +1 -10
- package/dist/board/cards/text.d.ts +20 -0
- package/dist/board/cards/text.js +59 -0
- package/dist/board/cards/tianzige.d.ts +16 -0
- package/dist/board/cards/tianzige.js +64 -0
- package/dist/board/cards/tutor.d.ts +72 -0
- package/dist/board/cards/tutor.js +134 -0
- package/dist/board/cards/word.d.ts +20 -0
- package/dist/board/cards/word.js +76 -0
- package/dist/board/lecture.d.ts +100 -0
- package/dist/board/lecture.js +204 -0
- package/dist/board/paper.d.ts +20 -0
- package/dist/board/paper.js +76 -0
- package/dist/board/parse.d.ts +118 -0
- package/dist/board/parse.js +324 -0
- package/dist/board/presentation.d.ts +289 -0
- package/dist/board/presentation.js +613 -0
- package/dist/board/sections.d.ts +16 -0
- package/dist/board/sections.js +130 -0
- package/dist/brain/api-tools.d.ts +8 -0
- package/dist/brain/api-tools.js +191 -0
- package/dist/brain/api.d.ts +57 -0
- package/dist/brain/api.js +394 -0
- package/dist/brain/index.d.ts +97 -0
- package/dist/brain/index.js +11 -0
- package/dist/brain/log.d.ts +5 -0
- package/dist/brain/log.js +22 -0
- package/dist/brain/runtime.d.ts +30 -0
- package/dist/brain/runtime.js +23 -0
- package/dist/brain/stream-json.d.ts +16 -0
- package/dist/brain/stream-json.js +82 -0
- package/dist/brain/stream.d.ts +20 -0
- package/dist/brain/stream.js +70 -0
- package/dist/brain/transcript.d.ts +45 -0
- package/dist/brain/transcript.js +132 -0
- package/dist/brain/types.d.ts +99 -0
- package/dist/brain/types.js +14 -0
- package/dist/chalk/actions.d.ts +37 -0
- package/dist/chalk/actions.js +69 -0
- package/dist/chalk/bundle.d.ts +26 -0
- package/dist/chalk/bundle.js +69 -0
- package/dist/chalk/check.d.ts +28 -0
- package/dist/chalk/check.js +291 -0
- package/dist/chalk/circle.d.ts +64 -0
- package/dist/chalk/circle.js +193 -0
- package/dist/chalk/clock.d.ts +84 -0
- package/dist/chalk/clock.js +84 -0
- package/dist/chalk/geometry.d.ts +44 -0
- package/dist/chalk/geometry.js +139 -0
- package/dist/chalk/glyphs/capitals.d.ts +12 -0
- package/dist/chalk/glyphs/capitals.js +264 -0
- package/dist/chalk/glyphs/index.d.ts +21 -0
- package/dist/chalk/glyphs/index.js +18 -0
- package/dist/chalk/glyphs/letters.d.ts +13 -0
- package/dist/chalk/glyphs/letters.js +280 -0
- package/dist/chalk/glyphs/metrics.d.ts +33 -0
- package/dist/chalk/glyphs/metrics.js +28 -0
- package/dist/chalk/glyphs/registry.d.ts +7 -0
- package/dist/chalk/glyphs/registry.js +8 -0
- package/dist/chalk/glyphs/sample.d.ts +32 -0
- package/dist/chalk/glyphs/sample.js +102 -0
- package/dist/chalk/glyphs/skeleton.d.ts +64 -0
- package/dist/chalk/glyphs/skeleton.js +126 -0
- package/dist/chalk/glyphs/types.d.ts +58 -0
- package/dist/chalk/glyphs/types.js +17 -0
- package/dist/chalk/index.d.ts +23 -0
- package/dist/chalk/index.js +15 -0
- package/dist/chalk/manifest.d.ts +41 -0
- package/dist/chalk/manifest.js +6 -0
- package/dist/chalk/paint.d.ts +180 -0
- package/dist/chalk/paint.js +210 -0
- package/dist/chalk/pointer.d.ts +8 -0
- package/dist/chalk/pointer.js +21 -0
- package/dist/chalk/prepare.d.ts +11 -0
- package/dist/chalk/prepare.js +15 -0
- package/dist/chalk/scene-schema.d.ts +199 -0
- package/dist/chalk/scene-schema.js +91 -0
- package/dist/chalk/seed.d.ts +3 -0
- package/dist/chalk/seed.js +10 -0
- package/dist/chalk/text-metrics.d.ts +8 -0
- package/dist/chalk/text-metrics.js +156 -0
- package/dist/chalk/timeline.d.ts +47 -0
- package/dist/chalk/timeline.js +84 -0
- package/dist/chalk/types.d.ts +150 -0
- package/dist/chalk/types.js +8 -0
- package/dist/lib/index.d.ts +14 -12
- package/dist/lib/index.js +14 -12
- package/dist/media/draw.d.ts +23 -0
- package/dist/media/draw.js +44 -0
- package/dist/media/mp3.d.ts +6 -0
- package/dist/media/mp3.js +58 -0
- package/dist/media/mp4.d.ts +1 -0
- package/dist/media/mp4.js +58 -0
- package/dist/media/tts-voices.d.ts +18 -0
- package/dist/media/tts-voices.js +606 -0
- package/dist/media/tts.d.ts +56 -0
- package/dist/media/tts.js +174 -0
- package/dist/media/vision.d.ts +25 -0
- package/dist/media/vision.js +71 -0
- package/dist/memory/commit.d.ts +67 -0
- package/dist/memory/commit.js +130 -0
- package/dist/memory/context.d.ts +86 -0
- package/dist/memory/context.js +97 -0
- package/dist/memory/diary.d.ts +84 -0
- package/dist/memory/diary.js +183 -0
- package/dist/memory/grade.d.ts +2 -0
- package/dist/memory/grade.js +7 -0
- package/dist/{lib → memory}/plan.d.ts +1 -1
- package/dist/{lib → memory}/plan.js +1 -1
- package/dist/memory/proposals.d.ts +11 -0
- package/dist/memory/proposals.js +43 -0
- package/dist/memory/retrieval.d.ts +44 -0
- package/dist/memory/retrieval.js +157 -0
- package/dist/{lib → memory}/timetable.d.ts +0 -3
- package/dist/{lib → memory}/timetable.js +0 -11
- package/dist/memory/vault-notes.d.ts +165 -0
- package/dist/memory/vault-notes.js +359 -0
- package/dist/memory/vault.d.ts +70 -0
- package/dist/memory/vault.js +169 -0
- package/dist/realtime/bailian.d.ts +120 -0
- package/dist/realtime/bailian.js +289 -0
- package/dist/realtime/cues.d.ts +51 -0
- package/dist/realtime/cues.js +94 -0
- package/dist/realtime/listen.d.ts +32 -0
- package/dist/realtime/listen.js +53 -0
- package/dist/realtime/preview.d.ts +23 -0
- package/dist/realtime/preview.js +38 -0
- package/dist/realtime/prompt.d.ts +8 -0
- package/dist/realtime/prompt.js +13 -0
- package/dist/realtime/voices.d.ts +21 -0
- package/dist/realtime/voices.js +71 -0
- package/dist/runtime/activities.d.ts +29 -0
- package/dist/runtime/activities.js +72 -0
- package/dist/runtime/activity-state.d.ts +22 -0
- package/dist/runtime/activity-state.js +83 -0
- package/dist/runtime/activity.d.ts +63 -0
- package/dist/runtime/activity.js +428 -0
- package/dist/runtime/agent-file.d.ts +24 -0
- package/dist/runtime/agent-file.js +59 -0
- package/dist/runtime/auto-bookkeep.d.ts +30 -0
- package/dist/runtime/auto-bookkeep.js +84 -0
- package/dist/{lib → runtime/context}/context-pack.d.ts +3 -3
- package/dist/runtime/context/context-pack.js +182 -0
- package/dist/runtime/context/thread-digest.d.ts +4 -0
- package/dist/runtime/context/thread-digest.js +35 -0
- package/dist/runtime/context/tutor-rules.d.ts +25 -0
- package/dist/runtime/context/tutor-rules.js +47 -0
- package/dist/runtime/delivery/delivery.d.ts +94 -0
- package/dist/runtime/delivery/delivery.js +145 -0
- package/dist/runtime/delivery/playback.d.ts +25 -0
- package/dist/runtime/delivery/playback.js +29 -0
- package/dist/runtime/delivery/player.d.ts +145 -0
- package/dist/runtime/delivery/player.js +221 -0
- package/dist/runtime/delivery/queue.d.ts +89 -0
- package/dist/runtime/delivery/queue.js +59 -0
- package/dist/runtime/home/edit.d.ts +39 -0
- package/dist/runtime/home/edit.js +132 -0
- package/dist/runtime/home/home.d.ts +191 -0
- package/dist/runtime/home/home.js +318 -0
- package/dist/runtime/home/store.d.ts +142 -0
- package/dist/runtime/home/store.js +455 -0
- package/dist/runtime/journal/conversation.d.ts +46 -0
- package/dist/runtime/journal/conversation.js +89 -0
- package/dist/runtime/journal/events.d.ts +27 -0
- package/dist/runtime/journal/events.js +136 -0
- package/dist/runtime/journal/kid-log.d.ts +105 -0
- package/dist/runtime/journal/kid-log.js +133 -0
- package/dist/runtime/journal/ledger.d.ts +17 -0
- package/dist/{lib → runtime/journal}/ledger.js +7 -40
- package/dist/runtime/journal/mix.d.ts +42 -0
- package/dist/runtime/journal/mix.js +129 -0
- package/dist/runtime/journal/mouth-index.d.ts +26 -0
- package/dist/runtime/journal/mouth-index.js +34 -0
- package/dist/runtime/journal/mouth.d.ts +54 -0
- package/dist/runtime/journal/mouth.js +102 -0
- package/dist/runtime/journal/recorder.d.ts +91 -0
- package/dist/runtime/journal/recorder.js +148 -0
- package/dist/runtime/journal/store.d.ts +123 -0
- package/dist/runtime/journal/store.js +316 -0
- package/dist/runtime/kid-input.d.ts +16 -0
- package/dist/runtime/kid-input.js +194 -0
- package/dist/runtime/kid-view.d.ts +124 -0
- package/dist/runtime/kid-view.js +157 -0
- package/dist/runtime/lecture.d.ts +86 -0
- package/dist/runtime/lecture.js +237 -0
- package/dist/runtime/live/call.d.ts +231 -0
- package/dist/runtime/live/call.js +1244 -0
- package/dist/runtime/live/turns.d.ts +48 -0
- package/dist/runtime/live/turns.js +102 -0
- package/dist/runtime/runner.d.ts +243 -0
- package/dist/runtime/runner.js +777 -0
- package/dist/runtime/talk-run.d.ts +21 -0
- package/dist/runtime/talk-run.js +34 -0
- package/dist/scenes/dictation/match.d.ts +57 -0
- package/dist/scenes/dictation/match.js +255 -0
- package/dist/scenes/dictation/recognize.d.ts +86 -0
- package/dist/scenes/dictation/recognize.js +163 -0
- package/dist/scenes/dictation/store.d.ts +112 -0
- package/dist/scenes/dictation/store.js +99 -0
- package/dist/scenes/look.d.ts +26 -0
- package/dist/scenes/look.js +1 -0
- package/dist/scenes/paint/painter.d.ts +84 -0
- package/dist/scenes/paint/painter.js +171 -0
- package/dist/scenes/paint/prompt.d.ts +23 -0
- package/dist/scenes/paint/prompt.js +36 -0
- package/dist/scenes/talk/en-words.d.ts +8 -0
- package/dist/scenes/talk/en-words.js +44 -0
- package/dist/scenes/talk/list.d.ts +44 -0
- package/dist/scenes/talk/list.js +88 -0
- package/dist/scenes/talk/store.d.ts +27 -0
- package/dist/scenes/talk/store.js +61 -0
- package/dist/scenes/talk/warmup.d.ts +16 -0
- package/dist/scenes/talk/warmup.js +39 -0
- package/dist/schema/activity.d.ts +149 -0
- package/dist/schema/activity.js +113 -0
- package/dist/schema/board.d.ts +143 -2
- package/dist/schema/board.js +15 -3
- package/dist/schema/config.d.ts +339 -103
- package/dist/schema/config.js +269 -84
- package/dist/schema/context-pack.d.ts +76 -14
- package/dist/schema/context-pack.js +91 -10
- package/dist/{lib/conversation.d.ts → schema/conversation-files.d.ts} +11 -33
- package/dist/schema/conversation-files.js +26 -0
- package/dist/schema/conversation.d.ts +391 -49
- package/dist/schema/conversation.js +135 -19
- package/dist/schema/events.d.ts +138 -0
- package/dist/schema/events.js +1 -0
- package/dist/schema/home.d.ts +56 -0
- package/dist/schema/home.js +35 -0
- package/dist/schema/index.d.ts +14 -3
- package/dist/schema/index.js +14 -3
- package/dist/schema/kid-device.d.ts +20 -0
- package/dist/schema/kid-device.js +32 -0
- package/dist/schema/ledger.d.ts +8 -63
- package/dist/schema/ledger.js +7 -31
- package/dist/schema/memory.d.ts +73 -0
- package/dist/schema/memory.js +47 -0
- package/dist/schema/plan.d.ts +2 -2
- package/dist/schema/plan.js +2 -2
- package/dist/schema/sections.d.ts +32 -25
- package/dist/schema/sections.js +21 -22
- package/dist/schema/theme.d.ts +25 -0
- package/dist/schema/theme.js +26 -0
- package/dist/schema/timetable.d.ts +2 -2
- package/dist/schema/timetable.js +2 -2
- package/dist/schema/workspace.d.ts +68 -0
- package/dist/schema/workspace.js +37 -0
- package/dist/shared/default-port.d.ts +2 -0
- package/dist/shared/default-port.js +2 -0
- package/dist/shared/errors.d.ts +8 -0
- package/dist/shared/errors.js +13 -0
- package/dist/shared/home.d.ts +2 -0
- package/dist/shared/home.js +16 -0
- package/dist/shared/human-notes.d.ts +5 -0
- package/dist/shared/human-notes.js +7 -0
- package/dist/shared/qianwen.d.ts +54 -0
- package/dist/shared/qianwen.js +113 -0
- package/dist/shared/site-url.d.ts +2 -0
- package/dist/shared/site-url.js +5 -0
- package/dist/shared/time.d.ts +9 -0
- package/dist/shared/time.js +22 -0
- package/dist/shared/tokens.d.ts +18 -0
- package/dist/shared/tokens.js +11 -0
- package/dist/shared/wav.d.ts +10 -0
- package/dist/shared/wav.js +50 -0
- package/dist/stage/chunk-226TNLQA.js +129 -0
- package/dist/stage/chunk-24LGQEKE.js +1 -0
- package/dist/stage/chunk-25XV6UY3.js +10 -0
- package/dist/stage/chunk-2AZI3NHJ.js +1 -0
- package/dist/stage/chunk-2BQZTTBE.js +1 -0
- package/dist/stage/chunk-2M7CGY3Y.js +11 -0
- package/dist/stage/chunk-2VR4WFQ7.js +10 -0
- package/dist/stage/chunk-2ZYXBUWG.js +9 -0
- package/dist/stage/chunk-32LAWMGY.js +1 -0
- package/dist/stage/chunk-3LEMTSOO.js +11 -0
- package/dist/stage/chunk-3QCKGZYE.js +32 -0
- package/dist/stage/chunk-44P66WFA.js +1 -0
- package/dist/stage/chunk-4AM6FRR6.js +7 -0
- package/dist/stage/chunk-4QDE4SUK.js +1 -0
- package/dist/stage/chunk-4QESHV3U.js +1 -0
- package/dist/stage/chunk-4SG5QPHB.js +2 -0
- package/dist/stage/chunk-4T4UVCOC.js +1 -0
- package/dist/stage/chunk-4WUEPPG3.js +34 -0
- package/dist/stage/chunk-4YCN6UZ5.js +99 -0
- package/dist/stage/chunk-5V7ZY2AP.js +1 -0
- package/dist/stage/chunk-5VS5Y2VJ.js +6 -0
- package/dist/stage/chunk-5W4NO2ZD.js +62 -0
- package/dist/stage/chunk-65CRNICM.js +1 -0
- package/dist/stage/chunk-66MULO7F.js +5 -0
- package/dist/stage/chunk-6COFQTBS.js +162 -0
- package/dist/stage/chunk-6VZG3M3I.js +8 -0
- package/dist/stage/chunk-7HVDH43T.js +1 -0
- package/dist/stage/chunk-7JLJN4EZ.js +8 -0
- package/dist/stage/chunk-7QDSP4LN.js +1 -0
- package/dist/stage/chunk-7R6OQAO3.js +1 -0
- package/dist/stage/chunk-7VTTHZKW.js +7 -0
- package/dist/stage/chunk-ATHR5KEN.js +10 -0
- package/dist/stage/chunk-B6R5LTP2.js +36 -0
- package/dist/stage/chunk-BD4WE264.js +1 -0
- package/dist/stage/chunk-BONANU47.js +206 -0
- package/dist/stage/chunk-BTVW7OFK.js +89 -0
- package/dist/stage/chunk-BUTJIDHG.js +8 -0
- package/dist/stage/chunk-C2IPYMML.js +84 -0
- package/dist/stage/chunk-C54FTPPV.js +9 -0
- package/dist/stage/chunk-C6LOUF2Z.js +90 -0
- package/dist/stage/chunk-CFF3PILO.js +339 -0
- package/dist/stage/chunk-CI2FQ2JY.js +9 -0
- package/dist/stage/chunk-CW5O4RV7.js +12 -0
- package/dist/stage/chunk-CYABNQYD.js +1 -0
- package/dist/stage/chunk-D7FFA4NS.js +15 -0
- package/dist/stage/chunk-DUNNXU6Z.js +8 -0
- package/dist/stage/chunk-E3E4Q6JF.js +6 -0
- package/dist/stage/chunk-EB3U3LH7.js +9 -0
- package/dist/stage/chunk-EGSZ736B.js +8 -0
- package/dist/stage/chunk-EOBXW5VQ.js +2 -0
- package/dist/stage/chunk-ERZC3B7Y.js +11 -0
- package/dist/stage/chunk-ESDOOBIH.js +11 -0
- package/dist/stage/chunk-EVU4QAL4.js +178 -0
- package/dist/stage/chunk-EVVZI2NY.js +39 -0
- package/dist/stage/chunk-FBKAZUKD.js +39 -0
- package/dist/stage/chunk-FDVKYQJN.js +1 -0
- package/dist/stage/chunk-FGPVYHVR.js +5 -0
- package/dist/stage/chunk-FHUD4AZC.js +1 -0
- package/dist/stage/chunk-FKUJ2DMY.js +96 -0
- package/dist/stage/chunk-FNZGVIJV.js +1 -0
- package/dist/stage/chunk-GBYSEGYM.js +78 -0
- package/dist/stage/chunk-GCO4TDHX.js +1 -0
- package/dist/stage/chunk-GKTML2LG.js +10 -0
- package/dist/stage/chunk-GMDIHHXQ.js +11 -0
- package/dist/stage/chunk-GOUNACI3.js +10 -0
- package/dist/stage/chunk-GXAYATPF.js +3 -0
- package/dist/stage/chunk-H2K2DDXV.js +8 -0
- package/dist/stage/chunk-H3UJI6ZY.js +13 -0
- package/dist/stage/chunk-H6PUGCME.js +7 -0
- package/dist/stage/chunk-HNBUIMIG.js +1 -0
- package/dist/stage/chunk-HRZY2BJQ.js +10 -0
- package/dist/stage/chunk-HSPJGALW.js +30 -0
- package/dist/stage/chunk-IBYORHIP.js +25 -0
- package/dist/stage/chunk-IHF4EWTY.js +1 -0
- package/dist/stage/chunk-ISBRPNKI.js +1 -0
- package/dist/stage/chunk-IZ3OI3C2.js +2 -0
- package/dist/stage/chunk-JEFZAC2R.js +1 -0
- package/dist/stage/chunk-JFIGRDPO.js +1 -0
- package/dist/stage/chunk-JFVYBOOC.js +9 -0
- package/dist/stage/chunk-JGD4TUTQ.js +1 -0
- package/dist/stage/chunk-JO4BEHDH.js +4 -0
- package/dist/stage/chunk-JOWBS42C.js +1 -0
- package/dist/stage/chunk-JP3TM2TG.js +1 -0
- package/dist/stage/chunk-JVK2C52O.js +1 -0
- package/dist/stage/chunk-K4I76XBX.js +14 -0
- package/dist/stage/chunk-KA6CZZ4M.js +1 -0
- package/dist/stage/chunk-KESSJ36M.js +1 -0
- package/dist/stage/chunk-LKATEVRU.js +1 -0
- package/dist/stage/chunk-LS4EJ2EI.js +1 -0
- package/dist/stage/chunk-LUKJQC2X.js +70 -0
- package/dist/stage/chunk-LWULR3SM.js +1 -0
- package/dist/stage/chunk-LWVRFMKX.js +2 -0
- package/dist/stage/chunk-LXC4ZBPZ.js +1 -0
- package/dist/stage/chunk-M2UP255H.js +1 -0
- package/dist/stage/chunk-MAPPXUZQ.js +231 -0
- package/dist/stage/chunk-MBMPW7Z5.js +1 -0
- package/dist/stage/chunk-MD3HMMTK.js +1 -0
- package/dist/stage/chunk-MLPCUIKR.js +17 -0
- package/dist/stage/chunk-MNQIRPDQ.js +8 -0
- package/dist/stage/chunk-MRG7MJVS.js +1 -0
- package/dist/stage/chunk-MU6EXW72.js +10 -0
- package/dist/stage/chunk-MVU2X6LU.js +4 -0
- package/dist/stage/chunk-N6UA5CZV.js +36 -0
- package/dist/stage/chunk-NLZIT2TJ.js +7 -0
- package/dist/stage/chunk-NOJR3J7M.js +1 -0
- package/dist/stage/chunk-NT7ARDOL.js +1 -0
- package/dist/stage/chunk-NWOGMPZH.js +1 -0
- package/dist/stage/chunk-NXE4KMG3.js +40 -0
- package/dist/stage/chunk-O4YCZXD2.js +257 -0
- package/dist/stage/chunk-OAJZ7HLK.js +1 -0
- package/dist/stage/chunk-OCFCFASO.js +1 -0
- package/dist/stage/chunk-ODGPG5RY.js +7 -0
- package/dist/stage/chunk-ODUEA52Q.js +3 -0
- package/dist/stage/chunk-OGDJ3FCI.js +1 -0
- package/dist/stage/chunk-OLDJ55TT.js +1 -0
- package/dist/stage/chunk-OOCL4ATI.js +2 -0
- package/dist/stage/chunk-OQEFDUDV.js +1 -0
- package/dist/stage/chunk-OQWVEWG7.js +4 -0
- package/dist/stage/chunk-OUIX6BGK.js +1 -0
- package/dist/stage/chunk-OV7OZYUO.js +7 -0
- package/dist/stage/chunk-PFGDY33O.js +1 -0
- package/dist/stage/chunk-PFJDUJB3.js +139 -0
- package/dist/stage/chunk-PGEW76ER.js +1 -0
- package/dist/stage/chunk-PP76TAQX.js +32 -0
- package/dist/stage/chunk-PTBOP4OT.js +2 -0
- package/dist/stage/chunk-PX2RVHCK.js +1 -0
- package/dist/stage/chunk-Q7K3PNAD.js +1 -0
- package/dist/stage/chunk-QDDPLZDB.js +1 -0
- package/dist/stage/chunk-QLGLZ77F.js +1 -0
- package/dist/stage/chunk-QOPFDFHI.js +1 -0
- package/dist/stage/chunk-QXT4KAEJ.js +1 -0
- package/dist/stage/chunk-R4YVZCIT.js +1 -0
- package/dist/stage/chunk-R6P6EHWA.js +62 -0
- package/dist/stage/chunk-RCH3OXBI.js +9 -0
- package/dist/stage/chunk-RHPE44I2.js +1 -0
- package/dist/stage/chunk-RJ2R4FVC.js +1 -0
- package/dist/stage/chunk-RJH2YVTD.js +1 -0
- package/dist/stage/chunk-RLWWW5OB.js +6 -0
- package/dist/stage/chunk-S3WO35Z7.js +120 -0
- package/dist/stage/chunk-S7ZGX6MW.js +1 -0
- package/dist/stage/chunk-SIAWX27B.js +1 -0
- package/dist/stage/chunk-SLG4X622.js +1 -0
- package/dist/stage/chunk-SLJRBC77.js +168 -0
- package/dist/stage/chunk-SRORWQJZ.js +1 -0
- package/dist/stage/chunk-STZTUIIF.js +2 -0
- package/dist/stage/chunk-SVQ6MWNV.js +9 -0
- package/dist/stage/chunk-TL3HLL2S.js +132 -0
- package/dist/stage/chunk-U3DOE6SF.js +24 -0
- package/dist/stage/chunk-UABQIZKW.js +6 -0
- package/dist/stage/chunk-UDK3R764.js +1 -0
- package/dist/stage/chunk-UFF4E54B.js +41 -0
- package/dist/stage/chunk-UFP5Q4AY.js +1 -0
- package/dist/stage/chunk-UMH2TSW2.js +72 -0
- package/dist/stage/chunk-UTASVNF5.js +10 -0
- package/dist/stage/chunk-UW7ML5ML.js +88 -0
- package/dist/stage/chunk-V3J7F6OP.js +1 -0
- package/dist/stage/chunk-VEHP5B5Q.js +5 -0
- package/dist/stage/chunk-VRXWB733.js +9 -0
- package/dist/stage/chunk-VVDHBBS5.js +5 -0
- package/dist/stage/chunk-VYFOH6FU.js +106 -0
- package/dist/stage/chunk-W3VZTLQS.js +3 -0
- package/dist/stage/chunk-W7WNRWTZ.js +8 -0
- package/dist/stage/chunk-WHUCV53C.js +1 -0
- package/dist/stage/chunk-WULMYHIF.js +1 -0
- package/dist/stage/chunk-X54EX7AW.js +9 -0
- package/dist/stage/chunk-X565ISZM.js +1 -0
- package/dist/stage/chunk-XGZMDECB.js +1 -0
- package/dist/stage/chunk-XHONC4RF.js +172 -0
- package/dist/stage/chunk-XIK4XQ6E.js +24 -0
- package/dist/stage/chunk-XJQQWFTE.js +1 -0
- package/dist/stage/chunk-XM4WOU3I.js +13 -0
- package/dist/stage/chunk-XM7Y5HP5.js +38 -0
- package/dist/stage/chunk-XNYYRGD5.js +292 -0
- package/dist/stage/chunk-XOYVR3SV.js +1 -0
- package/dist/stage/chunk-XQIW5HCE.js +1 -0
- package/dist/stage/chunk-YEWL7FUW.js +8 -0
- package/dist/stage/chunk-YI55PY3V.js +1 -0
- package/dist/stage/chunk-YM63HI6W.js +1 -0
- package/dist/stage/chunk-YNLGLU4P.js +9 -0
- package/dist/stage/chunk-YTNMNOWP.js +1 -0
- package/dist/stage/chunk-YV62XKTC.js +1 -0
- package/dist/stage/chunk-YVBA3QW6.js +1 -0
- package/dist/stage/chunk-Z2SY2HOC.js +1 -0
- package/dist/stage/chunk-ZBTCQEBK.js +10 -0
- package/dist/stage/chunk-ZCUFN74D.js +1 -0
- package/dist/stage/chunk-ZHOULXEJ.js +11 -0
- package/dist/stage/chunk-ZTRZIET2.js +1 -0
- package/dist/stage/index.html +1 -0
- package/dist/stage/stage.css +1 -1
- package/dist/stage/stage.js +1 -4383
- package/dist/ui/dev/dev-page.d.ts +1 -0
- package/dist/ui/dev/dev-page.js +2021 -0
- package/dist/ui/dev/dev-theme.d.ts +6 -0
- package/dist/ui/dev/dev-theme.js +67 -0
- package/dist/ui/dev/voice-gallery-page.d.ts +1 -0
- package/dist/ui/dev/voice-gallery-page.js +121 -0
- package/dist/ui/dev/voice-scenes.d.ts +21 -0
- package/dist/ui/dev/voice-scenes.js +30 -0
- package/dist/ui/dictation/en-box.d.ts +2 -0
- package/dist/ui/dictation/en-box.js +86 -0
- package/dist/ui/dictation/en-page.d.ts +1 -0
- package/dist/ui/dictation/en-page.js +484 -0
- package/dist/ui/dictation/page.d.ts +1 -0
- package/dist/ui/dictation/page.js +1084 -0
- package/dist/ui/dictation/parent-page.d.ts +1 -0
- package/dist/ui/dictation/parent-page.js +234 -0
- package/dist/ui/dictation/reel-mode.d.ts +1 -0
- package/dist/ui/dictation/reel-mode.js +87 -0
- package/dist/ui/dictation/reel-page.d.ts +1 -0
- package/dist/ui/dictation/reel-page.js +62 -0
- package/dist/ui/dictation/reel.d.ts +163 -0
- package/dist/ui/dictation/reel.js +436 -0
- package/dist/ui/dictation/ui.d.ts +44 -0
- package/dist/ui/dictation/ui.js +80 -0
- package/dist/ui/dictation/unlock.d.ts +7 -0
- package/dist/ui/dictation/unlock.js +16 -0
- package/dist/ui/kid/audio-client.d.ts +11 -0
- package/dist/ui/kid/audio-client.js +74 -0
- package/dist/ui/kid/board-mark-art.d.ts +37 -0
- package/dist/ui/kid/board-mark-art.js +5 -0
- package/dist/ui/kid/board-mark.d.ts +24 -0
- package/dist/ui/kid/board-mark.js +58 -0
- package/dist/ui/kid/home-tiles.d.ts +14 -0
- package/dist/ui/kid/home-tiles.js +44 -0
- package/dist/ui/kid/kid-log.d.ts +15 -0
- package/dist/ui/kid/kid-log.js +87 -0
- package/dist/ui/kid/kid-nav.d.ts +11 -0
- package/dist/ui/kid/kid-nav.js +22 -0
- package/dist/ui/kid/kid-page.d.ts +9 -0
- package/dist/ui/kid/kid-page.js +3684 -0
- package/dist/ui/kid/letters.d.ts +26 -0
- package/dist/ui/kid/letters.js +51 -0
- package/dist/ui/kid/photo-edit.d.ts +83 -0
- package/dist/ui/kid/photo-edit.js +106 -0
- package/dist/ui/kid/photo-ui.d.ts +23 -0
- package/dist/ui/kid/photo-ui.js +60 -0
- package/dist/ui/kid/reel.d.ts +419 -0
- package/dist/ui/kid/reel.js +648 -0
- package/dist/ui/kid/tianzige.d.ts +8 -0
- package/dist/ui/kid/tianzige.js +45 -0
- package/dist/ui/kid/tutor-face.d.ts +35 -0
- package/dist/ui/kid/tutor-face.js +84 -0
- package/dist/ui/kid/voice-ui.d.ts +70 -0
- package/dist/ui/kid/voice-ui.js +316 -0
- package/dist/ui/kid/voice-view.d.ts +71 -0
- package/dist/ui/kid/voice-view.js +75 -0
- package/dist/ui/kid/word-draw.d.ts +2 -0
- package/dist/ui/kid/word-draw.js +107 -0
- package/dist/ui/kid/word-emoji.d.ts +10 -0
- package/dist/ui/kid/word-emoji.js +68 -0
- package/dist/ui/kid/word-layout.d.ts +25 -0
- package/dist/ui/kid/word-layout.js +29 -0
- package/dist/ui/parent/parent-home-page.d.ts +1 -0
- package/dist/ui/parent/parent-home-page.js +722 -0
- package/dist/ui/parent/parent-page.d.ts +2 -0
- package/dist/ui/parent/parent-page.js +511 -0
- package/dist/ui/parent/parent-settings-page.d.ts +1 -0
- package/dist/ui/parent/parent-settings-page.js +133 -0
- package/dist/ui/parent/qr-page.d.ts +8 -0
- package/dist/ui/parent/qr-page.js +66 -0
- package/dist/ui/shared/brand.d.ts +38 -0
- package/dist/ui/shared/brand.js +53 -0
- package/dist/ui/shared/favicon.d.ts +12 -0
- package/dist/ui/shared/favicon.js +96 -0
- package/dist/ui/shared/icon.d.ts +9 -0
- package/dist/ui/shared/icon.js +35 -0
- package/dist/ui/shared/inline-lib.d.ts +1 -0
- package/dist/ui/shared/inline-lib.js +28 -0
- package/dist/ui/shared/logo.d.ts +31 -0
- package/dist/ui/shared/logo.js +43 -0
- package/dist/ui/shared/page-dom.d.ts +12 -0
- package/dist/ui/shared/page-dom.js +36 -0
- package/dist/ui/shared/png.d.ts +1 -0
- package/dist/ui/shared/png.js +45 -0
- package/dist/ui/shared/qr-svg.d.ts +3 -0
- package/dist/ui/shared/qr-svg.js +32 -0
- package/dist/ui/shared/qr.d.ts +14 -0
- package/dist/ui/shared/qr.js +281 -0
- package/dist/ui/shared/reel-dock.d.ts +22 -0
- package/dist/ui/shared/reel-dock.js +365 -0
- package/dist/ui/shared/tutor-color.d.ts +15 -0
- package/dist/ui/shared/tutor-color.js +47 -0
- package/dist/ui/talk/page.d.ts +6 -0
- package/dist/ui/talk/page.js +294 -0
- package/grades/grade-2/README.md +11 -0
- package/grades/grade-2/VALIDATION.md +41 -0
- package/grades/grade-2/agents/chinese-tutor/activities//344/275/240/350/257/264/346/210/221/347/224/273.md +157 -0
- package/grades/grade-2/agents/chinese-tutor/activities//344/275/240/350/257/264/346/210/221/347/224/273./344/276/213/345/255/220.md +78 -0
- package/grades/grade-2/agents/chinese-tutor/activities//344/276/213/345/255/220/345/233/276//345/200/237/344/274/236.jpg +0 -0
- package/grades/grade-2/agents/chinese-tutor/activities//344/276/213/345/255/220/345/233/276//345/260/217/347/214/264/346/221/230/346/241/203.jpg +0 -0
- package/grades/grade-2/agents/chinese-tutor/activities//345/206/231/350/257/235.md +64 -0
- package/grades/grade-2/agents/chinese-tutor/activities//345/206/231/350/257/235./344/276/213/345/255/220.md +31 -0
- package/grades/grade-2/agents/chinese-tutor/activities//345/220/254/345/206/231.md +48 -0
- package/grades/grade-2/agents/chinese-tutor/activities//345/244/215/344/271/240.md +79 -0
- package/grades/grade-2/agents/chinese-tutor/activities//345/244/215/344/271/240./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/chinese-tutor/activities//345/260/217/350/257/276/345/240/202.md +53 -0
- package/grades/grade-2/agents/chinese-tutor/activities//346/243/200/346/237/245/344/275/234/344/270/232.md +81 -0
- package/grades/grade-2/agents/chinese-tutor/activities//346/243/200/346/237/245/344/275/234/344/270/232./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/chinese-tutor/activities//347/234/213/345/233/276/350/257/264/350/257/235.md +94 -0
- package/grades/grade-2/agents/chinese-tutor/activities//347/234/213/345/233/276/350/257/264/350/257/235./344/276/213/345/255/220.md +63 -0
- package/grades/grade-2/agents/chinese-tutor/activities//351/242/204/344/271/240.md +82 -0
- package/grades/grade-2/agents/chinese-tutor/activities//351/242/204/344/271/240./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/chinese-tutor.md +59 -0
- package/grades/grade-2/agents/english-tutor/activities//345/217/243/350/257/255/350/257/276.md +149 -0
- package/grades/grade-2/agents/english-tutor/activities//345/217/243/350/257/255/350/257/276./344/276/213/345/255/220.md +13 -0
- package/grades/grade-2/agents/english-tutor/activities//345/220/254/345/206/231.md +47 -0
- package/grades/grade-2/agents/english-tutor/activities//345/244/215/344/271/240.md +78 -0
- package/grades/grade-2/agents/english-tutor/activities//345/244/215/344/271/240./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/english-tutor/activities//345/260/217/350/257/276/345/240/202.md +53 -0
- package/grades/grade-2/agents/english-tutor/activities//346/243/200/346/237/245/344/275/234/344/270/232.md +80 -0
- package/grades/grade-2/agents/english-tutor/activities//346/243/200/346/237/245/344/275/234/344/270/232./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/english-tutor/activities//351/242/204/344/271/240.md +86 -0
- package/grades/grade-2/agents/english-tutor/activities//351/242/204/344/271/240./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/english-tutor.md +57 -0
- package/grades/grade-2/agents/math-tutor/activities//345/244/215/344/271/240.md +78 -0
- package/grades/grade-2/agents/math-tutor/activities//345/244/215/344/271/240./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/math-tutor/activities//345/260/217/350/257/276/345/240/202.md +56 -0
- package/grades/grade-2/agents/math-tutor/activities//345/260/217/350/257/276/345/240/202./344/276/213/345/255/220.md +52 -0
- package/grades/grade-2/agents/math-tutor/activities//346/243/200/346/237/245/344/275/234/344/270/232.md +80 -0
- package/grades/grade-2/agents/math-tutor/activities//346/243/200/346/237/245/344/275/234/344/270/232./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/math-tutor/activities//351/242/204/344/271/240.md +81 -0
- package/grades/grade-2/agents/math-tutor/activities//351/242/204/344/271/240./344/276/213/345/255/220.md +35 -0
- package/grades/grade-2/agents/math-tutor.md +51 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/audio/index.json +44 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/audio/step-1.mp3 +0 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/audio/step-2.mp3 +0 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/audio/step-3.mp3 +0 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/audio/step-4.mp3 +0 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/audio/step-5.mp3 +0 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/bake.json +1 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/manifest.json +63 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen/scene.json +247 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen.md +40 -0
- package/grades/grade-2/examples/2026-10-27-pingjunfen.ts +26 -0
- package/grades/grade-2/examples//345/271/263/345/235/207/345/210/206./344/276/213/345/255/220.md +24 -0
- package/grades/grade-2/examples//346/225/260/345/255/246/345/271/263/345/235/207/345/210/206.md +42 -0
- package/grades/grade-2/validation/2026-10-27.json +4410 -0
- package/package.json +27 -15
- package/skills/chalk-cli/SKILL.md +62 -0
- package/skills/chalk-scene/SKILL.md +91 -0
- package/skills/chalk-teaching/SKILL.md +82 -0
- package/skills/chalk-teaching/models//344/272/244/351/224/231/346/225/260/345/210/227/345/210/206/350/241/214.md +8 -0
- package/skills/chalk-teaching/models//345/207/221/345/215/201.md +7 -0
- package/skills/chalk-teaching/models//345/221/250/346/234/237/350/247/204/345/276/213.md +6 -0
- package/skills/chalk-teaching/models//345/256/236/347/211/251/345/233/276-/345/242/236/345/207/217.md +6 -0
- package/skills/chalk-teaching/models//345/256/236/347/211/251/345/233/276-/346/257/224/345/244/232/345/260/221-/346/261/202/345/244/247/346/225/260/346/261/202/345/260/217/346/225/260.md +7 -0
- package/skills/chalk-teaching/models//345/256/236/347/211/251/345/233/276-/346/257/224/345/244/232/345/260/221-/346/261/202/345/267/256.md +6 -0
- package/skills/chalk-teaching/models//345/260/217/346/243/222/350/277/233/344/275/215/345/212/240.md +7 -0
- package/skills/chalk-teaching/models//345/260/217/346/243/222/351/200/200/344/275/215/345/207/217.md +6 -0
- package/skills/chalk-teaching/models//346/216/222/351/230/237/347/202/271/351/230/265.md +7 -0
- package/skills/chalk-teaching/models//346/227/266/351/227/264/346/225/260/350/275/264.md +6 -0
- package/skills/chalk-teaching/models//346/245/274/345/261/202/351/227/264/351/232/224/345/233/276.md +7 -0
- package/skills/chalk-teaching/models//347/240/264/345/215/201.md +7 -0
- package/skills/chalk-teaching/models//347/253/226/345/274/217/351/200/200/344/275/215.md +6 -0
- package/skills/chalk-teaching/models//347/272/277/346/256/265/345/233/276.md +7 -0
- package/skills/chalk-teaching/models-index.md +24 -0
- package/skills/chalk-teaching/references//350/256/262/350/247/243/346/250/241/346/235/277/344/270/211/346/241/243.md +32 -0
- package/skills/chalk-teaching/references//350/257/264/346/230/216/346/226/207/344/273/266.md +102 -0
- package/skills/chalk-verify/SKILL.md +57 -0
- package/skills/chalk-verify/references//350/257/204/345/210/244/346/240/207/345/207/206.md +69 -0
- package/skills/cotutor-analyze/SKILL.md +106 -0
- package/skills/cotutor-analyze/references//345/221/275/344/273/244/344/270/216/346/226/207/344/273/266.md +31 -0
- package/skills/cotutor-board/SKILL.md +373 -0
- package/skills/cotutor-board/references/README.md +38 -0
- package/skills/cotutor-board/references/canvas.md +68 -0
- package/skills/cotutor-board/references/choice.md +55 -0
- package/skills/cotutor-board/references/code.md +46 -0
- package/skills/cotutor-board/references/image.md +52 -0
- package/skills/cotutor-board/references/lecture.md +69 -0
- package/skills/cotutor-board/references/paint.md +77 -0
- package/skills/cotutor-board/references/photo.md +61 -0
- package/skills/cotutor-board/references/read.md +51 -0
- package/skills/cotutor-board/references/text.md +69 -0
- package/skills/cotutor-board/references/tianzige.md +78 -0
- package/skills/cotutor-board/references/word.md +91 -0
- package/skills/cotutor-home/SKILL.md +170 -0
- package/skills/cotutor-home/references/dictation.md +97 -0
- package/skills/cotutor-home/references/tutor.md +149 -0
- package/skills/cotutor-home/references//345/221/275/344/273/244.md +21 -0
- package/skills/cotutor-home/references//351/246/226/351/241/265/350/257/255/346/263/225.md +143 -0
- package/skills/cotutor-tune/SKILL.md +147 -0
- package/skills/cotutor-tune/references//345/255/227/346/256/265.md +53 -0
- package/skills/cotutor-tutor/SKILL.md +253 -0
- package/skills/cotutor-tutor/references//344/270/212/344/270/213/346/226/207/345/214/205.md +78 -0
- package/themes/default/kid.css +86 -0
- package/themes/default/theme.json +26 -0
- package/agents/chinese-tutor.md +0 -67
- package/agents/homework-tutor.md +0 -17
- package/agents/math-tutor.md +0 -68
- package/agents/planner.md +0 -18
- package/agents/reading-tutor.md +0 -65
- package/agents/scene-maker.md +0 -41
- package/dist/cards/canvas.d.ts +0 -22
- package/dist/cards/canvas.js +0 -65
- package/dist/cards/fill.d.ts +0 -14
- package/dist/cards/fill.js +0 -64
- package/dist/cards/index.d.ts +0 -48
- package/dist/cards/index.js +0 -115
- package/dist/cards/kind.js +0 -7
- package/dist/cards/scene.d.ts +0 -24
- package/dist/cards/scene.js +0 -67
- package/dist/cards/text.d.ts +0 -18
- package/dist/cards/text.js +0 -41
- package/dist/cli/cert.d.ts +0 -7
- package/dist/cli/cert.js +0 -36
- package/dist/cli/doctor.d.ts +0 -22
- package/dist/cli/doctor.js +0 -355
- package/dist/cli/init.js +0 -116
- package/dist/cli/main.js +0 -243
- package/dist/cli/serve.d.ts +0 -30
- package/dist/cli/serve.js +0 -56
- package/dist/cli/skeleton.d.ts +0 -39
- package/dist/cli/skeleton.js +0 -184
- package/dist/cli/skills.d.ts +0 -40
- package/dist/cli/skills.js +0 -170
- package/dist/cli/workspace.d.ts +0 -69
- package/dist/lib/agent-file.d.ts +0 -10
- package/dist/lib/agent-file.js +0 -16
- package/dist/lib/board.d.ts +0 -15
- package/dist/lib/board.js +0 -107
- package/dist/lib/context-pack.js +0 -55
- package/dist/lib/conversation.js +0 -88
- package/dist/lib/kid-board.d.ts +0 -148
- package/dist/lib/kid-board.js +0 -294
- package/dist/lib/kid-view.d.ts +0 -63
- package/dist/lib/kid-view.js +0 -93
- package/dist/lib/ledger.d.ts +0 -29
- package/dist/lib/run-plan.d.ts +0 -30
- package/dist/lib/run-plan.js +0 -32
- package/dist/lib/sections.d.ts +0 -12
- package/dist/lib/sections.js +0 -151
- package/dist/lib/stream.d.ts +0 -15
- package/dist/lib/stream.js +0 -69
- package/dist/lib/transcript.d.ts +0 -36
- package/dist/lib/transcript.js +0 -95
- package/dist/server/app.d.ts +0 -74
- package/dist/server/app.js +0 -406
- package/dist/server/kid-page.d.ts +0 -1
- package/dist/server/kid-page.js +0 -768
- package/dist/server/mock.js +0 -403
- package/dist/server/parent-page.d.ts +0 -8
- package/dist/server/parent-page.js +0 -393
- package/dist/server/runner.d.ts +0 -64
- package/dist/server/runner.js +0 -277
- package/dist/server/scene-props.d.ts +0 -16
- package/dist/server/scene-props.js +0 -39
- package/dist/server/store.d.ts +0 -43
- package/dist/server/store.js +0 -210
- package/dist/server/tts.d.ts +0 -51
- package/dist/server/tts.js +0 -99
- /package/dist/{cli → app/cli}/main.d.ts +0 -0
- /package/dist/{cards → board/cards}/choice.d.ts +0 -0
- /package/dist/{cards → board/cards}/code.d.ts +0 -0
- /package/dist/{cards → board/cards}/image.d.ts +0 -0
- /package/dist/{cards → board/cards}/read.d.ts +0 -0
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 服务的路由层:route(method, path, ctx, body) → {status, json|html},测试不用起端口。
|
|
3
|
+
* R1 的查询接口照旧;R2 加:对话(列日期、看一天的家长视图、发消息)、cotutor.json 补丁(老师团页)、工作台 /dev(2026-09-22 之前叫家长页 /parent;
|
|
4
|
+
* 现在 /parent 是家长端 = 家长板书页,给不懂技术的家长日常用)。
|
|
5
|
+
* R3 加:孩子端 `/`(kidPage)与 /api/kid/*(首页:课程表 + 老师卡 + 家长发布的首页卡;对话:服务端过滤后的孩子视图;发消息:from 固定 kid)、配音文件 /api/audio。
|
|
6
|
+
* 配置热重载:每个请求先读一遍 cotutor.json,原文变了就重读(不比修改时间,Windows 上连写两次常常一样);改坏了留旧配置并把错误挂在 /api/health 上。
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
9
|
+
import { appendFile, mkdir, readFile, readdir, stat } from 'node:fs/promises';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { foldRuns } from "../../brain/transcript.js";
|
|
12
|
+
import { RuntimeError } from "../../brain/index.js";
|
|
13
|
+
import { PHOTO_MAX_SIDE } from "../../ui/kid/photo-edit.js";
|
|
14
|
+
import { currentThread, lastJobOf, sameRuntime } from "../../runtime/journal/conversation.js";
|
|
15
|
+
import { localDate, weekOf } from "../../shared/time.js";
|
|
16
|
+
import { conversationFiles, threads } from "../../schema/index.js";
|
|
17
|
+
import { kidConversation, kidThreads, submittedCards, parentConversation } from "../../runtime/kid-view.js";
|
|
18
|
+
import { parseEvents } from "../../runtime/journal/events.js";
|
|
19
|
+
import {} from "../../schema/index.js";
|
|
20
|
+
import { NEUTRAL_COLOR, SUBJECT_COLORS, TUTOR_PALETTE, tutorColors } from "../../ui/shared/tutor-color.js";
|
|
21
|
+
import { boardMarkOf } from "../../ui/kid/board-mark.js";
|
|
22
|
+
import { buildReel, playRecordOk, reelCardTook, reelHolds, reelMissRuns } from "../../ui/kid/reel.js";
|
|
23
|
+
import { DATE_RE, FocusSchema, MESSAGE_FROM, listTutors, subjectLang, viaSendsLabel } from "../../schema/index.js";
|
|
24
|
+
import { ConfigError, patchConfig, reloadIfChanged, workspaceReport } from "../workspace.js";
|
|
25
|
+
import { UsageError } from "../../shared/errors.js";
|
|
26
|
+
import { redactHome } from "../../shared/home.js";
|
|
27
|
+
import { tutorStatuses } from "../cli/tutors.js";
|
|
28
|
+
import { configGapsOf, upgradeConfig } from "../cli/migrate.js";
|
|
29
|
+
import { ICON_SIZES, appIconPng, webManifest } from "../../ui/shared/icon.js";
|
|
30
|
+
import { faviconResponse } from "../../ui/shared/favicon.js";
|
|
31
|
+
import { cookieOf, createAccess, gatePage, isKidPath } from "./access.js";
|
|
32
|
+
import { factoryAvatarFile, shownAvatar } from "./avatars.js";
|
|
33
|
+
import { deviceCookie, newDeviceId, parseKidLog, readDevices, recordKidLog, renameDevice, validDevice } from "../../runtime/journal/kid-log.js";
|
|
34
|
+
import { DEVICE_COOKIE } from "../../schema/kid-device.js";
|
|
35
|
+
import { BUILD, codeChanged, headNow, shortCommit } from "../build.js";
|
|
36
|
+
import { qrPage } from "../../ui/parent/qr-page.js";
|
|
37
|
+
import { kidPage } from "../../ui/kid/kid-page.js";
|
|
38
|
+
import { parentPage } from "../../ui/parent/parent-page.js";
|
|
39
|
+
import { kidHomeView } from "../../runtime/home/store.js";
|
|
40
|
+
import { photosOf } from "../../runtime/kid-input.js";
|
|
41
|
+
import { DEV_PAGE } from "../../ui/dev/dev-page.js";
|
|
42
|
+
import { devOverview } from "./dev-overview.js";
|
|
43
|
+
import { ActivityConflict, checkDevActivity, findDevActivity, listDevActivities, readDevActivity, restoreDevActivity, saveDevActivity } from "./dev-activities.js";
|
|
44
|
+
import { checkDevTutorFile, hasDevTutorFile, listDevTutorFiles, readDevTutorFile, restoreDevTutorFile, saveDevTutorFile } from "./dev-tutor-files.js";
|
|
45
|
+
import { doctorWorkspace } from "../cli/doctor.js";
|
|
46
|
+
import { VOICE_GALLERY_PAGE } from "../../ui/dev/voice-gallery-page.js";
|
|
47
|
+
import { BusyError, Runner } from "../../runtime/runner.js";
|
|
48
|
+
import { sendFile } from "./send-file.js";
|
|
49
|
+
import { talkRoute } from "../talk/route.js";
|
|
50
|
+
import { parentHomeRoute } from "./parent-home.js";
|
|
51
|
+
import { parentLookRoute } from "./parent-look.js";
|
|
52
|
+
import { bailianRoute, createBailian } from "../machine/bailian.js";
|
|
53
|
+
import { PARENT_HOME_PAGE } from "../../ui/parent/parent-home-page.js";
|
|
54
|
+
import { PARENT_SETTINGS_PAGE } from "../../ui/parent/parent-settings-page.js";
|
|
55
|
+
import { dictationRoute } from "../dictation/route.js";
|
|
56
|
+
import { IndexError, capturePathOk, deleteThread, listDates, rateThread, readErrLog, readIndex, readTranscript, scanCards, undoVaultWrite, writeCapture, writeCardImage, writeCardState } from "../../runtime/journal/store.js";
|
|
57
|
+
import { memoryLineText } from "../../memory/vault-notes.js";
|
|
58
|
+
import { childItem } from "../../memory/proposals.js";
|
|
59
|
+
import { IMAGE_EXT, parseCardState, stripSecrets } from "../../board/cards/index.js";
|
|
60
|
+
import { isAbsolute, resolve, sep } from 'node:path';
|
|
61
|
+
import { bundleAsset, stageAsset, stageIndex, stageVersion } from "./stage.js";
|
|
62
|
+
import { themeFiles } from "./theme.js";
|
|
63
|
+
import { enrichPaints } from "../../scenes/paint/painter.js";
|
|
64
|
+
import { enrichLectures, inspectLecture, bakeSectionSoon, ensureBaked, lectureFrameSvg, parseRing, parseSvgMs } from "../../runtime/lecture.js";
|
|
65
|
+
import { tianzigeData } from "../../ui/kid/tianzige.js";
|
|
66
|
+
import { lettersData } from "../../ui/kid/letters.js";
|
|
67
|
+
import { fixtureOf, rawView } from "./raw-view.js";
|
|
68
|
+
import { DeviceSchema } from "../../schema/index.js";
|
|
69
|
+
import { CanvasStateSchema } from "../../board/cards/canvas.js";
|
|
70
|
+
import { PAPER_KEY_RE, dropPaper, readPaper, writePaper } from "../../board/paper.js";
|
|
71
|
+
import { addTutorFile, readTutorFile, removeTutorFile, writeTutorFile } from "../cli/tutors.js";
|
|
72
|
+
export function createContext(ws, opts = {}) {
|
|
73
|
+
let configText = null;
|
|
74
|
+
const ctx = {
|
|
75
|
+
ws,
|
|
76
|
+
runner: new Runner(() => ctx.ws, opts),
|
|
77
|
+
now: opts.now ?? (() => new Date()),
|
|
78
|
+
configError: null,
|
|
79
|
+
listen: null,
|
|
80
|
+
openCalls: null,
|
|
81
|
+
access: opts.access ?? createAccess({ now: () => ctx.now() }),
|
|
82
|
+
bailian: opts.bailian ?? createBailian({ env: opts.env }),
|
|
83
|
+
async reload() {
|
|
84
|
+
try {
|
|
85
|
+
const r = await reloadIfChanged(ctx.ws, configText);
|
|
86
|
+
ctx.ws = r.ws;
|
|
87
|
+
configText = r.text;
|
|
88
|
+
ctx.configError = null;
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
if (!(err instanceof ConfigError))
|
|
92
|
+
throw err;
|
|
93
|
+
ctx.configError = err.message;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
return ctx;
|
|
98
|
+
}
|
|
99
|
+
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c] ?? c);
|
|
100
|
+
export async function dayView(ctx, tutor, date) {
|
|
101
|
+
const index = await readIndex(ctx.ws, tutor, date);
|
|
102
|
+
const runs = {};
|
|
103
|
+
const errors = {};
|
|
104
|
+
for (const m of index.messages) {
|
|
105
|
+
const t = await readTranscript(ctx.ws, tutor, date, m.job);
|
|
106
|
+
runs[m.job] = t ? foldRuns(t.items) : [];
|
|
107
|
+
if (m.result === 'error') {
|
|
108
|
+
const tail = (await readErrLog(ctx.ws, tutor, date, m.job)).trim().split('\n').slice(-5).join('\n');
|
|
109
|
+
if (tail)
|
|
110
|
+
errors[m.job] = tail;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const active = ctx.runner.running(tutor);
|
|
114
|
+
return { index, running: active && active.date === date ? active.job : null, runs, errors };
|
|
115
|
+
}
|
|
116
|
+
const isObj = (v) => Boolean(v) && typeof v === 'object' && !Array.isArray(v);
|
|
117
|
+
export async function kidTutors(ctx) {
|
|
118
|
+
const out = [];
|
|
119
|
+
const colors = tutorColors(ctx.ws.config.tutors);
|
|
120
|
+
for (const t of listTutors(ctx.ws.config, { kidOnly: true })) {
|
|
121
|
+
out.push({ name: t.name, display: t.display, avatar: shownAvatar(t), subject: t.subject ?? null, color: colors[t.name], mark: boardMarkOf(t.subject), lang: subjectLang(t.subject), hasVoice: Boolean(t.voice), extras: t.extras.filter((x) => (x !== 'talk' || ctx.ws.config.talk.enabled)), listen: ctx.ws.config.live.listen });
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
export async function kidHome(ctx, now) {
|
|
126
|
+
const ws = ctx.ws;
|
|
127
|
+
const date = localDate(now);
|
|
128
|
+
const view = await kidHomeView(ws, now);
|
|
129
|
+
const figshot = ws.config.figshot ? { port: ws.config.figshot.port } : null;
|
|
130
|
+
return { title: ws.config.title, date, tutors: await kidTutors(ctx), home: view.home, cards: view.cards, figshot, hand: ws.config.kid.hand ?? 'right', ready: ctx.bailian.status().ready };
|
|
131
|
+
}
|
|
132
|
+
export async function kidHistory(ctx, tutor, days) {
|
|
133
|
+
const today = localDate(ctx.now());
|
|
134
|
+
const floor = localDate(new Date(ctx.now().getTime() - (days - 1) * 86400000));
|
|
135
|
+
const dates = (await listDates(ctx.ws, tutor)).filter((d) => d >= floor && d <= today).sort().reverse();
|
|
136
|
+
const out = [];
|
|
137
|
+
for (const date of dates) {
|
|
138
|
+
const index = await readIndex(ctx.ws, tutor, date);
|
|
139
|
+
const list = kidThreads(kidConversation(index)).reverse();
|
|
140
|
+
if (list.length)
|
|
141
|
+
out.push({ date, threads: list });
|
|
142
|
+
}
|
|
143
|
+
return { tutor, today, days: out };
|
|
144
|
+
}
|
|
145
|
+
export async function kidDay(ctx, tutor, date) {
|
|
146
|
+
const index = await readIndex(ctx.ws, tutor, date);
|
|
147
|
+
const active = ctx.runner.running(tutor);
|
|
148
|
+
const { states, assets } = await scanCards(ctx.ws, tutor, date);
|
|
149
|
+
const messages = kidConversation(index, states, assets);
|
|
150
|
+
// 流式:正在回的那条带上已经出来的板书(partial),卡随围栏闭合逐张出现;答案照样剥
|
|
151
|
+
const partial = active && active.date === date ? ctx.runner.partial(tutor) : null;
|
|
152
|
+
if (partial) {
|
|
153
|
+
const m = messages.find((x) => x.job === active.job);
|
|
154
|
+
if (m)
|
|
155
|
+
m.section = stripSecrets(partial);
|
|
156
|
+
}
|
|
157
|
+
// 小课堂卡:课读不读得出、那一段的起止,每次现读
|
|
158
|
+
for (const m of messages)
|
|
159
|
+
if (m.section) {
|
|
160
|
+
bakeSectionSoon(ctx.ws.dirs.bundles, m.section);
|
|
161
|
+
m.section = await enrichPaints(ctx.ws, tutor, date, m.job, m.at, await enrichLectures(ctx.ws, m.section));
|
|
162
|
+
}
|
|
163
|
+
return { tutor, date, messages, pending: active && active.date === date ? active.job : null, thread: currentThread(index) };
|
|
164
|
+
}
|
|
165
|
+
export async function parentDay(ctx, tutor, date) {
|
|
166
|
+
const index = await readIndex(ctx.ws, tutor, date);
|
|
167
|
+
const active = ctx.runner.running(tutor);
|
|
168
|
+
const { states, assets } = await scanCards(ctx.ws, tutor, date);
|
|
169
|
+
const messages = parentConversation(index, states, assets);
|
|
170
|
+
const partial = active && active.date === date ? ctx.runner.partial(tutor) : null;
|
|
171
|
+
if (partial) {
|
|
172
|
+
const m = messages.find((x) => x.job === active.job);
|
|
173
|
+
if (m)
|
|
174
|
+
m.section = partial;
|
|
175
|
+
}
|
|
176
|
+
for (const m of messages)
|
|
177
|
+
if (m.section) {
|
|
178
|
+
bakeSectionSoon(ctx.ws.dirs.bundles, m.section);
|
|
179
|
+
m.section = await enrichPaints(ctx.ws, tutor, date, m.job, m.at, await enrichLectures(ctx.ws, m.section), { parent: true });
|
|
180
|
+
}
|
|
181
|
+
// 「做了」旁注带上孩子在弹窗里想了多久、改过几次(有实录才有):这张卡从同一话题上一条消息到这条之间的弹窗
|
|
182
|
+
const plays = await readPlays(ctx.ws, tutor, date);
|
|
183
|
+
if (plays.length) {
|
|
184
|
+
const th = threads(index.messages);
|
|
185
|
+
const at = (m) => Date.parse(m.timing?.startedAt ?? '') || Date.parse(m.at);
|
|
186
|
+
for (const pm of messages) {
|
|
187
|
+
if (!pm.cards?.length)
|
|
188
|
+
continue;
|
|
189
|
+
const i = index.messages.findIndex((x) => x.job === pm.job);
|
|
190
|
+
if (i < 0)
|
|
191
|
+
continue;
|
|
192
|
+
const prev = index.messages.slice(0, i).reverse().find((_x, k) => th[i - 1 - k] === th[i]);
|
|
193
|
+
const [from, to] = [prev ? at(prev) : -Infinity, at(index.messages[i])];
|
|
194
|
+
pm.cards = pm.cards.map((c) => { const [job, n] = c.card.split('/'); const took = reelCardTook(plays, job, Number(n), from, to); return took ? { ...c, took } : c; });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return { tutor, date, messages, pending: active && active.date === date ? active.job : null, thread: currentThread(index) };
|
|
198
|
+
}
|
|
199
|
+
/** 一天里各轮的实录(<日期>.<job>.play.jsonl;jobs 给了就只读这几轮),合在一起按时刻排;坏行丢掉 */
|
|
200
|
+
async function readPlays(ws, tutor, date, jobs) {
|
|
201
|
+
const dir = join(ws.dirs.conversations, tutor);
|
|
202
|
+
const out = [];
|
|
203
|
+
const names = await readdir(dir).catch(() => []);
|
|
204
|
+
for (const name of names) {
|
|
205
|
+
const m = new RegExp(`^${date}\\.(\\d{4}-\\d+)\\.play\\.jsonl$`).exec(name);
|
|
206
|
+
if (!m || (jobs && !jobs.has(m[1])))
|
|
207
|
+
continue;
|
|
208
|
+
const text = await readFile(join(dir, name), 'utf8').catch(() => '');
|
|
209
|
+
for (const line of text.split('\n')) {
|
|
210
|
+
if (!line.trim())
|
|
211
|
+
continue;
|
|
212
|
+
try {
|
|
213
|
+
const r = JSON.parse(line);
|
|
214
|
+
if (playRecordOk(r))
|
|
215
|
+
out.push(r);
|
|
216
|
+
}
|
|
217
|
+
catch { /* 坏行丢掉 */ }
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return out.sort((a, b) => a.at - b.at);
|
|
221
|
+
}
|
|
222
|
+
export async function parentReel(ctx, tutor, date, thread) {
|
|
223
|
+
const index = await readIndex(ctx.ws, tutor, date);
|
|
224
|
+
const ths = threads(index.messages);
|
|
225
|
+
const mine = index.messages.filter((_m, i) => ths[i] === thread);
|
|
226
|
+
if (!mine.length)
|
|
227
|
+
return null;
|
|
228
|
+
const files = conversationFiles(ctx.ws.dirs.conversations, tutor, date);
|
|
229
|
+
const events = {};
|
|
230
|
+
for (const m of mine) {
|
|
231
|
+
const text = await readFile(files.events(m.job), 'utf8').catch(() => null);
|
|
232
|
+
if (text !== null)
|
|
233
|
+
events[m.job] = parseEvents(text);
|
|
234
|
+
}
|
|
235
|
+
const { states } = await scanCards(ctx.ws, tutor, date);
|
|
236
|
+
const jobs = new Set(mine.map((m) => m.job));
|
|
237
|
+
const cards = Object.fromEntries(Object.entries(states).filter(([job]) => jobs.has(job)));
|
|
238
|
+
const plays = await readPlays(ctx.ws, tutor, date, jobs);
|
|
239
|
+
const calls = mine.some((m) => m.live) ? await liveCalls(ctx, tutor, date, jobs) : [];
|
|
240
|
+
const reel = buildReel({ messages: mine, events, cards, now: ctx.now().getTime(), plays, calls });
|
|
241
|
+
if (!reel)
|
|
242
|
+
return null;
|
|
243
|
+
const day = await parentDay(ctx, tutor, date);
|
|
244
|
+
const kid = await kidDay(ctx, tutor, date);
|
|
245
|
+
const device = [...mine].reverse().find((m) => m.device)?.device ?? null;
|
|
246
|
+
const t = ctx.ws.config.tutors[tutor];
|
|
247
|
+
const face = { name: tutor, display: t?.display ?? tutor, avatar: t ? shownAvatar(t) : null, subject: t?.subject ?? null, color: tutorColors(ctx.ws.config.tutors)[tutor] ?? NEUTRAL_COLOR, mark: boardMarkOf(t?.subject) };
|
|
248
|
+
const live = date === localDate(ctx.now()) || mine.some((m) => m.result === 'running');
|
|
249
|
+
return { tutor, date, thread, reel, messages: day.messages.filter((m) => m.thread === thread), kid: kid.messages.filter((m) => m.thread === thread), device, face, live, realtime: mine.some((m) => m.live) };
|
|
250
|
+
}
|
|
251
|
+
/** 这一天实时老师的通话录像(<日期>.live/<时分秒>.reel.json,src/runtime/live/call.ts 落的)里有这几轮的;声音是同名的 .wav。坏的、没声音的跳过 */
|
|
252
|
+
async function liveCalls(ctx, tutor, date, jobs) {
|
|
253
|
+
const dir = join(ctx.ws.dirs.conversations, tutor, `${date}.live`);
|
|
254
|
+
const out = [];
|
|
255
|
+
for (const f of (await readdir(dir).catch(() => [])).filter((x) => /^\d{6}\.reel\.json$/.test(x)).sort()) {
|
|
256
|
+
const r = await readFile(join(dir, f), 'utf8').then((t) => JSON.parse(t), () => null);
|
|
257
|
+
const startAt = Date.parse(r?.startedAt ?? '');
|
|
258
|
+
if (!r || !Array.isArray(r.msgs) || !Array.isArray(r.playing) || Number.isNaN(startAt))
|
|
259
|
+
continue;
|
|
260
|
+
if (!r.msgs.some((x) => Array.isArray(x) && x[1] === 'o' && x[2]?.t === 'turn' && jobs.has(String(x[2].job))))
|
|
261
|
+
continue;
|
|
262
|
+
const wav = f.replace(/\.reel\.json$/, '.wav');
|
|
263
|
+
if (!existsSync(join(dir, wav)))
|
|
264
|
+
continue;
|
|
265
|
+
out.push({ audio: `${date}.live/${wav}`, startAt, msgs: r.msgs, playing: r.playing });
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* 一轮写进 vault 的每一笔,给家长过目(2026-10-30):记忆的行(memoryLines)、孩子的记忆的行(childLines)、日记那段(diaryBlock)。
|
|
271
|
+
* quote = 那一行对上了的孩子原话(这一轮的 memoryProposals 里核对过的那条)
|
|
272
|
+
*/
|
|
273
|
+
function vaultWrites(m) {
|
|
274
|
+
const verified = (m.memoryProposals ?? []).filter((p) => p.check === 'verified' && p.quote);
|
|
275
|
+
const quoteOf = (text, child) => verified.find((p) => {
|
|
276
|
+
const item = child ? childItem(p.item) : p.item;
|
|
277
|
+
return item === text || item.replace(/\s*(?:→|->)\s*/, ' → ').endsWith(` → ${text.replace(/^改:.*? → /, '')}`);
|
|
278
|
+
})?.quote;
|
|
279
|
+
const lines = (kind, ls) => (ls ?? []).map((l, n) => {
|
|
280
|
+
const text = memoryLineText(l);
|
|
281
|
+
const quote = quoteOf(text, kind === 'child');
|
|
282
|
+
return { job: m.job, kind, n, text: kind === 'child' ? `孩子的记忆:${text}` : text, ...(quote ? { quote } : {}) };
|
|
283
|
+
});
|
|
284
|
+
const diary = m.diaryBlock ? [{ job: m.job, kind: 'diary', n: 0, text: `日记:${m.diaryBlock.split('\n')[0].replace(/^##\s*/, '')}` }] : [];
|
|
285
|
+
return [...lines('memory', m.memoryLines), ...lines('child', m.childLines), ...diary];
|
|
286
|
+
}
|
|
287
|
+
export async function overview(ctx, date) {
|
|
288
|
+
const tutors = [];
|
|
289
|
+
const colors = tutorColors(ctx.ws.config.tutors);
|
|
290
|
+
for (const t of listTutors(ctx.ws.config, { kidOnly: true })) {
|
|
291
|
+
const index = await readIndex(ctx.ws, t.name, date);
|
|
292
|
+
const ths = threads(index.messages);
|
|
293
|
+
const by = new Map();
|
|
294
|
+
const diaries = [];
|
|
295
|
+
for (const [i, m] of index.messages.entries()) {
|
|
296
|
+
// 记账那轮不算一节,写进日记的那段挂回它记的话题
|
|
297
|
+
if (m.bookkeep && m.diaryBlock)
|
|
298
|
+
diaries.push({ id: ths[i], m });
|
|
299
|
+
if (m.bookkeep || m.tidy)
|
|
300
|
+
continue;
|
|
301
|
+
const id = ths[i];
|
|
302
|
+
let th = by.get(id);
|
|
303
|
+
if (!th) {
|
|
304
|
+
const via = m.via?.label ?? null;
|
|
305
|
+
const raw = via ? `首页 · ${via}` : m.from === 'kid' ? m.text : `系统:${m.text}`;
|
|
306
|
+
const b = m.via?.button;
|
|
307
|
+
const kind = m.from === 'system' ? 'system' : m.lecture ? 'lecture' : m.continues ? 'continue' : m.activity ? 'activity' : typeof b === 'number' ? 'start' : 'new';
|
|
308
|
+
th = { thread: id, at: m.at, title: Array.from(raw.trim()).slice(0, 20).join(''), from: m.from, via, start: { kind, label: kind === 'new' ? '新话题' : (via ?? m.lecture?.title ?? '') }, said: null, endAt: null, notes: [], remembered: [], writes: [], sections: 0, cards: 0, stoppedAt: null, rating: index.ratings[id] ?? null, booked: id in index.booked };
|
|
309
|
+
by.set(id, th);
|
|
310
|
+
}
|
|
311
|
+
if (m.lecture && !th.lecture)
|
|
312
|
+
th.lecture = { bundle: m.lecture.bundle, title: m.lecture.title, ...(m.lecture.video ? { video: true } : {}), watchedMs: m.lecture.watchedMs, finished: m.lecture.finished, marks: (m.lecture.marks ?? []).length };
|
|
313
|
+
// 孩子自己说的第一句:首页开场 / 接着按钮发出去的那句(正文就是按钮上的字)不算
|
|
314
|
+
if (th.said === null && m.from === 'kid' && m.text.trim() && !(m.via && viaSendsLabel(m.via) && m.via.label === m.text))
|
|
315
|
+
th.said = Array.from(m.text.trim()).slice(0, 30).join('');
|
|
316
|
+
const t0 = Date.parse(m.timing?.startedAt ?? '');
|
|
317
|
+
const dt = m.timing?.doneMs;
|
|
318
|
+
if (Number.isFinite(t0) && dt !== undefined)
|
|
319
|
+
th.endAt = new Date(t0 + dt).toISOString();
|
|
320
|
+
const tail = (m.parentText ?? '').replace(/^##\s*家长\s*/, '').trim();
|
|
321
|
+
if (tail)
|
|
322
|
+
th.notes.push(tail);
|
|
323
|
+
if (m.remembered?.length)
|
|
324
|
+
th.remembered.push(...m.remembered);
|
|
325
|
+
th.writes.push(...vaultWrites(m));
|
|
326
|
+
if (m.result === 'running')
|
|
327
|
+
th.stoppedAt = 'writing';
|
|
328
|
+
else if (m.result === 'ok' && m.section && (m.section.cards.length || m.section.lines.length)) {
|
|
329
|
+
th.sections++;
|
|
330
|
+
th.cards += m.section.cards.length;
|
|
331
|
+
const last = m.section.lines[m.section.lines.length - 1];
|
|
332
|
+
th.stoppedAt = last?.ask ? 'ask' : null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const d of diaries)
|
|
336
|
+
by.get(d.id)?.writes.push(...vaultWrites(d.m));
|
|
337
|
+
// 换过运行时的话题:卡上说一句,记账按钮不算它(runner.bookkeep 也会跳过)
|
|
338
|
+
const runtimeName = ctx.ws.config.tutors[t.name]?.runtime ?? ctx.ws.config.runtimes.default;
|
|
339
|
+
for (const th of by.values())
|
|
340
|
+
if (!th.booked && !sameRuntime(index, th.thread, runtimeName))
|
|
341
|
+
th.oldRuntime = index.sessions[th.thread].runtime;
|
|
342
|
+
// 按住说话连着没发出去:实录里的 hold;孩子发成的一句(开口、打字发出去)把一串断开
|
|
343
|
+
for (const th of by.values()) {
|
|
344
|
+
const mine = index.messages.filter((_m, i) => ths[i] === th.thread);
|
|
345
|
+
const plays = await readPlays(ctx.ws, t.name, date, new Set(mine.map((m) => m.job)));
|
|
346
|
+
const holds = reelHolds(plays);
|
|
347
|
+
if (!holds.length)
|
|
348
|
+
continue;
|
|
349
|
+
const sent = [...mine.filter((m) => m.from === 'kid').map((m) => (Date.parse(m.timing?.startedAt ?? '') || Date.parse(m.at))), ...plays.filter((r) => r.k === 'type' && r.e === 'send').map((r) => r.at)];
|
|
350
|
+
const n = Math.max(0, ...reelMissRuns(holds, sent).map((x) => x.n));
|
|
351
|
+
if (n)
|
|
352
|
+
th.misses = n;
|
|
353
|
+
}
|
|
354
|
+
const booking = index.messages.some((m) => (m.bookkeep || m.tidy) && m.result === 'running');
|
|
355
|
+
tutors.push({ name: t.name, display: t.display, avatar: shownAvatar(t), subject: t.subject ?? null, color: colors[t.name] ?? NEUTRAL_COLOR, turns: index.messages.length, threads: [...by.values()], booking, extras: t.extras.filter((x) => (x !== 'talk' || ctx.ws.config.talk.enabled)) });
|
|
356
|
+
}
|
|
357
|
+
const today = localDate(ctx.now());
|
|
358
|
+
const names = tutors.map((t) => t.name);
|
|
359
|
+
const week = await Promise.all(weekOf(date, today).map(async (d) => ({
|
|
360
|
+
date: d,
|
|
361
|
+
tutors: (await Promise.all(names.map(async (n) => ((await readIndex(ctx.ws, n, d)).messages.some((m) => !m.bookkeep && !m.tidy) ? n : null)))).filter((n) => n !== null),
|
|
362
|
+
})));
|
|
363
|
+
return { title: ctx.ws.config.title, date, today, tutors, week, ready: ctx.bailian.status().ready };
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* 卡的状态:孩子在舞台里选了、填了 → 存 <日期>.<job>.cards/<n>.json,不起老师;下一条消息带给老师。
|
|
367
|
+
* 画板:body 里可以带 image(data:image/png;base64,…),存成 .cards/<n>.png,状态里只留路径(相对 workspace 根,老师 Read 看)
|
|
368
|
+
*/
|
|
369
|
+
async function putCardState(ctx, ws, tutor, job, n, body) {
|
|
370
|
+
const date = localDate(ctx.now());
|
|
371
|
+
const index = await readIndex(ws, tutor, date);
|
|
372
|
+
const msg = index.messages.find((m) => m.job === job);
|
|
373
|
+
const target = msg?.result === 'ok' ? msg.section?.cards[n] : undefined;
|
|
374
|
+
if (!target)
|
|
375
|
+
return { status: 404, json: { error: 'no_such_card' } };
|
|
376
|
+
// 交过的卡锁住了,不能再改
|
|
377
|
+
if (submittedCards(index).has(`${job}/${n}`))
|
|
378
|
+
return { status: 409, json: { error: 'submitted' } };
|
|
379
|
+
let state = body;
|
|
380
|
+
if (target.kind === 'canvas' && isObj(body) && typeof body.image === 'string') {
|
|
381
|
+
const { image, ...rest } = body;
|
|
382
|
+
const m = /^data:image\/png;base64,([A-Za-z0-9+/=]+)$/.exec(image);
|
|
383
|
+
if (!m || m[1].length > 8_000_000)
|
|
384
|
+
return { status: 400, json: { error: 'bad_state' } };
|
|
385
|
+
const png = await writeCardImage(ws, tutor, date, job, n, Buffer.from(m[1], 'base64'));
|
|
386
|
+
state = { ...rest, image: `conversations/${tutor}/${png}` };
|
|
387
|
+
}
|
|
388
|
+
const r = parseCardState(target, state);
|
|
389
|
+
if (!r.ok)
|
|
390
|
+
return { status: 400, json: { error: 'bad_state' } };
|
|
391
|
+
// 画板清空前存的那几版:图只认 captures/ 里在的(先 POST photos 拿到的),别的路径不给老师 Read
|
|
392
|
+
if (target.kind === 'canvas' && isObj(r.state) && Array.isArray(r.state.cleared)) {
|
|
393
|
+
for (const c of r.state.cleared)
|
|
394
|
+
if (c.image && !(await capturePathOk(ws, c.image)))
|
|
395
|
+
delete c.image;
|
|
396
|
+
}
|
|
397
|
+
const last = index.messages[index.messages.length - 1];
|
|
398
|
+
// turn = 这张卡所在话题的末条 job:下一条发给同一话题时才算「上一轮之后改过的」
|
|
399
|
+
const mine = threads(index.messages)[index.messages.findIndex((m) => m.job === job)];
|
|
400
|
+
await writeCardState(ws, tutor, date, job, n, { at: ctx.now().toISOString(), turn: lastJobOf(index, mine) ?? last.job, state: r.state });
|
|
401
|
+
// 录像的实录:孩子的每一次存都记一条(选了又改、填空的过程、画板一笔一笔)
|
|
402
|
+
await appendFile(conversationFiles(ws.dirs.conversations, tutor, date).play(job), `${JSON.stringify({ at: ctx.now().getTime(), k: 'card', job, card: n, state: r.state })}\n`).catch(() => { });
|
|
403
|
+
return { status: 200, json: { ok: true, card: `${job}/${n}`, state: r.state } };
|
|
404
|
+
}
|
|
405
|
+
/** 卡的配音:<日期>.<job>.cards/<n>/<k>.mp3(第 n 张卡的第 k 个资产) */
|
|
406
|
+
const AUDIO_FILE_RE = /^\d{4}-\d{2}-\d{2}\.\d{4}-\d+\.cards\/\d+\/\d+\.mp3$/;
|
|
407
|
+
/** 实时老师一次通话的声音(两边混好的,src/runtime/live/call.ts):<日期>.live/<时分秒>.wav;录像里实时的轮从这里放 */
|
|
408
|
+
const LIVE_CALL_RE = /^\d{4}-\d{2}-\d{2}\.live\/\d{6}\.wav$/;
|
|
409
|
+
/** 实时那一轮嘴照念的声音(字幕重放,src/runtime/live/call.ts 落的):<日期>.<job>.mouth.wav */
|
|
410
|
+
const MOUTH_FILE_RE = /^\d{4}-\d{2}-\d{2}\.\d{4}-\d+\.mouth\.wav$/;
|
|
411
|
+
const IMAGE_TYPES = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif', svg: 'image/svg+xml' };
|
|
412
|
+
/** 作业照片一张最多这么大(解码后;页面先缩到长边 PHOTO_MAX_SIDE 的 jpeg,通常几百 KB) */
|
|
413
|
+
export const PHOTO_MAX_BYTES = 3_000_000;
|
|
414
|
+
/**
|
|
415
|
+
* 上传作业照片(R5):body {image: "data:image/jpeg;base64,…"}(也认 png)→ 落 captures/<日期>/<HHMM>-<n>.jpg → {path}。
|
|
416
|
+
* 孩子端与家长端同一条路;照片只是落盘,发消息时把 path 放进 photos[] 才到老师那里。
|
|
417
|
+
*/
|
|
418
|
+
async function uploadPhoto(ws, body, now) {
|
|
419
|
+
if (!isObj(body) || typeof body.image !== 'string')
|
|
420
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {image: data:image/jpeg;base64,…}' } };
|
|
421
|
+
const m = /^data:image\/(jpeg|png);base64,([A-Za-z0-9+/=]+)$/.exec(body.image);
|
|
422
|
+
if (!m)
|
|
423
|
+
return { status: 400, json: { error: 'bad_request', message: '只认 data:image/jpeg 或 image/png 的 base64' } };
|
|
424
|
+
const data = Buffer.from(m[2], 'base64');
|
|
425
|
+
if (!data.length || data.length > PHOTO_MAX_BYTES)
|
|
426
|
+
return { status: 413, json: { error: 'too_large', message: `一张最多 ${PHOTO_MAX_BYTES / 1_000_000} MB,页面该先缩到长边 ${PHOTO_MAX_SIDE}` } };
|
|
427
|
+
const path = await writeCapture(ws, now, data, m[1] === 'png' ? 'png' : 'jpg');
|
|
428
|
+
return { status: 201, json: { path } };
|
|
429
|
+
}
|
|
430
|
+
/** 左栏的纸:读 / 存一张;key 是话题 id 或 new */
|
|
431
|
+
async function paperRoute(ctx, tutor, date, method, url, body) {
|
|
432
|
+
const ws = ctx.ws;
|
|
433
|
+
const key = method === 'GET' ? (url.searchParams.get('key') ?? '') : isObj(body) && typeof body.key === 'string' ? body.key : '';
|
|
434
|
+
if (method !== 'GET' && method !== 'PUT')
|
|
435
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
436
|
+
if (!PAPER_KEY_RE.test(key))
|
|
437
|
+
return { status: 400, json: { error: 'bad_request' } };
|
|
438
|
+
if (method === 'GET')
|
|
439
|
+
return { status: 200, json: { key, state: await readPaper(ws, tutor, date, key) } };
|
|
440
|
+
const r = CanvasStateSchema.safeParse(isObj(body) ? body.state : null);
|
|
441
|
+
if (!r.success)
|
|
442
|
+
return { status: 400, json: { error: 'bad_state' } };
|
|
443
|
+
const cleared = [];
|
|
444
|
+
for (const c of r.data.cleared ?? [])
|
|
445
|
+
cleared.push(c.image && !(await capturePathOk(ws, c.image)) ? { ...c, image: undefined } : c);
|
|
446
|
+
await writePaper(ws, tutor, date, key, { ink: r.data.ink, ...(cleared.length ? { cleared } : {}) }, ctx.now());
|
|
447
|
+
// 话题有了,孩子端把 new 那张存到话题名下:new 那张删掉(服务端第一条已经改过名的话,这里没有可删的)
|
|
448
|
+
if (isObj(body) && body.from === 'new' && key !== 'new')
|
|
449
|
+
await dropPaper(ws, tutor, date, 'new');
|
|
450
|
+
return { status: 200, json: { ok: true, key } };
|
|
451
|
+
}
|
|
452
|
+
/** who:请求是谁发的(createHandler 按来源地址与 cookie 算);直接调 route 的测试与 CLI 缺省 local = 本机免密 */
|
|
453
|
+
export async function route(method, path, ctx, body, who = 'local', client = {}) {
|
|
454
|
+
await ctx.reload();
|
|
455
|
+
const ws = ctx.ws;
|
|
456
|
+
const url = new URL(path, 'http://x');
|
|
457
|
+
const p = url.pathname;
|
|
458
|
+
try {
|
|
459
|
+
// 服务起来的时刻、版本、跑的是哪个提交;仓里的提交变了 = 代码更新了,重起才用上(build.ts)。
|
|
460
|
+
// pid、mode(后台服务 service / 终端里 foreground)、vault 读不读得到(macOS 上后台服务读「文稿」、iCloud 云盘里的 vault 会被系统拦,没有弹窗):cotutor service status 看
|
|
461
|
+
if (p === '/api/health') {
|
|
462
|
+
const head = await headNow();
|
|
463
|
+
const vault = await readdir(ws.paths.vault).then(() => 'ok', (err) => (err.code === 'EPERM' || err.code === 'EACCES' ? 'denied' : 'missing'));
|
|
464
|
+
return { status: 200, json: { ok: true, configError: ctx.configError, started: BUILD.started, version: BUILD.version, commit: shortCommit(BUILD.commit), dirty: BUILD.dirty, head: shortCommit(head), changed: codeChanged(BUILD.commit, head), pid: process.pid, mode: process.env.COTUTOR_SERVICE ? 'service' : 'foreground', vault, calls: ctx.openCalls?.() ?? 0, bailian: ctx.bailian.status().ready } };
|
|
465
|
+
}
|
|
466
|
+
// 家长端与工作台的锁(access.ts):对 PIN 换 cookie;设了 PIN、没凭证的设备,孩子端以外的页面回输 PIN 的页、接口回 401。没设 PIN 什么都不拦
|
|
467
|
+
if (p === '/api/auth') {
|
|
468
|
+
if (method === 'GET')
|
|
469
|
+
return { status: 200, json: { who, pin: await ctx.access.pinSet() } };
|
|
470
|
+
if (method !== 'POST')
|
|
471
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
472
|
+
const r = await ctx.access.login(isObj(body) && typeof body.pin === 'string' ? body.pin : '', { secure: Boolean(ctx.listen?.().https) });
|
|
473
|
+
if (r.ok)
|
|
474
|
+
return { status: 200, json: { ok: true }, setCookie: r.cookie };
|
|
475
|
+
return { status: r.retryMs ? 429 : 401, json: { error: r.retryMs ? 'locked' : 'pin', ...(r.retryMs ? { retryMs: r.retryMs } : {}) } };
|
|
476
|
+
}
|
|
477
|
+
if (who === 'anon' && !isKidPath(p) && (await ctx.access.pinSet())) {
|
|
478
|
+
return method === 'GET' && !p.startsWith('/api/') ? { status: 401, html: gatePage(ws.config.title) } : { status: 401, json: { error: 'auth', message: '要家长 PIN:在 /parent 或 /dev 上输一次' } };
|
|
479
|
+
}
|
|
480
|
+
// 工作台概览:近七天的轮数、今天各老师、用量、要看一眼的轮次;体检 = doctor 不带 --live(不花钱)
|
|
481
|
+
if (p === '/api/dev/overview' && method === 'GET')
|
|
482
|
+
return { status: 200, json: await devOverview(ws) };
|
|
483
|
+
// 孩子端的设备:对话页拿它给每轮写设备名;起名写进设备表,空着 = 去掉名字
|
|
484
|
+
if (p === '/api/dev/devices' && method === 'GET') {
|
|
485
|
+
const table = await readDevices(ws);
|
|
486
|
+
return { status: 200, json: Object.fromEntries(Object.entries(table).map(([id, d]) => [id, { name: d.name ?? null, label: d.label }])) };
|
|
487
|
+
}
|
|
488
|
+
const devRename = /^\/api\/dev\/devices\/([0-9a-f]{12})$/.exec(p);
|
|
489
|
+
if (devRename && method === 'PATCH') {
|
|
490
|
+
if (!isObj(body) || typeof body.name !== 'string')
|
|
491
|
+
return { status: 400, json: { error: 'bad_request' } };
|
|
492
|
+
return (await renameDevice(ws, devRename[1], body.name)) ? { status: 200, json: { ok: true } } : { status: 404, json: { error: 'no_such_device' } };
|
|
493
|
+
}
|
|
494
|
+
if (p === '/api/dev/doctor' && method === 'POST') {
|
|
495
|
+
const r = await doctorWorkspace(ws.root, { live: false });
|
|
496
|
+
return { status: 200, json: { ok: r.ok, at: new Date().toISOString(), checks: r.checks.map((c) => ({ name: c.name, ok: c.ok, required: c.required, detail: redactHome(c.detail), fix: c.fix })) } };
|
|
497
|
+
}
|
|
498
|
+
// 工作台改 activity:只认 workspace 里列得出的名字;存要带读进来时的 hash,对不上 409
|
|
499
|
+
if (p === '/api/dev/activities' && method === 'GET')
|
|
500
|
+
return { status: 200, json: await listDevActivities(ws) };
|
|
501
|
+
const da = /^\/api\/dev\/activities\/([a-z0-9][a-z0-9-]*)\/([^/]+?)(\/check|\/restore)?$/.exec(p);
|
|
502
|
+
if (da) {
|
|
503
|
+
const [, tutor, raw, sub] = da;
|
|
504
|
+
let name;
|
|
505
|
+
try {
|
|
506
|
+
name = decodeURIComponent(raw);
|
|
507
|
+
}
|
|
508
|
+
catch {
|
|
509
|
+
return { status: 400, json: { error: 'bad_request' } };
|
|
510
|
+
}
|
|
511
|
+
if (!(await findDevActivity(ws, tutor, name)))
|
|
512
|
+
return { status: 404, json: { error: 'no_such_activity', tutor, name } };
|
|
513
|
+
if (!sub && method === 'GET')
|
|
514
|
+
return { status: 200, json: await readDevActivity(ws, tutor, name) };
|
|
515
|
+
if (sub === '/check' && method === 'POST') {
|
|
516
|
+
if (!isObj(body) || typeof body.text !== 'string')
|
|
517
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {text, params?}' } };
|
|
518
|
+
const params = isObj(body.params) ? Object.fromEntries(Object.entries(body.params).filter(([, v]) => typeof v === 'string')) : {};
|
|
519
|
+
return { status: 200, json: await checkDevActivity(ws, tutor, name, body.text, params) };
|
|
520
|
+
}
|
|
521
|
+
if (!sub && method === 'PUT') {
|
|
522
|
+
if (!isObj(body) || typeof body.text !== 'string' || typeof body.base !== 'string')
|
|
523
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {text, base}' } };
|
|
524
|
+
try {
|
|
525
|
+
return { status: 200, json: await saveDevActivity(ws, tutor, name, body.text, body.base) };
|
|
526
|
+
}
|
|
527
|
+
catch (err) {
|
|
528
|
+
if (err instanceof ActivityConflict)
|
|
529
|
+
return { status: 409, json: { error: 'conflict', message: '这份文件在别处改过了', hash: err.hash } };
|
|
530
|
+
throw err;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (sub === '/restore' && method === 'POST')
|
|
534
|
+
return { status: 200, json: await restoreDevActivity(ws, tutor, name) };
|
|
535
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
536
|
+
}
|
|
537
|
+
// 工作台改老师文件:「新话题」照的提示词;和 activity 同一套(存带 hash、对不上 409),检查有要改的不存(400)
|
|
538
|
+
if (p === '/api/dev/tutor-files' && method === 'GET')
|
|
539
|
+
return { status: 200, json: await listDevTutorFiles(ws) };
|
|
540
|
+
const dt = /^\/api\/dev\/tutor-files\/([a-z0-9][a-z0-9-]*)(\/check|\/restore)?$/.exec(p);
|
|
541
|
+
if (dt) {
|
|
542
|
+
const [, tutor, sub] = dt;
|
|
543
|
+
if (!(await hasDevTutorFile(ws, tutor)))
|
|
544
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
545
|
+
if (!sub && method === 'GET')
|
|
546
|
+
return { status: 200, json: await readDevTutorFile(ws, tutor) };
|
|
547
|
+
if (sub === '/check' && method === 'POST') {
|
|
548
|
+
if (!isObj(body) || typeof body.text !== 'string')
|
|
549
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {text}' } };
|
|
550
|
+
return { status: 200, json: await checkDevTutorFile(ws, tutor, body.text) };
|
|
551
|
+
}
|
|
552
|
+
if (!sub && method === 'PUT') {
|
|
553
|
+
if (!isObj(body) || typeof body.text !== 'string' || typeof body.base !== 'string')
|
|
554
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {text, base}' } };
|
|
555
|
+
try {
|
|
556
|
+
return { status: 200, json: await saveDevTutorFile(ws, tutor, body.text, body.base) };
|
|
557
|
+
}
|
|
558
|
+
catch (err) {
|
|
559
|
+
if (err instanceof ActivityConflict)
|
|
560
|
+
return { status: 409, json: { error: 'conflict', message: '这份文件在别处改过了', hash: err.hash } };
|
|
561
|
+
throw err;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (sub === '/restore' && method === 'POST')
|
|
565
|
+
return { status: 200, json: await restoreDevTutorFile(ws, tutor) };
|
|
566
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
567
|
+
}
|
|
568
|
+
if (p === '/api/workspace' && method === 'GET')
|
|
569
|
+
return { status: 200, json: workspaceReport(ws) };
|
|
570
|
+
if (p === '/api/config') {
|
|
571
|
+
if (method === 'GET') {
|
|
572
|
+
return {
|
|
573
|
+
status: 200,
|
|
574
|
+
json: {
|
|
575
|
+
title: ws.config.title,
|
|
576
|
+
root: redactHome(ws.root),
|
|
577
|
+
kid: ws.config.kid,
|
|
578
|
+
server: ws.config.server,
|
|
579
|
+
runtime: ws.config.runtimes.default,
|
|
580
|
+
runtimes: Object.keys(ws.config.runtimes).filter((k) => k !== 'default'),
|
|
581
|
+
policyDefaults: ws.config.policyDefaults,
|
|
582
|
+
paths: ws.config.paths,
|
|
583
|
+
resolvedPaths: Object.fromEntries(Object.entries(ws.paths).map(([k, v]) => [k, redactHome(v)])),
|
|
584
|
+
/** 实时老师:总开关、嘴的模型、哪几位老师走实时用哪个音色(家长端「样子与声音」改) */
|
|
585
|
+
live: ws.config.live,
|
|
586
|
+
theme: ws.config.kid.theme,
|
|
587
|
+
https: ws.config.server.https ?? null,
|
|
588
|
+
shipped: (await tutorStatuses(ws.root)).map((s) => s.name),
|
|
589
|
+
/** 老 workspace 的政策文件缺的出厂件(新老师 / 新运行时 / 模板里的新旗标);设置页据此提示一行 */
|
|
590
|
+
migrate: await configGapsOf(ws.root),
|
|
591
|
+
tutors: listTutors(ws.config),
|
|
592
|
+
/** 学科色:每位老师现在用的(写了的、主科的、自动分的),与工作台点选的色块 */
|
|
593
|
+
colors: tutorColors(ws.config.tutors),
|
|
594
|
+
palette: { subject: SUBJECT_COLORS, auto: TUTOR_PALETTE },
|
|
595
|
+
/** 老师条目的原始政策补丁(页面区分「继承」与「覆盖」) */
|
|
596
|
+
tutorPatches: Object.fromEntries(Object.entries(ws.config.tutors).map(([k, t]) => [k, t.policy ?? {}])),
|
|
597
|
+
},
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
if (method === 'PATCH') {
|
|
601
|
+
if (!isObj(body))
|
|
602
|
+
return { status: 400, json: { error: 'bad_request', message: '要一个 JSON 对象' } };
|
|
603
|
+
// 孩子那段(kid)工作台不改:按住说话在哪边在家长端设置页(/api/parent/settings),别的直接编辑文件
|
|
604
|
+
await patchConfig(ws, body);
|
|
605
|
+
await ctx.reload();
|
|
606
|
+
return { status: 200, json: { ok: true, tutors: listTutors(ctx.ws.config), runtime: ctx.ws.config.runtimes.default } };
|
|
607
|
+
}
|
|
608
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
609
|
+
}
|
|
610
|
+
// 政策文件补缺(与 cotutor upgrade --config 同一条路):只加缺的出厂件,家长写过的值不动
|
|
611
|
+
if (p === '/api/config/migrate' && method === 'POST') {
|
|
612
|
+
const r = await upgradeConfig(ws.root);
|
|
613
|
+
await ctx.reload();
|
|
614
|
+
return { status: 200, json: { ok: true, gaps: r.gaps, applied: r.applied, installed: r.installed } };
|
|
615
|
+
}
|
|
616
|
+
if (p === '/api/tutors' && method === 'GET') {
|
|
617
|
+
return { status: 200, json: listTutors(ws.config, { kidOnly: url.searchParams.get('kid') === '1' }) };
|
|
618
|
+
}
|
|
619
|
+
// ---- 加老师 / 老师文件 / 删老师:与 cotutor add 同一条路 ----
|
|
620
|
+
if (p === '/api/tutors' && method === 'POST') {
|
|
621
|
+
if (!isObj(body) || typeof body.name !== 'string' || typeof body.display !== 'string' || !body.display.trim())
|
|
622
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {name, display, subject?, avatar?, hidden?, description?}' } };
|
|
623
|
+
const name = body.name.trim();
|
|
624
|
+
if (ws.config.tutors[name])
|
|
625
|
+
return { status: 409, json: { error: 'exists', message: `cotutor.json 里已经有 ${name}` } };
|
|
626
|
+
const str = (k) => (typeof body[k] === 'string' && body[k].trim() ? body[k].trim() : undefined);
|
|
627
|
+
const r = await addTutorFile(ws.root, { name, display: body.display.trim(), subject: str('subject'), description: str('description') });
|
|
628
|
+
await patchConfig(ws, { tutors: { [name]: { display: body.display.trim(), ...(str('subject') ? { subject: str('subject') } : {}), ...(str('avatar') ? { avatar: str('avatar') } : {}), enabled: true, ...(body.hidden === true ? { hidden: true } : {}) } } });
|
|
629
|
+
await ctx.reload();
|
|
630
|
+
return { status: 201, json: { ok: true, ...r, tutors: listTutors(ctx.ws.config) } };
|
|
631
|
+
}
|
|
632
|
+
const tf = /^\/api\/tutors\/([a-z0-9][a-z0-9-]*)(\/file)?$/.exec(p);
|
|
633
|
+
if (tf) {
|
|
634
|
+
const [, name, isFile] = tf;
|
|
635
|
+
if (!ws.config.tutors[name])
|
|
636
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor: name } };
|
|
637
|
+
if (isFile && method === 'GET')
|
|
638
|
+
return { status: 200, json: await readTutorFile(ws.root, name) };
|
|
639
|
+
if (isFile && method === 'PUT') {
|
|
640
|
+
if (!isObj(body) || typeof body.text !== 'string')
|
|
641
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {text}' } };
|
|
642
|
+
return { status: 200, json: await writeTutorFile(ws.root, name, body.text) };
|
|
643
|
+
}
|
|
644
|
+
if (!isFile && method === 'DELETE') {
|
|
645
|
+
const r = await removeTutorFile(ws.root, name);
|
|
646
|
+
await patchConfig(ws, { tutors: { [name]: null } });
|
|
647
|
+
await ctx.reload();
|
|
648
|
+
return { status: 200, json: { ok: true, ...r, tutors: listTutors(ctx.ws.config) } };
|
|
649
|
+
}
|
|
650
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
651
|
+
}
|
|
652
|
+
// ---- 孩子端:过滤在服务端做,永远不带工具 / 错误 / 评判 ----
|
|
653
|
+
if (p === '/api/kid/home' && method === 'GET')
|
|
654
|
+
return { status: 200, json: await kidHome(ctx, ctx.now()) };
|
|
655
|
+
// 按住说话的诊断:识别全在浏览器里、出错静默,真机上哪一步断了只有它自己知道;只收事件码与毫秒,不收字也不收声音
|
|
656
|
+
// 孩子端的流水:一次打开、页面脚本出错;没有设备 cookie 就种一枚
|
|
657
|
+
if (p === '/api/kid/log' && method === 'POST') {
|
|
658
|
+
const row = parseKidLog(body);
|
|
659
|
+
if (!row)
|
|
660
|
+
return { status: 400, json: { error: 'bad_request' } };
|
|
661
|
+
const known = validDevice(client.device);
|
|
662
|
+
const device = known ?? newDeviceId();
|
|
663
|
+
await recordKidLog(ws, row, { device, ip: client.ip, srv: { v: BUILD.version, commit: shortCommit(BUILD.commit), started: BUILD.started } }, ctx.now()).catch((err) => console.error('kid-log: 落盘失败', err));
|
|
664
|
+
return { status: 200, json: { ok: true }, ...(known ? {} : { setCookie: deviceCookie(device, Boolean(ctx.listen?.().https)) }) };
|
|
665
|
+
}
|
|
666
|
+
if (p === '/api/kid/voice-diag' && method === 'POST') {
|
|
667
|
+
if (!isObj(body) || JSON.stringify(body).length > 4000)
|
|
668
|
+
return { status: 400, json: { error: 'bad_request' } };
|
|
669
|
+
const row = { at: ctx.now().toISOString(), ...body };
|
|
670
|
+
await mkdir(join(ws.root, '.cotutor'), { recursive: true });
|
|
671
|
+
await appendFile(join(ws.root, '.cotutor', 'voice-diag.jsonl'), `${JSON.stringify(row)}\n`).catch(() => { });
|
|
672
|
+
return { status: 200, json: { ok: true } };
|
|
673
|
+
}
|
|
674
|
+
const kid = /^\/api\/kid\/conversations\/([a-z0-9][a-z0-9-]*)\/(today|messages|history|photos|play|paper|\d{4}-\d{2}-\d{2})$/.exec(p);
|
|
675
|
+
if (kid) {
|
|
676
|
+
const [, tutor, tail] = kid;
|
|
677
|
+
const t = ws.config.tutors[tutor];
|
|
678
|
+
if (!t || !t.enabled || t.hidden)
|
|
679
|
+
return { status: 404, json: { error: 'no_such_tutor' } };
|
|
680
|
+
const date = localDate(ctx.now());
|
|
681
|
+
// 录像的实录:孩子端每 10 秒一批 {thread, sentAt, records};时刻按 sentAt 把两边的钟差校到服务端;
|
|
682
|
+
// 形状不对的、不是这个话题的、太旧太新的丢掉,卡的改动只认服务端自己记的;不回错(孩子端不报错)。记在话题当时的末条 job 上,删话题一起删
|
|
683
|
+
if (tail === 'play' && method === 'POST') {
|
|
684
|
+
if (!isObj(body) || typeof body.thread !== 'string' || !Array.isArray(body.records) || body.records.length > 400)
|
|
685
|
+
return { status: 400, json: { error: 'bad_request' } };
|
|
686
|
+
const index = await readIndex(ws, tutor, date);
|
|
687
|
+
const ths = threads(index.messages);
|
|
688
|
+
const jobs = new Set(index.messages.filter((_m, i) => ths[i] === body.thread).map((m) => m.job));
|
|
689
|
+
const last = jobs.size ? lastJobOf(index, body.thread) : null;
|
|
690
|
+
if (!last)
|
|
691
|
+
return { status: 200, json: { kept: 0 } };
|
|
692
|
+
const now = ctx.now().getTime();
|
|
693
|
+
const skew = typeof body.sentAt === 'number' && Math.abs(now - body.sentAt) < 86_400_000 ? now - body.sentAt : 0;
|
|
694
|
+
const rows = [];
|
|
695
|
+
for (const x of body.records) {
|
|
696
|
+
if (!playRecordOk(x) || x.k === 'card')
|
|
697
|
+
continue;
|
|
698
|
+
const at = Math.round(x.at + skew);
|
|
699
|
+
if (at > now + 60_000 || at < now - 86_400_000)
|
|
700
|
+
continue;
|
|
701
|
+
if ((x.k === 'stage' || x.k === 'scroll') && !jobs.has(x.job))
|
|
702
|
+
continue;
|
|
703
|
+
rows.push(JSON.stringify({ ...x, at }));
|
|
704
|
+
}
|
|
705
|
+
if (rows.length)
|
|
706
|
+
await appendFile(conversationFiles(ws.dirs.conversations, tutor, date).play(last), `${rows.join('\n')}\n`).catch(() => { });
|
|
707
|
+
return { status: 200, json: { kept: rows.length } };
|
|
708
|
+
}
|
|
709
|
+
// 作业照片(R5):先传图拿 path,再连 path 一起发消息;不起老师、不计上限
|
|
710
|
+
if (tail === 'photos')
|
|
711
|
+
return method === 'POST' ? uploadPhoto(ws, body, ctx.now()) : { status: 405, json: { error: 'method_not_allowed' } };
|
|
712
|
+
// 左栏的纸:GET ?key=<话题 | new> 读;PUT {key, state} 存(清掉那几版的图只认 captures/ 里在的)。不起老师
|
|
713
|
+
if (tail === 'paper')
|
|
714
|
+
return paperRoute(ctx, tutor, date, method, url, body);
|
|
715
|
+
if (tail === 'today' && method === 'GET') {
|
|
716
|
+
return { status: 200, json: await kidDay(ctx, tutor, date) };
|
|
717
|
+
}
|
|
718
|
+
// 以前的某一天(只读回放;未来的日期与坏日期 400)
|
|
719
|
+
if (DATE_RE.test(tail) && method === 'GET') {
|
|
720
|
+
if (tail > date || Number.isNaN(Date.parse(tail)))
|
|
721
|
+
return { status: 400, json: { error: 'bad_request' } };
|
|
722
|
+
return { status: 200, json: await kidDay(ctx, tutor, tail) };
|
|
723
|
+
}
|
|
724
|
+
if (tail === 'history' && method === 'GET') {
|
|
725
|
+
const days = Math.min(365, Math.max(1, Number(url.searchParams.get('days') ?? 30) || 30));
|
|
726
|
+
return { status: 200, json: await kidHistory(ctx, tutor, days) };
|
|
727
|
+
}
|
|
728
|
+
// 孩子端发一条只走实时那条连接(/api/live/<老师>/ws,src/runtime/live/turns.ts);2026-11-04 删了 HTTP 的发
|
|
729
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
730
|
+
}
|
|
731
|
+
// 字幕重放:实时那一轮嘴照念的声音在哪、多长、讲稿每句从哪开始(毫秒);只给实时的轮,没落过声音 404
|
|
732
|
+
const mouth = /^\/api\/kid\/conversations\/([a-z0-9][a-z0-9-]*)\/mouth\/(\d{4}-\d{2}-\d{2})\/(\d{4}-\d+)$/.exec(p);
|
|
733
|
+
if (mouth) {
|
|
734
|
+
const [, tutor, d, job] = mouth;
|
|
735
|
+
const t = ws.config.tutors[tutor];
|
|
736
|
+
if (!t || !t.enabled || t.hidden)
|
|
737
|
+
return { status: 404, json: { error: 'no_such_tutor' } };
|
|
738
|
+
if (method !== 'GET')
|
|
739
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
740
|
+
const m = (await readIndex(ws, tutor, d)).messages.find((x) => x.job === job);
|
|
741
|
+
if (m?.live !== true)
|
|
742
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
743
|
+
const raw = await readFile(conversationFiles(ws.dirs.conversations, tutor, d).mouth(job, 'json'), 'utf8').catch(() => null);
|
|
744
|
+
// 正在重落的那一下可能读到半截:当没有
|
|
745
|
+
let idx = null;
|
|
746
|
+
try {
|
|
747
|
+
idx = raw === null ? null : JSON.parse(raw);
|
|
748
|
+
}
|
|
749
|
+
catch {
|
|
750
|
+
idx = null;
|
|
751
|
+
}
|
|
752
|
+
if (!idx?.lines?.length)
|
|
753
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
754
|
+
return { status: 200, json: { audio: `/api/audio/${tutor}/${d}.${job}.mouth.wav`, ms: idx.ms, lines: idx.lines } };
|
|
755
|
+
}
|
|
756
|
+
// 卡的状态:孩子在舞台里选了、填了 → 存 <日期>.<job>.cards/<n>.json,不起老师;下一条消息带给老师
|
|
757
|
+
const card = /^\/api\/kid\/conversations\/([a-z0-9][a-z0-9-]*)\/cards\/(\d{4}-\d+)\/(\d+)$/.exec(p);
|
|
758
|
+
if (card) {
|
|
759
|
+
const [, tutor, job, nStr] = card;
|
|
760
|
+
const t = ws.config.tutors[tutor];
|
|
761
|
+
if (!t || !t.enabled || t.hidden)
|
|
762
|
+
return { status: 404, json: { error: 'no_such_tutor' } };
|
|
763
|
+
if (method !== 'PUT')
|
|
764
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
765
|
+
return putCardState(ctx, ws, tutor, job, Number(nStr), body);
|
|
766
|
+
}
|
|
767
|
+
// 老师头像(R5b,2026-09-16):cotutor.json 里 avatar 是图片相对路径时(figshot 写的 avatars/<老师>.png)从这里取;
|
|
768
|
+
// 没写(或还是旧的出厂 emoji)的三门主科给包里的出厂头像(avatars.ts);
|
|
769
|
+
// emoji 头像、越界、不是图、不存在都 404(孩子端退回显示 emoji / 首字)。no-cache:figshot 换了脸孩子端要马上见到
|
|
770
|
+
const av = /^\/api\/kid\/avatar\/([a-z0-9][a-z0-9-]*)$/.exec(p);
|
|
771
|
+
if (av && method === 'GET') {
|
|
772
|
+
const factory = ws.config.tutors[av[1]] ? factoryAvatarFile(ws.config.tutors[av[1]]) : null;
|
|
773
|
+
if (factory)
|
|
774
|
+
return { status: 200, file: factory, contentType: 'image/webp', cacheControl: 'no-cache' };
|
|
775
|
+
const rel = ws.config.tutors[av[1]]?.avatar ?? '';
|
|
776
|
+
const file = resolve(ws.root, rel);
|
|
777
|
+
const ext = IMAGE_EXT.exec(rel)?.[1]?.toLowerCase() ?? '';
|
|
778
|
+
if (!rel || isAbsolute(rel) || !file.startsWith(ws.root + sep) || !IMAGE_TYPES[ext])
|
|
779
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
780
|
+
if (!(await stat(file).catch(() => null))?.isFile())
|
|
781
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
782
|
+
return { status: 200, file, contentType: IMAGE_TYPES[ext], cacheControl: 'no-cache' };
|
|
783
|
+
}
|
|
784
|
+
// 写字卡的笔顺:一个汉字一份 JSON,数据包里现读;不是汉字 / 没有这个字 404(页面只显示字形不动)
|
|
785
|
+
const hz = /^\/api\/kid\/tianzige\/([^/]+)$/.exec(p);
|
|
786
|
+
if (hz && method === 'GET') {
|
|
787
|
+
const d = await tianzigeData(decodeURIComponent(hz[1]));
|
|
788
|
+
return d ? { status: 200, json: d, cacheControl: 'max-age=86400' } : { status: 404, json: { error: 'not_found' } };
|
|
789
|
+
}
|
|
790
|
+
// 单词卡的笔顺:词里每个字母的点序列(src/chalk/glyphs 现采);写不出的词 404(页面退成字体的字)
|
|
791
|
+
const lt = /^\/api\/kid\/letters\/([^/]+)$/.exec(p);
|
|
792
|
+
if (lt && method === 'GET') {
|
|
793
|
+
const d = lettersData(decodeURIComponent(lt[1]));
|
|
794
|
+
return d ? { status: 200, json: d, cacheControl: 'max-age=86400' } : { status: 404, json: { error: 'not_found' } };
|
|
795
|
+
}
|
|
796
|
+
// 视频小课堂(第 4 步):lectures/<id>/ 的课名与一句一段(舞台包的播放器拼时钟用),与 video.mp4(Range 由 sendFile 管)
|
|
797
|
+
const lv = /^\/api\/kid\/lectures\/([a-z0-9][a-z0-9-]*)\/(lecture\.json|video\.mp4)$/.exec(p);
|
|
798
|
+
if (lv && method === 'GET') {
|
|
799
|
+
const { lecture: l } = await inspectLecture(ws, lv[1]);
|
|
800
|
+
if (!l?.video)
|
|
801
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
802
|
+
if (lv[2] === 'video.mp4')
|
|
803
|
+
return { status: 200, file: join(ws.dirs.lectures, lv[1], 'video.mp4'), contentType: 'video/mp4', cacheControl: 'no-cache' };
|
|
804
|
+
return { status: 200, json: { title: l.title, total: l.clock.total, segments: l.clock.segments.map((x) => ({ start: x.start, len: x.len, line: x.line })) } };
|
|
805
|
+
}
|
|
806
|
+
// 图片卡的图:只认 workspace 根以内的图片文件(产物、照片);越界、不是图、不存在都 404
|
|
807
|
+
if (p === '/api/kid/image' && method === 'GET') {
|
|
808
|
+
const rel = url.searchParams.get('p') ?? '';
|
|
809
|
+
const file = resolve(ws.root, rel);
|
|
810
|
+
const ext = IMAGE_EXT.exec(rel)?.[1]?.toLowerCase() ?? '';
|
|
811
|
+
if (!rel || isAbsolute(rel) || !file.startsWith(ws.root + sep) || !IMAGE_TYPES[ext])
|
|
812
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
813
|
+
if (!(await stat(file).catch(() => null))?.isFile())
|
|
814
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
815
|
+
return { status: 200, file, contentType: IMAGE_TYPES[ext] };
|
|
816
|
+
}
|
|
817
|
+
const audio = /^\/api\/audio\/([a-z0-9][a-z0-9-]*)\/(.+)$/.exec(p);
|
|
818
|
+
if (audio && method === 'GET') {
|
|
819
|
+
const [, tutor, name] = audio;
|
|
820
|
+
const call = LIVE_CALL_RE.test(name) || MOUTH_FILE_RE.test(name);
|
|
821
|
+
if (!ws.config.tutors[tutor] || (!AUDIO_FILE_RE.test(name) && !call))
|
|
822
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
823
|
+
const file = join(ws.dirs.conversations, tutor, name);
|
|
824
|
+
if (!(await stat(file).catch(() => null))?.isFile())
|
|
825
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
826
|
+
// 嘴照念的那份一段一段重落(这一轮还在念时就取得到),别让孩子端拿到缓存里的半截
|
|
827
|
+
return { status: 200, file, contentType: call ? 'audio/wav' : 'audio/mpeg', ...(MOUTH_FILE_RE.test(name) ? { cacheControl: 'no-cache' } : {}) };
|
|
828
|
+
}
|
|
829
|
+
// 看原文(2026-09-11):一轮拆成六站,一个接口给全;/fixture 是原文原样一份,开发者放进 tests/fixtures/board/
|
|
830
|
+
const rawRe = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)\/(\d{4}-\d{2}-\d{2}|today)\/raw\/(\d{4}-\d+)(\/fixture)?$/.exec(p);
|
|
831
|
+
if (rawRe) {
|
|
832
|
+
const [, tutor, d, job, fixture] = rawRe;
|
|
833
|
+
if (method !== 'GET')
|
|
834
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
835
|
+
if (!ws.config.tutors[tutor])
|
|
836
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
837
|
+
const view = await rawView(ws, tutor, d === 'today' ? localDate(ctx.now()) : d, job);
|
|
838
|
+
if (!view)
|
|
839
|
+
return { status: 404, json: { error: 'not_found', message: `${d} 没有 ${job} 这一轮` } };
|
|
840
|
+
return { status: 200, json: fixture ? fixtureOf(view) : view };
|
|
841
|
+
}
|
|
842
|
+
// 话题打星(《obsidian仓库设计.md》§4):PUT {rating: 1–5 | null};记账:POST {threads?: [..]} → 每个话题一轮记账任务,老师回「## 记账」段,应用写日记
|
|
843
|
+
const rate = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)\/(\d{4}-\d{2}-\d{2})\/threads\/([^/]+)\/rating$/.exec(p);
|
|
844
|
+
if (rate && method === 'PUT') {
|
|
845
|
+
const [, tutor, date, thread] = rate;
|
|
846
|
+
if (!ws.config.tutors[tutor])
|
|
847
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
848
|
+
const rating = isObj(body) ? body.rating : undefined;
|
|
849
|
+
if (!(rating === null || (typeof rating === 'number' && Number.isInteger(rating) && rating >= 1 && rating <= 5)))
|
|
850
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {rating: 1–5 或 null}' } };
|
|
851
|
+
try {
|
|
852
|
+
const index = await rateThread(ws, tutor, date, decodeURIComponent(thread), rating);
|
|
853
|
+
return { status: 200, json: { tutor, date, thread: decodeURIComponent(thread), rating: index.ratings[decodeURIComponent(thread)] ?? null, keepScore: ws.config.vault.keepScore } };
|
|
854
|
+
}
|
|
855
|
+
catch (err) {
|
|
856
|
+
return { status: 404, json: { error: 'no_such_thread', message: err instanceof Error ? err.message : String(err) } };
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
// 看录像:一个话题按时间排好的轨道;没有孩子开口的话题 404
|
|
860
|
+
const reel = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)\/(today|\d{4}-\d{2}-\d{2})\/threads\/([^/]+)\/reel$/.exec(p);
|
|
861
|
+
if (reel && method === 'GET') {
|
|
862
|
+
const [, tutor, tail, raw] = reel;
|
|
863
|
+
if (!ws.config.tutors[tutor])
|
|
864
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
865
|
+
const date = tail === 'today' ? localDate(ctx.now()) : tail;
|
|
866
|
+
if (date > localDate(ctx.now()) || Number.isNaN(Date.parse(date)))
|
|
867
|
+
return { status: 400, json: { error: 'bad_request', message: '日期要是今天或以前' } };
|
|
868
|
+
const r = await parentReel(ctx, tutor, date, decodeURIComponent(raw));
|
|
869
|
+
return r ? { status: 200, json: r } : { status: 404, json: { error: 'no_reel', message: '这个话题没有录像' } };
|
|
870
|
+
}
|
|
871
|
+
// 删掉一个话题(家长板书页清单上的「删」,2026-09-22):那个话题还有轮在跑就 409;这个话题写进记忆、日记的一起撤(store.deleteThread,2026-10-05),回撤了多少
|
|
872
|
+
const del = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)\/(\d{4}-\d{2}-\d{2})\/threads\/([^/]+)$/.exec(p);
|
|
873
|
+
if (del && method === 'DELETE') {
|
|
874
|
+
const [, tutor, date, raw] = del;
|
|
875
|
+
const thread = decodeURIComponent(raw);
|
|
876
|
+
if (!ws.config.tutors[tutor])
|
|
877
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
878
|
+
const target = ws;
|
|
879
|
+
const active = ctx.runner.running(tutor);
|
|
880
|
+
if (active && active.date === date) {
|
|
881
|
+
const idx = await readIndex(target, tutor, date);
|
|
882
|
+
const i = idx.messages.findIndex((m) => m.job === active.job);
|
|
883
|
+
if (i >= 0 && threads(idx.messages)[i] === thread)
|
|
884
|
+
return { status: 409, json: { error: 'busy', message: '老师还在写这个话题,等它写完再删' } };
|
|
885
|
+
}
|
|
886
|
+
try {
|
|
887
|
+
const { index, undo } = await deleteThread(target, tutor, date, thread);
|
|
888
|
+
return { status: 200, json: { tutor, date, thread, threadsLeft: new Set(threads(index.messages)).size, undo } };
|
|
889
|
+
}
|
|
890
|
+
catch (err) {
|
|
891
|
+
if (err instanceof IndexError)
|
|
892
|
+
return { status: 404, json: { error: 'no_such_thread', message: err.message } };
|
|
893
|
+
throw err;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
// 撤回话题写进 vault 的一笔(家长端「记录」的「记住了」,2026-10-30):{job, kind, n},kind = memory / child / diary;这位老师这天还有轮在跑就 409(会写同一篇)
|
|
897
|
+
const unw = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)\/(\d{4}-\d{2}-\d{2})\/threads\/([^/]+)\/vault\/undo$/.exec(p);
|
|
898
|
+
if (unw && method === 'POST') {
|
|
899
|
+
const [, tutor, date, raw] = unw;
|
|
900
|
+
if (!ws.config.tutors[tutor])
|
|
901
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
902
|
+
const kinds = ['memory', 'child', 'diary'];
|
|
903
|
+
if (!isObj(body) || typeof body.job !== 'string' || typeof body.kind !== 'string' || !kinds.includes(body.kind) || (body.kind !== 'diary' && (typeof body.n !== 'number' || !Number.isInteger(body.n) || body.n < 0)))
|
|
904
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {job, kind: memory | child | diary, n}' } };
|
|
905
|
+
if (ctx.runner.running(tutor)?.date === date)
|
|
906
|
+
return { status: 409, json: { error: 'busy', message: '老师还在写,等它写完再撤' } };
|
|
907
|
+
try {
|
|
908
|
+
const { undo } = await undoVaultWrite(ws, tutor, date, decodeURIComponent(raw), { job: body.job, kind: body.kind, n: typeof body.n === 'number' ? body.n : 0 });
|
|
909
|
+
return undo.memory || undo.diary ? { status: 200, json: { ok: true, undo } } : { status: 409, json: { error: 'changed', message: undo.misses.join(';') || '找不到那一行,没撤', undo } };
|
|
910
|
+
}
|
|
911
|
+
catch (err) {
|
|
912
|
+
if (err instanceof IndexError)
|
|
913
|
+
return { status: 404, json: { error: 'no_such_write', message: err.message } };
|
|
914
|
+
throw err;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const book = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)\/(\d{4}-\d{2}-\d{2})\/bookkeep$/.exec(p);
|
|
918
|
+
if (book && method === 'POST') {
|
|
919
|
+
const [, tutor, date] = book;
|
|
920
|
+
if (!ws.config.tutors[tutor])
|
|
921
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
922
|
+
const only = isObj(body) && Array.isArray(body.threads) ? body.threads.filter((t) => typeof t === 'string') : undefined;
|
|
923
|
+
const { queued, skipped } = await ctx.runner.bookkeep(tutor, date, only);
|
|
924
|
+
return { status: 202, json: { tutor, date, queued, skipped } };
|
|
925
|
+
}
|
|
926
|
+
// 家长板书页:清单与一天的板书,都在家长命名空间下;/api/kid/* 不动
|
|
927
|
+
const ov = /^\/api\/overview\/(today|\d{4}-\d{2}-\d{2})$/.exec(p);
|
|
928
|
+
if (ov && method === 'GET') {
|
|
929
|
+
const date = ov[1] === 'today' ? localDate(ctx.now()) : ov[1];
|
|
930
|
+
if (date > localDate(ctx.now()) || Number.isNaN(Date.parse(date)))
|
|
931
|
+
return { status: 400, json: { error: 'bad_request', message: '日期要是今天或以前' } };
|
|
932
|
+
return { status: 200, json: await overview(ctx, date) };
|
|
933
|
+
}
|
|
934
|
+
const pb = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)\/(today|\d{4}-\d{2}-\d{2})\/board$/.exec(p);
|
|
935
|
+
if (pb && method === 'GET') {
|
|
936
|
+
const [, tutor, tail] = pb;
|
|
937
|
+
if (!ws.config.tutors[tutor])
|
|
938
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
939
|
+
const date = tail === 'today' ? localDate(ctx.now()) : tail;
|
|
940
|
+
if (date > localDate(ctx.now()) || Number.isNaN(Date.parse(date)))
|
|
941
|
+
return { status: 400, json: { error: 'bad_request', message: '日期要是今天或以前' } };
|
|
942
|
+
return { status: 200, json: await parentDay(ctx, tutor, date) };
|
|
943
|
+
}
|
|
944
|
+
const conv = /^\/api\/conversations\/([a-z0-9][a-z0-9-]*)(?:\/([^/]+))?$/.exec(p);
|
|
945
|
+
if (conv) {
|
|
946
|
+
const [, tutor, tail] = conv;
|
|
947
|
+
if (!ws.config.tutors[tutor])
|
|
948
|
+
return { status: 404, json: { error: 'no_such_tutor', tutor } };
|
|
949
|
+
if (tail === undefined && method === 'GET') {
|
|
950
|
+
return { status: 200, json: { tutor, today: localDate(ctx.now()), dates: await listDates(ws, tutor), running: ctx.runner.running(tutor) } };
|
|
951
|
+
}
|
|
952
|
+
// 工作台传照片:与孩子端同一条路(落 captures/,回 {path})
|
|
953
|
+
if (tail === 'photos')
|
|
954
|
+
return method === 'POST' ? uploadPhoto(ws, body, ctx.now()) : { status: 405, json: { error: 'method_not_allowed' } };
|
|
955
|
+
if (tail === 'messages' && method === 'POST') {
|
|
956
|
+
if (!isObj(body) || typeof body.text !== 'string')
|
|
957
|
+
return { status: 400, json: { error: 'bad_request', message: '要 {text, from?, focus?, runtime?, photos?}' } };
|
|
958
|
+
// 工作台 /dev 与 cotutor send 发的都算孩子的话(2026-10-05 起没有 from: parent;旧客户端带 parent 也当 kid)
|
|
959
|
+
const from = body.from === undefined || body.from === 'parent' ? 'kid' : body.from;
|
|
960
|
+
if (!MESSAGE_FROM.includes(from))
|
|
961
|
+
return { status: 400, json: { error: 'bad_request', message: `from 只能是 ${MESSAGE_FROM.join(' / ')}` } };
|
|
962
|
+
const focus = body.focus === undefined ? undefined : FocusSchema.safeParse(body.focus);
|
|
963
|
+
if (focus && !focus.success)
|
|
964
|
+
return { status: 400, json: { error: 'bad_request', message: 'focus 形状不对' } };
|
|
965
|
+
const photos = await photosOf(ws, body.photos);
|
|
966
|
+
if (photos === null)
|
|
967
|
+
return { status: 400, json: { error: 'bad_request', message: 'photos 要是 captures/ 里在的文件(先 POST …/photos 传图拿 path)' } };
|
|
968
|
+
// 工作台 /dev 不带 device,缺省当平板横屏
|
|
969
|
+
const device = body.device === undefined ? undefined : DeviceSchema.safeParse(body.device);
|
|
970
|
+
if (device && !device.success)
|
|
971
|
+
return { status: 400, json: { error: 'bad_request', message: 'device 只能是 phone / tablet' } };
|
|
972
|
+
const action = body.action === undefined ? undefined : body.action === 'submit' ? 'submit' : null;
|
|
973
|
+
if (action === null)
|
|
974
|
+
return { status: 400, json: { error: 'bad_request', message: 'action 只能是 continue / submit' } };
|
|
975
|
+
if (!body.text.trim() && !action && !photos?.length)
|
|
976
|
+
return { status: 400, json: { error: 'bad_request', message: '要说点什么' } };
|
|
977
|
+
const started = await ctx.runner.send(tutor, {
|
|
978
|
+
from: from,
|
|
979
|
+
text: body.text,
|
|
980
|
+
action,
|
|
981
|
+
focus: focus?.data,
|
|
982
|
+
runtime: typeof body.runtime === 'string' ? body.runtime : undefined,
|
|
983
|
+
newThread: body.newThread === true,
|
|
984
|
+
thread: typeof body.thread === 'string' ? body.thread : undefined,
|
|
985
|
+
photos,
|
|
986
|
+
device: device?.data,
|
|
987
|
+
// 孩子的话照实时写(同孩子端、同 replay:上下文包带 live:、不补提问卡、讲稿不截);嘴不在,接住与打断不带。系统发的不算(2026-11-04)
|
|
988
|
+
...(from === 'kid' ? { live: {} } : {}),
|
|
989
|
+
});
|
|
990
|
+
return { status: 202, json: { tutor, date: started.date, job: started.job, thread: started.thread, runtime: started.plan.runtime, resume: started.plan.resume } };
|
|
991
|
+
}
|
|
992
|
+
if (tail !== undefined && tail !== 'messages' && method === 'GET') {
|
|
993
|
+
const date = tail === 'today' ? localDate(ctx.now()) : tail;
|
|
994
|
+
if (!DATE_RE.test(date))
|
|
995
|
+
return { status: 400, json: { error: 'bad_request', message: '日期要是 YYYY-MM-DD 或 today' } };
|
|
996
|
+
return { status: 200, json: await dayView(ctx, tutor, date) };
|
|
997
|
+
}
|
|
998
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
999
|
+
}
|
|
1000
|
+
// 孩子端的主题(themes/<kid.theme>/):css 与清单现读,mtime 缓存;坏了退出厂 default(孩子端永远有样子)
|
|
1001
|
+
if (method === 'GET' && (p === '/kid/theme.css' || p === '/kid/theme.json')) {
|
|
1002
|
+
const t = await themeFiles(ws.root, ws.config.kid.theme);
|
|
1003
|
+
if (p === '/kid/theme.css')
|
|
1004
|
+
return { status: 200, html: t.css, contentType: 'text/css; charset=utf-8' };
|
|
1005
|
+
return { status: 200, json: { ...t.manifest, theme: ws.config.kid.theme, source: t.source, ...(t.error ? { error: t.error } : {}) } };
|
|
1006
|
+
}
|
|
1007
|
+
// 舞台包(重卡在 iframe 里开)与课包文件:静态,越界 404
|
|
1008
|
+
if (method === 'GET' && p.startsWith('/stage/')) {
|
|
1009
|
+
if (p === '/stage/') {
|
|
1010
|
+
const html = await stageIndex();
|
|
1011
|
+
return html === null ? { status: 404, json: { error: 'not_found' } } : { status: 200, html };
|
|
1012
|
+
}
|
|
1013
|
+
const f = await stageAsset(p);
|
|
1014
|
+
return f ? { status: 200, file: f.file, contentType: f.contentType } : { status: 404, json: { error: 'not_found' } };
|
|
1015
|
+
}
|
|
1016
|
+
// 课包某一刻的画面(画的卡、lecture 卡的缩略图、播放器截图的底):烤过的课包服务端现画;没烤过先烤,烤不了 404
|
|
1017
|
+
const frame = /^\/api\/bundles\/([a-z0-9][a-z0-9-]*)\/frame\.svg$/.exec(p);
|
|
1018
|
+
if (method === 'GET' && frame) {
|
|
1019
|
+
const svg = await lectureFrameSvg(ws, frame[1], parseSvgMs(url.searchParams.get('svg')), parseRing(url.searchParams.get('ring')), { bake: ensureBaked });
|
|
1020
|
+
return svg === null ? { status: 404, json: { error: 'not_found' } } : { status: 200, body: Buffer.from(svg), contentType: 'image/svg+xml; charset=utf-8' };
|
|
1021
|
+
}
|
|
1022
|
+
if (method === 'GET' && p.startsWith('/api/bundles/')) {
|
|
1023
|
+
const f = await bundleAsset(ws.dirs.bundles, p);
|
|
1024
|
+
return f ? { status: 200, file: f.file, contentType: f.contentType } : { status: 404, json: { error: 'not_found' } };
|
|
1025
|
+
}
|
|
1026
|
+
// 家长端「首页」的接口(/api/parent/*)
|
|
1027
|
+
const phr = await parentHomeRoute(method, p, ctx, body);
|
|
1028
|
+
if (phr)
|
|
1029
|
+
return phr;
|
|
1030
|
+
const plr = await parentLookRoute(method, p, url, ctx, body);
|
|
1031
|
+
if (plr)
|
|
1032
|
+
return plr;
|
|
1033
|
+
const blr = await bailianRoute(method, p, ctx, body, who);
|
|
1034
|
+
if (blr)
|
|
1035
|
+
return blr;
|
|
1036
|
+
// 口语课(路由 src/app/talk/,页面 src/ui/talk/,规则与存取 src/scenes/talk/):/talk 与 /api/talk/* 交给它;上课在英语老师的实时页(talk-run.ts)
|
|
1037
|
+
const tk = await talkRoute(method, url, ctx, body);
|
|
1038
|
+
if (tk)
|
|
1039
|
+
return tk;
|
|
1040
|
+
// 听写(路由 src/app/dictation/,页面 src/ui/dictation/,规则与存取 src/scenes/dictation/):/dictation 与 /api/dictation/* 交给它;首页的听写卡在 kid-page 画
|
|
1041
|
+
const tx = await dictationRoute(method, url, ctx, body);
|
|
1042
|
+
if (tx)
|
|
1043
|
+
return tx;
|
|
1044
|
+
if (method !== 'GET')
|
|
1045
|
+
return { status: 405, json: { error: 'method_not_allowed' } };
|
|
1046
|
+
// 工作台:对话原始视图、看原文、老师团、activity、设置——给有技术背景的家长与开发者;家长端在 /parent
|
|
1047
|
+
if (p === '/dev')
|
|
1048
|
+
return { status: 200, html: DEV_PAGE };
|
|
1049
|
+
// 按住说话的试验页(真机上比策略用;不在孩子端与家长端的入口里)
|
|
1050
|
+
// 按钮样张:老师页那颗「头像 + 按住说话」的每一种样子,调动画时看这一页
|
|
1051
|
+
if (p === '/dev/voice')
|
|
1052
|
+
return { status: 200, html: VOICE_GALLERY_PAGE };
|
|
1053
|
+
// 主屏幕(iPad「添加到主屏幕」):清单与图标都按标题现生成,没有静态资源
|
|
1054
|
+
if (p === '/manifest.webmanifest')
|
|
1055
|
+
return { status: 200, json: webManifest(ws.config.title), contentType: 'application/manifest+json; charset=utf-8' };
|
|
1056
|
+
const icon = /^\/icon-(\d{2,4})\.png$/.exec(p);
|
|
1057
|
+
if (icon) {
|
|
1058
|
+
const n = Number(icon[1]);
|
|
1059
|
+
if (!ICON_SIZES.includes(n))
|
|
1060
|
+
return { status: 404, json: { error: 'not_found' } };
|
|
1061
|
+
return { status: 200, body: appIconPng(n), contentType: 'image/png' };
|
|
1062
|
+
}
|
|
1063
|
+
// 网页图标(src/ui/shared/favicon.ts):所有页面都是 cotutor 的双 C;no-cache:换了 logo 马上见到
|
|
1064
|
+
const fav = faviconResponse(p);
|
|
1065
|
+
if (fav)
|
|
1066
|
+
return { status: 200, ...fav, cacheControl: 'no-cache' };
|
|
1067
|
+
if (p === '/')
|
|
1068
|
+
return { status: 200, html: kidPage(esc(ws.config.title), {}, await stageVersion()) };
|
|
1069
|
+
// 家长端:也是孩子端页面本身,数据走家长接口(答案在、家长的话在),卡锁着;自己的清单,加到主屏幕才不会拿到孩子端那份
|
|
1070
|
+
if (p === '/parent')
|
|
1071
|
+
return { status: 200, html: parentPage(esc(ws.config.title)) };
|
|
1072
|
+
// 家长端「首页」(设孩子的首页与几项常改的设置)
|
|
1073
|
+
if (p === '/parent/home')
|
|
1074
|
+
return { status: 200, html: PARENT_HOME_PAGE };
|
|
1075
|
+
// 家长端「设置」(设一次就不常动的:孩子的平板上按住说话那一栏放哪边)
|
|
1076
|
+
if (p === '/parent/settings')
|
|
1077
|
+
return { status: 200, html: PARENT_SETTINGS_PAGE };
|
|
1078
|
+
// 二维码的打印页:家长端「扫码打开」的「打印 ›」开它(不在孩子端的入口里)
|
|
1079
|
+
if (p === '/parent/qr')
|
|
1080
|
+
return ctx.listen ? { status: 200, html: qrPage(ws.config.title, ctx.listen(), url.searchParams.get('via') === 'ip' ? 'ip' : 'name', url.searchParams.get('to') === 'parent' ? 'parent' : 'kid') } : { status: 404, json: { error: 'not_listening' } };
|
|
1081
|
+
// 录像里孩子的屏幕:家长端录像时开在 iframe 里;直接打开也能看(调试),?tutor=&date=&thread=[&at=时:分:秒]
|
|
1082
|
+
if (p === '/reel')
|
|
1083
|
+
return { status: 200, html: kidPage(esc(ws.config.title), { reel: true }, await stageVersion()) };
|
|
1084
|
+
if (p === '/preview')
|
|
1085
|
+
return { status: 200, html: kidPage(esc(ws.config.title), { preview: true }, await stageVersion()) };
|
|
1086
|
+
if (p === '/parent/manifest.webmanifest')
|
|
1087
|
+
return { status: 200, json: webManifest(`${ws.config.title} · 家长`, { startUrl: '/parent', scope: '/parent' }), contentType: 'application/manifest+json; charset=utf-8' };
|
|
1088
|
+
return { status: 404, json: { error: 'not_found', path: p } };
|
|
1089
|
+
}
|
|
1090
|
+
catch (err) {
|
|
1091
|
+
if (err instanceof BusyError)
|
|
1092
|
+
return { status: 409, json: { error: 'busy', message: err.message } };
|
|
1093
|
+
if (err instanceof RuntimeError)
|
|
1094
|
+
return { status: 400, json: { error: 'bad_runtime', message: err.message } };
|
|
1095
|
+
if (err instanceof ConfigError)
|
|
1096
|
+
return { status: 422, json: { error: 'config', message: err.message } };
|
|
1097
|
+
if (err instanceof IndexError)
|
|
1098
|
+
return { status: 500, json: { error: 'index', message: err.message } };
|
|
1099
|
+
if (err instanceof UsageError)
|
|
1100
|
+
return { status: 400, json: { error: 'usage', message: err.message } };
|
|
1101
|
+
throw err;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
async function readBody(req) {
|
|
1105
|
+
const chunks = [];
|
|
1106
|
+
let size = 0;
|
|
1107
|
+
for await (const c of req) {
|
|
1108
|
+
size += c.length;
|
|
1109
|
+
if (size > 6_000_000)
|
|
1110
|
+
throw new UsageError('请求体超过 6MB');
|
|
1111
|
+
chunks.push(c);
|
|
1112
|
+
}
|
|
1113
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
1114
|
+
if (!text.trim())
|
|
1115
|
+
return undefined;
|
|
1116
|
+
try {
|
|
1117
|
+
return JSON.parse(text);
|
|
1118
|
+
}
|
|
1119
|
+
catch {
|
|
1120
|
+
throw new UsageError('请求体不是合法 JSON');
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* 发文件(配音、图、小课堂的视频……):都带 accept-ranges 与长度;GET 带单段 Range → 206 只发那一段(iPad Safari 放视频非这样不可,
|
|
1125
|
+
* 先要 bytes=0-1,拿不到 206 就不放;音频拖动也靠它),起点越界 416;HEAD 只发头。文件读之前没了 → 404
|
|
1126
|
+
*/
|
|
1127
|
+
/** 这个进程的启动号:每个 JSON 响应都带(x-cotutor-boot)。页面轮询时见它变了 = 服务重起过(多半是换了新代码),空下来就自己重载——iPad 上下拉刷新常拉不到位 */
|
|
1128
|
+
const BOOT = Date.now().toString(36);
|
|
1129
|
+
export function createHandler(ctx) {
|
|
1130
|
+
return (req, res) => {
|
|
1131
|
+
void (async () => {
|
|
1132
|
+
let r;
|
|
1133
|
+
try {
|
|
1134
|
+
const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : await readBody(req);
|
|
1135
|
+
// HEAD 照 GET 走路由;Node 对 HEAD 的响应本来就不发正文
|
|
1136
|
+
r = await route(req.method === 'HEAD' ? 'GET' : (req.method ?? 'GET'), req.url ?? '/', ctx, body, await ctx.access.whoOf(req), { device: cookieOf(req.headers.cookie, DEVICE_COOKIE), ip: req.socket.remoteAddress });
|
|
1137
|
+
}
|
|
1138
|
+
catch (err) {
|
|
1139
|
+
r = err instanceof UsageError ? { status: 400, json: { error: 'usage', message: err.message } } : { status: 500, json: { error: 'internal', message: err instanceof Error ? err.message : String(err) } };
|
|
1140
|
+
if (r.status === 500)
|
|
1141
|
+
console.error(err);
|
|
1142
|
+
}
|
|
1143
|
+
if (r.file !== undefined)
|
|
1144
|
+
await sendFile(req, res, r);
|
|
1145
|
+
else if (r.body !== undefined) {
|
|
1146
|
+
res.writeHead(r.status, { 'content-type': r.contentType ?? 'application/octet-stream', 'cache-control': r.cacheControl ?? 'private, max-age=86400' });
|
|
1147
|
+
res.end(Buffer.from(r.body));
|
|
1148
|
+
}
|
|
1149
|
+
else if (r.html !== undefined) {
|
|
1150
|
+
res.writeHead(r.status, { 'content-type': r.contentType ?? 'text/html; charset=utf-8', 'cache-control': 'no-store' });
|
|
1151
|
+
res.end(r.html);
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
res.writeHead(r.status, { 'content-type': r.contentType ?? 'application/json; charset=utf-8', 'cache-control': r.cacheControl ?? 'no-store', 'x-cotutor-boot': BOOT, ...(r.setCookie ? { 'set-cookie': r.setCookie } : {}) });
|
|
1155
|
+
res.end(JSON.stringify(r.json ?? null));
|
|
1156
|
+
}
|
|
1157
|
+
})();
|
|
1158
|
+
};
|
|
1159
|
+
}
|