MCPcopy Create free account
hub / github.com/explorerhq/sql-explorer / getAssistantHistory

Function getAssistantHistory

explorer/src/js/assistant.js:142–226  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140}
141
142function getAssistantHistory() {
143
144 const historyModalId = 'historyModal';
145
146 // Remove any existing modal with the same ID
147 const existingModal = document.getElementById(historyModalId);
148 if (existingModal) {
149 existingModal.remove()
150 }
151
152 const data = {
153 connection_id: document.getElementById("id_database_connection")?.value ?? null
154 };
155
156 fetch(`${window.baseUrlPath}assistant/history/`, {
157 method: 'POST',
158 headers: {
159 'Content-Type': 'application/json',
160 'X-CSRFToken': getCsrfToken()
161 },
162 body: JSON.stringify(data)
163 })
164 .then(response => {
165 if (!response.ok) {
166 throw new Error('Network response was not ok');
167 }
168 return response.json();
169 })
170 .then(data => {
171 // Create table rows from the fetched data
172 let tableRows = '';
173 data.logs.forEach(log => {
174 let md = DOMPurify.sanitize(marked.parse(log.response));
175 tableRows += `
176 <tr>
177 <td>${log.user_request}</td>
178 <td>${md}</td>
179 </tr>
180 `;
181 });
182
183 // Create the complete table HTML
184 const tableHtml = `
185 <table class="table table-striped">
186 <thead>
187 <tr>
188 <th>User Request</th>
189 <th>Response</th>
190 </tr>
191 </thead>
192 <tbody>
193 ${tableRows}
194 </tbody>
195 </table>
196 `;
197
198 // Insert the table into a new Bootstrap modal
199 const modalHtml = `

Callers

nothing calls this directly

Calls 1

getCsrfTokenFunction · 0.90

Tested by

no test coverage detected