- Cap maximum cooldown for rate limit handling in account unavailability and single-model chat flows

- Dynamic custom model fetching for model selection
This commit is contained in:
decolua 2026-04-24 16:14:18 +07:00
parent c42c0146ab
commit cca615eaff
19 changed files with 108 additions and 60 deletions

View file

@ -159,7 +159,9 @@ export async function POST(request) {
authData = JSON.parse(existingAuth);
} catch { /* No existing auth */ }
// Force apikey mode (keep existing tokens untouched for ChatGPT login reuse)
authData.OPENAI_API_KEY = apiKey;
authData.auth_mode = "apikey";
await fs.writeFile(authPath, JSON.stringify(authData, null, 2));
return NextResponse.json({
@ -215,7 +217,8 @@ export async function DELETE() {
const existingAuth = await fs.readFile(authPath, "utf-8");
const authData = JSON.parse(existingAuth);
delete authData.OPENAI_API_KEY;
delete authData.auth_mode;
// Write back or delete if empty
if (Object.keys(authData).length === 0) {
await fs.unlink(authPath);

View file

@ -1,5 +1,6 @@
import { NextResponse } from "next/server";
import { getComboById, updateCombo, deleteCombo, getComboByName } from "@/lib/localDb";
import { resetComboRotation } from "open-sse/services/combo.js";
// Validate combo name: only a-z, A-Z, 0-9, -, _
const VALID_NAME_REGEX = /^[a-zA-Z0-9_.\-]+$/;
@ -40,12 +41,18 @@ export async function PUT(request, { params }) {
}
}
// Capture previous name to invalidate rotation state on rename
const prev = await getComboById(id);
const combo = await updateCombo(id, body);
if (!combo) {
return NextResponse.json({ error: "Combo not found" }, { status: 404 });
}
// Invalidate rotation state (models/strategy/name may have changed)
if (prev?.name) resetComboRotation(prev.name);
if (combo.name && combo.name !== prev?.name) resetComboRotation(combo.name);
return NextResponse.json(combo);
} catch (error) {
console.log("Error updating combo:", error);
@ -57,11 +64,14 @@ export async function PUT(request, { params }) {
export async function DELETE(request, { params }) {
try {
const { id } = await params;
const prev = await getComboById(id);
const success = await deleteCombo(id);
if (!success) {
return NextResponse.json({ error: "Combo not found" }, { status: 404 });
}
if (prev?.name) resetComboRotation(prev.name);
return NextResponse.json({ success: true });
} catch (error) {

View file

@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { getSettings, updateSettings } from "@/lib/localDb";
import { applyOutboundProxyEnv } from "@/lib/network/outboundProxy";
import { setRtkEnabled } from "open-sse/rtk/flag.js";
import { resetComboRotation } from "open-sse/services/combo.js";
import bcrypt from "bcryptjs";
export async function GET() {
@ -67,10 +67,14 @@ export async function PATCH(request) {
applyOutboundProxyEnv(settings);
}
// Sync RTK toggle immediately (sync cache for request hot path)
if (Object.prototype.hasOwnProperty.call(body, "rtkEnabled")) {
setRtkEnabled(settings.rtkEnabled);
// Invalidate combo rotation state when strategy settings change
if (
Object.prototype.hasOwnProperty.call(body, "comboStrategy") ||
Object.prototype.hasOwnProperty.call(body, "comboStrategies")
) {
resetComboRotation();
}
const { password, ...safeSettings } = settings;
return NextResponse.json(safeSettings);
} catch (error) {