Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: replace all fetch() with apiFetch() for authenticated API calls

WeDone20c42491a2f8
diff --git a/web/app/(workspace)/agents/[botId]/chat/page.tsx b/web/app/(workspace)/agents/[botId]/chat/page.tsx
index b1af253f9..d1da39b5d 100644
--- a/web/app/(workspace)/agents/[botId]/chat/page.tsx
+++ b/web/app/(workspace)/agents/[botId]/chat/page.tsx
@@ -5,7 +5,7 @@ import dynamic from "next/dynamic";
import { useParams, useRouter } from "next/navigation";
import { useTranslation } from "react-i18next";
import { ArrowLeft, Bot, Loader2, Send } from "lucide-react";
-import { apiUrl, wsUrl } from "@/lib/api";
+import { apiFetch, apiUrl, wsUrl } from "@/lib/api";
import { firstParam } from "@/lib/route-params";
import AssistantResponse from "@/components/common/AssistantResponse";
import { SimpleComposerInput } from "@/components/chat/home/SimpleComposerInput";
@@ -125,7 +125,7 @@ export default function BotChatPage() {
thinkingRef.current = [];
setStreaming(false);
- fetch(apiUrl(`/api/v1/tutorbot/${botId}`))
+ apiFetch(apiUrl(`/api/v1/tutorbot/${botId}`))
.then((r) => (r.ok ? r.json() : null))
.then((data) => {
if (!cancelled) setBot(data);
@@ -134,7 +134,7 @@ export default function BotChatPage() {
if (!cancelled) setBot(null);
});
- fetch(apiUrl(`/api/v1/tutorbot/${botId}/history`))
+ apiFetch(apiUrl(`/api/v1/tutorbot/${botId}/history`))
.then((r) => (r.ok ? r.json() : []))
.then(
(
diff --git a/web/app/(workspace)/agents/page.tsx b/web/app/(workspace)/agents/page.tsx
index 2297fb550..6db31352f 100644
--- a/web/app/(workspace)/agents/page.tsx
+++ b/web/app/(workspace)/agents/page.tsx
@@ -103,8 +103,7 @@ export default function AgentsPage() {
setLoading(true);
try {
const res = await apiFetch(apiUrl("/api/v1/tutorbot"));
- const data = await res.json();
- setBots(Array.isArray(data) ? data : (data.bots ?? []));
+ setBots(await res.json());
} finally {
setLoading(false);
}
diff --git a/web/app/(workspace)/co-writer/[docId]/page.tsx b/web/app/(workspace)/co-writer/[docId]/page.tsx
index 282f3f9dc..5ee5eea64 100644
--- a/web/app/(workspace)/co-writer/[docId]/page.tsx
+++ b/web/app/(workspace)/co-writer/[docId]/page.tsx
@@ -41,7 +41,7 @@ import {
Workflow,
} from "lucide-react";
import { useParams, useRouter } from "next/navigation";
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
import { listKnowledgeBases } from "@/lib/knowledge-api";
import {
getCoWriterDocument,
@@ -955,7 +955,7 @@ export default function CoWriterPage() {
selectionRequestAbortRef.current = controller;
try {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl("/api/v1/co_writer/edit_react/stream"),
{
method: "POST",
@@ -1073,7 +1073,7 @@ export default function CoWriterPage() {
setError("");
setStatus("");
try {
- const response = await fetch(apiUrl("/api/v1/co_writer/edit"), {
+ const response = await apiFetch(apiUrl("/api/v1/co_writer/edit"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@@ -1107,7 +1107,7 @@ export default function CoWriterPage() {
setError("");
setStatus("");
try {
- const response = await fetch(apiUrl("/api/v1/co_writer/automark"), {
+ const response = await apiFetch(apiUrl("/api/v1/co_writer/automark"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: markdown }),
diff --git a/web/app/(workspace)/playground/page.tsx b/web/app/(workspace)/playground/page.tsx
index f8d1b2fb6..9ebfce0b6 100644
--- a/web/app/(workspace)/playground/page.tsx
+++ b/web/app/(workspace)/playground/page.tsx
@@ -23,7 +23,7 @@ import {
type LucideIcon,
} from "lucide-react";
import { useTranslation } from "react-i18next";
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
import AssistantResponse from "@/components/common/AssistantResponse";
import MarkdownRenderer from "@/components/common/MarkdownRenderer";
import ProcessLogs from "@/components/common/ProcessLogs";
@@ -399,7 +399,7 @@ function ToolExecutor({
else coerced[p.name] = raw;
}
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(`/api/v1/plugins/tools/${tool.name}/execute-stream`),
{
method: "POST",
@@ -837,7 +837,7 @@ function DeepQuestionTester({
max_questions: config.max_questions,
};
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(
`/api/v1/plugins/capabilities/${capability.name}/execute-stream`,
),
@@ -1235,7 +1235,7 @@ function DeepResearchTester({
setStreaming(true);
try {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(
`/api/v1/plugins/capabilities/${capability.name}/execute-stream`,
),
@@ -1522,7 +1522,7 @@ function CapabilityTester({
setStreaming(true);
try {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(
`/api/v1/plugins/capabilities/${capability.name}/execute-stream`,
),
@@ -1718,7 +1718,7 @@ export default function PlaygroundPage() {
setLoading(true);
try {
const [pluginRes, knowledgeBaseList] = await Promise.all([
- fetch(apiUrl("/api/v1/plugins/list")),
+ apiFetch(apiUrl("/api/v1/plugins/list")),
listKnowledgeBases(),
]);
const data = await pluginRes.json();
diff --git a/web/components/chat/preview/previewers/useTextSource.ts b/web/components/chat/preview/previewers/useTextSource.ts
index 3cb40235a..1a501d257 100644
--- a/web/components/chat/preview/previewers/useTextSource.ts
+++ b/web/components/chat/preview/previewers/useTextSource.ts
@@ -1,6 +1,7 @@
"use client";
import { useEffect, useRef, useState } from "react";
+import { apiFetch } from "@/lib/api";
const MAX_TEXT_BYTES = 8 * 1024 * 1024; // 8 MB — preview, not a download
@@ -48,7 +49,7 @@ export function useTextSource(
(async () => {
try {
- const res = await fetch(url, { signal: controller.signal });
+ const res = await apiFetch(url, { signal: controller.signal });
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
diff --git a/web/components/notebook/SaveToNotebookModal.tsx b/web/components/notebook/SaveToNotebookModal.tsx
index 0a6e7e773..6139f7633 100644
--- a/web/components/notebook/SaveToNotebookModal.tsx
+++ b/web/components/notebook/SaveToNotebookModal.tsx
@@ -11,7 +11,7 @@ import {
X,
} from "lucide-react";
import { useTranslation } from "react-i18next";
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
import {
listNotebooks,
type NotebookSummary as RealNotebookSummary,
@@ -301,7 +301,7 @@ export default function SaveToNotebookModal({
}
try {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl("/api/v1/notebook/add_record_with_summary"),
{
method: "POST",
diff --git a/web/components/sidebar/BookRecent.tsx b/web/components/sidebar/BookRecent.tsx
index 1243cc8d8..67fdc7dc1 100644
--- a/web/components/sidebar/BookRecent.tsx
+++ b/web/components/sidebar/BookRecent.tsx
@@ -2,7 +2,7 @@
import Link from "next/link";
import { useEffect, useState } from "react";
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
interface RecentBook {
id: string;
@@ -48,7 +48,7 @@ export function BookRecent({ collapsed = false, limit = 4 }: BookRecentProps) {
let cancelled = false;
(async () => {
try {
- const res = await fetch(apiUrl("/api/v1/book/books"));
+ const res = await apiFetch("/api/v1/book/books");
if (!res.ok) return;
const data = await res.json();
const items: RecentBook[] = Array.isArray(data?.books)
diff --git a/web/components/sidebar/TutorBotRecent.tsx b/web/components/sidebar/TutorBotRecent.tsx
index 6d0d80f40..e9c9478d4 100644
--- a/web/components/sidebar/TutorBotRecent.tsx
+++ b/web/components/sidebar/TutorBotRecent.tsx
@@ -2,7 +2,7 @@
import Link from "next/link";
import { useEffect, useState } from "react";
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
interface RecentBot {
bot_id: string;
@@ -30,7 +30,7 @@ export function TutorBotRecent({ collapsed = false }: { collapsed?: boolean }) {
let cancelled = false;
(async () => {
try {
- const res = await fetch(apiUrl("/api/v1/tutorbot/recent?limit=3"));
+ const res = await apiFetch(apiUrl("/api/v1/tutorbot/recent?limit=3"));
if (!res.ok) return;
const data = await res.json();
if (!cancelled) setBots(data);
diff --git a/web/components/space/MemorySection.tsx b/web/components/space/MemorySection.tsx
index 491e09457..834dca308 100644
--- a/web/components/space/MemorySection.tsx
+++ b/web/components/space/MemorySection.tsx
@@ -127,14 +127,10 @@ export default function MemorySection() {
const d = await readMemoryResponse(res);
setData(d);
setEditors({ summary: d.summary || "", profile: d.profile || "" });
- } catch (error) {
- setToast(
- error instanceof Error ? error.message : t("Memory request failed"),
- );
} finally {
setLoading(false);
}
- }, [t]);
+ }, []);
useEffect(() => {
void loadMemory();
@@ -202,10 +198,6 @@ export default function MemorySection() {
setData(d);
setEditors((prev) => ({ ...prev, [activeTab]: d[activeTab] || "" }));
setToast(t("{{label}} cleared", { label: t(tab.label) }));
- } catch (error) {
- setToast(
- error instanceof Error ? error.message : t("Memory clear failed"),
- );
} finally {
setClearing(false);
}
diff --git a/web/lib/admin-api.ts b/web/lib/admin-api.ts
index ec801ab77..5672d0a6d 100644
--- a/web/lib/admin-api.ts
+++ b/web/lib/admin-api.ts
@@ -1,4 +1,4 @@
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
export interface UserRecord {
id: string;
@@ -9,19 +9,16 @@ export interface UserRecord {
}
export async function listUsers(): Promise<UserRecord[]> {
- const res = await fetch(apiUrl("/api/v1/auth/users"), {
- credentials: "include",
- });
+ const res = await apiFetch(apiUrl("/api/v1/auth/users"));
if (!res.ok) throw new Error("Failed to fetch users");
return res.json();
}
export async function deleteUser(username: string): Promise<void> {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(`/api/v1/auth/users/${encodeURIComponent(username)}`),
{
method: "DELETE",
- credentials: "include",
},
);
if (!res.ok) {
@@ -34,12 +31,11 @@ export async function setUserRole(
username: string,
role: "admin" | "user",
): Promise<void> {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(`/api/v1/auth/users/${encodeURIComponent(username)}/role`),
{
method: "PUT",
headers: { "Content-Type": "application/json" },
- credentials: "include",
body: JSON.stringify({ role }),
},
);
@@ -60,10 +56,9 @@ export async function createUser(
username: string,
password: string,
): Promise<CreatedUser> {
- const res = await fetch(apiUrl("/api/v1/auth/users"), {
+ const res = await apiFetch(apiUrl("/api/v1/auth/users"), {
method: "POST",
headers: { "Content-Type": "application/json" },
- credentials: "include",
body: JSON.stringify({ username, password }),
});
if (!res.ok) {
diff --git a/web/lib/auth.ts b/web/lib/auth.ts
index 1529ae8b7..4c42868b1 100644
--- a/web/lib/auth.ts
+++ b/web/lib/auth.ts
@@ -1,4 +1,4 @@
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
export const AUTH_ENABLED = process.env.NEXT_PUBLIC_AUTH_ENABLED === "true";
@@ -17,9 +17,7 @@ export interface AuthStatus {
*/
export async function fetchAuthStatus(): Promise<AuthStatus | null> {
try {
- const res = await fetch(apiUrl("/api/v1/auth/status"), {
- credentials: "include",
- });
+ const res = await apiFetch(apiUrl("/api/v1/auth/status"));
if (!res.ok) return null;
return res.json();
} catch {
@@ -35,10 +33,9 @@ export async function login(
password: string,
): Promise<{ ok: boolean; error?: string }> {
try {
- const res = await fetch(apiUrl("/api/v1/auth/login"), {
+ const res = await apiFetch(apiUrl("/api/v1/auth/login"), {
method: "POST",
headers: { "Content-Type": "application/json" },
- credentials: "include",
body: JSON.stringify({ username, password }),
});
@@ -79,10 +76,9 @@ export async function register(
error?: string;
}> {
try {
- const res = await fetch(apiUrl("/api/v1/auth/register"), {
+ const res = await apiFetch(apiUrl("/api/v1/auth/register"), {
method: "POST",
headers: { "Content-Type": "application/json" },
- credentials: "include",
body: JSON.stringify({ username, password }),
});
@@ -100,9 +96,7 @@ export async function register(
*/
export async function checkIsFirstUser(): Promise<boolean> {
try {
- const res = await fetch(apiUrl("/api/v1/auth/is_first_user"), {
- credentials: "include",
- });
+ const res = await apiFetch(apiUrl("/api/v1/auth/is_first_user"));
if (!res.ok) return false;
const data = await res.json();
return Boolean(data.is_first_user);
@@ -116,9 +110,8 @@ export async function checkIsFirstUser(): Promise<boolean> {
*/
export async function logout(): Promise<void> {
try {
- await fetch(apiUrl("/api/v1/auth/logout"), {
+ await apiFetch(apiUrl("/api/v1/auth/logout"), {
method: "POST",
- credentials: "include",
});
} catch {
// Ignore — we'll redirect regardless
diff --git a/web/lib/book-api.ts b/web/lib/book-api.ts
index 513daa642..d0b0ca194 100644
--- a/web/lib/book-api.ts
+++ b/web/lib/book-api.ts
@@ -1,4 +1,4 @@
-import { apiUrl, wsUrl } from "@/lib/api";
+import { apiFetch, apiUrl, wsUrl } from "@/lib/api";
import type {
Book,
BookDetail,
@@ -11,7 +11,7 @@ import type {
const BASE = "/api/v1/book";
async function request<T>(path: string, init?: RequestInit): Promise<T> {
- const res = await fetch(apiUrl(`${BASE}${path}`), {
+ const res = await apiFetch(apiUrl(`${BASE}${path}`), {
headers: { "Content-Type": "application/json", ...(init?.headers || {}) },
...init,
});
@@ -217,7 +217,7 @@ export interface LegacyChatSession {
export async function getLegacyChatSession(
session_id: string,
): Promise<LegacyChatSession | null> {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(`/api/v1/chat/sessions/${encodeURIComponent(session_id)}`),
);
if (res.status === 404) return null;
diff --git a/web/lib/co-writer-api.ts b/web/lib/co-writer-api.ts
index 320bf168e..3e1fda9b4 100644
--- a/web/lib/co-writer-api.ts
+++ b/web/lib/co-writer-api.ts
@@ -1,4 +1,4 @@
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
const BASE = "/api/v1/co_writer";
@@ -31,7 +31,7 @@ async function jsonOrThrow<T>(res: Response): Promise<T> {
export async function listCoWriterDocuments(): Promise<
CoWriterDocumentSummary[]
> {
- const res = await fetch(apiUrl(`${BASE}/documents`), { cache: "no-store" });
+ const res = await apiFetch(apiUrl(`${BASE}/documents`), { cache: "no-store" });
const data = await jsonOrThrow<{ documents: CoWriterDocumentSummary[] }>(res);
return Array.isArray(data?.documents) ? data.documents : [];
}
@@ -40,7 +40,7 @@ export async function createCoWriterDocument(payload?: {
title?: string;
content?: string;
}): Promise<CoWriterDocument> {
- const res = await fetch(apiUrl(`${BASE}/documents`), {
+ const res = await apiFetch(apiUrl(`${BASE}/documents`), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@@ -54,7 +54,7 @@ export async function createCoWriterDocument(payload?: {
export async function getCoWriterDocument(
docId: string,
): Promise<CoWriterDocument> {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(`${BASE}/documents/${encodeURIComponent(docId)}`),
{
cache: "no-store",
@@ -67,7 +67,7 @@ export async function updateCoWriterDocument(
docId: string,
payload: { title?: string | null; content?: string | null },
): Promise<CoWriterDocument> {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(`${BASE}/documents/${encodeURIComponent(docId)}`),
{
method: "PUT",
@@ -82,7 +82,7 @@ export async function updateCoWriterDocument(
}
export async function deleteCoWriterDocument(docId: string): Promise<boolean> {
- const res = await fetch(
+ const res = await apiFetch(
apiUrl(`${BASE}/documents/${encodeURIComponent(docId)}`),
{
method: "DELETE",
diff --git a/web/lib/knowledge-api.ts b/web/lib/knowledge-api.ts
index fe162882a..ac5b4b947 100644
--- a/web/lib/knowledge-api.ts
+++ b/web/lib/knowledge-api.ts
@@ -4,7 +4,6 @@ import { invalidateClientCache, withClientCache } from "@/lib/client-cache";
const KNOWLEDGE_CACHE_PREFIX = "knowledge:";
export interface KnowledgeBaseSummary {
- id?: string;
name: string;
is_default?: boolean;
status?: string;
@@ -12,11 +11,6 @@ export interface KnowledgeBaseSummary {
metadata?: Record<string, unknown>;
progress?: Record<string, unknown>;
statistics?: Record<string, unknown>;
- source?: "admin" | "user";
- assigned?: boolean;
- read_only?: boolean;
- provenance_label?: string;
- available?: boolean;
}
export interface RagProviderSummary {
diff --git a/web/lib/notebook-api.ts b/web/lib/notebook-api.ts
index 160c80db1..beff27be0 100644
--- a/web/lib/notebook-api.ts
+++ b/web/lib/notebook-api.ts
@@ -1,4 +1,4 @@
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
// ── Real notebook system (file-backed under data/user/workspace/notebook) ──
//
@@ -43,7 +43,7 @@ export interface NotebookDetail extends NotebookSummary {
}
export async function listNotebooks(): Promise<NotebookSummary[]> {
- const response = await fetch(apiUrl("/api/v1/notebook/list"), {
+ const response = await apiFetch(apiUrl("/api/v1/notebook/list"), {
cache: "no-store",
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
@@ -52,7 +52,7 @@ export async function listNotebooks(): Promise<NotebookSummary[]> {
}
export async function getNotebook(notebookId: string): Promise<NotebookDetail> {
- const response = await fetch(apiUrl(`/api/v1/notebook/${notebookId}`), {
+ const response = await apiFetch(apiUrl(`/api/v1/notebook/${notebookId}`), {
cache: "no-store",
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
@@ -65,7 +65,7 @@ export async function createNotebook(payload: {
color?: string;
icon?: string;
}): Promise<NotebookSummary> {
- const response = await fetch(apiUrl("/api/v1/notebook/create"), {
+ const response = await apiFetch(apiUrl("/api/v1/notebook/create"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@@ -89,7 +89,7 @@ export async function updateNotebook(
icon?: string;
},
): Promise<NotebookSummary> {
- const response = await fetch(apiUrl(`/api/v1/notebook/${notebookId}`), {
+ const response = await apiFetch(apiUrl(`/api/v1/notebook/${notebookId}`), {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
@@ -100,7 +100,7 @@ export async function updateNotebook(
}
export async function deleteNotebook(notebookId: string): Promise<void> {
- const response = await fetch(apiUrl(`/api/v1/notebook/${notebookId}`), {
+ const response = await apiFetch(apiUrl(`/api/v1/notebook/${notebookId}`), {
method: "DELETE",
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
@@ -110,7 +110,7 @@ export async function deleteNotebookRecord(
notebookId: string,
recordId: string,
): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/notebook/${notebookId}/records/${recordId}`),
{ method: "DELETE" },
);
@@ -179,7 +179,7 @@ export async function listNotebookEntries(
if (filter.limit !== undefined) params.set("limit", String(filter.limit));
if (filter.offset !== undefined) params.set("offset", String(filter.offset));
const query = params.toString();
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/entries${query ? `?${query}` : ""}`),
{ cache: "no-store" },
);
@@ -189,7 +189,7 @@ export async function listNotebookEntries(
export async function getNotebookEntry(
entryId: number,
): Promise<NotebookEntry> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/entries/${entryId}`),
{
cache: "no-store",
@@ -206,7 +206,7 @@ export async function lookupNotebookEntry(
session_id: sessionId,
question_id: questionId,
});
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/entries/lookup/by-question?${params}`),
);
if (response.status === 404) return null;
@@ -217,7 +217,7 @@ export async function updateNotebookEntry(
entryId: number,
updates: { bookmarked?: boolean; followup_session_id?: string },
): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/entries/${entryId}`),
{
method: "PATCH",
@@ -240,7 +240,7 @@ export async function upsertNotebookEntry(data: {
user_answer?: string;
is_correct?: boolean;
}): Promise<NotebookEntry> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl("/api/v1/question-notebook/entries/upsert"),
{
method: "POST",
@@ -257,7 +257,7 @@ export async function upsertNotebookEntry(data: {
}
export async function deleteNotebookEntry(entryId: number): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/entries/${entryId}`),
{
method: "DELETE",
@@ -272,7 +272,7 @@ export async function addEntryToCategory(
entryId: number,
categoryId: number,
): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/entries/${entryId}/categories`),
{
method: "POST",
@@ -287,7 +287,7 @@ export async function removeEntryFromCategory(
entryId: number,
categoryId: number,
): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(
`/api/v1/question-notebook/entries/${entryId}/categories/${categoryId}`,
),
@@ -299,14 +299,14 @@ export async function removeEntryFromCategory(
// ── Categories ──────────────────────────────────────────────────
export async function listCategories(): Promise<NotebookCategory[]> {
- const response = await fetch(apiUrl("/api/v1/question-notebook/categories"), {
+ const response = await apiFetch(apiUrl("/api/v1/question-notebook/categories"), {
cache: "no-store",
});
return expectJson<NotebookCategory[]>(response);
}
export async function createCategory(name: string): Promise<NotebookCategory> {
- const response = await fetch(apiUrl("/api/v1/question-notebook/categories"), {
+ const response = await apiFetch(apiUrl("/api/v1/question-notebook/categories"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name }),
@@ -318,7 +318,7 @@ export async function renameCategory(
categoryId: number,
name: string,
): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/categories/${categoryId}`),
{
method: "PATCH",
@@ -330,7 +330,7 @@ export async function renameCategory(
}
export async function deleteCategory(categoryId: number): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/question-notebook/categories/${categoryId}`),
{
method: "DELETE",
diff --git a/web/lib/session-api.ts b/web/lib/session-api.ts
index 8c4f7bc3c..7a0c62780 100644
--- a/web/lib/session-api.ts
+++ b/web/lib/session-api.ts
@@ -1,4 +1,4 @@
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
import { invalidateClientCache, withClientCache } from "@/lib/client-cache";
import type { SurfaceKind } from "@/lib/session-surfaces";
import type { LLMSelection, StreamEvent } from "@/lib/unified-ws";
@@ -130,11 +130,10 @@ export async function listSessions(
return withClientCache<SessionSummary[]>(
`sessions:${kindKey}:${limit}:${offset}`,
async () => {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/sessions?${qs.toString()}`),
{
cache: "no-store",
- credentials: "include",
},
);
const data = await expectJson<{ sessions: SessionSummary[] }>(response);
@@ -148,9 +147,8 @@ export async function listSessions(
}
export async function getSession(sessionId: string): Promise<SessionDetail> {
- const response = await fetch(apiUrl(`/api/v1/sessions/${sessionId}`), {
+ const response = await apiFetch(apiUrl(`/api/v1/sessions/${sessionId}`), {
cache: "no-store",
- credentials: "include",
});
return expectJson<SessionDetail>(response);
}
@@ -159,10 +157,9 @@ export async function updateSessionTitle(
sessionId: string,
title: string,
): Promise<SessionDetail> {
- const response = await fetch(apiUrl(`/api/v1/sessions/${sessionId}`), {
+ const response = await apiFetch(apiUrl(`/api/v1/sessions/${sessionId}`), {
method: "PATCH",
headers: { "Content-Type": "application/json" },
- credentials: "include",
body: JSON.stringify({ title }),
});
const data = await expectJson<{ session: SessionDetail }>(response);
@@ -171,9 +168,8 @@ export async function updateSessionTitle(
}
export async function deleteSession(sessionId: string): Promise<void> {
- const response = await fetch(apiUrl(`/api/v1/sessions/${sessionId}`), {
+ const response = await apiFetch(apiUrl(`/api/v1/sessions/${sessionId}`), {
method: "DELETE",
- credentials: "include",
});
await expectJson<{ deleted: boolean }>(response);
invalidateClientCache("sessions:");
@@ -183,12 +179,11 @@ export async function recordQuizResults(
sessionId: string,
answers: QuizResultItem[],
): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/sessions/${sessionId}/quiz-results`),
{
method: "POST",
headers: { "Content-Type": "application/json" },
- credentials: "include",
body: JSON.stringify({ answers }),
},
);
diff --git a/web/lib/skills-api.ts b/web/lib/skills-api.ts
index f31cc5716..a9e4a001c 100644
--- a/web/lib/skills-api.ts
+++ b/web/lib/skills-api.ts
@@ -1,4 +1,4 @@
-import { apiUrl } from "@/lib/api";
+import { apiFetch, apiUrl } from "@/lib/api";
import { invalidateClientCache, withClientCache } from "@/lib/client-cache";
const SKILLS_CACHE_PREFIX = "skills:";
@@ -63,7 +63,7 @@ export async function listSkills(options?: {
return withClientCache<SkillInfo[]>(
`${SKILLS_CACHE_PREFIX}list`,
async () => {
- const response = await fetch(apiUrl("/api/v1/skills/list"), {
+ const response = await apiFetch(apiUrl("/api/v1/skills/list"), {
cache: "no-store",
});
const data = await asJson(response);
@@ -81,7 +81,7 @@ export async function listSkills(options?: {
}
export async function getSkill(name: string): Promise<SkillDetail> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/skills/${encodeURIComponent(name)}`),
{
cache: "no-store",
@@ -99,7 +99,7 @@ export async function getSkill(name: string): Promise<SkillDetail> {
export async function createSkill(
payload: CreateSkillPayload,
): Promise<SkillInfo> {
- const response = await fetch(apiUrl("/api/v1/skills/create"), {
+ const response = await apiFetch(apiUrl("/api/v1/skills/create"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
@@ -122,7 +122,7 @@ export async function updateSkill(
name: string,
payload: UpdateSkillPayload,
): Promise<SkillInfo> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/skills/${encodeURIComponent(name)}`),
{
method: "PUT",
@@ -140,7 +140,7 @@ export async function updateSkill(
}
export async function deleteSkill(name: string): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/skills/${encodeURIComponent(name)}`),
{
method: "DELETE",
@@ -156,7 +156,7 @@ export async function listSkillTags(options?: {
return withClientCache<string[]>(
SKILL_TAGS_CACHE_KEY,
async () => {
- const response = await fetch(apiUrl("/api/v1/skills/tags/list"), {
+ const response = await apiFetch(apiUrl("/api/v1/skills/tags/list"), {
cache: "no-store",
});
const data = await asJson(response);
@@ -167,7 +167,7 @@ export async function listSkillTags(options?: {
}
export async function createSkillTag(name: string): Promise<string> {
- const response = await fetch(apiUrl("/api/v1/skills/tags/create"), {
+ const response = await apiFetch(apiUrl("/api/v1/skills/tags/create"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name }),
@@ -181,7 +181,7 @@ export async function renameSkillTag(
oldName: string,
newName: string,
): Promise<string> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/skills/tags/${encodeURIComponent(oldName)}`),
{
method: "PUT",
@@ -195,7 +195,7 @@ export async function renameSkillTag(
}
export async function deleteSkillTag(name: string): Promise<void> {
- const response = await fetch(
+ const response = await apiFetch(
apiUrl(`/api/v1/skills/tags/${encodeURIComponent(name)}`),
{
method: "DELETE",