0 Votes

Changes for page LLMChatRenderer

Last modified by Ryan C on 2025/08/04 03:46

From version 12.1
edited by Ryan C
on 2025/08/04 03:30
Change comment: There is no comment for this version
To version 13.1
edited by Ryan C
on 2025/08/04 03:46
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,20 +5,14 @@
1 -{{velocity}}
2 -#if ($xcontext.action != 'jsx')
3 -$xwiki.parseContent("
4 -#macro(htmlMacro)
5 5  {{html}}
6 6  <script>
7 -console.log('Renderer script is running');
3 +console.log("Script running without Velocity");
8 8  
9 9  document.addEventListener('DOMContentLoaded', function () {
10 10   function processAssistantMessages() {
11 11   const messages = document.querySelectorAll('.assistantMessage');
12 -
13 13   messages.forEach(msg => {
14 14   const html = msg.innerHTML;
15 -
16 16   const chunkMap = {};
17 - const chunkRegex = /\\[(\\d+)\\]\\s*\\((https:\\/\\/[^)]+)\\)/g;
11 + const chunkRegex = /\[(\d+)\]\s*\((https:\/\/[^)]+)\)/g;
18 18   let match;
19 19   while ((match = chunkRegex.exec(html)) !== null) {
20 20   const index = match[1];
... ... @@ -24,19 +24,16 @@
24 24   }
25 25  
26 26   let currentIndex = null;
27 - const processed = html.replace(/(\\[\\d+\\])\\s*\\((https:\\/\\/[^)]+)\\)/g, (full, idx) => {
28 - currentIndex = idx.replace(/\\D/g, '');
21 + const processed = html.replace(/(\[\d+\])\s*\((https:\/\/[^)]+)\)/g, (full, idx) => {
22 + currentIndex = idx.replace(/\D/g, '');
29 29   return full;
30 - }).replace(/\\[\\[(image|doc_)?([^\\]]+?)\\]\\]/g, function (_, type, filename) {
24 + }).replace(/\[\[(image|doc_)?([^\]]+?)\]\]/g, function (_, type, filename) {
31 31   if (!currentIndex || !chunkMap[currentIndex]) return '';
32 32   const path = chunkMap[currentIndex];
33 33   const downloadURL = `/bin/download/${path}/${filename}`;
34 -
35 - if (type === 'image') {
36 - return `<img src='\${downloadURL}' style='max-width:300px; display:block; margin:1em 0;' />`;
37 - } else {
38 - return `<a href='\${downloadURL}' target='_blank'>📄 Download \${filename}</a>`;
39 - }
28 + return type === 'image'
29 + ? `<img src="${downloadURL}" style="max-width:300px; display:block; margin:1em 0;" />`
30 + : `<a href="${downloadURL}" target="_blank">📄 Download ${filename}</a>`;
40 40   });
41 41  
42 42   msg.innerHTML = processed;
... ... @@ -44,9 +44,8 @@
44 44   }
45 45  
46 46   function extractDownloadPath(viewURL) {
47 - const match = viewURL.match(/\\/bin\\/view\\/([^?#]+)/);
48 - if (!match) return null;
49 - return decodeURIComponent(match[1]);
38 + const match = viewURL.match(/\/bin\/view\/([^?#]+)/);
39 + return match ? decodeURIComponent(match[1]) : null;
50 50   }
51 51  
52 52   const observer = new MutationObserver(processAssistantMessages);
... ... @@ -54,9 +54,4 @@
54 54  });
55 55  </script>
56 56  {{/html}}
57 -#end
58 -#htmlMacro()
59 -")
60 -#end
61 -{{/velocity}}
62 62  

XWiki AI Chat