From 2c19dff2e78f0c31ff658b5525d64c404fb78f51 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?=
<80620802+burakboduroglu@users.noreply.github.com>
Date: Thu, 17 Sep 2026 16:29:13 +0300
Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=94=8C=20sync=20with=20the=20late?=
=?UTF-8?q?st=20backend=20contract?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- POST /users: admin creates an account directly (postUser, CreateUserInput)
- profiles carry a branş: shown beside the role badge, and a teacher+ picks it
from settings.branches in the profile form
- class members expose their stint (joined_at, left_at) and the şube a
rollover copied them from
- limits gain academic-year name length, the ders_saati bounds and the rag
rate tier
- chatbotStreamUrl joins the api layer; the çelebi panel stops building the
SSE path inline
---
src/api/__tests__/chatbot/chatbot.test.ts | 5 ++++-
src/api/__tests__/users/users.test.ts | 14 ++++++++++++
src/api/chatbot/chatbotStreamUrl.ts | 7 ++++++
src/api/chatbot/index.ts | 1 +
src/api/client/types.ts | 24 +++++++++++++++++++-
src/api/users/index.ts | 1 +
src/api/users/postUser.ts | 6 +++++
src/components/layout/celebi-panel.tsx | 4 ++--
src/components/users/profile-form.tsx | 27 +++++++++++++++++++++--
src/i18n/messages.ts | 6 +++++
src/pages/profile-page.tsx | 8 ++++++-
11 files changed, 96 insertions(+), 7 deletions(-)
create mode 100644 src/api/chatbot/chatbotStreamUrl.ts
create mode 100644 src/api/users/postUser.ts
diff --git a/src/api/__tests__/chatbot/chatbot.test.ts b/src/api/__tests__/chatbot/chatbot.test.ts
index 098addf..6b21ef8 100644
--- a/src/api/__tests__/chatbot/chatbot.test.ts
+++ b/src/api/__tests__/chatbot/chatbot.test.ts
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from "vitest";
-import { deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread } from "../../chatbot";
+import { chatbotStreamUrl, deleteChatbotThreadById, getChatbotMessageById, getChatbotThreadMessages, getChatbotThreads, patchChatbotThreadById, postChatbotMessage, postChatbotThread } from "../../chatbot";
import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
describe("chatbot API", () => {
@@ -38,4 +38,7 @@ describe("chatbot API", () => {
expect(url).toBe("/api/chatbot/threads/thread-1/messages/answer-1");
expect(init?.method).toBe("GET");
});
+ it("chatbotStreamUrl builds the SSE path for an EventSource", () => {
+ expect(chatbotStreamUrl("t 1", "m1")).toBe("/api/chatbot/threads/t%201/messages/m1/stream");
+ });
});
diff --git a/src/api/__tests__/users/users.test.ts b/src/api/__tests__/users/users.test.ts
index a847091..bc1ba6a 100644
--- a/src/api/__tests__/users/users.test.ts
+++ b/src/api/__tests__/users/users.test.ts
@@ -14,6 +14,7 @@ import { postMyAvatar } from "../../users";
import { deleteMyAvatar } from "../../users";
import { deleteUserAvatar } from "../../users";
import { getUserAvatarUrl } from "../../users";
+import { postUser } from "../../users";
import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
describe("users API", () => {
@@ -214,4 +215,17 @@ describe("users API", () => {
expect(getUserAvatarUrl("u1", 3)).toBe("/api/users/u1/avatar?v=3");
expect(getUserAvatarUrl("u/1")).toBe("/api/users/u%2F1/avatar");
});
+ it("postUser posts the new account to /users", async () => {
+ const mockUser = { id: "u9", username: "ayse", role: "teacher" };
+ mockFetchSuccess(mockUser);
+
+ const body = { username: "ayse", password: "secret123", role: "teacher" as const };
+ const result = await postUser(body);
+ expect(result).toEqual(mockUser);
+
+ const [url, init] = lastFetchCall();
+ expect(url).toBe("/api/users");
+ expect(init?.method).toBe("POST");
+ expect(JSON.parse(init?.body as string)).toEqual(body);
+ });
});
diff --git a/src/api/chatbot/chatbotStreamUrl.ts b/src/api/chatbot/chatbotStreamUrl.ts
new file mode 100644
index 0000000..9c73078
--- /dev/null
+++ b/src/api/chatbot/chatbotStreamUrl.ts
@@ -0,0 +1,7 @@
+/**
+ * The SSE URL for one pending turn: `delta` chunks, then one `done` or
+ * `error`. Not a request — hand it to an `EventSource` (`withCredentials: true`).
+ */
+export function chatbotStreamUrl(threadId: string, messageId: string): string {
+ return `/api/chatbot/threads/${encodeURIComponent(threadId)}/messages/${encodeURIComponent(messageId)}/stream`;
+}
diff --git a/src/api/chatbot/index.ts b/src/api/chatbot/index.ts
index 33c87a2..233620f 100644
--- a/src/api/chatbot/index.ts
+++ b/src/api/chatbot/index.ts
@@ -5,4 +5,5 @@ export * from "./patchChatbotThreadById";
export * from "./deleteChatbotThreadById";
export * from "./postChatbotMessage";
export * from "./postChatbotThread";
+export * from "./chatbotStreamUrl";
export * from "./types";
diff --git a/src/api/client/types.ts b/src/api/client/types.ts
index 426427d..242f56e 100644
--- a/src/api/client/types.ts
+++ b/src/api/client/types.ts
@@ -38,6 +38,17 @@ export type ProfileUpdate = {
birth_date?: string | null;
display_name?: string | null;
bio?: string | null;
+ // The teacher's branş, by name from settings.branches.
+ branch?: string | null;
+};
+
+// POST /users (admin): the school office opens an account directly. `role`
+// defaults to student on the server; an existing person joins this school only
+// when the password matches their credential (409 otherwise).
+export type CreateUserInput = {
+ username: string;
+ password: string;
+ role?: Role;
};
export type PersonRef = {
@@ -105,6 +116,8 @@ export type Profile = {
display_name: string | null;
role: Role;
bio: string | null;
+ // The teacher's branş, one of settings.branches; null when unset.
+ branch: string | null;
avatar: AvatarMeta | null;
// Capped at limits.user.max_profile_classes; stats.classes holds the true total.
classes: ProfileClassRef[];
@@ -395,6 +408,12 @@ export type ClassMember = {
class: string;
user: PersonRef;
added_by: PersonRef;
+ // One stint: a leave-and-rejoin is a fresh row with a fresh id.
+ joined_at: number;
+ // Null while the stint is live; the roster routes only list live rows.
+ left_at: number | null;
+ // The şube a year rollover copied this member out of; null when placed by hand.
+ source_class_group: string | null;
};
// The instance as the class routes return it: an Instance plus who attached
@@ -833,6 +852,9 @@ export type Limits = {
max_class_grade_len: number;
max_class_members: number;
max_class_courses: number;
+ max_academic_year_name_len: number;
+ min_ders_saati: number;
+ max_ders_saati: number;
};
exam: {
max_title_len: number;
@@ -934,7 +956,7 @@ export type Limits = {
required_attendance_statuses: string[];
};
request: { max_page_limit: number; max_request_id_len: number; schedule_past_grace_ms: number; request_timeout_secs: number };
- rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number };
+ rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number; rag_per_minute: number };
// The RAG nest. Message length, thread titles, history depth and the thread
// cap are the chatbot's own knobs, republished so a RAG client need not read
// the chatbot group to bound its input.
diff --git a/src/api/users/index.ts b/src/api/users/index.ts
index ac8f0c4..feff523 100644
--- a/src/api/users/index.ts
+++ b/src/api/users/index.ts
@@ -13,3 +13,4 @@ export * from "./postMyAvatar";
export * from "./deleteMyAvatar";
export * from "./deleteUserAvatar";
export * from "./getUserAvatarUrl";
+export * from "./postUser";
diff --git a/src/api/users/postUser.ts b/src/api/users/postUser.ts
new file mode 100644
index 0000000..f61707f
--- /dev/null
+++ b/src/api/users/postUser.ts
@@ -0,0 +1,6 @@
+import { client } from "../client";
+import type { CreateUserInput, User } from "../client";
+
+export function postUser(body: CreateUserInput): Promise
{p().bio || t("profile.bioEmpty")}
@@ -220,7 +225,8 @@ function ProfileContent() {
{(u) => (