freellm 1.0.11 → 1.0.12
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/client-dist/assets/index-nnyuHthF.js +96 -0
- package/client-dist/index.html +1 -1
- package/dist/cli.js +3 -5
- package/dist/db/index.d.ts +10 -0
- package/dist/db/index.js +22 -0
- package/dist/index.js +7 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/routes/api/auth.js +12 -6
- package/dist/routes/api/custom-providers.d.ts +1 -0
- package/dist/routes/api/custom-providers.js +48 -0
- package/dist/services/health.js +1 -34
- package/package.json +1 -2
- package/client-dist/assets/index-cDIZ2w-M.js +0 -96
package/dist/db/index.d.ts
CHANGED
|
@@ -43,6 +43,16 @@ export declare function upsertModelsFromList(platform: string, models: Array<{
|
|
|
43
43
|
id: string;
|
|
44
44
|
display_name?: string;
|
|
45
45
|
}>): number;
|
|
46
|
+
export type CustomProvider = {
|
|
47
|
+
platform: string;
|
|
48
|
+
name: string;
|
|
49
|
+
base_url: string;
|
|
50
|
+
default_model: string;
|
|
51
|
+
created_at: number;
|
|
52
|
+
};
|
|
53
|
+
export declare function listCustomProviders(): CustomProvider[];
|
|
54
|
+
export declare function addCustomProvider(platform: string, name: string, baseUrl: string, defaultModel: string): void;
|
|
55
|
+
export declare function deleteCustomProvider(platform: string): void;
|
|
46
56
|
export declare function logRequest(data: {
|
|
47
57
|
platform: string;
|
|
48
58
|
model_id: string;
|
package/dist/db/index.js
CHANGED
|
@@ -21,6 +21,9 @@ exports.updateModelOrder = updateModelOrder;
|
|
|
21
21
|
exports.toggleModel = toggleModel;
|
|
22
22
|
exports.listModelsByPlatform = listModelsByPlatform;
|
|
23
23
|
exports.upsertModelsFromList = upsertModelsFromList;
|
|
24
|
+
exports.listCustomProviders = listCustomProviders;
|
|
25
|
+
exports.addCustomProvider = addCustomProvider;
|
|
26
|
+
exports.deleteCustomProvider = deleteCustomProvider;
|
|
24
27
|
exports.logRequest = logRequest;
|
|
25
28
|
exports.getAnalytics = getAnalytics;
|
|
26
29
|
exports.createSession = createSession;
|
|
@@ -95,6 +98,14 @@ function migrate() {
|
|
|
95
98
|
error_code TEXT
|
|
96
99
|
);
|
|
97
100
|
|
|
101
|
+
CREATE TABLE IF NOT EXISTS custom_providers (
|
|
102
|
+
platform TEXT PRIMARY KEY,
|
|
103
|
+
name TEXT NOT NULL,
|
|
104
|
+
base_url TEXT NOT NULL,
|
|
105
|
+
default_model TEXT NOT NULL,
|
|
106
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
107
|
+
);
|
|
108
|
+
|
|
98
109
|
CREATE INDEX IF NOT EXISTS idx_analytics_ts ON analytics(ts);
|
|
99
110
|
CREATE INDEX IF NOT EXISTS idx_analytics_platform ON analytics(platform);
|
|
100
111
|
`);
|
|
@@ -175,6 +186,17 @@ function upsertModelsFromList(platform, models) {
|
|
|
175
186
|
}
|
|
176
187
|
return added;
|
|
177
188
|
}
|
|
189
|
+
function listCustomProviders() {
|
|
190
|
+
return db.prepare('SELECT * FROM custom_providers ORDER BY created_at').all();
|
|
191
|
+
}
|
|
192
|
+
function addCustomProvider(platform, name, baseUrl, defaultModel) {
|
|
193
|
+
db.prepare('INSERT INTO custom_providers (platform, name, base_url, default_model) VALUES (?, ?, ?, ?)').run(platform, name, baseUrl, defaultModel);
|
|
194
|
+
}
|
|
195
|
+
function deleteCustomProvider(platform) {
|
|
196
|
+
db.prepare('DELETE FROM custom_providers WHERE platform = ?').run(platform);
|
|
197
|
+
db.prepare('DELETE FROM provider_keys WHERE platform = ?').run(platform);
|
|
198
|
+
db.prepare('DELETE FROM models WHERE platform = ?').run(platform);
|
|
199
|
+
}
|
|
178
200
|
// ─── Analytics ───────────────────────────────────────────────────────────────
|
|
179
201
|
function logRequest(data) {
|
|
180
202
|
db.prepare(`
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
13
13
|
const crypto_1 = __importDefault(require("crypto"));
|
|
14
14
|
const crypto_2 = require("./crypto");
|
|
15
15
|
const index_1 = require("./db/index");
|
|
16
|
+
const providers_1 = require("./providers");
|
|
16
17
|
const chat_1 = require("./routes/v1/chat");
|
|
17
18
|
const models_1 = require("./routes/v1/models");
|
|
18
19
|
const images_1 = require("./routes/v1/images");
|
|
@@ -21,6 +22,7 @@ const auth_1 = require("./routes/api/auth");
|
|
|
21
22
|
const keys_1 = require("./routes/api/keys");
|
|
22
23
|
const models_2 = require("./routes/api/models");
|
|
23
24
|
const analytics_1 = require("./routes/api/analytics");
|
|
25
|
+
const custom_providers_1 = require("./routes/api/custom-providers");
|
|
24
26
|
const health_1 = require("./services/health");
|
|
25
27
|
async function startServer(config = {}) {
|
|
26
28
|
const port = config.port ?? Number(process.env.PORT ?? 3000);
|
|
@@ -42,6 +44,10 @@ async function startServer(config = {}) {
|
|
|
42
44
|
}
|
|
43
45
|
(0, crypto_2.initCrypto)(encKey);
|
|
44
46
|
(0, index_1.initDb)(dbPath);
|
|
47
|
+
// Register persisted custom providers
|
|
48
|
+
for (const p of (0, index_1.listCustomProviders)()) {
|
|
49
|
+
(0, providers_1.registerCustomProvider)(p.platform, p.base_url, p.default_model);
|
|
50
|
+
}
|
|
45
51
|
// Ensure unified key exists
|
|
46
52
|
if (!(0, index_1.getSetting)('unified_key')) {
|
|
47
53
|
(0, index_1.setSetting)('unified_key', (0, crypto_2.generateUnifiedKey)());
|
|
@@ -74,6 +80,7 @@ async function startServer(config = {}) {
|
|
|
74
80
|
app.use('/api', auth_1.requireAuth, keys_1.keysRouter);
|
|
75
81
|
app.use('/api', auth_1.requireAuth, models_2.modelsApiRouter);
|
|
76
82
|
app.use('/api', auth_1.requireAuth, analytics_1.analyticsRouter);
|
|
83
|
+
app.use('/api', auth_1.requireAuth, custom_providers_1.customProvidersRouter);
|
|
77
84
|
// Serve React dashboard
|
|
78
85
|
const clientDist = path_1.default.join(__dirname, '..', 'client-dist');
|
|
79
86
|
if (fs_1.default.existsSync(clientDist)) {
|
|
@@ -12,3 +12,4 @@ export declare function getProvider(platform: string, type: 'image'): BaseImageP
|
|
|
12
12
|
export declare function getProvider(platform: string, type: 'tts'): BaseTTSProvider | undefined;
|
|
13
13
|
export declare function allProviders(type?: 'chat' | 'image' | 'tts'): string[];
|
|
14
14
|
export declare function registerCustomProvider(platform: string, baseUrl: string, defaultModel: string): void;
|
|
15
|
+
export declare function unregisterCustomProvider(platform: string): void;
|
package/dist/providers/index.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.getTTSProvider = getTTSProvider;
|
|
|
7
7
|
exports.getProvider = getProvider;
|
|
8
8
|
exports.allProviders = allProviders;
|
|
9
9
|
exports.registerCustomProvider = registerCustomProvider;
|
|
10
|
+
exports.unregisterCustomProvider = unregisterCustomProvider;
|
|
10
11
|
const openai_compat_1 = require("./openai-compat");
|
|
11
12
|
Object.defineProperty(exports, "OpenAICompatProvider", { enumerable: true, get: function () { return openai_compat_1.OpenAICompatProvider; } });
|
|
12
13
|
const google_1 = require("./google");
|
|
@@ -58,3 +59,6 @@ function allProviders(type = 'chat') {
|
|
|
58
59
|
function registerCustomProvider(platform, baseUrl, defaultModel) {
|
|
59
60
|
chatRegistry[platform] = new openai_compat_1.OpenAICompatProvider(platform, baseUrl, defaultModel);
|
|
60
61
|
}
|
|
62
|
+
function unregisterCustomProvider(platform) {
|
|
63
|
+
delete chatRegistry[platform];
|
|
64
|
+
}
|
package/dist/routes/api/auth.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.authRouter = void 0;
|
|
4
7
|
exports.requireAuth = requireAuth;
|
|
5
8
|
const express_1 = require("express");
|
|
6
|
-
const
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
10
|
const db_1 = require("../../db");
|
|
8
|
-
const
|
|
11
|
+
const crypto_2 = require("../../crypto");
|
|
12
|
+
function makeToken() {
|
|
13
|
+
return crypto_1.default.randomBytes(36).toString('base64url');
|
|
14
|
+
}
|
|
9
15
|
exports.authRouter = (0, express_1.Router)();
|
|
10
16
|
// Middleware: protect API routes with session token
|
|
11
17
|
function requireAuth(req, res, next) {
|
|
@@ -32,8 +38,8 @@ exports.authRouter.post('/auth/setup', (req, res) => {
|
|
|
32
38
|
if ((0, db_1.getSetting)('password_hash')) {
|
|
33
39
|
return res.status(409).json({ error: 'Already set up' });
|
|
34
40
|
}
|
|
35
|
-
(0, db_1.setSetting)('password_hash', (0,
|
|
36
|
-
const token = (
|
|
41
|
+
(0, db_1.setSetting)('password_hash', (0, crypto_2.hashPassword)(password));
|
|
42
|
+
const token = makeToken();
|
|
37
43
|
(0, db_1.createSession)(token);
|
|
38
44
|
res.cookie('freellm-session', token, { httpOnly: true, sameSite: 'strict' });
|
|
39
45
|
return res.json({ token });
|
|
@@ -42,10 +48,10 @@ exports.authRouter.post('/auth/setup', (req, res) => {
|
|
|
42
48
|
exports.authRouter.post('/auth/login', (req, res) => {
|
|
43
49
|
const { password } = req.body;
|
|
44
50
|
const hash = (0, db_1.getSetting)('password_hash');
|
|
45
|
-
if (!hash || !password || !(0,
|
|
51
|
+
if (!hash || !password || !(0, crypto_2.verifyPassword)(password, hash)) {
|
|
46
52
|
return res.status(401).json({ error: 'Invalid password' });
|
|
47
53
|
}
|
|
48
|
-
const token = (
|
|
54
|
+
const token = makeToken();
|
|
49
55
|
(0, db_1.createSession)(token);
|
|
50
56
|
res.cookie('freellm-session', token, { httpOnly: true, sameSite: 'strict' });
|
|
51
57
|
return res.json({ token });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const customProvidersRouter: import("express-serve-static-core").Router;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customProvidersRouter = void 0;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const db_1 = require("../../db");
|
|
6
|
+
const providers_1 = require("../../providers");
|
|
7
|
+
exports.customProvidersRouter = (0, express_1.Router)();
|
|
8
|
+
function slugify(name) {
|
|
9
|
+
return name
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.trim()
|
|
12
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
13
|
+
.replace(/^-+|-+$/g, '');
|
|
14
|
+
}
|
|
15
|
+
exports.customProvidersRouter.get('/custom-providers', (_req, res) => {
|
|
16
|
+
return res.json((0, db_1.listCustomProviders)().map((p) => ({
|
|
17
|
+
platform: p.platform,
|
|
18
|
+
name: p.name,
|
|
19
|
+
baseUrl: p.base_url,
|
|
20
|
+
defaultModel: p.default_model,
|
|
21
|
+
})));
|
|
22
|
+
});
|
|
23
|
+
exports.customProvidersRouter.post('/custom-providers', (req, res) => {
|
|
24
|
+
const { name, baseUrl, defaultModel, apiKey } = req.body;
|
|
25
|
+
if (!name || !baseUrl || !defaultModel) {
|
|
26
|
+
return res.status(400).json({ error: 'name, baseUrl and defaultModel are required' });
|
|
27
|
+
}
|
|
28
|
+
const platform = slugify(name);
|
|
29
|
+
if (!platform) {
|
|
30
|
+
return res.status(400).json({ error: 'provider name must contain letters or numbers' });
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
(0, db_1.addCustomProvider)(platform, name.trim(), baseUrl.trim(), defaultModel.trim());
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return res.status(409).json({ error: `provider '${name}' already exists` });
|
|
37
|
+
}
|
|
38
|
+
(0, providers_1.registerCustomProvider)(platform, baseUrl.trim(), defaultModel.trim());
|
|
39
|
+
// Always create a key row (empty key for providers without auth) so the
|
|
40
|
+
// platform can sync models and appear in /v1/models
|
|
41
|
+
const keyId = (0, db_1.addKey)(platform, (apiKey ?? '').trim(), name.trim());
|
|
42
|
+
return res.status(201).json({ platform, keyId });
|
|
43
|
+
});
|
|
44
|
+
exports.customProvidersRouter.delete('/custom-providers/:platform', (req, res) => {
|
|
45
|
+
(0, db_1.deleteCustomProvider)(req.params.platform);
|
|
46
|
+
(0, providers_1.unregisterCustomProvider)(req.params.platform);
|
|
47
|
+
return res.json({ ok: true });
|
|
48
|
+
});
|
package/dist/services/health.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.startHealthService = startHealthService;
|
|
37
4
|
exports.stopHealthService = stopHealthService;
|
|
@@ -59,7 +26,7 @@ async function runHealthChecks() {
|
|
|
59
26
|
if (!provider)
|
|
60
27
|
continue;
|
|
61
28
|
try {
|
|
62
|
-
const { decrypt } = await
|
|
29
|
+
const { decrypt } = await import('../crypto.js');
|
|
63
30
|
const rawKey = decrypt(k.key_enc);
|
|
64
31
|
const ok = await provider.healthCheck(rawKey);
|
|
65
32
|
(0, db_1.updateKeyStatus)(k.id, ok ? 'healthy' : 'error');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "freellm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "One OpenAI-compatible endpoint for 15+ free LLM providers. Smart routing, failover, encrypted keys. Run with npx freellm.",
|
|
5
5
|
"keywords": ["llm", "openai", "proxy", "groq", "gemini", "mistral", "free", "api-gateway"],
|
|
6
6
|
"author": "",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"cookie-parser": "^1.4.6",
|
|
32
32
|
"cors": "^2.8.5",
|
|
33
33
|
"express": "^4.18.3",
|
|
34
|
-
"nanoid": "^5.0.7",
|
|
35
34
|
"open": "^10.1.0",
|
|
36
35
|
"react": "^18.2.0",
|
|
37
36
|
"react-dom": "^18.2.0"
|