freellm 1.0.1 → 1.0.3

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.
package/dist/db/index.js CHANGED
@@ -14,6 +14,7 @@ exports.decryptKey = decryptKey;
14
14
  exports.updateKeyStatus = updateKeyStatus;
15
15
  exports.deleteKey = deleteKey;
16
16
  exports.toggleKey = toggleKey;
17
+ exports.updateKey = updateKey;
17
18
  exports.listModels = listModels;
18
19
  exports.listEnabledModels = listEnabledModels;
19
20
  exports.updateModelOrder = updateModelOrder;
@@ -42,58 +43,58 @@ function getDb() {
42
43
  return db;
43
44
  }
44
45
  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);
46
+ db.exec(`
47
+ CREATE TABLE IF NOT EXISTS settings (
48
+ key TEXT PRIMARY KEY,
49
+ value TEXT NOT NULL
50
+ );
51
+
52
+ CREATE TABLE IF NOT EXISTS sessions (
53
+ token TEXT PRIMARY KEY,
54
+ created_at INTEGER NOT NULL DEFAULT (unixepoch()),
55
+ expires_at INTEGER NOT NULL
56
+ );
57
+
58
+ CREATE TABLE IF NOT EXISTS provider_keys (
59
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
60
+ platform TEXT NOT NULL,
61
+ label TEXT NOT NULL DEFAULT '',
62
+ key_enc TEXT NOT NULL,
63
+ enabled INTEGER NOT NULL DEFAULT 1,
64
+ status TEXT NOT NULL DEFAULT 'unknown',
65
+ last_check INTEGER,
66
+ created_at INTEGER NOT NULL DEFAULT (unixepoch())
67
+ );
68
+
69
+ CREATE TABLE IF NOT EXISTS models (
70
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
71
+ platform TEXT NOT NULL,
72
+ model_id TEXT NOT NULL,
73
+ display_name TEXT NOT NULL,
74
+ supports_tools INTEGER NOT NULL DEFAULT 0,
75
+ supports_vision INTEGER NOT NULL DEFAULT 0,
76
+ supports_stream INTEGER NOT NULL DEFAULT 1,
77
+ type TEXT NOT NULL DEFAULT 'chat',
78
+ context_length INTEGER,
79
+ fallback_order INTEGER NOT NULL DEFAULT 999,
80
+ enabled INTEGER NOT NULL DEFAULT 1,
81
+ UNIQUE(platform, model_id)
82
+ );
83
+
84
+ CREATE TABLE IF NOT EXISTS analytics (
85
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
86
+ ts INTEGER NOT NULL DEFAULT (unixepoch()),
87
+ platform TEXT NOT NULL,
88
+ model_id TEXT NOT NULL,
89
+ prompt_tokens INTEGER NOT NULL DEFAULT 0,
90
+ complete_tokens INTEGER NOT NULL DEFAULT 0,
91
+ latency_ms INTEGER,
92
+ success INTEGER NOT NULL DEFAULT 1,
93
+ error_code TEXT
94
+ );
95
+
96
+ CREATE INDEX IF NOT EXISTS idx_analytics_ts ON analytics(ts);
97
+ CREATE INDEX IF NOT EXISTS idx_analytics_platform ON analytics(platform);
97
98
  `);
98
99
  seedModels();
99
100
  }
@@ -131,6 +132,9 @@ function deleteKey(id) {
131
132
  function toggleKey(id, enabled) {
132
133
  db.prepare('UPDATE provider_keys SET enabled = ? WHERE id = ?').run(enabled ? 1 : 0, id);
133
134
  }
135
+ function updateKey(id, rawKey, label) {
136
+ db.prepare('UPDATE provider_keys SET key_enc = ?, label = ? WHERE id = ?').run((0, crypto_1.encrypt)(rawKey), label, id);
137
+ }
134
138
  // ─── Models ──────────────────────────────────────────────────────────────────
135
139
  function listModels(type = 'chat') {
136
140
  return db
@@ -150,9 +154,9 @@ function toggleModel(id, enabled) {
150
154
  }
151
155
  // ─── Analytics ───────────────────────────────────────────────────────────────
152
156
  function logRequest(data) {
153
- db.prepare(`
154
- INSERT INTO analytics (platform, model_id, prompt_tokens, complete_tokens, latency_ms, success, error_code)
155
- VALUES (?, ?, ?, ?, ?, ?, ?)
157
+ db.prepare(`
158
+ INSERT INTO analytics (platform, model_id, prompt_tokens, complete_tokens, latency_ms, success, error_code)
159
+ VALUES (?, ?, ?, ?, ?, ?, ?)
156
160
  `).run(data.platform, data.model_id, data.prompt_tokens, data.complete_tokens, data.latency_ms, data.success ? 1 : 0, data.error_code ?? null);
157
161
  }
158
162
  function getAnalytics(windowHours = 24) {
@@ -207,10 +211,10 @@ function deleteSession(token) {
207
211
  }
208
212
  // ─── Seed models ─────────────────────────────────────────────────────────────
209
213
  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
+ db.prepare(`
215
+ INSERT INTO models (platform, model_id, display_name, supports_tools, supports_vision, supports_stream, type, context_length, fallback_order, enabled)
216
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
217
+ ON CONFLICT(platform, model_id) DO NOTHING
214
218
  `).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
219
  }
216
220
  function seedModels() {
package/dist/index.js CHANGED
@@ -84,10 +84,10 @@ async function startServer(config = {}) {
84
84
  }
85
85
  else {
86
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>
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
91
  </body></html>`);
92
92
  });
93
93
  }
