Merge pull request #834 from oyi77/feat/cache-page-prompt-cache-tracking

fix(debug/sidebar): debug toggle and sidebar visibility
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-03-30 20:47:54 -03:00
committed by GitHub
9 changed files with 77 additions and 12 deletions

View File

@@ -106,7 +106,10 @@ export default function AppearanceTab() {
{ id: "cyan", color: COLOR_THEMES.cyan, label: t("themeCyan") },
];
const sidebarSections = SIDEBAR_SECTIONS.map((section) => ({
const showDebug = settings.debugMode === true;
const sidebarSections = SIDEBAR_SECTIONS.filter(
(section) => section.visibility !== "debug" || showDebug
).map((section) => ({
...section,
title: getSidebarLabel(section.titleKey, section.titleFallback),
items: section.items.map((item) => ({ ...item, label: tSidebar(item.i18nKey) })),

View File

@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from "next/server";
import { getDbInstance } from "@/lib/db/core";
import { isAuthenticated } from "@/shared/utils/apiAuth";
interface CacheEntry {
id: string;
@@ -12,6 +13,10 @@ interface CacheEntry {
}
export async function GET(req: NextRequest) {
if (!(await isAuthenticated(req))) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
try {
const { searchParams } = new URL(req.url);
const page = Math.max(1, parseInt(searchParams.get("page") || "1", 10));
@@ -71,6 +76,10 @@ export async function GET(req: NextRequest) {
}
export async function DELETE(req: NextRequest) {
if (!(await isAuthenticated(req))) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
try {
const { searchParams } = new URL(req.url);
const signature = searchParams.get("signature");

View File

@@ -9,15 +9,21 @@ import {
} from "@/lib/semanticCache";
import { getIdempotencyStats } from "@/lib/idempotencyLayer";
import { getCacheMetrics, getCacheTrend } from "@/lib/db/settings";
import { isAuthenticated } from "@/shared/utils/apiAuth";
function errorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
export async function GET(req: NextRequest) {
if (!(await isAuthenticated(req))) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
try {
const { searchParams } = new URL(req.url);
const trendHours = parseInt(searchParams.get("trendHours") || "24", 10);
const rawHours = parseInt(searchParams.get("trendHours") || "24", 10);
const trendHours = Math.min(720, Math.max(1, Number.isNaN(rawHours) ? 24 : rawHours));
const cacheStats = getCacheStats();
const idempotencyStats = getIdempotencyStats();
@@ -36,6 +42,10 @@ export async function GET(req: NextRequest) {
}
export async function DELETE(req: NextRequest) {
if (!(await isAuthenticated(req))) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
try {
const { searchParams } = new URL(req.url);
const model = searchParams.get("model");

View File

@@ -630,7 +630,7 @@ export async function getCacheMetrics() {
totalCachedTokens: totalsRow?.totalCachedTokens || 0,
totalCacheCreationTokens: totalsRow?.totalCacheCreationTokens || 0,
tokensSaved,
estimatedCostSaved: 0, // Would need pricing data to calculate
estimatedCostSaved,
byProvider,
byStrategy,
lastUpdated: new Date().toISOString(),

View File

@@ -1 +1 @@
export { analyzePrefix, shouldInjectCacheControl } from "./prefixAnalyzer";
export { analyzePrefix, shouldInjectCacheControl, generatePromptCacheKey } from "./prefixAnalyzer";

View File

@@ -75,3 +75,11 @@ export function analyzePrefix(messages: Message[]): PrefixAnalysis {
export function shouldInjectCacheControl(analysis: PrefixAnalysis, minTokens = 1024): boolean {
return analysis.prefixTokens >= minTokens && analysis.confidence >= 0.7;
}
export function generatePromptCacheKey(messages: Message[]): string {
const analysis = analyzePrefix(messages);
if (analysis.prefixHash) {
return `omni-${analysis.prefixHash.slice(0, 32)}`;
}
return "";
}

View File

@@ -40,7 +40,7 @@ export default function Sidebar({
useEffect(() => {
const applySettings = (data) => {
setShowDebug(data?.enableRequestLogs === true);
setShowDebug(data?.debugMode === true);
setHiddenSidebarItems(normalizeHiddenSidebarItems(data?.[HIDDEN_SIDEBAR_ITEMS_SETTING_KEY]));
};
@@ -52,8 +52,8 @@ export default function Sidebar({
const handleSettingsUpdated = (event: Event) => {
const detail = (event as CustomEvent<Record<string, unknown>>).detail || {};
if ("enableRequestLogs" in detail) {
setShowDebug(detail.enableRequestLogs === true);
if ("debugMode" in detail) {
setShowDebug(detail.debugMode === true);
}
if (HIDDEN_SIDEBAR_ITEMS_SETTING_KEY in detail) {