7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(keys): actionable no-catalog notice — name the base URL, skip bogus advice (#1327) (#1329)
tashdroida0befbc6718b
diff --git a/server/src/__tests__/routes/keys.test.ts b/server/src/__tests__/routes/keys.test.tsindex 4a2de5ce..f1e7cc38 100644--- a/server/src/__tests__/routes/keys.test.ts+++ b/server/src/__tests__/routes/keys.test.ts@@ -123,6 +123,69 @@ describe('Keys API', () => {expect(body.notice).toMatch(/no agnes models/i);});+ it('#1327: the no-catalog notice names the provider base URL so the custom-provider workaround is actionable', async () => {+ const db = getDb();+ db.prepare("UPDATE models SET enabled = 0 WHERE platform = 'agnes'").run();++ const { body } = await request(app, 'POST', '/api/keys', {+ platform: 'agnes',+ key: 'agnes_test_key_123456',+ });+ // Agnes is an OpenAI-compat provider: the notice must quote its actual+ // base URL, which is what the workaround tells the user to paste.+ expect(body.notice).toMatch(/base URL https:\/\/apihub\.agnes-ai\.com\/v1/);+ });++ it('#1327: a non-OpenAI-compat provider gets no bogus custom-provider advice', async () => {+ const db = getDb();+ db.prepare("DELETE FROM media_models WHERE platform = 'speechify'").run();+ const { body } = await request(app, 'POST', '/api/keys', {+ platform: 'speechify',+ key: 'speechify_test_key_123456',+ });+ // Speechify speaks its own TTS API; suggesting the custom+ // OpenAI-compatible path for it sends users into a dead end.+ expect(body.notice).toMatch(/no speechify models/i);+ expect(body.notice).not.toMatch(/custom OpenAI-compatible/);+ });++ it('#1327: a media-only provider whose TTS models are in the catalog gets no notice', async () => {+ const db = getDb();+ db.prepare("DELETE FROM media_models WHERE platform = 'speechify'").run();+ db.prepare(`+ INSERT INTO media_models (platform, model_id, display_name, modality, priority, enabled)+ VALUES ('speechify', 'simba-english', 'Speechify Simba English', 'audio', 1, 1)+ `).run();+ try {+ const { status, body } = await request(app, 'POST', '/api/keys', {+ platform: 'speechify',+ key: 'speechify_test_key_123456',+ });+ expect(status).toBe(201);+ expect(body.modelsAvailable).toBe(1);+ expect(body.notice).toBeUndefined();+ } finally {+ db.prepare("DELETE FROM media_models WHERE platform = 'speechify'").run();+ }+ });++ it('#1327: a Premium install is not told to add a Premium license key', async () => {+ const db = getDb();+ db.prepare("UPDATE models SET enabled = 0 WHERE platform = 'agnes'").run();+ db.prepare("INSERT OR REPLACE INTO settings (key, value) VALUES ('catalog_applied_tier', 'live')").run();+ try {+ const { body } = await request(app, 'POST', '/api/keys', {+ platform: 'agnes',+ key: 'agnes_test_key_123456',+ });+ expect(body.notice).toMatch(/Premium catalog does not list any agnes models/);+ expect(body.notice).not.toMatch(/Add a Premium license key/);+ expect(body.notice).toMatch(/base URL https:\/\/apihub\.agnes-ai\.com\/v1/);+ } finally {+ db.prepare("DELETE FROM settings WHERE key = 'catalog_applied_tier'").run();+ }+ });+it('POST /api/keys does not warn when the platform has catalog models', async () => {const { status, body } = await request(app, 'POST', '/api/keys', {platform: 'groq',diff --git a/server/src/routes/keys.ts b/server/src/routes/keys.tsindex d2273220..100a28a0 100644--- a/server/src/routes/keys.ts+++ b/server/src/routes/keys.ts@@ -5,6 +5,8 @@ import multer from 'multer';import path from 'path';import { getDb } from '../db/index.js';import { resolveProvider, getAllProviders } from '../providers/index.js';+import { OpenAICompatProvider } from '../providers/openai-compat.js';+import { getSyncState } from '../services/catalog-sync.js';import { encrypt, decrypt, maskKey } from '../lib/crypto.js';import { parseKeysFromFile, stripJsoncComments, stripTrailingCommas } from '../lib/key-parser.js';import { assessProviderUrl } from '../lib/url-guard.js';@@ -197,24 +199,58 @@ export function isExportableKey(row: { platform: string; baseUrl: string | null;return v.length > 0 && v !== 'no-key';}+// Every model a platform's key can serve: chat rows, plus embedding and+// generative-media rows. Media-only providers (Speechify is TTS-only) never+// have a chat row, so counting `models` alone reported "no models" — and fired+// the no-catalog notice — for them even on a fully synced Premium install+// (#1327).function enabledModelCount(platform: string): number {const db = getDb();- const row = db.prepare(- 'SELECT COUNT(*) AS c FROM models WHERE platform = ? AND enabled = 1',- ).get(platform) as { c: number };+ const row = db.prepare(`+ SELECT (SELECT COUNT(*) FROM models WHERE platform = ? AND enabled = 1)+ + (SELECT COUNT(*) FROM embedding_models WHERE platform = ? AND enabled = 1)+ + (SELECT COUNT(*) FROM media_models WHERE platform = ? AND enabled = 1) AS c+ `).get(platform, platform, platform) as { c: number };return row.c;}+// The public API root the custom-provider workaround needs, or null when the+// platform does not speak the OpenAI-compatible protocol that path speaks+// (e.g. Speechify's own TTS API), in which case that advice is a dead end.+function openAICompatBaseUrl(platform: string): string | null {+ const provider = resolveProvider(platform as Platform);+ if (!(provider instanceof OpenAICompatProvider)) return null;+ return provider.modelsUrl.replace(/\/models\/?$/, '');+}+// Non-null when the just-added key has no usable models yet, so the client can// explain the silence instead of leaving the user staring at an empty list.+//+// #1327: the old copy told a Premium user to "add a Premium license key", and+// told everyone to add the provider as a custom OpenAI-compatible endpoint+// "with its base URL" without naming it — even for providers with no such+// endpoint. The notice now matches the install's actual catalog tier, names+// the base URL, and only offers the custom-provider route where it works.function noModelsNotice(platform: string): string | undefined {if (enabledModelCount(platform) > 0) return undefined;+ const baseUrl = openAICompatBaseUrl(platform);+ const customRoute = baseUrl+ ? `add ${platform} as a custom OpenAI-compatible provider with base URL ${baseUrl}`+ : null;+ const premium = getSyncState().appliedTier === 'live';+ if (premium) {+ return (+ `Key saved, but your Premium catalog does not list any ${platform} models yet. ` ++ `Try Check for updates on the Premium page to pull the latest catalog` ++ (customRoute ? `, or ${customRoute}.` : '.')+ );+ }return (`Key saved, but no ${platform} models are in your current catalog yet. ` +`Newer providers are published to the premium catalog first and appear ` +- `for free-tier installs once they age into the monthly catalog. Add a ` +- `Premium license key to use them now, or add ${platform} as a custom ` +- `OpenAI-compatible provider with its base URL.`+ `for free-tier installs once they age into the monthly catalog. ` ++ `Add a Premium license key to use them now` ++ (customRoute ? `, or ${customRoute}.` : '.'));}