@@ -63,3 +63,12 @@ exports.keysRouter.patch('/keys/:id/toggle', (req, res) => {
63
63
  (0, db_1.toggleKey)(Number(req.params.id), !!enabled);
64
64
  return res.json({ ok: true });
65
65
  });
66
+ // Update provider key
67
+ exports.keysRouter.put('/keys/:id', (req, res) => {
68
+ const { key, label } = req.body;
69
+ if (!key) {
70
+ return res.status(400).json({ error: 'key is required' });
71
+ }
72
+ (0, db_1.updateKey)(Number(req.params.id), key, label ?? '');
73
+ return res.json({ ok: true });
74
+ });
@@ -5,12 +5,19 @@ const express_1 = require("express");
5
5
  const db_1 = require("../../db");
6
6
  exports.modelsApiRouter = (0, express_1.Router)();
7
7
  exports.modelsApiRouter.get('/models', (req, res) => {
8
+ const showAll = req.query.all === '1';
8
9
  const type = req.query.type;
9
- if (!type || type === 'all') {
10
- const all = [...(0, db_1.listModels)('chat'), ...(0, db_1.listModels)('image'), ...(0, db_1.listModels)('tts')];
10
+ const all = type && type !== 'all'
11
+ ? (0, db_1.listModels)(type)
12
+ : [...(0, db_1.listModels)('chat'), ...(0, db_1.listModels)('image'), ...(0, db_1.listModels)('tts')];
13
+ if (showAll)
11
14
  return res.json(all);
15
+ const keyedPlatforms = new Set();
16
+ for (const key of (0, db_1.listKeys)()) {
17
+ if (key.enabled)
18
+ keyedPlatforms.add(key.platform);
12
19
  }
13
- return res.json((0, db_1.listModels)(type));
20
+ return res.json(all.filter((m) => keyedPlatforms.has(m.platform)));
14
21
  });
15
22
  exports.modelsApiRouter.patch('/models/:id/toggle', (req, res) => {
16
23
  const { enabled } = req.body;
@@ -5,9 +5,14 @@ const express_1 = require("express");
5
5
  const db_1 = require("../../db");
6
6
  exports.modelsRouter = (0, express_1.Router)();
7
7
  exports.modelsRouter.get('/models', (_req, res) => {
8
- const chatModels = (0, db_1.listEnabledModels)('chat');
9
- const imageModels = (0, db_1.listEnabledModels)('image');
10
- const ttsModels = (0, db_1.listEnabledModels)('tts');
8
+ const keyedPlatforms = new Set();
9
+ for (const key of (0, db_1.listKeys)()) {
10
+ if (key.enabled)
11
+ keyedPlatforms.add(key.platform);
12
+ }
13
+ const chatModels = (0, db_1.listEnabledModels)('chat').filter((m) => keyedPlatforms.has(m.platform));
14
+ const imageModels = (0, db_1.listEnabledModels)('image').filter((m) => keyedPlatforms.has(m.platform));
15
+ const ttsModels = (0, db_1.listEnabledModels)('tts').filter((m) => keyedPlatforms.has(m.platform));
11
16
  const data = [
12
17
  ...chatModels.map((m) => ({
13
18
  id: m.model_id,
package/package.json CHANGED
@@ -1,57 +1,57 @@
1
- {
2
- "name": "freellm",
3
- "version": "1.0.1",
4
- "description": "One OpenAI-compatible endpoint for 15+ free LLM providers. Smart routing, failover, encrypted keys. Run with npx freellm.",
5
- "keywords": ["llm", "openai", "proxy", "groq", "gemini", "mistral", "free", "api-gateway"],
6
- "author": "",
7
- "license": "MIT",
8
- "bin": {
9
- "freellm": "bin/cli.js"
10
- },
11
- "main": "dist/index.js",
12
- "files": [
13
- "bin/",
14
- "dist/",
15
- "client-dist/"
16
- ],
17
- "scripts": {
18
- "dev": "concurrently \"npm run dev:server\" \"npm run dev:client\"",
19
- "dev:server": "tsx watch src/cli.ts -- --no-open",
20
- "dev:client": "vite --config client/vite.config.ts",
21
- "build": "npm run build:server && npm run build:client",
22
- "build:server": "tsc -p tsconfig.json",
23
- "build:client": "vite build --config client/vite.config.ts",
24
- "prepublishOnly": "npm run build",
25
- "start": "node dist/cli.js",
26
- "test": "vitest run"
27
- },
28
- "dependencies": {
29
- "chalk": "^5.3.0",
30
- "compression": "^1.7.4",
31
- "cookie-parser": "^1.4.6",
32
- "cors": "^2.8.5",
33
- "express": "^4.18.3",
34
- "nanoid": "^5.0.7",
35
- "open": "^10.1.0",
36
- "react": "^18.2.0",
37
- "react-dom": "^18.2.0"
38
- },
39
- "devDependencies": {
40
- "@types/compression": "^1.7.5",
41
- "@types/cookie-parser": "^1.4.7",
42
- "@types/cors": "^2.8.17",
43
- "@types/express": "^4.17.21",
44
- "@types/node": "^22.0.0",
45
- "@types/react": "^18.2.73",
46
- "@types/react-dom": "^18.2.23",
47
- "@vitejs/plugin-react": "^4.2.1",
48
- "concurrently": "^8.2.2",
49
- "tsx": "^4.7.1",
50
- "typescript": "^5.4.3",
51
- "vite": "^5.2.6",
52
- "vitest": "^1.4.0"
53
- },
54
- "engines": {
55
- "node": ">=22.5.0"
56
- }
57
- }
1
+ {
2
+ "name": "freellm",
3
+ "version": "1.0.3",
4
+ "description": "One OpenAI-compatible endpoint for 15+ free LLM providers. Smart routing, failover, encrypted keys. Run with npx freellm.",
5
+ "keywords": ["llm", "openai", "proxy", "groq", "gemini", "mistral", "free", "api-gateway"],
6
+ "author": "",
7
+ "license": "MIT",
8
+ "bin": {
9
+ "freellm": "bin/cli.js"
10
+ },
11
+ "main": "dist/index.js",
12
+ "files": [
13
+ "bin/",
14
+ "dist/",
15
+ "client-dist/"
16
+ ],
17
+ "scripts": {
18
+ "dev": "concurrently \"npm run dev:server\" \"npm run dev:client\"",
19
+ "dev:server": "tsx watch src/cli.ts -- --no-open",
20
+ "dev:client": "vite --config client/vite.config.ts",
21
+ "build": "npm run build:server && npm run build:client",
22
+ "build:server": "tsc -p tsconfig.json",
23
+ "build:client": "vite build --config client/vite.config.ts",
24
+ "prepublishOnly": "npm run build",
25
+ "start": "node dist/cli.js",
26
+ "test": "vitest run"
27
+ },
28
+ "dependencies": {
29
+ "chalk": "^5.3.0",
30
+ "compression": "^1.7.4",
31
+ "cookie-parser": "^1.4.6",
32
+ "cors": "^2.8.5",
33
+ "express": "^4.18.3",
34
+ "nanoid": "^5.0.7",
35
+ "open": "^10.1.0",
36
+ "react": "^18.2.0",
37
+ "react-dom": "^18.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/compression": "^1.7.5",
41
+ "@types/cookie-parser": "^1.4.7",
42
+ "@types/cors": "^2.8.17",
43
+ "@types/express": "^4.17.21",
44
+ "@types/node": "^22.0.0",
45
+ "@types/react": "^18.2.73",
46
+ "@types/react-dom": "^18.2.23",
47
+ "@vitejs/plugin-react": "^4.2.1",
48
+ "concurrently": "^8.2.2",
49
+ "tsx": "^4.7.1",
50
+ "typescript": "^5.4.3",
51
+ "vite": "^5.2.6",
52
+ "vitest": "^1.4.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=22.5.0"
56
+ }
57
+ }