MCPcopy Create free account
hub / github.com/tiann/hapi / listCursorModels

Function listCursorModels

cli/src/modules/common/cursorModels.ts:261–319  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

259}
260
261export async function listCursorModels(): Promise<ListCursorModelsResponse> {
262 if (isAgentAcpTransportActive()) {
263 return listCursorModelsWhileAcpActive();
264 }
265
266 const acp = getCursorAcpModelsSnapshot();
267 if (acp && acp.availableModels.length > 0) {
268 return applyInMemoryCache({ success: true, ...acp });
269 }
270
271 if (cache.expiresAt > Date.now() && (cache.response.availableModels?.length ?? 0) > 0) {
272 return enrichCursorModelsWithCliSkus(cache.response);
273 }
274
275 const shared = readSharedCursorModelsCache();
276 if (shared) {
277 return applyInMemoryCache(shared);
278 }
279
280 if (inflight) {
281 return inflight;
282 }
283
284 inflight = (async () => {
285 try {
286 const acpResponse = await runCursorAcpModelProbe();
287 if (cursorProbeResponseHasWireCatalog(acpResponse)) {
288 return applyInMemoryCache(acpResponse);
289 }
290
291 let probeResponse: ListCursorModelsResponse | null = null;
292 if (!isAgentAcpTransportActive()) {
293 probeResponse = await runCursorModelProbe();
294 if (cursorProbeResponseHasWireCatalog(probeResponse)) {
295 return applyInMemoryCache(probeResponse);
296 }
297 }
298
299 // CLI `--list-models` returns slug ids without bracket params; never cache
300 // those for the web picker (New Session would show only Default + current slug).
301 if (acpResponse.success) {
302 return acpResponse;
303 }
304 if (probeResponse?.success) {
305 return { success: true, availableModels: [], currentModelId: null };
306 }
307 return probeResponse ?? acpResponse;
308 } catch (error) {
309 return {
310 success: false,
311 error: getErrorMessage(error, 'Failed to discover Cursor models')
312 };
313 } finally {
314 inflight = null;
315 }
316 })();
317
318 return inflight;

Calls 10

runCursorAcpModelProbeFunction · 0.90
getErrorMessageFunction · 0.90
applyInMemoryCacheFunction · 0.85
runCursorModelProbeFunction · 0.85

Tested by

no test coverage detected