User Message Utilities API
The User Message Utilities API provides a convenient, object-based interface for accessing all aspects of the current user message. It wraps the User Message Manager with a cleaner, more intuitive API.
Overview
The user message utilities enable you to:
- Access Message Data: Get message text, IDs, and metadata
- Extract Mentions: Retrieve mentioned files, folders, MCPs, and agents
- Get Context: Access current file, selection, and images
- Manage Configuration: View and update processing settings
- Session Management: Store and retrieve session-specific data
User Message Utilities vs User Message Manager
The User Message Utilities provide a cleaner, object-based API:
import { userMessageUtilities } from '@codebolt/codeboltjs';
// Utilities API (preferred)
const text = userMessageUtilities.getText();
const files = userMessageUtilities.getMentionedFiles();
The User Message Manager provides function-based exports:
import { getUserMessageText, getMentionedFiles } from '@codebolt/codeboltjs';
// Manager API
const text = getUserMessageText();
const files = getMentionedFiles();
Both APIs access the same underlying data. Choose the one you prefer.
Quick Start Example
import { userMessageUtilities } from '@codebolt/codeboltjs';
// Check if there's a message
if (userMessageUtilities.hasMessage()) {
// Get message text
const text = userMessageUtilities.getText();
console.log('User said:', text);
// Get mentions
const files = userMessageUtilities.getMentionedFiles();
const mcpTools = userMessageUtilities.getMentionedMCPs();
console.log('Files mentioned:', files);
console.log('MCP tools mentioned:', mcpTools);
// Get context
const currentFile = userMessageUtilities.getCurrentFile();
const selection = userMessageUtilities.getSelection();
if (currentFile) {
console.log('Working in file:', currentFile);
}
if (selection) {
console.log('Selected text:', selection);
}
// Store session data
userMessageUtilities.setSessionData('processingStart', Date.now());
// Check processing config
const shouldProcessFiles = userMessageUtilities.isProcessingEnabled('processMentionedFiles');
console.log('Process files?', shouldProcessFiles);
// Clear when done
userMessageUtilities.clear();
}
API Categories
1. Message Access
getCurrent()- Get complete message objectgetText()- Get message text contentgetMessageId()- Get message IDgetThreadId()- Get thread IDgetTimestamp()- Get message timestamphasMessage()- Check if message exists
2. Mentions
getMentionedFiles()- Get mentioned file pathsgetMentionedFolders()- Get mentioned folder pathsgetMentionedMCPs()- Get mentioned MCP toolsgetMentionedAgents()- Get mentioned agents
3. Context
getCurrentFile()- Get current file pathgetSelection()- Get selected textgetUploadedImages()- Get uploaded imagesgetRemixPrompt()- Get remix prompt
4. Configuration
getProcessingConfig()- Get processing configurationisProcessingEnabled()- Check if processing is enabledupdateProcessingConfig()- Update processing configuration
5. Session Data
setSessionData()- Store session datagetSessionData()- Retrieve session data
6. Cleanup
clear()- Clear message state
Best Practices
- Always Check First: Use
hasMessage()before accessing data - Use Object API: Prefer
userMessageUtilitiesfor cleaner code - Clean Up: Call
clear()when done processing - Session Data: Use session data for temporary state
- Type Safety: Check return values (may be undefined)
- getCurrent - Gets the current user message object.
- getText - Gets the text content of the current user message.
- getMentionedMCPs - Gets mentioned MCP tools from the current message.
- getMentionedFiles - Gets mentioned file paths from the current message.
- getMentionedFolders - Gets mentioned folder paths from the current message.
- getMentionedAgents - Gets mentioned agents from the current message.
- getRemixPrompt - Gets the remix prompt from the current message.
- getUploadedImages - Gets uploaded images from the current message.
- getCurrentFile - Gets the current file path from the message.
- getSelection - Gets the text selection from the message.
- getMessageId - Gets the message ID from the current message.
- getThreadId - Gets the thread ID from the current message.
- getProcessingConfig - Gets the processing configuration.
- isProcessingEnabled - Checks if a specific processing type is enabled.
- setSessionData - Sets session data for the current message.
- getSessionData - Gets session data for the current message.
- getTimestamp - Gets the timestamp when the message was received.
- hasMessage - Checks if there is a current message.
- updateProcessingConfig - Updates the processing configuration.
- clear - Clears the current user message.