datamule 1.0.3__py3-none-any.whl → 1.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datamule/__init__.py +2 -13
- datamule/document.py +8 -9
- datamule/helper.py +85 -105
- datamule/portfolio.py +105 -29
- datamule/submission.py +0 -38
- {datamule-1.0.3.dist-info → datamule-1.0.7.dist-info}/METADATA +2 -8
- datamule-1.0.7.dist-info/RECORD +10 -0
- datamule/book/__init__.py +0 -0
- datamule/book/book.py +0 -34
- datamule/book/eftsquery.py +0 -127
- datamule/book/xbrl_retriever.py +0 -88
- datamule/data/company_former_names.csv +0 -8148
- datamule/data/company_metadata.csv +0 -10049
- datamule/data/company_tickers.csv +0 -9999
- datamule/data/sec-glossary.csv +0 -728
- datamule/data/xbrl_descriptions.csv +0 -10024
- datamule/downloader/downloader.py +0 -374
- datamule/downloader/premiumdownloader.py +0 -335
- datamule/mapping_dicts/txt_mapping_dicts.py +0 -234
- datamule/mapping_dicts/xml_mapping_dicts.py +0 -19
- datamule/monitor.py +0 -283
- datamule/mulebot/__init__.py +0 -1
- datamule/mulebot/helper.py +0 -35
- datamule/mulebot/mulebot.py +0 -130
- datamule/mulebot/mulebot_server/__init__.py +0 -1
- datamule/mulebot/mulebot_server/server.py +0 -87
- datamule/mulebot/mulebot_server/static/css/minimalist.css +0 -174
- datamule/mulebot/mulebot_server/static/scripts/artifacts.js +0 -68
- datamule/mulebot/mulebot_server/static/scripts/chat.js +0 -92
- datamule/mulebot/mulebot_server/static/scripts/filingArtifacts.js +0 -56
- datamule/mulebot/mulebot_server/static/scripts/listArtifacts.js +0 -15
- datamule/mulebot/mulebot_server/static/scripts/main.js +0 -57
- datamule/mulebot/mulebot_server/static/scripts/prefilledPrompt.js +0 -27
- datamule/mulebot/mulebot_server/static/scripts/suggestions.js +0 -47
- datamule/mulebot/mulebot_server/static/scripts/tableArtifacts.js +0 -129
- datamule/mulebot/mulebot_server/static/scripts/utils.js +0 -28
- datamule/mulebot/mulebot_server/templates/chat-minimalist.html +0 -91
- datamule/mulebot/search.py +0 -52
- datamule/mulebot/tools.py +0 -82
- datamule/packageupdater.py +0 -207
- datamule-1.0.3.dist-info/RECORD +0 -43
- {datamule-1.0.3.dist-info → datamule-1.0.7.dist-info}/WHEEL +0 -0
- {datamule-1.0.3.dist-info → datamule-1.0.7.dist-info}/top_level.txt +0 -0
@@ -1,174 +0,0 @@
|
|
1
|
-
/* Global Styles */
|
2
|
-
body {
|
3
|
-
background-color: #f8f9fa;
|
4
|
-
color: #343a40;
|
5
|
-
}
|
6
|
-
|
7
|
-
/* Cards */
|
8
|
-
.card {
|
9
|
-
border: none;
|
10
|
-
box-shadow: 0 4px 6px rgba(0, 0, 0, .1);
|
11
|
-
}
|
12
|
-
|
13
|
-
/* Buttons */
|
14
|
-
.btn-primary {
|
15
|
-
background-color: #6c757d;
|
16
|
-
border-color: #6c757d;
|
17
|
-
}
|
18
|
-
|
19
|
-
.btn-primary:hover {
|
20
|
-
background-color: #5a6268;
|
21
|
-
border-color: #545b62;
|
22
|
-
}
|
23
|
-
|
24
|
-
.btn-primary:disabled {
|
25
|
-
background-color: #6c757d;
|
26
|
-
border-color: #6c757d;
|
27
|
-
opacity: 0.65;
|
28
|
-
}
|
29
|
-
|
30
|
-
/* Social Buttons */
|
31
|
-
.social-btn {
|
32
|
-
display: inline-flex;
|
33
|
-
align-items: center;
|
34
|
-
justify-content: center;
|
35
|
-
width: auto;
|
36
|
-
height: 36px;
|
37
|
-
border-radius: 6px;
|
38
|
-
margin: 0 5px;
|
39
|
-
padding: 0 12px;
|
40
|
-
background-color: #f8f9fa;
|
41
|
-
border: 1px solid #6c757d;
|
42
|
-
color: #6c757d;
|
43
|
-
font-size: 14px;
|
44
|
-
text-decoration: none;
|
45
|
-
transition: all 0.3s ease;
|
46
|
-
}
|
47
|
-
|
48
|
-
.social-btn:hover {
|
49
|
-
background-color: #6c757d;
|
50
|
-
color: #ffffff;
|
51
|
-
transform: translateY(-2px);
|
52
|
-
}
|
53
|
-
|
54
|
-
.social-btn:hover svg {
|
55
|
-
fill: #ffffff;
|
56
|
-
}
|
57
|
-
|
58
|
-
.social-btn svg {
|
59
|
-
width: 18px;
|
60
|
-
height: 18px;
|
61
|
-
fill: #6c757d;
|
62
|
-
margin-right: 6px;
|
63
|
-
transition: fill 0.3s ease;
|
64
|
-
}
|
65
|
-
|
66
|
-
/* Chat container */
|
67
|
-
#chat-outer-container {
|
68
|
-
position: relative;
|
69
|
-
height: 400px;
|
70
|
-
overflow: hidden;
|
71
|
-
}
|
72
|
-
|
73
|
-
#chat-container {
|
74
|
-
height: 100%;
|
75
|
-
overflow-y: auto;
|
76
|
-
padding-bottom: 40px;
|
77
|
-
/* Make room for the thinking indicator */
|
78
|
-
}
|
79
|
-
|
80
|
-
/* Artifact container */
|
81
|
-
#artifact-container {
|
82
|
-
max-height: 400px;
|
83
|
-
overflow-y: auto;
|
84
|
-
}
|
85
|
-
|
86
|
-
/* Suggestion Box */
|
87
|
-
.suggestion-box {
|
88
|
-
background-color: #f8f9fa;
|
89
|
-
border-radius: 10px;
|
90
|
-
padding: 15px;
|
91
|
-
margin-top: 20px;
|
92
|
-
}
|
93
|
-
|
94
|
-
.suggestion-item {
|
95
|
-
background-color: white;
|
96
|
-
border-radius: 8px;
|
97
|
-
padding: 8px 12px;
|
98
|
-
margin-bottom: 10px;
|
99
|
-
cursor: pointer;
|
100
|
-
transition: background-color 0.3s;
|
101
|
-
}
|
102
|
-
|
103
|
-
.suggestion-item:hover {
|
104
|
-
background-color: #f0f0f0;
|
105
|
-
}
|
106
|
-
|
107
|
-
/* Autocomplete */
|
108
|
-
.select-wrapper {
|
109
|
-
position: relative;
|
110
|
-
}
|
111
|
-
|
112
|
-
.autocomplete-items {
|
113
|
-
position: absolute;
|
114
|
-
border: 1px solid #d4d4d4;
|
115
|
-
border-top: none;
|
116
|
-
z-index: 99;
|
117
|
-
top: 100%;
|
118
|
-
left: 0;
|
119
|
-
right: 0;
|
120
|
-
max-height: 200px;
|
121
|
-
overflow-y: auto;
|
122
|
-
background-color: #fff;
|
123
|
-
}
|
124
|
-
|
125
|
-
.autocomplete-items div {
|
126
|
-
padding: 10px;
|
127
|
-
cursor: pointer;
|
128
|
-
background-color: #fff;
|
129
|
-
border-bottom: 1px solid #d4d4d4;
|
130
|
-
}
|
131
|
-
|
132
|
-
.autocomplete-items div:hover {
|
133
|
-
background-color: #e9e9e9;
|
134
|
-
}
|
135
|
-
|
136
|
-
.autocomplete-active {
|
137
|
-
background-color: DodgerBlue !important;
|
138
|
-
color: #ffffff;
|
139
|
-
}
|
140
|
-
|
141
|
-
/* Thinking Indicator */
|
142
|
-
.thinking-indicator {
|
143
|
-
position: absolute;
|
144
|
-
bottom: 0;
|
145
|
-
left: 0;
|
146
|
-
right: 0;
|
147
|
-
padding: 10px;
|
148
|
-
background-color: #f0f0f0;
|
149
|
-
border-radius: 5px 5px 0 0;
|
150
|
-
display: none;
|
151
|
-
z-index: 1000;
|
152
|
-
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
|
153
|
-
}
|
154
|
-
|
155
|
-
.dot-animation {
|
156
|
-
display: inline-block;
|
157
|
-
width: 20px;
|
158
|
-
text-align: left;
|
159
|
-
animation: dotAnimation 1.5s infinite;
|
160
|
-
}
|
161
|
-
|
162
|
-
@keyframes dotAnimation {
|
163
|
-
0% {
|
164
|
-
content: '.';
|
165
|
-
}
|
166
|
-
|
167
|
-
33% {
|
168
|
-
content: '..';
|
169
|
-
}
|
170
|
-
|
171
|
-
66% {
|
172
|
-
content: '...';
|
173
|
-
}
|
174
|
-
}
|
@@ -1,68 +0,0 @@
|
|
1
|
-
// artifacts.js
|
2
|
-
import { renderTableArtifact } from './tableArtifacts.js';
|
3
|
-
import { renderListArtifact } from './listArtifacts.js';
|
4
|
-
import { renderFilingArtifact } from './filingArtifacts.js';
|
5
|
-
|
6
|
-
export let artifactContent = null;
|
7
|
-
export let artifactContainer = null;
|
8
|
-
export let suggestionContainer = null;
|
9
|
-
export let toggleArtifactsBtn = null;
|
10
|
-
export let allArtifacts = [];
|
11
|
-
|
12
|
-
export function initializeArtifacts() {
|
13
|
-
artifactContent = document.getElementById('artifact-content');
|
14
|
-
artifactContainer = document.getElementById('artifact-container');
|
15
|
-
suggestionContainer = document.querySelector('.suggestion-box');
|
16
|
-
toggleArtifactsBtn = document.getElementById('toggle-artifacts');
|
17
|
-
|
18
|
-
if (toggleArtifactsBtn) {
|
19
|
-
toggleArtifactsBtn.addEventListener('click', toggleArtifacts);
|
20
|
-
}
|
21
|
-
|
22
|
-
// Initially hide artifacts
|
23
|
-
hideArtifacts();
|
24
|
-
}
|
25
|
-
|
26
|
-
export function renderArtifact(artifactData, artifactType) {
|
27
|
-
if (artifactType === 'artifact-table') {
|
28
|
-
const newArtifacts = Array.isArray(artifactData) ? artifactData : [artifactData];
|
29
|
-
newArtifacts.forEach(artifact => {
|
30
|
-
artifact.type = artifactType;
|
31
|
-
});
|
32
|
-
allArtifacts = [...allArtifacts, ...newArtifacts];
|
33
|
-
renderTableArtifact(artifactData[0]);
|
34
|
-
}
|
35
|
-
else if (artifactType === 'artifact-list') {
|
36
|
-
renderListArtifact(artifactData);
|
37
|
-
}
|
38
|
-
else if (artifactType === 'artifact-filing') {
|
39
|
-
renderFilingArtifact(artifactData);
|
40
|
-
}
|
41
|
-
else {
|
42
|
-
console.log('Unsupported artifact type:', artifactType);
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
export function showArtifacts() {
|
47
|
-
if (artifactContainer && suggestionContainer) {
|
48
|
-
artifactContainer.style.display = 'block';
|
49
|
-
suggestionContainer.style.display = 'none';
|
50
|
-
if (toggleArtifactsBtn) toggleArtifactsBtn.textContent = 'Hide Artifacts';
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
export function hideArtifacts() {
|
55
|
-
if (artifactContainer && suggestionContainer) {
|
56
|
-
artifactContainer.style.display = 'none';
|
57
|
-
suggestionContainer.style.display = 'block';
|
58
|
-
if (toggleArtifactsBtn) toggleArtifactsBtn.textContent = 'Show Artifacts';
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
function toggleArtifacts() {
|
63
|
-
if (artifactContainer.style.display === 'none') {
|
64
|
-
showArtifacts();
|
65
|
-
} else {
|
66
|
-
hideArtifacts();
|
67
|
-
}
|
68
|
-
}
|
@@ -1,92 +0,0 @@
|
|
1
|
-
// chat.js
|
2
|
-
import { renderArtifact, showArtifacts } from './artifacts.js';
|
3
|
-
|
4
|
-
let thinkingIndicator = null;
|
5
|
-
let isHandlingResponse = false;
|
6
|
-
|
7
|
-
export function appendMessage(sender, message) {
|
8
|
-
console.log(`Appending message from ${sender}: ${message}`);
|
9
|
-
const chatContainer = document.getElementById('chat-container');
|
10
|
-
const messageElement = document.createElement('div');
|
11
|
-
messageElement.innerHTML = `<strong>${sender}:</strong> ${message}`;
|
12
|
-
chatContainer.appendChild(messageElement);
|
13
|
-
scrollChatToBottom();
|
14
|
-
}
|
15
|
-
|
16
|
-
function scrollChatToBottom() {
|
17
|
-
const chatContainer = document.getElementById('chat-container');
|
18
|
-
chatContainer.scrollTop = chatContainer.scrollHeight;
|
19
|
-
}
|
20
|
-
|
21
|
-
export function showThinkingIndicator() {
|
22
|
-
if (!thinkingIndicator) {
|
23
|
-
thinkingIndicator = document.createElement('div');
|
24
|
-
thinkingIndicator.className = 'thinking-indicator';
|
25
|
-
thinkingIndicator.innerHTML = '<span>Bot is thinking</span><span class="dot-animation">...</span>';
|
26
|
-
document.getElementById('chat-container').appendChild(thinkingIndicator);
|
27
|
-
}
|
28
|
-
thinkingIndicator.style.display = 'block';
|
29
|
-
scrollChatToBottom();
|
30
|
-
}
|
31
|
-
|
32
|
-
export function hideThinkingIndicator() {
|
33
|
-
if (thinkingIndicator) {
|
34
|
-
thinkingIndicator.style.display = 'none';
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
export async function sendMessage(message) {
|
39
|
-
console.log(`Sending message: ${message}`);
|
40
|
-
showThinkingIndicator();
|
41
|
-
try {
|
42
|
-
const response = await fetch('/chat', {
|
43
|
-
method: 'POST',
|
44
|
-
headers: {
|
45
|
-
'Content-Type': 'application/json',
|
46
|
-
},
|
47
|
-
body: JSON.stringify({ message }),
|
48
|
-
});
|
49
|
-
const data = await response.json();
|
50
|
-
console.log('Received response:', data);
|
51
|
-
return data;
|
52
|
-
} finally {
|
53
|
-
hideThinkingIndicator();
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
export function handleResponse(response) {
|
58
|
-
if (isHandlingResponse) {
|
59
|
-
console.log('Already handling a response, skipping.');
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
isHandlingResponse = true;
|
63
|
-
console.log('Handling response:', response);
|
64
|
-
|
65
|
-
try {
|
66
|
-
if (response.response.type === 'text') {
|
67
|
-
appendMessage('Bot', response.response.content);
|
68
|
-
} else if (response.response.type === 'artifact') {
|
69
|
-
let artifactType = response.response.artifact_type;
|
70
|
-
let artifactContent = response.response.content;
|
71
|
-
|
72
|
-
if (artifactType === 'artifact-filing') {
|
73
|
-
artifactContent = {
|
74
|
-
content: response.response.content,
|
75
|
-
data: response.response.data,
|
76
|
-
section_id: response.response.section_id
|
77
|
-
};
|
78
|
-
}
|
79
|
-
|
80
|
-
appendMessage('Bot', `I have prepared an ${artifactType} for you. Please check the artifact view.`);
|
81
|
-
renderArtifact(artifactContent, artifactType);
|
82
|
-
showArtifacts();
|
83
|
-
} else {
|
84
|
-
appendMessage('Bot', 'I have received a response, but it is not a supported type.');
|
85
|
-
}
|
86
|
-
} finally {
|
87
|
-
isHandlingResponse = false;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
// Make sendMessage globally accessible
|
92
|
-
window.sendMessage = sendMessage;
|
@@ -1,56 +0,0 @@
|
|
1
|
-
// filingArtifacts.js
|
2
|
-
export function renderFilingArtifact(artifactData) {
|
3
|
-
const { content: html, data, section_id } = artifactData;
|
4
|
-
|
5
|
-
const container = document.createElement('div');
|
6
|
-
container.className = 'filing-container';
|
7
|
-
container.style.width = '100%';
|
8
|
-
container.style.height = '600px';
|
9
|
-
|
10
|
-
const iframe = document.createElement('iframe');
|
11
|
-
iframe.srcdoc = html;
|
12
|
-
iframe.style.width = '100%';
|
13
|
-
iframe.style.height = '100%';
|
14
|
-
iframe.style.border = 'none';
|
15
|
-
|
16
|
-
container.appendChild(iframe);
|
17
|
-
|
18
|
-
const artifactContent = document.getElementById('artifact-content');
|
19
|
-
if (artifactContent) {
|
20
|
-
artifactContent.innerHTML = '';
|
21
|
-
artifactContent.appendChild(container);
|
22
|
-
}
|
23
|
-
|
24
|
-
iframe.onload = () => {
|
25
|
-
if (section_id) {
|
26
|
-
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
|
27
|
-
const targetElement = iframeDocument.getElementById(section_id);
|
28
|
-
if (targetElement) {
|
29
|
-
targetElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
30
|
-
}
|
31
|
-
}
|
32
|
-
};
|
33
|
-
|
34
|
-
const buttonContainer = document.createElement('div');
|
35
|
-
buttonContainer.className = 'mt-3';
|
36
|
-
|
37
|
-
const downloadHtmlBtn = document.createElement('button');
|
38
|
-
downloadHtmlBtn.className = 'btn btn-secondary me-2';
|
39
|
-
downloadHtmlBtn.textContent = 'Download Filing HTML';
|
40
|
-
downloadHtmlBtn.onclick = () => {
|
41
|
-
const blob = new Blob([html], { type: 'text/html' });
|
42
|
-
saveAs(blob, 'filing.html');
|
43
|
-
};
|
44
|
-
buttonContainer.appendChild(downloadHtmlBtn);
|
45
|
-
|
46
|
-
const downloadJsonBtn = document.createElement('button');
|
47
|
-
downloadJsonBtn.className = 'btn btn-secondary';
|
48
|
-
downloadJsonBtn.textContent = 'Download Filing Data (JSON)';
|
49
|
-
downloadJsonBtn.onclick = () => {
|
50
|
-
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
51
|
-
saveAs(blob, 'filing_data.json');
|
52
|
-
};
|
53
|
-
buttonContainer.appendChild(downloadJsonBtn);
|
54
|
-
|
55
|
-
artifactContent.appendChild(buttonContainer);
|
56
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
// listArtifacts.js
|
2
|
-
export function renderListArtifact(listData) {
|
3
|
-
let html = `<h4>URLs</h4><ul class="list-group">`;
|
4
|
-
|
5
|
-
listData.forEach(url => {
|
6
|
-
html += `<li class="list-group-item"><a href="${url}" target="_blank">${url}</a></li>`;
|
7
|
-
});
|
8
|
-
|
9
|
-
html += '</ul>';
|
10
|
-
|
11
|
-
const artifactContent = document.getElementById('artifact-content');
|
12
|
-
if (artifactContent) {
|
13
|
-
artifactContent.innerHTML = html;
|
14
|
-
}
|
15
|
-
}
|
@@ -1,57 +0,0 @@
|
|
1
|
-
// main.js
|
2
|
-
import { appendMessage, sendMessage, handleResponse, showThinkingIndicator, hideThinkingIndicator } from './chat.js';
|
3
|
-
import { initializeArtifacts } from './artifacts.js';
|
4
|
-
import { handleDocumentClick } from './tableArtifacts.js';
|
5
|
-
import { initializeSuggestions } from './suggestions.js';
|
6
|
-
import { handlePrefilledPrompt } from './prefilledPrompt.js';
|
7
|
-
|
8
|
-
let chatInitialized = false;
|
9
|
-
|
10
|
-
function initializeChat() {
|
11
|
-
if (chatInitialized) return;
|
12
|
-
chatInitialized = true;
|
13
|
-
|
14
|
-
console.log('Initializing chat');
|
15
|
-
|
16
|
-
initializeArtifacts();
|
17
|
-
initializeSuggestions();
|
18
|
-
|
19
|
-
const chatForm = document.getElementById('chat-form');
|
20
|
-
const userInput = document.getElementById('user-input');
|
21
|
-
|
22
|
-
if (chatForm) {
|
23
|
-
chatForm.addEventListener('submit', async (e) => {
|
24
|
-
e.preventDefault();
|
25
|
-
console.log('Form submitted');
|
26
|
-
const message = userInput.value.trim();
|
27
|
-
if (message) {
|
28
|
-
appendMessage('You', message);
|
29
|
-
userInput.value = '';
|
30
|
-
showThinkingIndicator();
|
31
|
-
try {
|
32
|
-
const response = await sendMessage(message);
|
33
|
-
handleResponse(response);
|
34
|
-
} catch (error) {
|
35
|
-
console.error('Error processing message:', error);
|
36
|
-
} finally {
|
37
|
-
hideThinkingIndicator();
|
38
|
-
}
|
39
|
-
}
|
40
|
-
});
|
41
|
-
}
|
42
|
-
|
43
|
-
document.addEventListener('click', handleDocumentClick);
|
44
|
-
}
|
45
|
-
|
46
|
-
// Wait for the DOM to be fully loaded before initializing
|
47
|
-
if (document.readyState === 'loading') {
|
48
|
-
document.addEventListener('DOMContentLoaded', initializeChat);
|
49
|
-
} else {
|
50
|
-
initializeChat();
|
51
|
-
}
|
52
|
-
|
53
|
-
// Add this new event listener for the window load event
|
54
|
-
window.addEventListener('load', () => {
|
55
|
-
console.log('Window fully loaded, handling prefilled prompt');
|
56
|
-
handlePrefilledPrompt();
|
57
|
-
});
|
@@ -1,27 +0,0 @@
|
|
1
|
-
// prefilledPrompt.js
|
2
|
-
import { sendMessage, handleResponse, appendMessage } from './chat.js';
|
3
|
-
|
4
|
-
export function handlePrefilledPrompt() {
|
5
|
-
const urlParams = new URLSearchParams(window.location.search);
|
6
|
-
const prefilled_prompt = urlParams.get('prompt');
|
7
|
-
if (prefilled_prompt) {
|
8
|
-
const userInput = document.getElementById('user-input');
|
9
|
-
if (userInput) {
|
10
|
-
userInput.value = prefilled_prompt;
|
11
|
-
appendMessage('You', prefilled_prompt); // Show the user's message in the chat
|
12
|
-
}
|
13
|
-
if (typeof sendMessage === 'function') {
|
14
|
-
sendMessage(prefilled_prompt).then(response => {
|
15
|
-
handleResponse(response);
|
16
|
-
if (userInput) {
|
17
|
-
userInput.value = ''; // Clear the input field after sending
|
18
|
-
}
|
19
|
-
}).catch(error => {
|
20
|
-
console.error('Error processing prefilled prompt:', error);
|
21
|
-
if (userInput) {
|
22
|
-
userInput.value = ''; // Clear the input field even if there's an error
|
23
|
-
}
|
24
|
-
});
|
25
|
-
}
|
26
|
-
}
|
27
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
// suggestions.js
|
2
|
-
import { appendMessage, sendMessage, handleResponse, showThinkingIndicator, hideThinkingIndicator } from './chat.js';
|
3
|
-
import { renderArtifact, showArtifacts } from './artifacts.js';
|
4
|
-
|
5
|
-
export function initializeSuggestions() {
|
6
|
-
const userInput = document.getElementById('user-input');
|
7
|
-
const chatForm = document.getElementById('chat-form');
|
8
|
-
const suggestionItems = document.querySelectorAll('.suggestion-item');
|
9
|
-
|
10
|
-
// Function to handle suggestion click
|
11
|
-
function handleSuggestionClick(event) {
|
12
|
-
const suggestionText = event.target.textContent;
|
13
|
-
userInput.value = suggestionText;
|
14
|
-
executeChatRequest(suggestionText);
|
15
|
-
userInput.value = ''; // Clear the input after executing the request
|
16
|
-
}
|
17
|
-
|
18
|
-
// Add click event listeners to all suggestion items
|
19
|
-
suggestionItems.forEach(item => {
|
20
|
-
item.addEventListener('click', handleSuggestionClick);
|
21
|
-
});
|
22
|
-
|
23
|
-
// Function to execute chat request
|
24
|
-
async function executeChatRequest(message) {
|
25
|
-
try {
|
26
|
-
appendMessage('You', message);
|
27
|
-
showThinkingIndicator();
|
28
|
-
const response = await sendMessage(message);
|
29
|
-
handleResponse(response);
|
30
|
-
} catch (error) {
|
31
|
-
console.error('Error executing chat request:', error);
|
32
|
-
appendMessage('Bot', 'Sorry, there was an error processing your request.');
|
33
|
-
} finally {
|
34
|
-
hideThinkingIndicator();
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
// Prevent default form submission
|
39
|
-
chatForm.addEventListener('submit', function (event) {
|
40
|
-
event.preventDefault();
|
41
|
-
const message = userInput.value.trim();
|
42
|
-
if (message) {
|
43
|
-
executeChatRequest(message);
|
44
|
-
userInput.value = ''; // Clear the input after executing the request
|
45
|
-
}
|
46
|
-
});
|
47
|
-
}
|
@@ -1,129 +0,0 @@
|
|
1
|
-
// tableArtifacts.js
|
2
|
-
import { renderMetadata, downloadCSV } from './utils.js';
|
3
|
-
import { allArtifacts } from './artifacts.js';
|
4
|
-
|
5
|
-
export function renderTableArtifact(tableData) {
|
6
|
-
let html = `
|
7
|
-
<div class="mb-3 select-wrapper">
|
8
|
-
<input type="text" id="artifact-select" class="form-control" placeholder="Select a table..." value="${tableData.fact}">
|
9
|
-
<div id="autocomplete-list" class="autocomplete-items"></div>
|
10
|
-
</div>
|
11
|
-
<div class="mb-3">
|
12
|
-
<button id="download-csv" class="btn btn-secondary me-2">Download Selected Table (CSV)</button>
|
13
|
-
<button id="download-all-zip" class="btn btn-secondary">Download All Tables (ZIP)</button>
|
14
|
-
</div>
|
15
|
-
<div id="metadata-content"></div>
|
16
|
-
`;
|
17
|
-
|
18
|
-
if (tableData.table && tableData.table.length > 0) {
|
19
|
-
html += '<table class="table table-striped mt-3"><thead><tr>';
|
20
|
-
Object.keys(tableData.table[0]).forEach(header => {
|
21
|
-
html += `<th>${header}</th>`;
|
22
|
-
});
|
23
|
-
html += '</tr></thead><tbody>';
|
24
|
-
tableData.table.forEach(row => {
|
25
|
-
html += '<tr>';
|
26
|
-
Object.values(row).forEach(cell => {
|
27
|
-
html += `<td>${cell}</td>`;
|
28
|
-
});
|
29
|
-
html += '</tr>';
|
30
|
-
});
|
31
|
-
html += '</tbody></table>';
|
32
|
-
} else {
|
33
|
-
html += '<p>No table data available.</p>';
|
34
|
-
}
|
35
|
-
|
36
|
-
const artifactContent = document.getElementById('artifact-content');
|
37
|
-
if (artifactContent) {
|
38
|
-
artifactContent.innerHTML = html;
|
39
|
-
}
|
40
|
-
renderMetadata(tableData);
|
41
|
-
setupTableEventListeners(tableData);
|
42
|
-
}
|
43
|
-
|
44
|
-
function setupTableEventListeners(tableData) {
|
45
|
-
const artifactSelect = document.getElementById('artifact-select');
|
46
|
-
const downloadCsvBtn = document.getElementById('download-csv');
|
47
|
-
const downloadAllZipBtn = document.getElementById('download-all-zip');
|
48
|
-
|
49
|
-
if (artifactSelect) {
|
50
|
-
artifactSelect.addEventListener('input', handleArtifactSelectInput);
|
51
|
-
artifactSelect.addEventListener('focus', handleArtifactSelectFocus);
|
52
|
-
}
|
53
|
-
|
54
|
-
if (downloadCsvBtn) {
|
55
|
-
downloadCsvBtn.addEventListener('click', () => downloadCSV(tableData));
|
56
|
-
}
|
57
|
-
|
58
|
-
if (downloadAllZipBtn) {
|
59
|
-
downloadAllZipBtn.addEventListener('click', handleDownloadAllZip);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
export function handleArtifactSelectInput(e) {
|
64
|
-
const inputValue = e.target.value.toLowerCase().trim();
|
65
|
-
const filteredTables = allArtifacts.filter(table =>
|
66
|
-
table.fact.toLowerCase().includes(inputValue)
|
67
|
-
);
|
68
|
-
createAutocompleteList(filteredTables);
|
69
|
-
}
|
70
|
-
|
71
|
-
export function handleArtifactSelectFocus() {
|
72
|
-
createAutocompleteList(allArtifacts);
|
73
|
-
}
|
74
|
-
|
75
|
-
function createAutocompleteList(tables) {
|
76
|
-
const autocompleteList = document.getElementById('autocomplete-list');
|
77
|
-
if (!autocompleteList) return;
|
78
|
-
|
79
|
-
autocompleteList.innerHTML = '';
|
80
|
-
autocompleteList.style.display = 'block';
|
81
|
-
|
82
|
-
if (tables.length === 0) {
|
83
|
-
autocompleteList.innerHTML = '<div style="color: #999;">No matching tables found</div>';
|
84
|
-
} else {
|
85
|
-
tables.forEach(table => {
|
86
|
-
const div = document.createElement("div");
|
87
|
-
div.textContent = table.fact;
|
88
|
-
div.addEventListener("click", function () {
|
89
|
-
document.getElementById('artifact-select').value = this.textContent;
|
90
|
-
renderTableArtifact(table);
|
91
|
-
closeAutocompleteList();
|
92
|
-
});
|
93
|
-
autocompleteList.appendChild(div);
|
94
|
-
});
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
export function handleDocumentClick(e) {
|
99
|
-
if (e.target.id !== 'artifact-select') {
|
100
|
-
closeAutocompleteList();
|
101
|
-
}
|
102
|
-
}
|
103
|
-
|
104
|
-
function closeAutocompleteList() {
|
105
|
-
const autocompleteList = document.getElementById('autocomplete-list');
|
106
|
-
if (autocompleteList) {
|
107
|
-
autocompleteList.style.display = 'none';
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
async function handleDownloadAllZip() {
|
112
|
-
const tables = allArtifacts.filter(artifact => artifact.type === 'artifact-table');
|
113
|
-
if (tables.length === 0) {
|
114
|
-
alert('No tables available to download.');
|
115
|
-
return;
|
116
|
-
}
|
117
|
-
const zip = new JSZip();
|
118
|
-
tables.forEach(table => {
|
119
|
-
let csv = '';
|
120
|
-
const headers = Object.keys(table.table[0]);
|
121
|
-
csv += headers.join(',') + '\n';
|
122
|
-
table.table.forEach(row => {
|
123
|
-
csv += Object.values(row).join(',') + '\n';
|
124
|
-
});
|
125
|
-
zip.file(`${table.fact}.csv`, csv);
|
126
|
-
});
|
127
|
-
const content = await zip.generateAsync({ type: "blob" });
|
128
|
-
saveAs(content, "all_tables.zip");
|
129
|
-
}
|