feat(kilo): fetch free models from Kilo API + Windows build fixes (#455)

- Add /api/providers/kilo/free-models endpoint with 1hr cache
- Fetch and merge Kilo free models with hardcoded models for kilocode provider
- Display 'Free' badge on models fetched from Kilo API
- Fix Windows build: add cross-env, remove --webpack flag, add turbopack config
- Add outputFileTracingExcludes for Windows system directories
This commit is contained in:
Vishal Raj V
2026-03-31 07:52:21 +05:30
committed by GitHub
parent ffa172c92d
commit 8640503b36
4 changed files with 89 additions and 5 deletions

View File

@@ -0,0 +1,55 @@
import { NextResponse } from "next/server";
const KILO_MODELS_URL = "https://api.kilo.ai/api/gateway/models";
// In-memory cache with TTL
let cachedModels = null;
let cacheTimestamp = 0;
const CACHE_TTL_MS = 60 * 60 * 1000; // 1 hour
export async function GET() {
const now = Date.now();
// Return cached result if still valid
if (cachedModels && now - cacheTimestamp < CACHE_TTL_MS) {
return NextResponse.json({ models: cachedModels, cached: true });
}
try {
const res = await fetch(KILO_MODELS_URL, {
headers: { "Accept": "application/json" },
signal: AbortSignal.timeout(10000),
});
if (!res.ok) {
throw new Error(`Kilo API returned ${res.status}`);
}
const json = await res.json();
const allModels = json.data || [];
const freeModels = allModels
.filter((m) => m.isFree === true)
.map((m) => ({
id: m.id,
name: m.name,
isFree: true,
context_length: m.context_length || 0,
}));
cachedModels = freeModels;
cacheTimestamp = now;
return NextResponse.json({ models: freeModels, cached: false });
} catch (error) {
// Return cached data if available, even if expired
if (cachedModels) {
return NextResponse.json({ models: cachedModels, cached: true, warning: error.message });
}
return NextResponse.json(
{ models: [], error: `Failed to fetch Kilo models: ${error.message}` },
{ status: 502 }
);
}
}