9router/src/app/api/providers/suggested-models/route.js
Delcado19 9ee8b32887 fix: include free OpenCode models without -free suffix in suggested models (#1535)
The "opencode-free" suggested-models filter only kept models whose id ends
in "-free", so free-but-unsuffixed models like `big-pickle` (routed via
open-sse/executors/opencode.js MESSAGES_MODELS) never appeared in the
import UI.

Extract the filters into a testable module and include a
KNOWN_FREE_OPENCODE_MODELS allowlist (big-pickle) alongside the "-free"
suffix check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-29 17:36:27 +07:00

32 lines
893 B
JavaScript

import { NextResponse } from "next/server";
import { FILTERS } from "./filters.js";
export const dynamic = "force-dynamic";
export async function GET(request) {
const { searchParams } = new URL(request.url);
const url = searchParams.get("url");
const type = searchParams.get("type");
if (!url || !type) {
return NextResponse.json({ error: "Missing url or type" }, { status: 400 });
}
const filter = FILTERS[type];
if (!filter) {
return NextResponse.json({ error: "Unknown filter type" }, { status: 400 });
}
try {
const res = await fetch(url);
if (!res.ok) {
return NextResponse.json({ data: [] });
}
const json = await res.json();
const raw = json.data ?? json.models ?? json;
const data = filter(Array.isArray(raw) ? raw : []);
return NextResponse.json({ data });
} catch {
return NextResponse.json({ data: [] });
}
}