()
| 106 | * 1234 is LM Studio default; 8080 is llama.cpp default; 11435 is a common Ollama-clone port. |
| 107 | */ |
| 108 | export async function detectLMStudioModels(): Promise<DetectedModel[]> { |
| 109 | const ports = [1234, 8080]; |
| 110 | const all: DetectedModel[] = []; |
| 111 | const seen = new Set<string>(); |
| 112 | // Pull real context windows from LM Studio's native API up-front (one probe). |
| 113 | const ctxMap = await detectLmStudioContextWindows(ports); |
| 114 | for (const port of ports) { |
| 115 | const r = await fetchWithTimeout(`http://127.0.0.1:${port}/v1/models`); |
| 116 | if (!r || !r.ok) continue; |
| 117 | try { |
| 118 | const body = await r.json() as { data?: Array<{ id: string; meta?: any }> }; |
| 119 | if (!Array.isArray(body.data)) continue; |
| 120 | for (const m of body.data) { |
| 121 | if (seen.has(m.id)) continue; |
| 122 | seen.add(m.id); |
| 123 | // Skip embedding-only models — they can't drive a chat agent. |
| 124 | if (/embed/i.test(m.id)) continue; |
| 125 | const paramsB = parseParamsFromId(m.id) ?? (m.meta?.n_params ? m.meta.n_params / 1e9 : undefined); |
| 126 | const sizeGb = m.meta?.size ? m.meta.size / (1024 ** 3) : undefined; |
| 127 | all.push({ |
| 128 | provider: 'openai', |
| 129 | id: m.id, |
| 130 | label: m.id, |
| 131 | source: 'lm-studio', |
| 132 | sizeGb: sizeGb ? Math.round(sizeGb * 10) / 10 : undefined, |
| 133 | paramsB: paramsB ? Math.round(paramsB) : undefined, |
| 134 | // LM Studio surfaces an OpenAI-compatible API; whether the model honours |
| 135 | // structured tool_calls depends on the model itself. Same heuristic. |
| 136 | toolCallsLikely: looksLikeToolCallCapable(m.id), |
| 137 | // Real window from the native API, else a RAM-safe family heuristic. |
| 138 | contextWindow: ctxMap[m.id] ?? guessContextWindow(m.id), |
| 139 | visionLikely: looksVisionCapable(m.id), |
| 140 | }); |
| 141 | } |
| 142 | } catch (e: any) { |
| 143 | logger.debug(`LM Studio response parse failed on port ${port}`, { err: e?.message }); |
| 144 | } |
| 145 | } |
| 146 | return all; |
| 147 | } |
| 148 | |
| 149 | /** Run all detectors in parallel; combine + sort results. */ |
| 150 | export async function detectAllLocalModels(): Promise<DetectedModel[]> { |
no test coverage detected