From 22d6d3a432e12110d096bc09581866bf606bf8a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 18 Sep 2026 03:11:02 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=8E=AF=20give=20each=20role=20its?= =?UTF-8?q?=20own=20=C3=87elebi=20examples=20on=20the=20AI=20hub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hub showed the same three example questions to every viewer; for a staff viewer two of them sit outside the role's scope, so the live assistant answered with a refusal or a "please rephrase" — the UI was advertising questions its own viewer cannot ask. - the launcher picks its examples with the same role predicate the hub uses for its tabs: student, teacher, and a manager+admin band (a parent never reaches the tab and keeps the student fallback) - every string is one the deployed assistant answers for the role that sees it, checked over HTTP per role (POST /chatbot/threads/{id}/messages, reply read back); the old "summarise my next exam" example is dropped because the live bot answers it with its clarification fallback even for students - the examples stay Turkish in both locales: Çelebi's intent engine only understands Turkish, and the English wording of the same questions comes back as "please rephrase" --- src/components/ai/celebi-launcher.test.tsx | 46 ++++++++++++++++++++++ src/components/ai/celebi-launcher.tsx | 37 ++++++++++++++++- src/i18n/messages.ts | 40 ++++++++++++++----- 3 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 src/components/ai/celebi-launcher.test.tsx diff --git a/src/components/ai/celebi-launcher.test.tsx b/src/components/ai/celebi-launcher.test.tsx new file mode 100644 index 0000000..164e739 --- /dev/null +++ b/src/components/ai/celebi-launcher.test.tsx @@ -0,0 +1,46 @@ +import { cleanup, render } from "@solidjs/testing-library"; +import { afterEach, expect, test, vi } from "vitest"; +import { CelebiLauncher } from "@/components/ai/celebi-launcher"; +import { PreferencesProvider } from "@/stores/preferences-context"; + +const { authUser } = vi.hoisted(() => ({ authUser: { role: "student" as string } })); + +vi.mock("@/stores/auth-context", () => ({ + useAuth: () => ({ user: () => ({ id: "u-1", username: "demo", role: authUser.role }) }), +})); +vi.mock("@/stores/celebi-panel", () => ({ openCelebiPanel: () => undefined })); + +function mount() { + return render(() => ( + + + + )); +} + +afterEach(cleanup); + +test("a student gets questions the assistant answers for students", () => { + authUser.role = "student"; + const { container } = mount(); + expect(container.textContent).toContain("Bu hafta hangi ödevlerin teslimi var?"); + expect(container.textContent).toContain("Notlarımı nereden görürüm?"); + expect(container.textContent).not.toContain("Yoklama nasıl alınır?"); + expect(container.textContent).not.toContain("Yeni akademik dönem eklemek istiyorum"); +}); + +test("a teacher gets the teacher questions, not the student ones", () => { + authUser.role = "teacher"; + const { container } = mount(); + expect(container.textContent).toContain("Yoklama nasıl alınır?"); + expect(container.textContent).toContain("Sınavı nasıl puanlarım?"); + expect(container.textContent).not.toContain("Bu hafta hangi ödevlerin teslimi var?"); +}); + +test.each(["manager", "admin"])("a %s gets the school-management questions", (role) => { + authUser.role = role; + const { container } = mount(); + expect(container.textContent).toContain("Yeni akademik dönem eklemek istiyorum"); + expect(container.textContent).toContain("Personel mesai kayıtlarını nereden yönetirim?"); + expect(container.textContent).not.toContain("Yoklama nasıl alınır?"); +}); diff --git a/src/components/ai/celebi-launcher.tsx b/src/components/ai/celebi-launcher.tsx index e5a0990..5e855a2 100644 --- a/src/components/ai/celebi-launcher.tsx +++ b/src/components/ai/celebi-launcher.tsx @@ -1,14 +1,49 @@ import { For } from "solid-js"; import { Button } from "@/components/ui/button"; import { IconSparkles } from "@/components/ui/icons"; +import type { MessageKey } from "@/i18n/messages"; +import { hasMinRole } from "@/lib/roles"; import { openCelebiPanel } from "@/stores/celebi-panel"; +import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; +// Every example is a question the deployed Çelebi assistant answers for the +// role that sees it — a prompt outside the viewer's scope comes back as a +// refusal or a "please rephrase", so the sets are checked against the live bot +// rather than guessed. The manager band covers managers and admins; a student +// set is the fallback because a parent never reaches this tab. +const EXAMPLE_KEYS: Record<"student" | "teacher" | "manager", MessageKey[]> = { + student: [ + "aiHub.celebiExample.student1", + "aiHub.celebiExample.student2", + "aiHub.celebiExample.student3", + ], + teacher: [ + "aiHub.celebiExample.teacher1", + "aiHub.celebiExample.teacher2", + "aiHub.celebiExample.teacher3", + ], + manager: [ + "aiHub.celebiExample.manager1", + "aiHub.celebiExample.manager2", + "aiHub.celebiExample.manager3", + ], +}; + // Çelebi itself is a shell panel — it follows the viewer across every route, // so the hub tab opens that one panel instead of mounting a second chat. export function CelebiLauncher() { const t = useT(); - const examples = () => [t("aiHub.celebiExample1"), t("aiHub.celebiExample2"), t("aiHub.celebiExample3")]; + const auth = useAuth(); + const examples = () => { + const role = auth.user()?.role; + const band = hasMinRole(role, "manager") + ? "manager" + : hasMinRole(role, "teacher") + ? "teacher" + : "student"; + return EXAMPLE_KEYS[band].map((key) => t(key)); + }; return (
diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 97b6945..f28b545 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -35,9 +35,15 @@ export type MessageKey = | "aiHub.description" | "aiHub.tab.studio" | "aiHub.tab.insights" - | "aiHub.celebiExample1" - | "aiHub.celebiExample2" - | "aiHub.celebiExample3" + | "aiHub.celebiExample.student1" + | "aiHub.celebiExample.student2" + | "aiHub.celebiExample.student3" + | "aiHub.celebiExample.teacher1" + | "aiHub.celebiExample.teacher2" + | "aiHub.celebiExample.teacher3" + | "aiHub.celebiExample.manager1" + | "aiHub.celebiExample.manager2" + | "aiHub.celebiExample.manager3" | "aiHub.celebiHint" | "nav.today" | "nav.classes" @@ -2129,9 +2135,19 @@ const en: Dict = { "aiHub.description": "Every AI surface in one place: note outputs and podcasts, student analysis, and Çelebi.", "aiHub.tab.studio": "Note studio", "aiHub.tab.insights": "Analysis", - "aiHub.celebiExample1": "Which homework is due this week?", - "aiHub.celebiExample2": "How many days has my class missed?", - "aiHub.celebiExample3": "Summarise the topics of my next exam.", + // Çelebi's intent engine only understands Turkish: the same English wording + // comes back as "please rephrase" from the live assistant, so the examples + // ship the Turkish question verbatim in both locales. Each one is checked + // against the deployed assistant for the role that sees it. + "aiHub.celebiExample.student1": "Bu hafta hangi ödevlerin teslimi var?", + "aiHub.celebiExample.student2": "Sınıfım kaç gün devamsızlık yaptı?", + "aiHub.celebiExample.student3": "Notlarımı nereden görürüm?", + "aiHub.celebiExample.teacher1": "Yoklama nasıl alınır?", + "aiHub.celebiExample.teacher2": "Dersime nasıl sınav eklerim?", + "aiHub.celebiExample.teacher3": "Sınavı nasıl puanlarım?", + "aiHub.celebiExample.manager1": "Yeni akademik dönem eklemek istiyorum", + "aiHub.celebiExample.manager2": "Personel mesai kayıtlarını nereden yönetirim?", + "aiHub.celebiExample.manager3": "Ücret tahsilatını nereden takip ederim", "aiHub.celebiHint": "Çelebi opens as a side panel and stays with you on every page.", "nav.today": "Today", "nav.classes": "Courses", @@ -4234,9 +4250,15 @@ const tr: Dict = { "aiHub.description": "Tüm yapay zekâ araçları tek yerde: not çıktıları ve podcast, öğrenci analizi ve Çelebi.", "aiHub.tab.studio": "Not stüdyosu", "aiHub.tab.insights": "Analiz", - "aiHub.celebiExample1": "Bu hafta hangi ödevlerin teslimi var?", - "aiHub.celebiExample2": "Sınıfım kaç gün devamsızlık yaptı?", - "aiHub.celebiExample3": "Yaklaşan sınavımın konularını özetle.", + "aiHub.celebiExample.student1": "Bu hafta hangi ödevlerin teslimi var?", + "aiHub.celebiExample.student2": "Sınıfım kaç gün devamsızlık yaptı?", + "aiHub.celebiExample.student3": "Notlarımı nereden görürüm?", + "aiHub.celebiExample.teacher1": "Yoklama nasıl alınır?", + "aiHub.celebiExample.teacher2": "Dersime nasıl sınav eklerim?", + "aiHub.celebiExample.teacher3": "Sınavı nasıl puanlarım?", + "aiHub.celebiExample.manager1": "Yeni akademik dönem eklemek istiyorum", + "aiHub.celebiExample.manager2": "Personel mesai kayıtlarını nereden yönetirim?", + "aiHub.celebiExample.manager3": "Ücret tahsilatını nereden takip ederim", "aiHub.celebiHint": "Çelebi yan panel olarak açılır ve her sayfada seninle kalır.", "nav.today": "Bugün", "nav.classes": "Dersler",