Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: normalize object entries under the models key too, not just data (#3634)
[._.]/ Adam Eivybae1b8d3660c
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.jsindex e68fafa371..2363d5bfca 100644--- a/server/lib/aiToolkit/providers.js+++ b/server/lib/aiToolkit/providers.js@@ -855,22 +855,22 @@ export function createProviderService(config = {}) {throw new Error('Model list response was not valid JSON');}- if (Array.isArray(responseData.data)) {- // Entries are usually `{ id }`, but some OpenAI-compatible servers emit- // bare id strings (or key the name). `m.id` alone turned those into a- // list of `undefined` — a persisted, plausible-looking, entirely unusable- // catalog. Anything that still resolves to nothing means the shape isn't- // one we understand, so throw rather than save it.- const ids = responseData.data.map(m => (typeof m === 'string' ? m : (m?.id || m?.name)));+ // Entries are usually `{ id }` under `data` and bare strings under+ // `models`, but servers mix all four shapes. Returning them unmapped (or+ // mapping `m.id` blindly) persisted raw objects / a list of `undefined` —+ // a plausible-looking, entirely unusable catalog. Anything that still+ // resolves to nothing means the shape isn't one we understand, so throw+ // rather than save it, same posture as the unparseable-body case above.+ const toModelIds = (entries, key) => {+ const ids = entries.map(m => (typeof m === 'string' ? m : (m?.id || m?.name || m?.model)));if (ids.some(id => typeof id !== 'string' || !id)) {- throw new Error('Model list response had "data" entries with no usable model id');+ throw new Error(`Model list response had "${key}" entries with no usable model id`);}return ids;- }+ };- if (Array.isArray(responseData.models)) {- return responseData.models;- }+ if (Array.isArray(responseData.data)) return toModelIds(responseData.data, 'data');+ if (Array.isArray(responseData.models)) return toModelIds(responseData.models, 'models');throw new Error('Model list response had no recognizable "data" or "models" array');},diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.jsindex c3ab13f12f..47506279f4 100644--- a/server/lib/aiToolkit/providers.test.js+++ b/server/lib/aiToolkit/providers.test.js@@ -1216,6 +1216,30 @@ describe('Provider Service', () => {expect((await providerService.getProviderById(bad.id)).models).toEqual(['model-a']);});+ it('normalizes object entries under "models" the same way as "data"', async () => {+ // A non-Ollama gateway keying `models` with objects used to persist the raw+ // objects as if they were model ids.+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({+ ok: true,+ json: async () => ({ models: [{ id: 'model-a' }, 'model-b', { model: 'model-c' }] }),+ }));+ const ok = await providerService.createProvider({+ name: 'Models Key API', type: 'api', endpoint: 'https://api.generic.com/v1', allowCustomEndpoint: true,+ });+ expect((await providerService.refreshProviderModels(ok.id)).models).toEqual(['model-a', 'model-b', 'model-c']);++ vi.stubGlobal('fetch', vi.fn().mockResolvedValue({+ ok: true,+ json: async () => ({ models: [null] }),+ }));+ const bad = await providerService.createProvider({+ name: 'Null Models API', type: 'api', endpoint: 'https://api.generic.com/v1', models: ['model-a'], allowCustomEndpoint: true,+ });+ const err = await providerService.refreshProviderModels(bad.id).catch(e => e);+ expect(err.message).toMatch(/"models" entries with no usable model id/);+ expect((await providerService.getProviderById(bad.id)).models).toEqual(['model-a']);+ });+it('throws and leaves the stored list untouched when a 200 body is not JSON', async () => {// A captive portal / login page / proxy error served as HTTP 200. Degrading// to `[]` here emptied the model dropdown while the UI toasted "Models