File size: 1,625 Bytes
077865a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Router } from 'express';
import { getDb } from '../db/index.js';
import { hasProvider } from '../providers/index.js';
export const modelsRouter = Router();
// List all models with availability info
modelsRouter.get('/', (_req, res) => {
    const db = getDb();
    const models = db.prepare(`
    SELECT m.*, fc.priority, fc.enabled as fallback_enabled
    FROM models m
    LEFT JOIN fallback_config fc ON fc.model_db_id = m.id
    ORDER BY COALESCE(fc.priority, m.intelligence_rank) ASC
  `).all();
    // Count keys per platform
    const keyCounts = db.prepare(`
    SELECT platform, COUNT(*) as count
    FROM api_keys
    WHERE enabled = 1
    GROUP BY platform
  `).all();
    const keyCountMap = new Map(keyCounts.map(k => [k.platform, k.count]));
    const result = models.map(m => ({
        id: m.id,
        platform: m.platform,
        modelId: m.model_id,
        displayName: m.display_name,
        intelligenceRank: m.intelligence_rank,
        speedRank: m.speed_rank,
        sizeLabel: m.size_label,
        rpmLimit: m.rpm_limit,
        rpdLimit: m.rpd_limit,
        tpmLimit: m.tpm_limit,
        tpdLimit: m.tpd_limit,
        monthlyTokenBudget: m.monthly_token_budget,
        contextWindow: m.context_window,
        enabled: m.enabled === 1,
        supportsVision: m.supports_vision === 1,
        supportsTools: m.supports_tools === 1,
        priority: m.priority,
        fallbackEnabled: m.fallback_enabled === 1,
        hasProvider: hasProvider(m.platform),
        keyCount: keyCountMap.get(m.platform) ?? 0,
    }));
    res.json(result);
});
//# sourceMappingURL=models.js.map