mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
Enhance token refresh logic and improve MITM server handling
- Introduced a caching mechanism for in-flight token refresh requests to prevent race conditions and reduce unnecessary API calls. - Added error handling for unrecoverable refresh errors, ensuring that the application can gracefully handle token reuse and invalidation scenarios. - Updated the MITM server management to handle port 443 conflicts, allowing users to kill processes occupying the port before starting the server. - Improved user feedback in the MitmServerCard component regarding port conflicts and admin privileges. - Refactored the ComboList component to streamline the display of media provider combos. This update aims to enhance the reliability and user experience of the token management and MITM functionalities.
This commit is contained in:
@@ -6,11 +6,13 @@ import {
|
||||
isValidApiKey,
|
||||
} from "../services/auth.js";
|
||||
import { getSettings } from "@/lib/localDb";
|
||||
import { getModelInfo } from "../services/model.js";
|
||||
import { getModelInfo, getComboModels } from "../services/model.js";
|
||||
import { handleImageGenerationCore } from "open-sse/handlers/imageGenerationCore.js";
|
||||
import { errorResponse, unavailableResponse } from "open-sse/utils/error.js";
|
||||
import { HTTP_STATUS } from "open-sse/config/runtimeConfig.js";
|
||||
import { updateProviderCredentials, checkAndRefreshToken } from "../services/tokenRefresh.js";
|
||||
import { handleComboChat } from "open-sse/services/combo.js";
|
||||
import * as log from "../utils/logger.js";
|
||||
|
||||
// Providers that don't require credentials (noAuth)
|
||||
const NO_AUTH_PROVIDERS = new Set(["sdwebui", "comfyui"]);
|
||||
@@ -44,6 +46,28 @@ export async function handleImageGeneration(request) {
|
||||
if (!modelStr) return errorResponse(HTTP_STATUS.BAD_REQUEST, "Missing model");
|
||||
if (!body.prompt) return errorResponse(HTTP_STATUS.BAD_REQUEST, "Missing required field: prompt");
|
||||
|
||||
// Combo expansion: model may be a combo name → run fallback/round-robin across models
|
||||
const comboModels = await getComboModels(modelStr);
|
||||
if (comboModels) {
|
||||
const comboStrategies = settings.comboStrategies || {};
|
||||
const comboStrategy = comboStrategies[modelStr]?.fallbackStrategy || settings.comboStrategy || "fallback";
|
||||
const comboStickyLimit = settings.comboStickyRoundRobinLimit;
|
||||
log.info("IMAGE", `Combo "${modelStr}" with ${comboModels.length} models (strategy: ${comboStrategy}, sticky: ${comboStickyLimit})`);
|
||||
return handleComboChat({
|
||||
body,
|
||||
models: comboModels,
|
||||
handleSingleModel: (b, m) => handleSingleModelImage(b, m, { wantsStream, binaryOutput, preferredConnectionId }),
|
||||
log,
|
||||
comboName: modelStr,
|
||||
comboStrategy,
|
||||
comboStickyLimit,
|
||||
});
|
||||
}
|
||||
|
||||
return handleSingleModelImage(body, modelStr, { wantsStream, binaryOutput, preferredConnectionId });
|
||||
}
|
||||
|
||||
async function handleSingleModelImage(body, modelStr, { wantsStream, binaryOutput, preferredConnectionId } = {}) {
|
||||
const modelInfo = await getModelInfo(modelStr);
|
||||
if (!modelInfo.provider) return errorResponse(HTTP_STATUS.BAD_REQUEST, "Invalid model format");
|
||||
|
||||
|
||||
+24
-1
@@ -3,11 +3,12 @@ import {
|
||||
getProviderCredentials, markAccountUnavailable,
|
||||
} from "../services/auth.js";
|
||||
import { getSettings } from "@/lib/localDb";
|
||||
import { getModelInfo } from "../services/model.js";
|
||||
import { getModelInfo, getComboModels } from "../services/model.js";
|
||||
import { handleTtsCore } from "open-sse/handlers/ttsCore.js";
|
||||
import { errorResponse, unavailableResponse } from "open-sse/utils/error.js";
|
||||
import { HTTP_STATUS } from "open-sse/config/runtimeConfig.js";
|
||||
import { AI_PROVIDERS } from "@/shared/constants/providers";
|
||||
import { handleComboChat } from "open-sse/services/combo.js";
|
||||
import * as log from "../utils/logger.js";
|
||||
|
||||
// Derived from providers.js: any TTS provider not noAuth requires stored credentials
|
||||
@@ -41,6 +42,28 @@ export async function handleTts(request) {
|
||||
if (!modelStr) return errorResponse(HTTP_STATUS.BAD_REQUEST, "Missing model");
|
||||
if (!body.input) return errorResponse(HTTP_STATUS.BAD_REQUEST, "Missing required field: input");
|
||||
|
||||
// Combo expansion: model may be a combo name → run fallback/round-robin across models
|
||||
const comboModels = await getComboModels(modelStr);
|
||||
if (comboModels) {
|
||||
const comboStrategies = settings.comboStrategies || {};
|
||||
const comboStrategy = comboStrategies[modelStr]?.fallbackStrategy || settings.comboStrategy || "fallback";
|
||||
const comboStickyLimit = settings.comboStickyRoundRobinLimit;
|
||||
log.info("TTS", `Combo "${modelStr}" with ${comboModels.length} models (strategy: ${comboStrategy}, sticky: ${comboStickyLimit})`);
|
||||
return handleComboChat({
|
||||
body,
|
||||
models: comboModels,
|
||||
handleSingleModel: (b, m) => handleSingleModelTts(b, m, responseFormat),
|
||||
log,
|
||||
comboName: modelStr,
|
||||
comboStrategy,
|
||||
comboStickyLimit,
|
||||
});
|
||||
}
|
||||
|
||||
return handleSingleModelTts(body, modelStr, responseFormat);
|
||||
}
|
||||
|
||||
async function handleSingleModelTts(body, modelStr, responseFormat) {
|
||||
const modelInfo = await getModelInfo(modelStr);
|
||||
if (!modelInfo.provider) return errorResponse(HTTP_STATUS.BAD_REQUEST, "Invalid model format");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user