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

Function parseCursorModelsOutput

cli/src/modules/common/cursorModels.ts:138–175  ·  view source on GitHub ↗
(output: string)

Source from the content-addressed store, hash-verified

136let inflight: Promise<ListCursorModelsResponse> | null = null;
137
138export function parseCursorModelsOutput(output: string): {
139 availableModels: CursorModelSummary[];
140 currentModelId: string | null;
141} {
142 const availableModels: CursorModelSummary[] = [];
143 let currentModelId: string | null = null;
144
145 for (const rawLine of output.split(/\r?\n/)) {
146 const line = rawLine.trim();
147 if (!line || line === 'Available models' || line.startsWith('Tip:')) {
148 continue;
149 }
150
151 const separatorIndex = line.indexOf(' - ');
152 if (separatorIndex <= 0) {
153 continue;
154 }
155
156 const modelId = line.slice(0, separatorIndex).trim();
157 const rawName = line.slice(separatorIndex + 3).trim();
158 if (!modelId || !rawName) {
159 continue;
160 }
161
162 const isCurrent = /\s*\(current\)\s*$/.test(rawName);
163 const isDefault = /\s*\(default\)\s*$/.test(rawName);
164 const name = rawName.replace(/\s*\((?:current|default)\)\s*$/, '').trim();
165 availableModels.push(name && name !== modelId ? { modelId, name } : { modelId });
166
167 if (isCurrent) {
168 currentModelId = modelId;
169 } else if (isDefault && currentModelId === null) {
170 currentModelId = modelId;
171 }
172 }
173
174 return { availableModels, currentModelId };
175}
176
177async function runCursorModelProbe(): Promise<ListCursorModelsResponse> {
178 if (isAgentAcpTransportActive()) {

Callers 2

runCursorModelProbeFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected