MCPcopy Index your code
hub / github.com/continuedev/continue / processMessage

Function processMessage

extensions/cli/src/commands/chat.ts:342–434  ·  view source on GitHub ↗
(
  options: ProcessMessageOptions,
)

Source from the content-addressed store, hash-verified

340}
341
342async function processMessage(
343 options: ProcessMessageOptions,
344): Promise<{ compactionIndex?: number | null } | void> {
345 const {
346 userInput,
347 chatHistory,
348 model,
349 llmApi,
350 isHeadless,
351 format,
352 silent,
353 compactionIndex: initialCompactionIndex,
354 firstAssistantResponse = false,
355 } = options;
356 let compactionIndex = initialCompactionIndex;
357 // Check for slash commands in headless mode
358 if (userInput.trim() === "/compact") {
359 return handleManualCompaction(chatHistory, model, llmApi, isHeadless);
360 }
361
362 // Track user prompt
363 telemetryService.logUserPrompt(userInput.length, userInput);
364
365 // Check if auto-compacting is needed BEFORE adding user message
366 // The handleAutoCompaction function decides whether compaction is actually needed
367 const autoCompactionResult = await handleAutoCompaction(
368 chatHistory,
369 model,
370 llmApi,
371 isHeadless,
372 format,
373 );
374 if (autoCompactionResult !== null) {
375 compactionIndex = autoCompactionResult;
376 // Service already updated in handleAutoCompaction via setHistory
377 }
378
379 // Add user message to history AFTER potential compaction
380 services.chatHistory.addUserMessage(userInput);
381
382 // Get AI response with potential tool usage
383 if (!isHeadless) {
384 console.info(`\n${chalk.bold.blue("Assistant:")}`);
385 }
386
387 try {
388 // Get AI response with potential tool usage
389 const finalResponse = await getStreamingResponse(
390 compactionIndex,
391 model,
392 llmApi,
393 );
394
395 // Generate session title after first assistant response
396 if (firstAssistantResponse && finalResponse && finalResponse.trim()) {
397 await handleTitleGeneration(finalResponse, llmApi, model);
398 }
399

Callers 1

runHeadlessModeFunction · 0.70

Calls 13

handleManualCompactionFunction · 0.85
getStreamingResponseFunction · 0.85
handleTitleGenerationFunction · 0.85
processAndOutputResponseFunction · 0.85
updateSessionHistoryFunction · 0.85
formatAnthropicErrorFunction · 0.85
formatErrorFunction · 0.85
logUserPromptMethod · 0.80
addUserMessageMethod · 0.80
infoMethod · 0.80
errorMethod · 0.80
handleAutoCompactionFunction · 0.70

Tested by

no test coverage detected