freellm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +89 -0
  2. package/bin/cli.js +25 -0
  3. package/client-dist/assets/index-aUFet1Mp.js +84 -0
  4. package/client-dist/index.html +16 -0
  5. package/dist/cli.d.ts +1 -0
  6. package/dist/cli.js +38 -0
  7. package/dist/crypto.d.ts +6 -0
  8. package/dist/crypto.js +56 -0
  9. package/dist/db/index.d.ts +62 -0
  10. package/dist/db/index.js +368 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.js +100 -0
  13. package/dist/providers/cloudflare.d.ts +10 -0
  14. package/dist/providers/cloudflare.js +140 -0
  15. package/dist/providers/google.d.ts +8 -0
  16. package/dist/providers/google.js +181 -0
  17. package/dist/providers/index.d.ts +14 -0
  18. package/dist/providers/index.js +60 -0
  19. package/dist/providers/ollama.d.ts +10 -0
  20. package/dist/providers/ollama.js +99 -0
  21. package/dist/providers/openai-compat.d.ts +11 -0
  22. package/dist/providers/openai-compat.js +115 -0
  23. package/dist/providers/openai-image-compat.d.ts +10 -0
  24. package/dist/providers/openai-image-compat.js +40 -0
  25. package/dist/providers/openai-tts-compat.d.ts +10 -0
  26. package/dist/providers/openai-tts-compat.js +40 -0
  27. package/dist/providers/pollinations-image.d.ts +7 -0
  28. package/dist/providers/pollinations-image.js +50 -0
  29. package/dist/providers/pollinations.d.ts +9 -0
  30. package/dist/providers/pollinations.js +76 -0
  31. package/dist/providers/types.d.ts +132 -0
  32. package/dist/providers/types.js +66 -0
  33. package/dist/routes/api/analytics.d.ts +1 -0
  34. package/dist/routes/api/analytics.js +10 -0
  35. package/dist/routes/api/auth.d.ts +3 -0
  36. package/dist/routes/api/auth.js +60 -0
  37. package/dist/routes/api/keys.d.ts +1 -0
  38. package/dist/routes/api/keys.js +65 -0
  39. package/dist/routes/api/models.d.ts +1 -0
  40. package/dist/routes/api/models.js +26 -0
  41. package/dist/routes/v1/audio.d.ts +1 -0
  42. package/dist/routes/v1/audio.js +94 -0
  43. package/dist/routes/v1/chat.d.ts +1 -0
  44. package/dist/routes/v1/chat.js +131 -0
  45. package/dist/routes/v1/images.d.ts +1 -0
  46. package/dist/routes/v1/images.js +85 -0
  47. package/dist/routes/v1/models.d.ts +1 -0
  48. package/dist/routes/v1/models.js +59 -0
  49. package/dist/services/health.d.ts +2 -0
  50. package/dist/services/health.js +80 -0
  51. package/dist/services/ratelimit.d.ts +4 -0
  52. package/dist/services/ratelimit.js +88 -0
  53. package/dist/services/router.d.ts +14 -0
  54. package/dist/services/router.js +72 -0
  55. package/package.json +57 -0
