freellm 1.0.0 → 1.0.2

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.
@@ -33,6 +33,7 @@ export declare function decryptKey(enc: string): string;
33
33
  export declare function updateKeyStatus(id: number, status: string): void;
34
34
  export declare function deleteKey(id: number): void;
35
35
  export declare function toggleKey(id: number, enabled: boolean): void;
36
+ export declare function updateKey(id: number, rawKey: string, label: string): void;
36
37
  export declare function listModels(type?: string): Model[];
37
38
  export declare function listEnabledModels(type?: string): Model[];
38
39
  export declare function updateModelOrder(id: number, order: number): void;
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;
@@ -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
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "freellm",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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": "",