Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

feat(providers): add lmStudio model catalog and fetch routing

Neeraj9bef76ddc69b
diff --git a/src/utils/provider-models.test.ts b/src/utils/provider-models.test.ts
index 74a464b5..3ad20f9f 100644
--- a/src/utils/provider-models.test.ts
+++ b/src/utils/provider-models.test.ts
@@ -116,4 +116,24 @@ describe('buildModelCatalog', () => {
expect(catalog.recommendedModel).toBe('model-a');
});
+
+ it('uses the first model as recommended for LM Studio when no preferred list exists', () => {
+ const catalog = buildModelCatalog(
+ 'lmStudio',
+ ['llama-3.2-3b-instruct', 'mistral-7b-instruct-v0.3'],
+ );
+
+ expect(catalog.recommendedModel).toBe('llama-3.2-3b-instruct');
+ expect(catalog.models).toContain('mistral-7b-instruct-v0.3');
+ });
+
+ it('falls back to the current model for LM Studio when no preferred list exists', () => {
+ const catalog = buildModelCatalog(
+ 'lmStudio',
+ ['qwen2.5-7b-instruct'],
+ 'qwen2.5-7b-instruct',
+ );
+
+ expect(catalog.recommendedModel).toBe('qwen2.5-7b-instruct');
+ });
});
diff --git a/src/utils/provider-models.ts b/src/utils/provider-models.ts
index 3a50d38f..3ac34bec 100644
--- a/src/utils/provider-models.ts
+++ b/src/utils/provider-models.ts
@@ -72,6 +72,7 @@ const MIMO_PREFERRED_MODELS = [
const MIMO_TOKEN_PLAN_PREFERRED_MODELS = MIMO_PREFERRED_MODELS;
const OPENAI_COMPAT_PREFERRED_MODELS = [] as const;
+const LM_STUDIO_PREFERRED_MODELS = [] as const;
const CHATGPT_WEB_PREFERRED_MODELS = [
'gpt-5.5',
@@ -199,6 +200,7 @@ function chooseRecommendedModel(
mimo: MIMO_PREFERRED_MODELS,
mimoTokenPlan: MIMO_TOKEN_PLAN_PREFERRED_MODELS,
chatgptWeb: CHATGPT_WEB_PREFERRED_MODELS,
+ lmStudio: LM_STUDIO_PREFERRED_MODELS,
githubCopilot: GITHUB_COPILOT_PREFERRED_MODELS,
};
@@ -238,6 +240,7 @@ export function buildModelCatalog(
mimoTokenPlan: MIMO_TOKEN_PLAN_PREFERRED_MODELS,
chatgptWeb: CHATGPT_WEB_PREFERRED_MODELS,
githubCopilot: GITHUB_COPILOT_PREFERRED_MODELS,
+ lmStudio: LM_STUDIO_PREFERRED_MODELS,
};
const withoutRecommended = filtered.filter((model) => model !== recommendedModel);
@@ -343,6 +346,20 @@ async function fetchOllamaCloudModels(config: ProviderConfig): Promise<ProviderM
return buildModelCatalog('ollamaCloud', ids, config.model);
}
+async function fetchLmStudioModels(config: ProviderConfig): Promise<ProviderModelCatalog> {
+ const data = await fetchJson<OpenAIModelResponse>(
+ `${trimTrailingSlash(config.baseUrl)}/models`,
+ {},
+ 'Mercury could not fetch models from LM Studio. Make sure LM Studio is running and the Developer API is enabled.',
+ );
+
+ const ids = (data.data ?? [])
+ .map((model) => model.id?.trim() ?? '')
+ .filter(Boolean);
+
+ return buildModelCatalog('lmStudio', ids, config.model);
+}
+
async function fetchOllamaLocalModels(config: ProviderConfig): Promise<ProviderModelCatalog> {
const data = await fetchJson<OllamaTagsResponse>(
`${trimTrailingSlash(config.baseUrl)}/tags`,
@@ -423,6 +440,10 @@ export async function fetchProviderModelCatalog(
return fetchOpenAICompatModels(provider, config);
}
+ if (provider === 'lmStudio') {
+ return fetchLmStudioModels(config);
+ }
+
if (provider === 'mimo') {
return fetchMiMoModels(config);
}