0 Votes

Changes for page LLMChatRenderer

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

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

Summary

Details

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