DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
Merge pull request #1106 from evan188199-tech/codex/feat-reading-study-guidance
Bingxi Zhao (Frank)37fc1f1b0695
diff --cc pyproject.tomlindex 8876db303,7f8ebaa8b..70513f2fe--- a/pyproject.toml+++ b/pyproject.toml@@@ -85,7 -84,7 +85,8 @@@ dependencies =deeptutor = "deeptutor_cli.main:main"[project.entry-points."deeptutor.reading_extensions"]+read_aloud = "deeptutor.reading.read_aloud:ReadAloudExtension"+ guided_learning = "deeptutor.reading.study_guidance:StudyGuidanceExtension"[project.optional-dependencies]# Compatibility extra for source installs and older docs. These packages arediff --cc tests/reading/test_read_aloud.pyindex af10ec6d8,000000000..ef92017e7mode 100644,000000..100644--- a/tests/reading/test_read_aloud.py+++ b/tests/reading/test_read_aloud.py@@@ -1,78 -1,0 +1,78 @@@+from __future__ import annotations++from pathlib import Path+import tomllib++from fastapi import FastAPI+from fastapi.testclient import TestClient++from deeptutor.api.routers import reading_extensions+from deeptutor.reading import ReadingStore+from deeptutor.reading.extensions import ReadingContext, ReadingExtensionRegistry+from deeptutor.reading.read_aloud import ReadAloudExtension+from deeptutor.services.path_service import PathService+++def test_read_aloud_returns_verified_visible_text_only():+ context = ReadingContext(+ material_id="material",+ locator=2,+ locale="zh-CN",+ visible_text="Visible passage",+ )++ result = ReadAloudExtension().run_action("read", context)++ assert result.type == "browser_speech"+ assert result.payload == {"text": "Visible passage", "locale": "zh-CN"}+++def test_read_aloud_is_registered_as_a_packaged_extension():+ project = tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))+ group = project["project"]["entry-points"]["deeptutor.reading_extensions"]+- assert group == {"read_aloud": "deeptutor.reading.read_aloud:ReadAloudExtension"}++ assert group["read_aloud"] == "deeptutor.reading.read_aloud:ReadAloudExtension"+++def test_read_aloud_crosses_the_authenticated_api_boundary_with_stored_text(monkeypatch, tmp_path):+ monkeypatch.setenv("DEEPTUTOR_HOME", str(tmp_path))+ PathService.reset_instance()+ source = tmp_path / "source.txt"+ source.write_text("Stored unit text only.", encoding="utf-8")+ material = ReadingStore().ingest(source)+ registry = ReadingExtensionRegistry([ReadAloudExtension()])+ monkeypatch.setattr(+ reading_extensions,+ "get_reading_extension_registry",+ lambda: registry,+ )+ app = FastAPI()+ app.include_router(reading_extensions.router, prefix="/api/v1/reading")+ client = TestClient(app)++ try:+ response = client.post(+ f"/api/v1/reading/materials/{material.material_id}/extensions/read_aloud/actions/read",+ json={"locator": 1, "visible_text": "Forged text", "locale": "zh-CN"},+ )+ finally:+ PathService.reset_instance()++ assert response.status_code == 200, response.text+ assert response.json() == {+ "type": "browser_speech",+ "title": "",+ "message": "",+ "payload": {"text": "Stored unit text only.", "locale": "zh-CN"},+ }+++def test_read_aloud_rejects_undeclared_actions():+ context = ReadingContext(material_id="material", locator=1, visible_text="Text")++ try:+ ReadAloudExtension().run_action("summarize", context)+ except ValueError as exc:+ assert "Unsupported read-aloud action" in str(exc)+ else:+ raise AssertionError("undeclared action must fail")diff --cc web/components/reading/ReadingExtensionBar.tsxindex 5d89974c2,f068a1662..36672e42c--- a/web/components/reading/ReadingExtensionBar.tsx+++ b/web/components/reading/ReadingExtensionBar.tsx@@@ -162,6 -129,13 +161,16 @@@ export function ReadingExtensionBar();}+ function builtInActionLabel(extensionId: string, actionId: string) {++ if (extensionId === "read_aloud" && actionId === "read") {++ return "Read aloud";++ }+ if (extensionId === "guided_learning" && actionId === "guide") {+ return "Guide me";+ }+ return "";+ }+function ExtensionResult({result,closeLabel,diff --cc web/locales/en/app.jsonindex 6d9ca8b65,75d67bbcd..09062f90f--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@@ -3989,9 -3840,7 +3989,10 @@@"What DeepTutor has noticed": "What DeepTutor has noticed","Mastery path": "Mastery path","Reading": "Reading",+ "Read aloud": "Read aloud",+ "Reading aloud": "Reading aloud",+ "Stop reading aloud": "Stop reading aloud",+ "Guide me": "Guide me","Partner group": "Partner group","Everything this course studies with. Conversations here start with these already in hand.": "Everything this course studies with. Conversations here start with these already in hand.","Nothing attached yet. Add a textbook or knowledge base and this course starts knowing what it is about.": "Nothing attached yet. Add a textbook or knowledge base and this course starts knowing what it is about.",diff --cc web/locales/zh/app.jsonindex baa0959fa,538a470f5..523bf0b55--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@@ -3989,9 -3840,7 +3989,10 @@@"What DeepTutor has noticed": "DeepTutor 注意到的","Mastery path": "精通之路","Reading": "阅读",+ "Read aloud": "朗读",+ "Reading aloud": "正在朗读",+ "Stop reading aloud": "停止朗读",+ "Guide me": "引导我","Partner group": "伙伴群组","Everything this course studies with. Conversations here start with these already in hand.": "这门课用到的一切。课内对话开口就带着它们。","Nothing attached yet. Add a textbook or knowledge base and this course starts knowing what it is about.": "还没挂任何资料。挂上教材或知识库,这门课就知道自己在讲什么了。",diff --cc web/tests/reading-extensions.test.tsindex dad380501,fa9b73a2d..31249adae--- a/web/tests/reading-extensions.test.ts+++ b/web/tests/reading-extensions.test.ts@@@ -41,23 -41,19 +41,42 @@@ test("a malformed extension catalog can);});+test("browser speech is stoppable and cannot continue after navigation", () => {+ assert.match(component, /const \[speaking, setSpeaking\] = useState\(false\)/);+ assert.match(component, /function stopSpeaking\(\)/);+ assert.match(component, /window\.speechSynthesis\?\.cancel\(\)/);+ assert.match(component, /utterance\.onend = \(\) => setSpeaking\(false\)/);+ assert.match(component, /utterance\.onerror = \(\) => setSpeaking\(false\)/);+ assert.match(component, /\}, \[locator, materialId\]\);/);+ assert.match(component, /aria-label=\{t\("Stop reading aloud"\)\}/);+});++test("the built-in read-aloud action is localized", () => {- assert.match(component, /extension\.id === "read_aloud" && action\.id === "read"/);- assert.match(component, /t\("Read aloud"\)/);++ assert.match(++ component,++ /extensionId === "read_aloud" && actionId === "read"/,++ );+ assert.match(english, /"Read aloud": "Read aloud"/);+ assert.match(chinese, /"Read aloud": "朗读"/);+ assert.match(english, /"Reading aloud": "Reading aloud"/);+ assert.match(chinese, /"Reading aloud": "正在朗读"/);+ assert.match(english, /"Stop reading aloud": "Stop reading aloud"/);+ assert.match(chinese, /"Stop reading aloud": "停止朗读"/);+});+++ test("the built-in study-guidance action is localized", () => {+ assert.match(component, /function builtInActionLabel/);+ assert.match(+ component,+ /extensionId === "guided_learning" && actionId === "guide"/,+ );+ assert.match(component, /t\(builtInLabel\)/);+ assert.match(english, /"Guide me": "Guide me"/);+ assert.match(chinese, /"Guide me": "引导我"/);+ });++ test("study-guidance steps are visible in the result card", () => {+ assert.match(component, /result\.payload\.steps/);+ assert.match(component, /steps\.map\(\(step, index\) =>/);+ assert.match(component, /list-decimal/);+ });