Merge branch 'fix/role-aware-celebi-examples'
Browse files at this commit3 changed files +113 -10
- src/components/ai/celebi-launcher.test.tsx +46 -0
- src/components/ai/celebi-launcher.tsx +36 -1
- src/i18n/messages.ts +31 -9
src/components/ai/celebi-launcher.test.tsxadded+46 -0
| @@ -0,0 +1,46 @@ | |||
| 1 | +import { cleanup, render } from "@solidjs/testing-library"; | ||
| 2 | +import { afterEach, expect, test, vi } from "vitest"; | ||
| 3 | +import { CelebiLauncher } from "@/components/ai/celebi-launcher"; | ||
| 4 | +import { PreferencesProvider } from "@/stores/preferences-context"; | ||
| 5 | + | ||
| 6 | +const { authUser } = vi.hoisted(() => ({ authUser: { role: "student" as string } })); | ||
| 7 | + | ||
| 8 | +vi.mock("@/stores/auth-context", () => ({ | ||
| 9 | + useAuth: () => ({ user: () => ({ id: "u-1", username: "demo", role: authUser.role }) }), | ||
| 10 | +})); | ||
| 11 | +vi.mock("@/stores/celebi-panel", () => ({ openCelebiPanel: () => undefined })); | ||
| 12 | + | ||
| 13 | +function mount() { | ||
| 14 | + return render(() => ( | ||
| 15 | + <PreferencesProvider> | ||
| 16 | + <CelebiLauncher /> | ||
| 17 | + </PreferencesProvider> | ||
| 18 | + )); | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +afterEach(cleanup); | ||
| 22 | + | ||
| 23 | +test("a student gets questions the assistant answers for students", () => { | ||
| 24 | + authUser.role = "student"; | ||
| 25 | + const { container } = mount(); | ||
| 26 | + expect(container.textContent).toContain("Bu hafta hangi ödevlerin teslimi var?"); | ||
| 27 | + expect(container.textContent).toContain("Notlarımı nereden görürüm?"); | ||
| 28 | + expect(container.textContent).not.toContain("Yoklama nasıl alınır?"); | ||
| 29 | + expect(container.textContent).not.toContain("Yeni akademik dönem eklemek istiyorum"); | ||
| 30 | +}); | ||
| 31 | + | ||
| 32 | +test("a teacher gets the teacher questions, not the student ones", () => { | ||
| 33 | + authUser.role = "teacher"; | ||
| 34 | + const { container } = mount(); | ||
| 35 | + expect(container.textContent).toContain("Yoklama nasıl alınır?"); | ||
| 36 | + expect(container.textContent).toContain("Sınavı nasıl puanlarım?"); | ||
| 37 | + expect(container.textContent).not.toContain("Bu hafta hangi ödevlerin teslimi var?"); | ||
| 38 | +}); | ||
| 39 | + | ||
| 40 | +test.each(["manager", "admin"])("a %s gets the school-management questions", (role) => { | ||
| 41 | + authUser.role = role; | ||
| 42 | + const { container } = mount(); | ||
| 43 | + expect(container.textContent).toContain("Yeni akademik dönem eklemek istiyorum"); | ||
| 44 | + expect(container.textContent).toContain("Personel mesai kayıtlarını nereden yönetirim?"); | ||
| 45 | + expect(container.textContent).not.toContain("Yoklama nasıl alınır?"); | ||
| 46 | +}); | ||
src/components/ai/celebi-launcher.tsxmodified+36 -1
| @@ -1,14 +1,49 @@ | |||
| 1 | import { For } from "solid-js"; | 1 | import { For } from "solid-js"; |
| 2 | import { Button } from "@/components/ui/button"; | 2 | import { Button } from "@/components/ui/button"; |
| 3 | import { IconSparkles } from "@/components/ui/icons"; | 3 | import { IconSparkles } from "@/components/ui/icons"; |
| 4 | +import type { MessageKey } from "@/i18n/messages"; | ||
| 5 | +import { hasMinRole } from "@/lib/roles"; | ||
| 4 | import { openCelebiPanel } from "@/stores/celebi-panel"; | 6 | import { openCelebiPanel } from "@/stores/celebi-panel"; |
| 7 | +import { useAuth } from "@/stores/auth-context"; | ||
| 5 | import { useT } from "@/stores/preferences-context"; | 8 | import { useT } from "@/stores/preferences-context"; |
| 6 | 9 | ||
| 10 | +// Every example is a question the deployed Çelebi assistant answers for the | ||
| 11 | +// role that sees it — a prompt outside the viewer's scope comes back as a | ||
| 12 | +// refusal or a "please rephrase", so the sets are checked against the live bot | ||
| 13 | +// rather than guessed. The manager band covers managers and admins; a student | ||
| 14 | +// set is the fallback because a parent never reaches this tab. | ||
| 15 | +const EXAMPLE_KEYS: Record<"student" | "teacher" | "manager", MessageKey[]> = { | ||
| 16 | + student: [ | ||
| 17 | + "aiHub.celebiExample.student1", | ||
| 18 | + "aiHub.celebiExample.student2", | ||
| 19 | + "aiHub.celebiExample.student3", | ||
| 20 | + ], | ||
| 21 | + teacher: [ | ||
| 22 | + "aiHub.celebiExample.teacher1", | ||
| 23 | + "aiHub.celebiExample.teacher2", | ||
| 24 | + "aiHub.celebiExample.teacher3", | ||
| 25 | + ], | ||
| 26 | + manager: [ | ||
| 27 | + "aiHub.celebiExample.manager1", | ||
| 28 | + "aiHub.celebiExample.manager2", | ||
| 29 | + "aiHub.celebiExample.manager3", | ||
| 30 | + ], | ||
| 31 | +}; | ||
| 32 | + | ||
| 7 | // Çelebi itself is a shell panel — it follows the viewer across every route, | 33 | // Çelebi itself is a shell panel — it follows the viewer across every route, |
| 8 | // so the hub tab opens that one panel instead of mounting a second chat. | 34 | // so the hub tab opens that one panel instead of mounting a second chat. |
| 9 | export function CelebiLauncher() { | 35 | export function CelebiLauncher() { |
| 10 | const t = useT(); | 36 | const t = useT(); |
| 11 | - const examples = () => [t("aiHub.celebiExample1"), t("aiHub.celebiExample2"), t("aiHub.celebiExample3")]; | 37 | + const auth = useAuth(); |
| 38 | + const examples = () => { | ||
| 39 | + const role = auth.user()?.role; | ||
| 40 | + const band = hasMinRole(role, "manager") | ||
| 41 | + ? "manager" | ||
| 42 | + : hasMinRole(role, "teacher") | ||
| 43 | + ? "teacher" | ||
| 44 | + : "student"; | ||
| 45 | + return EXAMPLE_KEYS[band].map((key) => t(key)); | ||
| 46 | + }; | ||
| 12 | 47 | ||
| 13 | return ( | 48 | return ( |
| 14 | <section class="mx-auto flex max-w-3xl flex-col items-center gap-5 rounded-xl border border-dashed border-primary/25 bg-primary/[0.03] px-6 py-10 text-center"> | 49 | <section class="mx-auto flex max-w-3xl flex-col items-center gap-5 rounded-xl border border-dashed border-primary/25 bg-primary/[0.03] px-6 py-10 text-center"> |
src/i18n/messages.tsmodified+31 -9
| @@ -35,9 +35,15 @@ export type MessageKey = | |||
| 35 | | "aiHub.description" | 35 | | "aiHub.description" |
| 36 | | "aiHub.tab.studio" | 36 | | "aiHub.tab.studio" |
| 37 | | "aiHub.tab.insights" | 37 | | "aiHub.tab.insights" |
| 38 | - | "aiHub.celebiExample1" | 38 | + | "aiHub.celebiExample.student1" |
| 39 | - | "aiHub.celebiExample2" | 39 | + | "aiHub.celebiExample.student2" |
| 40 | - | "aiHub.celebiExample3" | 40 | + | "aiHub.celebiExample.student3" |
| 41 | + | "aiHub.celebiExample.teacher1" | ||
| 42 | + | "aiHub.celebiExample.teacher2" | ||
| 43 | + | "aiHub.celebiExample.teacher3" | ||
| 44 | + | "aiHub.celebiExample.manager1" | ||
| 45 | + | "aiHub.celebiExample.manager2" | ||
| 46 | + | "aiHub.celebiExample.manager3" | ||
| 41 | | "aiHub.celebiHint" | 47 | | "aiHub.celebiHint" |
| 42 | | "nav.today" | 48 | | "nav.today" |
| 43 | | "nav.classes" | 49 | | "nav.classes" |
| @@ -2129,9 +2135,19 @@ const en: Dict = { | |||
| 2129 | "aiHub.description": "Every AI surface in one place: note outputs and podcasts, student analysis, and Çelebi.", | 2135 | "aiHub.description": "Every AI surface in one place: note outputs and podcasts, student analysis, and Çelebi.", |
| 2130 | "aiHub.tab.studio": "Note studio", | 2136 | "aiHub.tab.studio": "Note studio", |
| 2131 | "aiHub.tab.insights": "Analysis", | 2137 | "aiHub.tab.insights": "Analysis", |
| 2132 | - "aiHub.celebiExample1": "Which homework is due this week?", | 2138 | + // Çelebi's intent engine only understands Turkish: the same English wording |
| 2133 | - "aiHub.celebiExample2": "How many days has my class missed?", | 2139 | + // comes back as "please rephrase" from the live assistant, so the examples |
| 2134 | - "aiHub.celebiExample3": "Summarise the topics of my next exam.", | 2140 | + // ship the Turkish question verbatim in both locales. Each one is checked |
| 2141 | + // against the deployed assistant for the role that sees it. | ||
| 2142 | + "aiHub.celebiExample.student1": "Bu hafta hangi ödevlerin teslimi var?", | ||
| 2143 | + "aiHub.celebiExample.student2": "Sınıfım kaç gün devamsızlık yaptı?", | ||
| 2144 | + "aiHub.celebiExample.student3": "Notlarımı nereden görürüm?", | ||
| 2145 | + "aiHub.celebiExample.teacher1": "Yoklama nasıl alınır?", | ||
| 2146 | + "aiHub.celebiExample.teacher2": "Dersime nasıl sınav eklerim?", | ||
| 2147 | + "aiHub.celebiExample.teacher3": "Sınavı nasıl puanlarım?", | ||
| 2148 | + "aiHub.celebiExample.manager1": "Yeni akademik dönem eklemek istiyorum", | ||
| 2149 | + "aiHub.celebiExample.manager2": "Personel mesai kayıtlarını nereden yönetirim?", | ||
| 2150 | + "aiHub.celebiExample.manager3": "Ücret tahsilatını nereden takip ederim", | ||
| 2135 | "aiHub.celebiHint": "Çelebi opens as a side panel and stays with you on every page.", | 2151 | "aiHub.celebiHint": "Çelebi opens as a side panel and stays with you on every page.", |
| 2136 | "nav.today": "Today", | 2152 | "nav.today": "Today", |
| 2137 | "nav.classes": "Courses", | 2153 | "nav.classes": "Courses", |
| @@ -4234,9 +4250,15 @@ const tr: Dict = { | |||
| 4234 | "aiHub.description": "Tüm yapay zekâ araçları tek yerde: not çıktıları ve podcast, öğrenci analizi ve Çelebi.", | 4250 | "aiHub.description": "Tüm yapay zekâ araçları tek yerde: not çıktıları ve podcast, öğrenci analizi ve Çelebi.", |
| 4235 | "aiHub.tab.studio": "Not stüdyosu", | 4251 | "aiHub.tab.studio": "Not stüdyosu", |
| 4236 | "aiHub.tab.insights": "Analiz", | 4252 | "aiHub.tab.insights": "Analiz", |
| 4237 | - "aiHub.celebiExample1": "Bu hafta hangi ödevlerin teslimi var?", | 4253 | + "aiHub.celebiExample.student1": "Bu hafta hangi ödevlerin teslimi var?", |
| 4238 | - "aiHub.celebiExample2": "Sınıfım kaç gün devamsızlık yaptı?", | 4254 | + "aiHub.celebiExample.student2": "Sınıfım kaç gün devamsızlık yaptı?", |
| 4239 | - "aiHub.celebiExample3": "Yaklaşan sınavımın konularını özetle.", | 4255 | + "aiHub.celebiExample.student3": "Notlarımı nereden görürüm?", |
| 4256 | + "aiHub.celebiExample.teacher1": "Yoklama nasıl alınır?", | ||
| 4257 | + "aiHub.celebiExample.teacher2": "Dersime nasıl sınav eklerim?", | ||
| 4258 | + "aiHub.celebiExample.teacher3": "Sınavı nasıl puanlarım?", | ||
| 4259 | + "aiHub.celebiExample.manager1": "Yeni akademik dönem eklemek istiyorum", | ||
| 4260 | + "aiHub.celebiExample.manager2": "Personel mesai kayıtlarını nereden yönetirim?", | ||
| 4261 | + "aiHub.celebiExample.manager3": "Ücret tahsilatını nereden takip ederim", | ||
| 4240 | "aiHub.celebiHint": "Çelebi yan panel olarak açılır ve her sayfada seninle kalır.", | 4262 | "aiHub.celebiHint": "Çelebi yan panel olarak açılır ve her sayfada seninle kalır.", |
| 4241 | "nav.today": "Bugün", | 4263 | "nav.today": "Bugün", |
| 4242 | "nav.classes": "Dersler", | 4264 | "nav.classes": "Dersler", |