Files
9router/src/app/api/models/route.js
decolua d4bc42e1f5 feat: add STT support, Gemini TTS, and expand usage tracking
- Speech-to-Text: full pipeline with sttCore handler, /v1/audio/transcriptions
  endpoint, sttConfig for OpenAI, Gemini, Groq, Deepgram, AssemblyAI,
  HuggingFace, NVIDIA Parakeet; new 9router-stt skill
- Gemini TTS: add gemini provider with 30 prebuilt voices and TTS_PROVIDER_CONFIG
- Usage: implement GLM (intl/cn) and MiniMax (intl/cn) quota fetchers; refactor
  Gemini CLI usage to use retrieveUserQuota with per-model buckets
- Disabled models: lowdb-backed disabledModelsDb + /api/models/disabled route
- Header search: reusable Zustand store (headerSearchStore) wired into Header
- CLI tools: add Claude Cowork tool card and cowork-settings API
- Providers: introduce mediaPriority sorting in getProvidersByKind, add
  Kimi K2.6, reorder hermes, drop qwen STT kind
- UI: expand media-providers/[kind]/[id] page (+314), enhance OAuthModal,
  ModelSelectModal, ProviderTopology, ProxyPools, ProviderLimits
- Assets: refresh provider PNGs (alicode, byteplus, cloudflare-ai, nvidia,
  ollama, vertex, volcengine-ark) and add aws-polly, fal-ai, jina-ai, recraft,
  runwayml, stability-ai, topaz, black-forest-labs
2026-05-05 10:32:59 +07:00

65 lines
2.0 KiB
JavaScript

import { NextResponse } from "next/server";
import { getModelAliases, setModelAlias } from "@/models";
import { getDisabledModels } from "@/lib/disabledModelsDb";
import { AI_MODELS } from "@/shared/constants/config";
import { getProviderAlias } from "@/shared/constants/providers";
// GET /api/models - Get models with aliases
export async function GET() {
try {
const modelAliases = await getModelAliases();
const disabled = await getDisabledModels();
const models = AI_MODELS
.filter((m) => {
const alias = getProviderAlias(m.provider) || m.provider;
const list = disabled[alias] || disabled[m.provider] || [];
return !list.includes(m.model);
})
.map((m) => {
const fullModel = `${m.provider}/${m.model}`;
return {
...m,
fullModel,
alias: modelAliases[fullModel] || m.model,
};
});
return NextResponse.json({ models });
} catch (error) {
console.log("Error fetching models:", error);
return NextResponse.json({ error: "Failed to fetch models" }, { status: 500 });
}
}
// PUT /api/models - Update model alias
export async function PUT(request) {
try {
const body = await request.json();
const { model, alias } = body;
if (!model || !alias) {
return NextResponse.json({ error: "Model and alias required" }, { status: 400 });
}
const modelAliases = await getModelAliases();
// Check if alias already exists for different model
const existingModel = Object.entries(modelAliases).find(
([key, val]) => val === alias && key !== model
);
if (existingModel) {
return NextResponse.json({ error: "Alias already in use" }, { status: 400 });
}
// Update alias
await setModelAlias(model, alias);
return NextResponse.json({ success: true, model, alias });
} catch (error) {
console.log("Error updating alias:", error);
return NextResponse.json({ error: "Failed to update alias" }, { status: 500 });
}
}