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

Function processSlashCommand

src/browser/utils/chatCommands.ts:267–911  ·  view source on GitHub ↗
(
  parsed: ParsedCommand,
  context: SlashCommandContext
)

Source from the content-addressed store, hash-verified

265 * Returns false if it's not a command (should be sent as message) - though parsed usually implies it is a command
266 */
267export async function processSlashCommand(
268 parsed: ParsedCommand,
269 context: SlashCommandContext
270): Promise<CommandHandlerResult> {
271 if (!parsed) return { clearInput: false, toastShown: false };
272 const { api: client, setInput, setToast, variant, setVimEnabled, setPreferredModel } = context;
273
274 const requireClient = (): RouterClient<AppRouter> | null => {
275 if (client) return client;
276 setToast({
277 id: Date.now().toString(),
278 type: "error",
279 message: "Not connected to server",
280 });
281 return null;
282 };
283
284 // 1. Global Commands
285 if (parsed.type === "model-set") {
286 const modelString = parsed.modelString;
287
288 const activeClient = client;
289 const normalized = normalizeModelInput(modelString);
290
291 if (!normalized.model) {
292 setToast({
293 id: Date.now().toString(),
294 type: "error",
295 message: `Invalid model format: expected "provider:model"`,
296 });
297 return { clearInput: false, toastShown: true };
298 }
299
300 const selectedModel = normalized.model;
301 const separatorIndex = selectedModel.indexOf(":");
302 const provider = selectedModel.slice(0, separatorIndex);
303 const modelId = selectedModel.slice(separatorIndex + 1);
304 const canonicalModel = normalizeToCanonical(selectedModel);
305 const explicitGateway = getExplicitGatewayPrefix(selectedModel);
306
307 try {
308 let providersConfig: ProvidersConfigMap | null = null;
309 let providersConfigLoadFailed = false;
310 if (activeClient) {
311 try {
312 providersConfig = await activeClient.providers.getConfig();
313 } catch (error) {
314 providersConfigLoadFailed = true;
315 console.error("Failed to load provider settings:", error);
316 }
317 }
318
319 const providerConfig = providersConfig?.[provider];
320 if (!isValidProvider(provider) && !isCustomOpenAICompatibleProviderConfig(providerConfig)) {
321 setToast({
322 id: Date.now().toString(),
323 type: "error",
324 message: providersConfigLoadFailed

Callers 3

useCreationWorkspaceFunction · 0.90
executeParsedCommandFunction · 0.90

Calls 15

normalizeModelInputFunction · 0.90
normalizeToCanonicalFunction · 0.90
getExplicitGatewayPrefixFunction · 0.90
isValidProviderFunction · 0.90
modelHasPricingDataFunction · 0.90
getProviderModelEntryIdFunction · 0.90
trackCommandUsedFunction · 0.90
isExperimentEnabledFunction · 0.90
createCustomEventFunction · 0.90
createCommandToastFunction · 0.90

Tested by

no test coverage detected