MCPcopy Create free account
hub / github.com/Coneja-Chibi/CarrotKernel / addRAGButtonToMessage

Function addRAGButtonToMessage

fullsheet-rag.js:3629–3704  ·  view source on GitHub ↗

* Add RAG button to a message containing a fullsheet * * @param {number} messageId - Message ID

(messageId)

Source from the content-addressed store, hash-verified

3627 // Universal name extraction: Find the first tag in the document (usually the name tag)
3628 // Works for ANY language: <NAME:John>, <名前:太郎>, <NOMBRE:Juan>, <ИМЯ:Иван>, etc.
3629 // [^\s>]+ matches any non-whitespace characters (all Unicode scripts)
3630 const firstTagMatch = messageText.match(/<[^\s>]+:\s*([^>]+)>/);
3631 CarrotDebug.ui(` First tag match:`, firstTagMatch);
3632
3633 const characterName = firstTagMatch ? firstTagMatch[1].trim().replace(/_/g, ' ') : 'Unknown';
3634 CarrotDebug.ui(` Extracted name suggestion: "${characterName}" (user can override this)`);
3635
3636 const result = {
3637 characterName,
3638 content: messageText,
3639 sectionCount: sectionMatches?.length || 0
3640 };
3641
3642 CarrotDebug.ui('✅ [detectFullsheetInMessage] Fullsheet detected!', result);
3643 debugLog('Fullsheet detected in message', result);
3644
3645 return result;
3646}
3647
3648/**
3649 * Add RAG button to a message containing a fullsheet
3650 *
3651 * @param {number} messageId - Message ID
3652 */
3653function addRAGButtonToMessage(messageId) {
3654 const settings = getRAGSettings();
3655 if (!settings.enabled) {
3656 return;
3657 }
3658
3659 // Find the message element
3660 const messageElement = $(`.mes[mesid="${messageId}"]`);
3661 if (messageElement.length === 0) {
3662 // Message not in DOM (scrolled away, etc.) - silently skip
3663 return;
3664 }
3665
3666 // Check if button already exists
3667 if (messageElement.find(`.${RAG_BUTTON_CLASS}`).length > 0) {
3668 return;
3669 }
3670
3671 // Get message data
3672 const message = chat[messageId];
3673 if (!message || !message.mes) {
3674 return;
3675 }
3676
3677 // Detect fullsheet
3678 const fullsheetInfo = detectFullsheetInMessage(message.mes);
3679 if (!fullsheetInfo) {
3680 return;
3681 }
3682
3683 debugLog(`Adding RAG button to message ${messageId}`, fullsheetInfo);
3684
3685 // Create the button
3686 const button = $('<div>')

Callers 2

initializeRAGFunction · 0.85

Calls 4

getRAGSettingsFunction · 0.85
debugLogFunction · 0.85
handleRAGButtonClickFunction · 0.85
detectFullsheetInMessageFunction · 0.70

Tested by

no test coverage detected