(cwd?: string)
| 17 | * Zed-style wire catalog. Used for New Session when no on-disk ACP cache exists. |
| 18 | */ |
| 19 | export async function runCursorAcpModelProbe(cwd?: string): Promise<ListCursorModelsResponse> { |
| 20 | const resolvedCwd = cwd?.trim() || process.cwd(); |
| 21 | const backend = createCursorAcpBackend({ cwd: resolvedCwd }); |
| 22 | |
| 23 | try { |
| 24 | await backend.initialize(); |
| 25 | const sessionId = await backend.newSession({ |
| 26 | cwd: resolvedCwd, |
| 27 | mcpServers: [] |
| 28 | }); |
| 29 | const snapshot = buildCursorModelsSnapshotFromAcp(backend, sessionId); |
| 30 | if (!snapshot || snapshot.availableModels.length === 0) { |
| 31 | return { success: false, error: 'Cursor ACP session/new returned no models' }; |
| 32 | } |
| 33 | |
| 34 | const response: ListCursorModelsResponse = { |
| 35 | success: true, |
| 36 | availableModels: snapshot.availableModels, |
| 37 | currentModelId: snapshot.currentModelId |
| 38 | }; |
| 39 | if (!hasAcpWireCatalog(response)) { |
| 40 | return { success: false, error: 'Cursor ACP catalog has no wire model ids' }; |
| 41 | } |
| 42 | return response; |
| 43 | } catch (error) { |
| 44 | return { |
| 45 | success: false, |
| 46 | error: getErrorMessage(error, 'Failed to discover Cursor models via ACP') |
| 47 | }; |
| 48 | } finally { |
| 49 | await backend.disconnect().catch(() => undefined); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | export function cursorProbeResponseHasWireCatalog(response: ListCursorModelsResponse): boolean { |
| 54 | return response.success === true && hasAcpWireCatalog(response); |
no test coverage detected