Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
feat(compression): add settings API route for compression configuration
oyi770fb535db8ec5
diff --git a/src/app/api/settings/compression/route.ts b/src/app/api/settings/compression/route.tsnew file mode 100644index 0000000000..7bc9ead411--- /dev/null+++ b/src/app/api/settings/compression/route.ts@@ -0,0 +1,58 @@+import { NextRequest, NextResponse } from "next/server";+import { z } from "zod";+import { isAuthenticated } from "@/shared/utils/apiAuth";+import { isValidationFailure, validateBody } from "@/shared/validation/helpers";+import { getCompressionSettings, updateCompressionSettings } from "@/lib/db/compression";++const compressionModeSchema = z.enum(["off", "lite", "standard", "aggressive", "ultra"]);++const compressionSettingsUpdateSchema = z+ .object({+ enabled: z.boolean().optional(),+ defaultMode: compressionModeSchema.optional(),+ autoTriggerTokens: z.number().int().min(0).optional(),+ cacheMinutes: z.number().int().min(1).max(60).optional(),+ preserveSystemPrompt: z.boolean().optional(),+ comboOverrides: z.record(z.string(), compressionModeSchema).optional(),+ })+ .strict();++export async function GET(request: NextRequest) {+ if (!(await isAuthenticated(request))) {+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });+ }++ try {+ const settings = await getCompressionSettings();+ return NextResponse.json(settings);+ } catch (error) {+ return NextResponse.json({ error: String(error) }, { status: 500 });+ }+}++export async function PUT(request: NextRequest) {+ if (!(await isAuthenticated(request))) {+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });+ }++ try {+ let rawBody: unknown;+ try {+ rawBody = await request.json();+ } catch {+ return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });+ }++ const validation = validateBody(compressionSettingsUpdateSchema, rawBody);+ if (isValidationFailure(validation)) {+ return NextResponse.json({ error: validation.error }, { status: 400 });+ }++ const settings = await updateCompressionSettings(+ validation.data as Parameters<typeof updateCompressionSettings>[0]+ );+ return NextResponse.json(settings);+ } catch (error) {+ return NextResponse.json({ error: String(error) }, { status: 500 });+ }+}