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

Function parseOneshotCommandKey

src/browser/utils/slashCommands/parser.ts:132–166  ·  view source on GitHub ↗

* Parse a oneshot command key into model + thinking overrides. * * Supported forms: * - "haiku" → model override only (existing behavior) * - "opus+2" → model + numeric thinking level (0=off, 1=low, 2=medium, 3=high, 4=max) * - "haiku+medium" → model + named thinking level * - "+0

(
  key: string
)

Source from the content-addressed store, hash-verified

130 * Returns null if the key doesn't match any valid oneshot pattern.
131 */
132function parseOneshotCommandKey(
133 key: string
134): { modelString?: string; thinkingLevel?: ParsedThinkingInput } | null {
135 const plusIndex = key.indexOf("+");
136
137 if (plusIndex === -1) {
138 // No "+": plain model alias (e.g., "haiku")
139 if (!Object.hasOwn(MODEL_ABBREVIATIONS, key)) return null;
140 const normalized = normalizeModelInput(key);
141 return { modelString: normalized.model ?? MODEL_ABBREVIATIONS[key] };
142 }
143
144 // Has "+": parse model (optional) and thinking level
145 const modelPart = key.substring(0, plusIndex); // "" for "+0"
146 const thinkingPart = key.substring(plusIndex + 1); // "2", "medium", etc.
147
148 // Thinking part is required when "+" is present
149 if (!thinkingPart) return null;
150
151 const thinkingLevel = parseThinkingInput(thinkingPart);
152 if (thinkingLevel == null) return null;
153
154 // Thinking-only override (e.g., "+0", "+high")
155 if (!modelPart) {
156 return { thinkingLevel };
157 }
158
159 // Model + thinking override (e.g., "opus+2", "haiku+medium")
160 if (!Object.hasOwn(MODEL_ABBREVIATIONS, modelPart)) return null;
161 const normalized = normalizeModelInput(modelPart);
162 return {
163 modelString: normalized.model ?? MODEL_ABBREVIATIONS[modelPart],
164 thinkingLevel,
165 };
166}

Callers 1

parseCommandFunction · 0.85

Calls 2

normalizeModelInputFunction · 0.90
parseThinkingInputFunction · 0.90

Tested by

no test coverage detected