package/dist/crypto.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initCrypto = initCrypto;
7
+ exports.encrypt = encrypt;
8
+ exports.decrypt = decrypt;
9
+ exports.generateUnifiedKey = generateUnifiedKey;
10
+ exports.hashPassword = hashPassword;
11
+ exports.verifyPassword = verifyPassword;
12
+ const crypto_1 = __importDefault(require("crypto"));
13
+ const ALGO = 'aes-256-gcm';
14
+ const IV_LEN = 12;
15
+ const TAG_LEN = 16;
16
+ let encKey = null;
17
+ function initCrypto(hexKey) {
18
+ if (hexKey.length !== 64)
19
+ throw new Error('ENCRYPTION_KEY must be 32 bytes (64 hex chars)');
20
+ encKey = Buffer.from(hexKey, 'hex');
21
+ }
22
+ function getKey() {
23
+ if (!encKey)
24
+ throw new Error('Crypto not initialized — call initCrypto() first');
25
+ return encKey;
26
+ }
27
+ function encrypt(plaintext) {
28
+ const iv = crypto_1.default.randomBytes(IV_LEN);
29
+ const cipher = crypto_1.default.createCipheriv(ALGO, getKey(), iv);
30
+ const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
31
+ const tag = cipher.getAuthTag();
32
+ // Format: iv(12) + tag(16) + ciphertext
33
+ return Buffer.concat([iv, tag, encrypted]).toString('base64');
34
+ }
35
+ function decrypt(encoded) {
36
+ const buf = Buffer.from(encoded, 'base64');
37
+ const iv = buf.subarray(0, IV_LEN);
38
+ const tag = buf.subarray(IV_LEN, IV_LEN + TAG_LEN);
39
+ const ciphertext = buf.subarray(IV_LEN + TAG_LEN);
40
+ const decipher = crypto_1.default.createDecipheriv(ALGO, getKey(), iv);
41
+ decipher.setAuthTag(tag);
42
+ return decipher.update(ciphertext) + decipher.final('utf8');
43
+ }
44
+ function generateUnifiedKey() {
45
+ return 'freellm-' + crypto_1.default.randomBytes(24).toString('hex');
46
+ }
47
+ function hashPassword(password) {
48
+ const salt = crypto_1.default.randomBytes(16).toString('hex');
49
+ const hash = crypto_1.default.scryptSync(password, salt, 64).toString('hex');
50
+ return `${salt}:${hash}`;
51
+ }
52
+ function verifyPassword(password, stored) {
53
+ const [salt, hash] = stored.split(':');
54
+ const derived = crypto_1.default.scryptSync(password, salt, 64).toString('hex');
55
+ return crypto_1.default.timingSafeEqual(Buffer.from(hash, 'hex'), Buffer.from(derived, 'hex'));
56
+ }
@@ -0,0 +1,62 @@
1
+ import { DatabaseSync } from 'node:sqlite';
2
+ export declare function initDb(dbPath: string): void;
3
+ export declare function getDb(): DatabaseSync;
4
+ export type ProviderKey = {
5
+ id: number;
6
+ platform: string;
7
+ label: string;
8
+ key_enc: string;
9
+ enabled: number;
10
+ status: string;
11
+ last_check: number | null;
12
+ created_at: number;
13
+ };
14
+ export type Model = {
15
+ id: number;
16
+ platform: string;
17
+ model_id: string;
18
+ display_name: string;
19
+ supports_tools: number;
20
+ supports_vision: number;
21
+ supports_stream: number;
22
+ type: string;
23
+ context_length: number | null;
24
+ fallback_order: number;
25
+ enabled: number;
26
+ };
27
+ export declare function getSetting(key: string): string | undefined;
28
+ export declare function setSetting(key: string, value: string): void;
29
+ export declare function addKey(platform: string, rawKey: string, label?: string): number;
30
+ export declare function listKeys(): ProviderKey[];
31
+ export declare function getKey(id: number): ProviderKey | undefined;
32
+ export declare function decryptKey(enc: string): string;
33
+ export declare function updateKeyStatus(id: number, status: string): void;
34
+ export declare function deleteKey(id: number): void;
35
+ export declare function toggleKey(id: number, enabled: boolean): void;
36
+ export declare function listModels(type?: string): Model[];
37
+ export declare function listEnabledModels(type?: string): Model[];
38
+ export declare function updateModelOrder(id: number, order: number): void;
39
+ export declare function toggleModel(id: number, enabled: boolean): void;
40
+ export declare function logRequest(data: {
41
+ platform: string;
42
+ model_id: string;
43
+ prompt_tokens: number;
44
+ complete_tokens: number;
45
+ latency_ms: number;
46
+ success: boolean;
47
+ error_code?: string;
48
+ }): void;
49
+ export declare function getAnalytics(windowHours?: number): {
50
+ total: number;
51
+ success: number;
52
+ totalPromptTokens: number;
53
+ totalCompleteTokens: number;
54
+ avgLatencyMs: number;
55
+ byPlatform: Record<string, {
56
+ requests: number;
57
+ tokens: number;
58
+ }>;
59
+ };
60
+ export declare function createSession(token: string, ttlSeconds?: number): void;
61
+ export declare function validateSession(token: string): boolean;
62
+ export declare function deleteSession(token: string): void;
@@ -0,0 +1,368 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initDb = initDb;
7
+ exports.getDb = getDb;
8
+ exports.getSetting = getSetting;
9
+ exports.setSetting = setSetting;
10
+ exports.addKey = addKey;
11
+ exports.listKeys = listKeys;
12
+ exports.getKey = getKey;
13
+ exports.decryptKey = decryptKey;
14
+ exports.updateKeyStatus = updateKeyStatus;
15
+ exports.deleteKey = deleteKey;
16
+ exports.toggleKey = toggleKey;
17
+ exports.listModels = listModels;
18
+ exports.listEnabledModels = listEnabledModels;
19
+ exports.updateModelOrder = updateModelOrder;
20
+ exports.toggleModel = toggleModel;
21
+ exports.logRequest = logRequest;
22
+ exports.getAnalytics = getAnalytics;
23
+ exports.createSession = createSession;
24
+ exports.validateSession = validateSession;
25
+ exports.deleteSession = deleteSession;
26
+ // Uses built-in node:sqlite (available since Node 22.5) — no native compilation needed
27
+ const node_sqlite_1 = require("node:sqlite");
28
+ const path_1 = __importDefault(require("path"));
29
+ const fs_1 = __importDefault(require("fs"));
30
+ const crypto_1 = require("../crypto");
31
+ let db;
32
+ function initDb(dbPath) {
33
+ const dir = path_1.default.dirname(dbPath);
34
+ if (!fs_1.default.existsSync(dir))
35
+ fs_1.default.mkdirSync(dir, { recursive: true });
36
+ db = new node_sqlite_1.DatabaseSync(dbPath);
37
+ db.exec('PRAGMA journal_mode = WAL');
38
+ db.exec('PRAGMA foreign_keys = ON');
39
+ migrate();
40
+ }
41
+ function getDb() {
42
+ return db;
43
+ }
44
+ function migrate() {
45
+ db.exec(`
46
+ CREATE TABLE IF NOT EXISTS settings (
47
+ key TEXT PRIMARY KEY,
48
+ value TEXT NOT NULL
49
+ );
50
+
51
+ CREATE TABLE IF NOT EXISTS sessions (
52
+ token TEXT PRIMARY KEY,
53
+ created_at INTEGER NOT NULL DEFAULT (unixepoch()),
54
+ expires_at INTEGER NOT NULL
55
+ );
56
+
57
+ CREATE TABLE IF NOT EXISTS provider_keys (
58
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
59
+ platform TEXT NOT NULL,
60
+ label TEXT NOT NULL DEFAULT '',
61
+ key_enc TEXT NOT NULL,
62
+ enabled INTEGER NOT NULL DEFAULT 1,
63
+ status TEXT NOT NULL DEFAULT 'unknown',
64
+ last_check INTEGER,
65
+ created_at INTEGER NOT NULL DEFAULT (unixepoch())
66
+ );
67
+
68
+ CREATE TABLE IF NOT EXISTS models (
69
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
70
+ platform TEXT NOT NULL,
71
+ model_id TEXT NOT NULL,
72
+ display_name TEXT NOT NULL,
73
+ supports_tools INTEGER NOT NULL DEFAULT 0,
74
+ supports_vision INTEGER NOT NULL DEFAULT 0,
75
+ supports_stream INTEGER NOT NULL DEFAULT 1,
76
+ type TEXT NOT NULL DEFAULT 'chat',
77
+ context_length INTEGER,
78
+ fallback_order INTEGER NOT NULL DEFAULT 999,
79
+ enabled INTEGER NOT NULL DEFAULT 1,
80
+ UNIQUE(platform, model_id)
81
+ );
82
+
83
+ CREATE TABLE IF NOT EXISTS analytics (
84
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
85
+ ts INTEGER NOT NULL DEFAULT (unixepoch()),
86
+ platform TEXT NOT NULL,
87
+ model_id TEXT NOT NULL,
88
+ prompt_tokens INTEGER NOT NULL DEFAULT 0,
89
+ complete_tokens INTEGER NOT NULL DEFAULT 0,
90
+ latency_ms INTEGER,
91
+ success INTEGER NOT NULL DEFAULT 1,
92
+ error_code TEXT
93
+ );
94
+
95
+ CREATE INDEX IF NOT EXISTS idx_analytics_ts ON analytics(ts);
96
+ CREATE INDEX IF NOT EXISTS idx_analytics_platform ON analytics(platform);
97
+ `);
98
+ seedModels();
99
+ }
100
+ // ─── Settings ────────────────────────────────────────────────────────────────
101
+ function getSetting(key) {
102
+ const stmt = db.prepare('SELECT value FROM settings WHERE key = ?');
103
+ const row = stmt.get(key);
104
+ return row?.value;
105
+ }
106
+ function setSetting(key, value) {
107
+ db.prepare('INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)').run(key, value);
108
+ }
109
+ // ─── Provider keys ────────────────────────────────────────────────────────────
110
+ function addKey(platform, rawKey, label = '') {
111
+ const result = db
112
+ .prepare('INSERT INTO provider_keys (platform, label, key_enc) VALUES (?, ?, ?)')
113
+ .run(platform, label, (0, crypto_1.encrypt)(rawKey));
114
+ return Number(result.lastInsertRowid);
115
+ }
116
+ function listKeys() {
117
+ return db.prepare('SELECT * FROM provider_keys ORDER BY platform, id').all();
118
+ }
119
+ function getKey(id) {
120
+ return db.prepare('SELECT * FROM provider_keys WHERE id = ?').get(id);
121
+ }
122
+ function decryptKey(enc) {
123
+ return (0, crypto_1.decrypt)(enc);
124
+ }
125
+ function updateKeyStatus(id, status) {
126
+ db.prepare('UPDATE provider_keys SET status = ?, last_check = unixepoch() WHERE id = ?').run(status, id);
127
+ }
128
+ function deleteKey(id) {
129
+ db.prepare('DELETE FROM provider_keys WHERE id = ?').run(id);
130
+ }
131
+ function toggleKey(id, enabled) {
132
+ db.prepare('UPDATE provider_keys SET enabled = ? WHERE id = ?').run(enabled ? 1 : 0, id);
133
+ }
134
+ // ─── Models ──────────────────────────────────────────────────────────────────
135
+ function listModels(type = 'chat') {
136
+ return db
137
+ .prepare('SELECT * FROM models WHERE type = ? ORDER BY fallback_order, id')
138
+ .all(type);
139
+ }
140
+ function listEnabledModels(type = 'chat') {
141
+ return db
142
+ .prepare('SELECT * FROM models WHERE enabled = 1 AND type = ? ORDER BY fallback_order, id')
143
+ .all(type);
144
+ }
145
+ function updateModelOrder(id, order) {
146
+ db.prepare('UPDATE models SET fallback_order = ? WHERE id = ?').run(order, id);
147
+ }
148
+ function toggleModel(id, enabled) {
149
+ db.prepare('UPDATE models SET enabled = ? WHERE id = ?').run(enabled ? 1 : 0, id);
150
+ }
151
+ // ─── Analytics ───────────────────────────────────────────────────────────────
152
+ function logRequest(data) {
153
+ db.prepare(`
154
+ INSERT INTO analytics (platform, model_id, prompt_tokens, complete_tokens, latency_ms, success, error_code)
155
+ VALUES (?, ?, ?, ?, ?, ?, ?)
156
+ `).run(data.platform, data.model_id, data.prompt_tokens, data.complete_tokens, data.latency_ms, data.success ? 1 : 0, data.error_code ?? null);
157
+ }
158
+ function getAnalytics(windowHours = 24) {
159
+ const since = Math.floor(Date.now() / 1000) - windowHours * 3600;
160
+ const rows = db
161
+ .prepare('SELECT * FROM analytics WHERE ts >= ?')
162
+ .all(since);
163
+ const byPlatform = {};
164
+ let totalPromptTokens = 0;
165
+ let totalCompleteTokens = 0;
166
+ let totalLatency = 0;
167
+ let success = 0;
168
+ for (const r of rows) {
169
+ totalPromptTokens += r.prompt_tokens;
170
+ totalCompleteTokens += r.complete_tokens;
171
+ totalLatency += r.latency_ms ?? 0;
172
+ if (r.success)
173
+ success++;
174
+ if (!byPlatform[r.platform])
175
+ byPlatform[r.platform] = { requests: 0, tokens: 0 };
176
+ byPlatform[r.platform].requests++;
177
+ byPlatform[r.platform].tokens += r.prompt_tokens + r.complete_tokens;
178
+ }
179
+ return {
180
+ total: rows.length,
181
+ success,
182
+ totalPromptTokens,
183
+ totalCompleteTokens,
184
+ avgLatencyMs: rows.length > 0 ? Math.round(totalLatency / rows.length) : 0,
185
+ byPlatform,
186
+ };
187
+ }
188
+ // ─── Sessions ─────────────────────────────────────────────────────────────────
189
+ function createSession(token, ttlSeconds = 86400 * 7) {
190
+ const expires = Math.floor(Date.now() / 1000) + ttlSeconds;
191
+ db.prepare('INSERT OR REPLACE INTO sessions (token, expires_at) VALUES (?, ?)').run(token, expires);
192
+ }
193
+ function validateSession(token) {
194
+ const row = db
195
+ .prepare('SELECT expires_at FROM sessions WHERE token = ?')
196
+ .get(token);
197
+ if (!row)
198
+ return false;
199
+ if (row.expires_at < Math.floor(Date.now() / 1000)) {
200
+ db.prepare('DELETE FROM sessions WHERE token = ?').run(token);
201
+ return false;
202
+ }
203
+ return true;
204
+ }
205
+ function deleteSession(token) {
206
+ db.prepare('DELETE FROM sessions WHERE token = ?').run(token);
207
+ }
208
+ // ─── Seed models ─────────────────────────────────────────────────────────────
209
+ function upsertModel(m) {
210
+ db.prepare(`
211
+ INSERT INTO models (platform, model_id, display_name, supports_tools, supports_vision, supports_stream, type, context_length, fallback_order, enabled)
212
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
213
+ ON CONFLICT(platform, model_id) DO NOTHING
214
+ `).run(m.platform, m.model_id, m.display_name, m.supports_tools, m.supports_vision, m.supports_stream, m.type, m.context_length ?? null, m.fallback_order, m.enabled);
215
+ }
216
+ function seedModels() {
217
+ const models = [
218
+ // Google Gemini
219
+ { platform: 'google', model_id: 'gemini-2.5-flash', display_name: 'Gemini 2.5 Flash', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 1, enabled: 1 },
220
+ { platform: 'google', model_id: 'gemini-2.5-flash-lite', display_name: 'Gemini 2.5 Flash Lite', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 2, enabled: 1 },
221
+ { platform: 'google', model_id: 'gemini-2.0-flash', display_name: 'Gemini 2.0 Flash', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 3, enabled: 1 },
222
+ { platform: 'google', model_id: 'gemini-1.5-flash', display_name: 'Gemini 1.5 Flash', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 4, enabled: 1 },
223
+ // Groq
224
+ { platform: 'groq', model_id: 'llama-3.3-70b-versatile', display_name: 'Llama 3.3 70B (Groq)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 5, enabled: 1 },
225
+ { platform: 'groq', model_id: 'llama-3.1-8b-instant', display_name: 'Llama 3.1 8B Instant (Groq)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 6, enabled: 1 },
226
+ { platform: 'groq', model_id: 'gemma2-9b-it', display_name: 'Gemma 2 9B (Groq)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 8192, fallback_order: 7, enabled: 1 },
227
+ // Cerebras
228
+ { platform: 'cerebras', model_id: 'llama3.1-8b', display_name: 'Llama 3.1 8B (Cerebras)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 8192, fallback_order: 8, enabled: 1 },
229
+ { platform: 'cerebras', model_id: 'llama-3.3-70b', display_name: 'Llama 3.3 70B (Cerebras)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 8192, fallback_order: 9, enabled: 1 },
230
+ // Mistral
231
+ { platform: 'mistral', model_id: 'mistral-small-latest', display_name: 'Mistral Small', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 32768, fallback_order: 10, enabled: 1 },
232
+ { platform: 'mistral', model_id: 'open-mistral-nemo', display_name: 'Mistral Nemo 128K', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 11, enabled: 1 },
233
+ { platform: 'mistral', model_id: 'codestral-latest', display_name: 'Codestral (Mistral)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 32768, fallback_order: 12, enabled: 1 },
234
+ // OpenRouter free models
235
+ { platform: 'openrouter', model_id: 'meta-llama/llama-3.2-3b-instruct:free', display_name: 'Llama 3.2 3B (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 13, enabled: 1 },
236
+ { platform: 'openrouter', model_id: 'meta-llama/llama-3.2-1b-instruct:free', display_name: 'Llama 3.2 1B (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 14, enabled: 1 },
237
+ { platform: 'openrouter', model_id: 'google/gemma-3-27b-it:free', display_name: 'Gemma 3 27B (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 15, enabled: 1 },
238
+ { platform: 'openrouter', model_id: 'qwen/qwen-2-7b-instruct:free', display_name: 'Qwen 2 7B (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 32768, fallback_order: 16, enabled: 1 },
239
+ // GitHub Models
240
+ { platform: 'github', model_id: 'gpt-4o', display_name: 'GPT-4o (GitHub)', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 17, enabled: 1 },
241
+ { platform: 'github', model_id: 'gpt-4o-mini', display_name: 'GPT-4o Mini (GitHub)', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 18, enabled: 1 },
242
+ // Cohere
243
+ { platform: 'cohere', model_id: 'command-r-plus', display_name: 'Command R+ (Cohere)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 19, enabled: 1 },
244
+ { platform: 'cohere', model_id: 'command-r', display_name: 'Command R (Cohere)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 20, enabled: 1 },
245
+ // Cloudflare Workers AI
246
+ { platform: 'cloudflare', model_id: '@cf/meta/llama-3.1-8b-instruct', display_name: 'Llama 3.1 8B (Cloudflare)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 8192, fallback_order: 21, enabled: 1 },
247
+ { platform: 'cloudflare', model_id: '@cf/google/gemma-7b-it', display_name: 'Gemma 7B (Cloudflare)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 8192, fallback_order: 22, enabled: 1 },
248
+ // HuggingFace
249
+ { platform: 'huggingface', model_id: 'meta-llama/Meta-Llama-3-8B-Instruct', display_name: 'Llama 3 8B (HuggingFace)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 8192, fallback_order: 23, enabled: 1 },
250
+ // Ollama (local — disabled by default until user enables)
251
+ { platform: 'ollama', model_id: 'llama3.2', display_name: 'Llama 3.2 (Ollama local)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: null, fallback_order: 50, enabled: 0 },
252
+ { platform: 'ollama', model_id: 'mistral', display_name: 'Mistral (Ollama local)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: null, fallback_order: 51, enabled: 0 },
253
+ { platform: 'ollama', model_id: 'gemma3', display_name: 'Gemma 3 (Ollama local)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: null, fallback_order: 52, enabled: 0 },
254
+ // Pollinations (no key needed)
255
+ { platform: 'pollinations', model_id: 'openai', display_name: 'GPT-OSS (Pollinations)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'chat', context_length: null, fallback_order: 40, enabled: 1 },
256
+ { platform: 'pollinations', model_id: 'mistral', display_name: 'Mistral (Pollinations)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'chat', context_length: null, fallback_order: 41, enabled: 1 },
257
+ // LLM7 (no key needed)
258
+ { platform: 'llm7', model_id: 'gpt-4o-mini', display_name: 'GPT-4o Mini (LLM7)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: null, fallback_order: 42, enabled: 1 },
259
+ { platform: 'llm7', model_id: 'llama-3.1-70b', display_name: 'Llama 3.1 70B (LLM7)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: null, fallback_order: 43, enabled: 1 },
260
+ // OVH AI Endpoints (no key needed)
261
+ { platform: 'ovh', model_id: 'Llama-3.3-70B-Instruct', display_name: 'Llama 3.3 70B (OVH)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 44, enabled: 1 },
262
+ { platform: 'ovh', model_id: 'Mistral-7B-Instruct-v0.3', display_name: 'Mistral 7B (OVH)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 32768, fallback_order: 45, enabled: 1 },
263
+ // ─── NVIDIA NIM (recurring free tier, 40 RPM) ────────────────────────────
264
+ { platform: 'nvidia', model_id: 'deepseek-ai/deepseek-v4-pro', display_name: 'DeepSeek V4 Pro (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 46, enabled: 1 },
265
+ { platform: 'nvidia', model_id: 'minimaxai/minimax-m2.7', display_name: 'MiniMax M2.7 (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 196608, fallback_order: 47, enabled: 1 },
266
+ { platform: 'nvidia', model_id: 'mistralai/mistral-large-3-675b-instruct-2512', display_name: 'Mistral Large 3 675B (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 48, enabled: 1 },
267
+ { platform: 'nvidia', model_id: 'moonshotai/kimi-k2.6', display_name: 'Kimi K2.6 (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 49, enabled: 1 },
268
+ { platform: 'nvidia', model_id: 'deepseek-ai/deepseek-v4-flash', display_name: 'DeepSeek V4 Flash (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 50, enabled: 1 },
269
+ { platform: 'nvidia', model_id: 'z-ai/glm-5.1', display_name: 'GLM-5.1 (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 200000, fallback_order: 51, enabled: 1 },
270
+ { platform: 'nvidia', model_id: 'meta/llama-4-maverick-17b-128e-instruct', display_name: 'Llama 4 Maverick (NVIDIA)', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 52, enabled: 1 },
271
+ { platform: 'nvidia', model_id: 'meta/llama-3.1-70b-instruct', display_name: 'Llama 3.1 70B (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 53, enabled: 1 },
272
+ { platform: 'nvidia', model_id: 'meta/llama-3.3-70b-instruct', display_name: 'Llama 3.3 70B (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 54, enabled: 1 },
273
+ { platform: 'nvidia', model_id: 'nvidia/nemotron-3-nano-30b-a3b', display_name: 'Nemotron 3 Nano 30B (NVIDIA)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 55, enabled: 1 },
274
+ { platform: 'nvidia', model_id: 'nvidia/nemotron-3-super-120b-a12b', display_name: 'Nemotron 3 Super 120B (NVIDIA)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 56, enabled: 1 },
275
+ // ─── Zhipu AI ────────────────────────────────────────────────────────────
276
+ { platform: 'zhipu', model_id: 'glm-4.7-flash', display_name: 'GLM-4.7 Flash (Zhipu)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 57, enabled: 1 },
277
+ { platform: 'zhipu', model_id: 'glm-4.6v-flash', display_name: 'GLM-4.6V Flash (Zhipu)', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 58, enabled: 1 },
278
+ // ─── Kilo Gateway (anonymous, no key) ────────────────────────────────────
279
+ { platform: 'kilo', model_id: 'poolside/laguna-m.1:free', display_name: 'Poolside Laguna M.1 (Kilo)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 59, enabled: 1 },
280
+ { platform: 'kilo', model_id: 'stepfun/step-3.7-flash:free', display_name: 'StepFun Step 3.7 Flash (Kilo)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 60, enabled: 1 },
281
+ { platform: 'kilo', model_id: 'nvidia/nemotron-3-super-120b-a12b:free', display_name: 'Nemotron 3 Super 120B (Kilo)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 61, enabled: 1 },
282
+ // ─── OpenCode Zen (promo models) ─────────────────────────────────────────
283
+ { platform: 'opencode', model_id: 'deepseek-v4-flash-free', display_name: 'DeepSeek V4 Flash Free (OpenCode Zen)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 62, enabled: 1 },
284
+ { platform: 'opencode', model_id: 'big-pickle', display_name: 'Big Pickle (OpenCode Zen)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 63, enabled: 1 },
285
+ { platform: 'opencode', model_id: 'mimo-v2.5-free', display_name: 'MiMo-V2.5 Free (OpenCode Zen)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 64, enabled: 1 },
286
+ // ─── New LLM7 models ────────────────────────────────────────────────────
287
+ { platform: 'llm7', model_id: 'codestral-latest', display_name: 'Codestral (LLM7)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 32000, fallback_order: 65, enabled: 1 },
288
+ // ─── New Google models ──────────────────────────────────────────────────
289
+ { platform: 'google', model_id: 'gemini-3.5-flash', display_name: 'Gemini 3.5 Flash', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 66, enabled: 1 },
290
+ { platform: 'google', model_id: 'gemini-3-flash-preview', display_name: 'Gemini 3 Flash Preview', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 67, enabled: 1 },
291
+ { platform: 'google', model_id: 'gemma-4-31b-it', display_name: 'Gemma 4 31B IT', supports_tools: 0, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 32768, fallback_order: 68, enabled: 1 },
292
+ { platform: 'google', model_id: 'gemma-4-26b-a4b-it', display_name: 'Gemma 4 26B IT', supports_tools: 0, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 32768, fallback_order: 69, enabled: 1 },
293
+ // ─── New Groq models ────────────────────────────────────────────────────
294
+ { platform: 'groq', model_id: 'groq/compound', display_name: 'Compound (Groq)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 70, enabled: 1 },
295
+ { platform: 'groq', model_id: 'openai/gpt-oss-120b', display_name: 'GPT-OSS 120B (Groq)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 71, enabled: 1 },
296
+ { platform: 'groq', model_id: 'groq/compound-mini', display_name: 'Compound Mini (Groq)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 72, enabled: 1 },
297
+ { platform: 'groq', model_id: 'openai/gpt-oss-20b', display_name: 'GPT-OSS 20B (Groq)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 73, enabled: 1 },
298
+ { platform: 'groq', model_id: 'openai/gpt-oss-safeguard-20b', display_name: 'GPT-OSS Safeguard 20B (Groq)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 74, enabled: 1 },
299
+ { platform: 'groq', model_id: 'meta-llama/llama-4-scout-17b-16e-instruct', display_name: 'Llama 4 Scout (Groq)', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 75, enabled: 1 },
300
+ { platform: 'groq', model_id: 'qwen/qwen3-32b', display_name: 'Qwen3 32B (Groq)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 76, enabled: 1 },
301
+ // ─── New Cerebras models ────────────────────────────────────────────────
302
+ { platform: 'cerebras', model_id: 'gpt-oss-120b', display_name: 'GPT-OSS 120B (Cerebras)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 77, enabled: 1 },
303
+ { platform: 'cerebras', model_id: 'zai-glm-4.7', display_name: 'GLM-4.7 (Cerebras)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 8192, fallback_order: 78, enabled: 1 },
304
+ // ─── New Mistral models ────────────────────────────────────────────────
305
+ { platform: 'mistral', model_id: 'mistral-large-latest', display_name: 'Mistral Large 3', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 79, enabled: 1 },
306
+ { platform: 'mistral', model_id: 'mistral-medium-latest', display_name: 'Mistral Medium 3.5', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 80, enabled: 1 },
307
+ { platform: 'mistral', model_id: 'devstral-latest', display_name: 'Devstral', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 81, enabled: 1 },
308
+ { platform: 'mistral', model_id: 'magistral-medium-latest', display_name: 'Magistral Medium', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 82, enabled: 1 },
309
+ // ─── New OpenRouter models ─────────────────────────────────────────────
310
+ { platform: 'openrouter', model_id: 'qwen/qwen3-coder:free', display_name: 'Qwen3 Coder 480B (OpenRouter)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 83, enabled: 1 },
311
+ { platform: 'openrouter', model_id: 'qwen/qwen3-next-80b-a3b-instruct:free', display_name: 'Qwen3-Next 80B (OpenRouter)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 84, enabled: 1 },
312
+ { platform: 'openrouter', model_id: 'openrouter/owl-alpha', display_name: 'Owl Alpha (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 1048576, fallback_order: 85, enabled: 1 },
313
+ { platform: 'openrouter', model_id: 'openai/gpt-oss-120b:free', display_name: 'GPT-OSS 120B (OpenRouter)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 86, enabled: 1 },
314
+ { platform: 'openrouter', model_id: 'nvidia/nemotron-3-ultra-550b-a55b:free', display_name: 'Nemotron 3 Ultra 550B (OpenRouter)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 1000000, fallback_order: 87, enabled: 1 },
315
+ { platform: 'openrouter', model_id: 'poolside/laguna-m.1:free', display_name: 'Poolside Laguna M.1 (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 88, enabled: 1 },
316
+ { platform: 'openrouter', model_id: 'openai/gpt-oss-20b:free', display_name: 'GPT-OSS 20B (OpenRouter)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 89, enabled: 1 },
317
+ { platform: 'openrouter', model_id: 'meta-llama/llama-3.3-70b-instruct:free', display_name: 'Llama 3.3 70B (OpenRouter)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 90, enabled: 1 },
318
+ { platform: 'openrouter', model_id: 'nousresearch/hermes-3-llama-3.1-405b:free', display_name: 'Hermes 3 405B (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 91, enabled: 1 },
319
+ { platform: 'openrouter', model_id: 'google/gemma-4-31b-it:free', display_name: 'Gemma 4 31B (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 92, enabled: 1 },
320
+ // ─── New GitHub models ─────────────────────────────────────────────────
321
+ { platform: 'github', model_id: 'openai/gpt-4.1', display_name: 'GPT-4.1 (GitHub)', supports_tools: 1, supports_vision: 1, supports_stream: 1, type: 'chat', context_length: 128000, fallback_order: 93, enabled: 1 },
322
+ // ─── New Cohere models ─────────────────────────────────────────────────
323
+ { platform: 'cohere', model_id: 'command-a-reasoning-08-2025', display_name: 'Command A Reasoning (Cohere)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 256000, fallback_order: 94, enabled: 1 },
324
+ // ─── New Cloudflare models ─────────────────────────────────────────────
325
+ { platform: 'cloudflare', model_id: '@cf/moonshotai/kimi-k2.6', display_name: 'Kimi K2.6 (Cloudflare)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 95, enabled: 1 },
326
+ { platform: 'cloudflare', model_id: '@cf/openai/gpt-oss-120b', display_name: 'GPT-OSS 120B (Cloudflare)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 96, enabled: 1 },
327
+ { platform: 'cloudflare', model_id: '@cf/qwen/qwen3-30b-a3b-fp8', display_name: 'Qwen3 30B-A3B (Cloudflare)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 97, enabled: 1 },
328
+ { platform: 'cloudflare', model_id: '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b', display_name: 'DeepSeek R1 Distill Qwen 32B (Cloudflare)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 98, enabled: 1 },
329
+ { platform: 'cloudflare', model_id: '@cf/nvidia/nemotron-3-120b-a12b', display_name: 'Nemotron 3 120B (Cloudflare)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 99, enabled: 1 },
330
+ { platform: 'cloudflare', model_id: '@cf/zai-org/glm-4.7-flash', display_name: 'GLM-4.7 Flash (Cloudflare)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 100, enabled: 1 },
331
+ { platform: 'cloudflare', model_id: '@cf/meta/llama-4-scout-17b-16e-instruct', display_name: 'Llama 4 Scout (Cloudflare)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 101, enabled: 1 },
332
+ { platform: 'cloudflare', model_id: '@cf/meta/llama-3.3-70b-instruct-fp8-fast', display_name: 'Llama 3.3 70B fp8-fast (Cloudflare)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 24000, fallback_order: 102, enabled: 1 },
333
+ { platform: 'cloudflare', model_id: '@cf/google/gemma-4-26b-a4b-it', display_name: 'Gemma 4 26B-A4B (Cloudflare)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 103, enabled: 1 },
334
+ // ─── New HuggingFace models ────────────────────────────────────────────
335
+ { platform: 'huggingface', model_id: 'Qwen/Qwen3-Coder-Next', display_name: 'Qwen3-Coder Next (HuggingFace)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 104, enabled: 1 },
336
+ { platform: 'huggingface', model_id: 'moonshotai/Kimi-K2.6', display_name: 'Kimi K2.6 (HuggingFace)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 105, enabled: 1 },
337
+ { platform: 'huggingface', model_id: 'deepseek-ai/DeepSeek-V4-Flash', display_name: 'DeepSeek V4 Flash (HuggingFace)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 106, enabled: 1 },
338
+ // ─── New Ollama models ─────────────────────────────────────────────────
339
+ { platform: 'ollama', model_id: 'qwen3-coder:480b', display_name: 'Qwen3-Coder 480B (Ollama)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 107, enabled: 1 },
340
+ { platform: 'ollama', model_id: 'qwen3-coder-next', display_name: 'Qwen3-Coder Next (Ollama)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 108, enabled: 1 },
341
+ { platform: 'ollama', model_id: 'glm-4.7', display_name: 'GLM-4.7 (Ollama)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 109, enabled: 1 },
342
+ { platform: 'ollama', model_id: 'gpt-oss:120b', display_name: 'GPT-OSS 120B (Ollama)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 110, enabled: 1 },
343
+ { platform: 'ollama', model_id: 'gpt-oss:20b', display_name: 'GPT-OSS 20B (Ollama)', supports_tools: 1, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 111, enabled: 1 },
344
+ { platform: 'ollama', model_id: 'gemma4:31b', display_name: 'Gemma 4 31B (Ollama)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 262144, fallback_order: 112, enabled: 1 },
345
+ // ─── New Pollinations model ────────────────────────────────────────────
346
+ { platform: 'pollinations', model_id: 'openai-fast', display_name: 'GPT-OSS 20B (Pollinations)', supports_tools: 0, supports_vision: 0, supports_stream: 1, type: 'chat', context_length: 131072, fallback_order: 113, enabled: 1 },
347
+ // ─── Image Models ────────────────────────────────────────────────────────
348
+ // Pollinations (no key needed)
349
+ { platform: 'pollinations', model_id: 'flux', display_name: 'Flux (Pollinations)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'image', context_length: null, fallback_order: 60, enabled: 1 },
350
+ { platform: 'pollinations', model_id: 'flux-realism', display_name: 'Flux Realism (Pollinations)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'image', context_length: null, fallback_order: 61, enabled: 1 },
351
+ { platform: 'pollinations', model_id: 'flux-anime', display_name: 'Flux Anime (Pollinations)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'image', context_length: null, fallback_order: 62, enabled: 1 },
352
+ { platform: 'pollinations', model_id: 'any-dark', display_name: 'Any Dark (Pollinations)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'image', context_length: null, fallback_order: 63, enabled: 1 },
353
+ // OpenRouter image models
354
+ { platform: 'openrouter', model_id: 'black-forest-labs/flux-1.1-pro', display_name: 'Flux 1.1 Pro (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'image', context_length: null, fallback_order: 64, enabled: 1 },
355
+ // GitHub image models
356
+ { platform: 'github', model_id: 'dall-e-3', display_name: 'DALL-E 3 (GitHub)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'image', context_length: null, fallback_order: 65, enabled: 1 },
357
+ { platform: 'github', model_id: 'dall-e-2', display_name: 'DALL-E 2 (GitHub)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'image', context_length: null, fallback_order: 66, enabled: 1 },
358
+ // ─── TTS Models ──────────────────────────────────────────────────────────
359
+ // OpenRouter TTS models
360
+ { platform: 'openrouter', model_id: 'openai/tts-1', display_name: 'TTS-1 (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'tts', context_length: null, fallback_order: 70, enabled: 1 },
361
+ { platform: 'openrouter', model_id: 'openai/tts-1-hd', display_name: 'TTS-1 HD (OpenRouter)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'tts', context_length: null, fallback_order: 71, enabled: 1 },
362
+ // GitHub TTS models
363
+ { platform: 'github', model_id: 'tts-1', display_name: 'TTS-1 (GitHub)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'tts', context_length: null, fallback_order: 72, enabled: 1 },
364
+ { platform: 'github', model_id: 'tts-1-hd', display_name: 'TTS-1 HD (GitHub)', supports_tools: 0, supports_vision: 0, supports_stream: 0, type: 'tts', context_length: null, fallback_order: 73, enabled: 1 },
365
+ ];
366
+ for (const m of models)
367
+ upsertModel(m);
368
+ }
@@ -0,0 +1,10 @@
1
+ export interface ServerConfig {
2
+ port?: number;
3
+ dataDir?: string;
4
+ encryptionKey?: string;
5
+ openBrowser?: boolean;
6
+ }
7
+ export declare function startServer(config?: ServerConfig): Promise<{
8
+ port: number;
9
+ url: string;
10
+ }>;
package/dist/index.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.startServer = startServer;
7
+ const express_1 = __importDefault(require("express"));
8
+ const cors_1 = __importDefault(require("cors"));
9
+ const compression_1 = __importDefault(require("compression"));
10
+ const cookie_parser_1 = __importDefault(require("cookie-parser"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const crypto_1 = __importDefault(require("crypto"));
14
+ const crypto_2 = require("./crypto");
15
+ const index_1 = require("./db/index");
16
+ const chat_1 = require("./routes/v1/chat");
17
+ const models_1 = require("./routes/v1/models");
18
+ const images_1 = require("./routes/v1/images");
19
+ const audio_1 = require("./routes/v1/audio");
20
+ const auth_1 = require("./routes/api/auth");
21
+ const keys_1 = require("./routes/api/keys");
22
+ const models_2 = require("./routes/api/models");
23
+ const analytics_1 = require("./routes/api/analytics");
24
+ const health_1 = require("./services/health");
25
+ async function startServer(config = {}) {
26
+ const port = config.port ?? Number(process.env.PORT ?? 3000);
27
+ const dataDir = config.dataDir ?? process.env.FREELLM_DATA_DIR ?? path_1.default.join(process.env.HOME ?? process.env.USERPROFILE ?? '.', '.freellm');
28
+ const dbPath = path_1.default.join(dataDir, 'data.db');
29
+ // Encryption key — generate and persist if not provided
30
+ const encKeyFile = path_1.default.join(dataDir, '.enc_key');
31
+ if (!fs_1.default.existsSync(dataDir))
32
+ fs_1.default.mkdirSync(dataDir, { recursive: true });
33
+ let encKey = config.encryptionKey ?? process.env.ENCRYPTION_KEY;
34
+ if (!encKey) {
35
+ if (fs_1.default.existsSync(encKeyFile)) {
36
+ encKey = fs_1.default.readFileSync(encKeyFile, 'utf8').trim();
37
+ }
38
+ else {
39
+ encKey = crypto_1.default.randomBytes(32).toString('hex');
40
+ fs_1.default.writeFileSync(encKeyFile, encKey, { mode: 0o600 });
41
+ }
42
+ }
43
+ (0, crypto_2.initCrypto)(encKey);
44
+ (0, index_1.initDb)(dbPath);
45
+ // Ensure unified key exists
46
+ if (!(0, index_1.getSetting)('unified_key')) {
47
+ (0, index_1.setSetting)('unified_key', (0, crypto_2.generateUnifiedKey)());
48
+ }
49
+ const app = (0, express_1.default)();
50
+ app.use((0, compression_1.default)());
51
+ app.use((0, cors_1.default)({ origin: true, credentials: true }));
52
+ app.use(express_1.default.json({ limit: '10mb' }));
53
+ app.use((0, cookie_parser_1.default)());
54
+ // Unified key auth middleware for /v1 routes
55
+ app.use('/v1', (req, res, next) => {
56
+ const authHeader = req.headers['authorization'];
57
+ const unifiedKey = (0, index_1.getSetting)('unified_key');
58
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
59
+ return res.status(401).json({ error: { message: 'Missing Authorization header', type: 'auth_error' } });
60
+ }
61
+ const token = authHeader.slice(7);
62
+ if (token !== unifiedKey) {
63
+ return res.status(401).json({ error: { message: 'Invalid API key', type: 'auth_error' } });
64
+ }
65
+ return next();
66
+ });
67
+ // v1 proxy routes
68
+ app.use('/v1', chat_1.chatRouter);
69
+ app.use('/v1', models_1.modelsRouter);
70
+ app.use('/v1', images_1.imagesRouter);
71
+ app.use('/v1', audio_1.audioRouter);
72
+ // Dashboard API routes (auth protected except /auth/*)
73
+ app.use('/api', auth_1.authRouter);
74
+ app.use('/api', auth_1.requireAuth, keys_1.keysRouter);
75
+ app.use('/api', auth_1.requireAuth, models_2.modelsApiRouter);
76
+ app.use('/api', auth_1.requireAuth, analytics_1.analyticsRouter);
77
+ // Serve React dashboard
78
+ const clientDist = path_1.default.join(__dirname, '..', 'client-dist');
79
+ if (fs_1.default.existsSync(clientDist)) {
80
+ app.use(express_1.default.static(clientDist));
81
+ app.get('*', (_req, res) => {
82
+ res.sendFile(path_1.default.join(clientDist, 'index.html'));
83
+ });
84
+ }
85
+ else {
86
+ app.get('/', (_req, res) => {
87
+ res.send(`<html><body style="font-family:sans-serif;padding:2rem">
88
+ <h1>UniLLM is running</h1>
89
+ <p>API endpoint: <code>http://localhost:${port}/v1</code></p>
90
+ <p>Dashboard not built. Run <code>npm run build:client</code> to build the UI.</p>
91
+ </body></html>`);
92
+ });
93
+ }
94
+ await new Promise((resolve) => {
95
+ app.listen(port, () => resolve());
96
+ });
97
+ (0, health_1.startHealthService)();
98
+ const url = `http://localhost:${port}`;
99
+ return { port, url };
100
+ }
@@ -0,0 +1,10 @@
1
+ import { BaseProvider, ChatRequest, ChatResponse, StreamChunk } from './types';
2
+ export declare class CloudflareProvider extends BaseProvider {
3
+ readonly platform = "cloudflare";
4
+ readonly baseUrl = "https://api.cloudflare.com/client/v4";
5
+ protected defaultModel(): string;
6
+ private parseKey;
7
+ private toMessages;
8
+ chat(apiKey: string, req: ChatRequest): Promise<ChatResponse>;
9
+ streamChat(apiKey: string, req: ChatRequest, onChunk: (chunk: StreamChunk) => void, onDone: () => void, onError: (err: Error) => void): Promise<void>;
10
+ }