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

Function openChunkVisualizer

chunk-visualizer.js:129–194  ·  view source on GitHub ↗
(collectionId)

Source from the content-addressed store, hash-verified

127// =============================================================================
128
129export function openChunkVisualizer(collectionId) {
130 if (!fullsheetAPI) {
131 toastr.error('Chunk Visualizer not properly initialized');
132 return;
133 }
134
135 const library = fullsheetAPI.getContextualLibrary();
136 const chunks = library[collectionId];
137
138 if (!chunks) {
139 toastr.warning('No chunks found for this collection.');
140 return;
141 }
142
143 const characterName = getCharacterNameFromCollectionId(collectionId);
144 const contextLevel = fullsheetAPI.getCurrentContextLevel ? fullsheetAPI.getCurrentContextLevel() : 'global';
145
146 currentEditingCollection = collectionId;
147 modifiedChunks = JSON.parse(JSON.stringify(chunks));
148 hasUnsavedChanges = false;
149
150 CarrotDebug.ui('🔍 Loading chunks for editing:', Object.keys(modifiedChunks).length, 'chunks');
151
152 Object.entries(modifiedChunks).forEach(([hash, chunk]) => {
153 if (chunk.customWeights && Object.keys(chunk.customWeights).length > 0) {
154 CarrotDebug.ui(`📊 Chunk ${hash} has custom weights:`, chunk.customWeights);
155 }
156 initializeChunkKeywordMetadata(chunk);
157 chunk._editing = false;
158 });
159
160 // Update modal title
161 $('#carrot-rag-modal-title').html(
162 `<i class="fa-solid fa-cube"></i> ${escapeHtml(characterName)} <span style="font-size: 0.7em; color: #8b5cf6; text-transform: uppercase;">[${contextLevel}]</span>`
163 );
164 $('#carrot-rag-modal-subtitle').text(`${Object.keys(chunks).length} chunks`);
165
166 // Initialize format toggle button state
167 const ragState = extension_settings[extensionName].rag;
168 const $formatBtn = $('#carrot-rag-format-toggle');
169 const $formatLabel = $formatBtn.find('.chunk-format-label');
170 chunkFormattingEnabled = ragState.chunkFormattingEnabled || false;
171 $formatLabel.text(chunkFormattingEnabled ? 'Formatted' : 'Plain');
172
173 // Initialize case-sensitivity toggle button state
174 const $caseBtn = $('#carrot-rag-case-toggle');
175 const $caseLabel = $caseBtn.find('.chunk-case-label');
176 if (ragState.caseSensitiveKeywords) {
177 $caseLabel.text('Case: Match');
178 $caseBtn.attr('title', 'Keyword matching is case-sensitive (click to ignore case)');
179 } else {
180 $caseLabel.text('Case: Ignore');
181 $caseBtn.attr('title', 'Keyword matching ignores case (click for case-sensitive)');
182 }
183
184 renderChunks(modifiedChunks);
185 bindChunkVisualizerEvents();
186

Callers

nothing calls this directly

Calls 7

escapeHtmlFunction · 0.90
renderChunksFunction · 0.85
errorMethod · 0.80
uiMethod · 0.80

Tested by

no test coverage detected