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

Function applyCursorAcpModel

cli/src/cursor/utils/cursorModeConfig.ts:108–153  ·  view source on GitHub ↗
(
    backend: AcpSdkBackend,
    sessionId: string,
    modelId: string | null | undefined
)

Source from the content-addressed store, hash-verified

106 * Only wire ids present in `availableModels` are accepted.
107 */
108export async function applyCursorAcpModel(
109 backend: AcpSdkBackend,
110 sessionId: string,
111 modelId: string | null | undefined
112): Promise<ApplyCursorAcpModelResult> {
113 const trimmed = modelId?.trim();
114 if (!trimmed || isDefaultCursorModelId(trimmed)) {
115 return { applied: false };
116 }
117
118 const metadata = backend.getSessionModelsMetadata(sessionId);
119 const available = metadata?.availableModels ?? [];
120 const modelOption = backend.getConfigOptionByCategory?.(sessionId, 'model');
121 const optionWireIds = modelOption?.options?.map((option) => ({ modelId: option.value })) ?? [];
122 const catalog = [...available, ...optionWireIds];
123 const resolved = resolveCursorAcpWireId(trimmed, catalog);
124 if (!resolved) {
125 logger.debug(`[cursor-acp] Model ${trimmed} is not in ACP configOptions; skipping`);
126 return { applied: false };
127 }
128
129 const trySetConfigOption = async (): Promise<boolean> => {
130 if (!modelOption || !backend.setConfigOption) {
131 return false;
132 }
133 try {
134 await backend.setConfigOption(sessionId, modelOption.id, resolved);
135 return true;
136 } catch (error) {
137 logger.debug('[cursor-acp] session/set_config_option failed, trying set_model', error);
138 return false;
139 }
140 };
141
142 for (let attempt = 0; attempt < 2; attempt += 1) {
143 if (await trySetConfigOption()) {
144 backend.pinSessionModelWireId(sessionId, resolved);
145 return { applied: true, resolvedWireId: resolved, requestedWireId: trimmed };
146 }
147 if (attempt === 0) {
148 await new Promise((resolve) => setTimeout(resolve, 150));
149 }
150 }
151
152 return { applied: false };
153}

Callers 2

applyLiveModelMethod · 0.90

Calls 7

resolveCursorAcpWireIdFunction · 0.85
trySetConfigOptionFunction · 0.85
debugMethod · 0.80
pinSessionModelWireIdMethod · 0.80
isDefaultCursorModelIdFunction · 0.70

Tested by

no test coverage detected