MCPcopy
hub / github.com/coder/mux / enforceThinkingPolicy

Function enforceThinkingPolicy

src/common/utils/thinking/policy.ts:241–276  ·  view source on GitHub ↗
(
  modelString: string,
  requested: ThinkingLevel,
  minimum?: ThinkingLevel | null
)

Source from the content-addressed store, hash-verified

239 * preserves the legacy capability-only behavior.
240 */
241export function enforceThinkingPolicy(
242 modelString: string,
243 requested: ThinkingLevel,
244 minimum?: ThinkingLevel | null
245): ThinkingLevel {
246 const allowed = getAvailableThinkingLevels(modelString, minimum);
247
248 if (allowed.includes(requested)) {
249 return requested;
250 }
251
252 const orderedAllowed = [...allowed].sort(
253 (left, right) => THINKING_LEVELS.indexOf(left) - THINKING_LEVELS.indexOf(right)
254 );
255 const minAllowed = orderedAllowed[0] ?? "off";
256 const maxAllowed = orderedAllowed[orderedAllowed.length - 1] ?? minAllowed;
257 const requestedIndex = THINKING_LEVELS.indexOf(requested);
258
259 if (requestedIndex <= THINKING_LEVELS.indexOf(minAllowed)) {
260 return minAllowed;
261 }
262
263 if (requestedIndex >= THINKING_LEVELS.indexOf(maxAllowed)) {
264 return maxAllowed;
265 }
266
267 const closest = orderedAllowed.reduce((nearest, level) => {
268 const nearestIndex = THINKING_LEVELS.indexOf(nearest);
269 const levelIndex = THINKING_LEVELS.indexOf(level);
270 return Math.abs(levelIndex - requestedIndex) < Math.abs(nearestIndex - requestedIndex)
271 ? level
272 : nearest;
273 }, minAllowed);
274
275 return closest;
276}
277/**
278 * Resolve a parsed thinking input to a concrete ThinkingLevel for a given model.
279 *

Callers 15

ThinkingSliderComponentFunction · 0.90
buildCoreSourcesFunction · 0.90
applyCompactionOverridesFunction · 0.90
updateAgentDefaultEntryFunction · 0.90
normalizeAdvisorDraftFunction · 0.90
handleKeyDownFunction · 0.90
mainFunction · 0.90

Calls 2

absMethod · 0.80

Tested by

no test coverage detected