mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-23 07:32:20 +03:00
⭐4 — Suporte de backend nativo Bun + Dockerfile.bun multi-stage + fallback dinâmico de driver SQLite (better-sqlite3 prioritário sob Bun, bun:sqlite fallback; Node preservado) + correção de estabilidade do DAST CI smoke.
Validado a fundo (worktree board sobre tip): bun-support 4/4, typecheck:core limpo, dashboard-typecheck OK (220 dentro do baseline), open-sse-typecheck OK (5 pré-existentes), gate de runtime OK sob Node, changelog-integrity OK, file-size/complexity/cognitive/dead-code OK. Verificado que o driver preserva a cadeia Node/falback conforme AGENTS.md; teste bun-support presente. Baselines de typecheck removidos são ratchet honesto (erros não existem mais).
OBS: destravei 2 base-reds do tip neste turno (push direto 7ffa3ef): movi o changelog fragment da #11050 da seção inválida breaking/ para fixes/, e rebaselinei AddApiKeyModal 1067->1073 (crescimento da #11056). Sem isso a #11039 e o resto da fila ficariam vermelhos.
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
export const dynamic = "force-dynamic";
|
|
import { isAuthenticated } from "@/shared/utils/apiAuth";
|
|
import {
|
|
clearReasoningCacheAll,
|
|
deleteReasoningCacheEntry,
|
|
getReasoningCacheServiceEntries,
|
|
getReasoningCacheServiceStats,
|
|
} from "@omniroute/open-sse/services/reasoningCache.ts";
|
|
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error";
|
|
|
|
function errorMessage(error: unknown): string {
|
|
return sanitizeErrorMessage(error);
|
|
}
|
|
|
|
/**
|
|
* GET /api/cache/reasoning
|
|
*
|
|
* Returns reasoning replay cache stats + paginated entries.
|
|
* Query params: ?provider=deepseek&model=deepseek-reasoner&limit=50&offset=0
|
|
*/
|
|
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 provider = searchParams.get("provider") || undefined;
|
|
const model = searchParams.get("model") || undefined;
|
|
const limit = parseInt(searchParams.get("limit") || "50", 10);
|
|
const offset = parseInt(searchParams.get("offset") || "0", 10);
|
|
|
|
const stats = getReasoningCacheServiceStats();
|
|
const entries = getReasoningCacheServiceEntries({
|
|
limit: Math.min(Math.max(limit, 1), 200),
|
|
offset: Math.max(offset, 0),
|
|
provider,
|
|
model,
|
|
});
|
|
|
|
return NextResponse.json({ stats, entries });
|
|
} catch (error) {
|
|
return NextResponse.json({ error: errorMessage(error) }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* DELETE /api/cache/reasoning
|
|
*
|
|
* Clears reasoning cache entries.
|
|
* Query params: ?toolCallId=call_abc (single entry), ?provider=deepseek, or no params.
|
|
*/
|
|
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 toolCallId = searchParams.get("toolCallId") || undefined;
|
|
const provider = searchParams.get("provider") || undefined;
|
|
|
|
if (toolCallId) {
|
|
const cleared = deleteReasoningCacheEntry(toolCallId);
|
|
return NextResponse.json({
|
|
ok: true,
|
|
cleared,
|
|
scope: "toolCallId",
|
|
toolCallId,
|
|
});
|
|
}
|
|
|
|
const cleared = clearReasoningCacheAll(provider);
|
|
|
|
return NextResponse.json({
|
|
ok: true,
|
|
cleared,
|
|
scope: provider ? "provider" : "all",
|
|
...(provider ? { provider } : {}),
|
|
});
|
|
} catch (error) {
|
|
return NextResponse.json({ error: errorMessage(error) }, { status: 500 });
|
|
}
|
|
}
|