refactor(open-sse): translator DRY + schema enums, bug fixes, dead code cleanup
- Bug B1-B7: media UI m.kind||m.type, serviceKinds, gemini mediaPriority, schema kind, models/info lookup by kind - Dead code D1-D6: safeParseJSON, drop PROVIDER_ENDPOINTS, orphan fetcher, GITHUB_CONFIG derive, getProviderConfig internal, legacy kiro file - Translator concerns: toOpenAIUsage, toOpenAIFinish (gemini/kiro/ollama + fix kiro tool finish), thinking effort maps - Reorg helpers/ → concerns/ (logic) + formats/ (per-format) + schema/ (pure enums: roles/blocks/finishReasons/defaults) - Wire ~280 hardcoded role/block/finish/default literals to schema enums across 20+ files - collapseTextParts + extractTextContent dedup - Normalize translator fn names to openaiToXRequest / xToOpenAIResponse - Golden tests lock behavior; 0 regression (byte-for-byte providers/alias, 26=26 known fails) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -134,7 +134,7 @@ const KIND_EXAMPLE_CONFIG = {
|
||||
function EmbeddingExampleCard({ providerId, customAlias }) {
|
||||
const isCustom = isCustomEmbeddingProvider(providerId);
|
||||
const providerAlias = isCustom ? (customAlias || providerId) : getProviderAlias(providerId);
|
||||
const embeddingModels = isCustom ? [] : getModelsByProviderId(providerId).filter((m) => m.type === "embedding");
|
||||
const embeddingModels = isCustom ? [] : getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "embedding");
|
||||
|
||||
const [selectedModel, setSelectedModel] = useState(embeddingModels[0]?.id ?? "");
|
||||
const [input, setInput] = useState("The quick brown fox jumps over the lazy dog");
|
||||
@@ -431,7 +431,7 @@ function TtsExampleCard({ providerId }) {
|
||||
// Use per-model voices if available, else flat list
|
||||
const voices = (config.voicesPerModel && defaultModel)
|
||||
? (getTtsVoicesForModel(providerId, defaultModel) || [])
|
||||
: getModelsByProviderId(config.voiceKey || providerId).filter((m) => m.type === "tts");
|
||||
: getModelsByProviderId(config.voiceKey || providerId).filter((m) => (m.kind || m.type) === "tts");
|
||||
if (voices.length) {
|
||||
if (config.hasBrowseButton) {
|
||||
// Google TTS: pre-select "en" (English) as default, show as single voice chip
|
||||
@@ -475,7 +475,7 @@ function TtsExampleCard({ providerId }) {
|
||||
if (config.voiceSource === "hardcoded") {
|
||||
// Build languages/byLang from static providerModels data
|
||||
const voiceKey = config.voiceKey || providerId;
|
||||
const voices = getModelsByProviderId(voiceKey).filter((m) => m.type === "tts");
|
||||
const voices = getModelsByProviderId(voiceKey).filter((m) => (m.kind || m.type) === "tts");
|
||||
const byLangMap = {};
|
||||
for (const v of voices) {
|
||||
if (!byLangMap[v.id]) byLangMap[v.id] = { code: v.id, name: v.name, voices: [{ id: v.id, name: v.name }] };
|
||||
@@ -735,13 +735,13 @@ function TtsExampleCard({ providerId }) {
|
||||
<select
|
||||
value={selectedVoice}
|
||||
onChange={(e) => {
|
||||
const m = getModelsByProviderId(providerId).filter((m) => m.type === "tts").find((m) => m.id === e.target.value);
|
||||
const m = getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "tts").find((m) => m.id === e.target.value);
|
||||
setSelectedVoice(e.target.value);
|
||||
setSelectedVoiceName(m?.name || e.target.value);
|
||||
}}
|
||||
className="w-full px-3 py-1.5 text-sm border border-border rounded-lg bg-background focus:outline-none focus:border-primary"
|
||||
>
|
||||
{getModelsByProviderId(providerId).filter((m) => m.type === "tts").map((m) => (
|
||||
{getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "tts").map((m) => (
|
||||
<option key={m.id} value={m.id}>{m.name || m.id}</option>
|
||||
))}
|
||||
</select>
|
||||
@@ -925,7 +925,7 @@ function GenericExampleCard({ providerId, kind }) {
|
||||
const safeExConfig = exConfig || {};
|
||||
|
||||
// Get models for this kind (e.g., type="image")
|
||||
const kindModels = getModelsByProviderId(providerId).filter((m) => m.type === kind);
|
||||
const kindModels = getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === kind);
|
||||
// Kinds that need a model identifier in the request (image/video/music)
|
||||
const KIND_NEEDS_MODEL = new Set(["image", "video", "music", "imageToText"]);
|
||||
const needsModel = KIND_NEEDS_MODEL.has(kind);
|
||||
@@ -1429,7 +1429,7 @@ function GenericExampleCard({ providerId, kind }) {
|
||||
// ─── STT Example Card ────────────────────────────────────────────────────────
|
||||
function SttExampleCard({ providerId }) {
|
||||
const providerAlias = getProviderAlias(providerId);
|
||||
const builtinSttModels = getModelsByProviderId(providerId).filter((m) => m.type === "stt");
|
||||
const builtinSttModels = getModelsByProviderId(providerId).filter((m) => (m.kind || m.type) === "stt");
|
||||
const [customSttModels, setCustomSttModels] = useState([]);
|
||||
const sttModels = [...builtinSttModels, ...customSttModels];
|
||||
|
||||
@@ -1467,7 +1467,7 @@ function SttExampleCard({ providerId }) {
|
||||
fetch("/api/models/custom", { cache: "no-store" })
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
const list = (d.models || []).filter((m) => m.type === "stt" && m.providerAlias === providerAlias);
|
||||
const list = (d.models || []).filter((m) => (m.kind || m.type) === "stt" && m.providerAlias === providerAlias);
|
||||
setCustomSttModels(list);
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
@@ -206,14 +206,14 @@ export default function ModelsCard({ providerId, kindFilter, providerAliasOverri
|
||||
const builtInModels = kindFilter
|
||||
? allBuiltIn.filter((m) => {
|
||||
if (m.kinds) return m.kinds.includes(kindFilter);
|
||||
return (m.type || "llm") === kindFilter;
|
||||
return (m.kind || m.type || "llm") === kindFilter;
|
||||
})
|
||||
: allBuiltIn;
|
||||
|
||||
// Custom models for this provider + kind, dedupe vs built-in
|
||||
const myCustomModels = customModels.filter(
|
||||
(m) => m.providerAlias === providerAlias
|
||||
&& (m.type || "llm") === effectiveType
|
||||
&& (m.kind || m.type || "llm") === effectiveType
|
||||
&& !builtInModels.some((b) => b.id === m.id)
|
||||
);
|
||||
|
||||
|
||||
@@ -122,6 +122,9 @@ export default function ProvidersPage() {
|
||||
|
||||
const sortByPriority = (entries, authType) =>
|
||||
[...entries].sort(([ka, a], [kb, b]) => {
|
||||
const pa = a.priority ?? 999;
|
||||
const pb = b.priority ?? 999;
|
||||
if (pa !== pb) return pa - pb;
|
||||
const sa = getProviderStats(ka, authType);
|
||||
const sb = getProviderStats(kb, authType);
|
||||
const ca = sa.connected > 0 ? 1 : 0;
|
||||
@@ -132,6 +135,9 @@ export default function ProvidersPage() {
|
||||
|
||||
const sortItemsByPriority = (items, authType) =>
|
||||
[...items].sort((a, b) => {
|
||||
const pa = a.priority ?? 999;
|
||||
const pb = b.priority ?? 999;
|
||||
if (pa !== pb) return pa - pb;
|
||||
const sa = getProviderStats(a.id, authType);
|
||||
const sb = getProviderStats(b.id, authType);
|
||||
const ca = sa.connected > 0 ? 1 : 0;
|
||||
@@ -273,15 +279,22 @@ export default function ProvidersPage() {
|
||||
}))
|
||||
.filter((p) => matchSearch(p.name));
|
||||
|
||||
const oauthEntries = Object.entries(OAUTH_PROVIDERS).filter(
|
||||
([, info]) => !info.hidden && matchSearch(info.name),
|
||||
const oauthEntries = sortByPriority(
|
||||
Object.entries(OAUTH_PROVIDERS).filter(([, info]) => !info.hidden && matchSearch(info.name)),
|
||||
"oauth",
|
||||
);
|
||||
const freeEntries = Object.entries(FREE_PROVIDERS).filter(
|
||||
([, info]) => !info.hidden && matchSearch(info.name),
|
||||
);
|
||||
const freeTierEntries = Object.entries(FREE_TIER_PROVIDERS).filter(
|
||||
([, info]) => !info.hidden && matchSearch(info.name),
|
||||
);
|
||||
const freeTierEntries = Object.entries(FREE_TIER_PROVIDERS)
|
||||
.filter(([, info]) => !info.hidden && matchSearch(info.name))
|
||||
.sort(([, a], [, b]) => {
|
||||
// hasFree providers first, then by priority
|
||||
const fa = a.hasFree ? 0 : 1;
|
||||
const fb = b.hasFree ? 0 : 1;
|
||||
if (fa !== fb) return fa - fb;
|
||||
return (a.priority ?? 999) - (b.priority ?? 999);
|
||||
});
|
||||
const apikeyEntries = sortByPriority(
|
||||
Object.entries(APIKEY_PROVIDERS).filter(
|
||||
([, info]) =>
|
||||
|
||||
Reference in New Issue
Block a user