mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-21 06:32:16 +03:00
New routes: - POST /api/memory/retrieve-preview (dry-run playground) - GET /api/memory/embedding-providers - GET /api/memory/engine-status - POST /api/memory/summarize - POST /api/memory/reindex - GET/PUT /api/settings/qdrant - GET /api/settings/qdrant/health - POST /api/settings/qdrant/search - POST /api/settings/qdrant/cleanup Modified: - PUT /api/memory/[id] added (Hard Rule #12 sanitize) - /api/memory/route.ts: Hard Rule #12 fix (sanitizeErrorMessage) - /api/settings/memory/route.ts: MemorySettingsExtendedSchema (D9 7 new fields) Tests: 7 integration test files (33 tests total) all passing. Hard Rules #5, #7, #8, #12 verified.
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getSettings, updateSettings } from "@/lib/localDb";
|
|
import { isAuthenticated } from "@/shared/utils/apiAuth";
|
|
import { isValidationFailure, validateBody } from "@/shared/validation/helpers";
|
|
import { MemorySettingsExtendedSchema } from "@/shared/schemas/memory";
|
|
import {
|
|
invalidateMemorySettingsCache,
|
|
normalizeMemorySettings,
|
|
toMemorySettingsUpdates,
|
|
} from "@/lib/memory/settings";
|
|
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error.ts";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
if (!(await isAuthenticated(request))) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const settings = (await getSettings()) as Record<string, unknown>;
|
|
return NextResponse.json(normalizeMemorySettings(settings));
|
|
} catch (err: unknown) {
|
|
const message = sanitizeErrorMessage(err instanceof Error ? err.message : String(err));
|
|
return NextResponse.json({ error: { message } }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function PUT(request: NextRequest) {
|
|
if (!(await isAuthenticated(request))) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
let rawBody: unknown;
|
|
try {
|
|
rawBody = await request.json();
|
|
} catch {
|
|
return NextResponse.json(
|
|
{ error: { message: "Invalid JSON body", details: [] } },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const validation = validateBody(MemorySettingsExtendedSchema, rawBody);
|
|
if (isValidationFailure(validation)) {
|
|
return NextResponse.json(validation.error, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const updates = toMemorySettingsUpdates(validation.data);
|
|
const settings = (await updateSettings(updates)) as Record<string, unknown>;
|
|
invalidateMemorySettingsCache();
|
|
|
|
return NextResponse.json(normalizeMemorySettings(settings));
|
|
} catch (err: unknown) {
|
|
const message = sanitizeErrorMessage(err instanceof Error ? err.message : String(err));
|
|
return NextResponse.json({ error: { message } }, { status: 500 });
|
|
}
|
|
}
|