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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// static/js/ui/tools.js
|
| 2 |
+
|
| 3 |
+
import { dom } from './dom.js';
|
| 4 |
+
import { escapeHTML } from './chat.js';
|
| 5 |
+
|
| 6 |
+
export function toggleFilePopupMenu(show) {
|
| 7 |
+
dom.toolsMenu.classList.remove('active');
|
| 8 |
+
if (show) {
|
| 9 |
+
dom.filePopupMenu.classList.add('active');
|
| 10 |
+
} else {
|
| 11 |
+
dom.filePopupMenu.classList.remove('active');
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export function toggleToolsMenu(show) {
|
| 16 |
+
dom.filePopupMenu.classList.remove('active');
|
| 17 |
+
if (show) {
|
| 18 |
+
dom.toolsMenu.classList.add('active');
|
| 19 |
+
} else {
|
| 20 |
+
dom.toolsMenu.classList.remove('active');
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
export function updateToolsButton(toolName) {
|
| 25 |
+
if (toolName) {
|
| 26 |
+
dom.toolsButtonText.textContent = toolName;
|
| 27 |
+
dom.toolsDefaultIcon.style.display = 'none';
|
| 28 |
+
dom.clearToolSelection.style.display = 'flex';
|
| 29 |
+
dom.toolsButton.classList.add('tool-selected');
|
| 30 |
+
} else {
|
| 31 |
+
dom.toolsButtonText.textContent = 'ابزارها';
|
| 32 |
+
dom.toolsDefaultIcon.style.display = 'flex';
|
| 33 |
+
dom.clearToolSelection.style.display = 'none';
|
| 34 |
+
dom.toolsButton.classList.remove('tool-selected');
|
| 35 |
+
dom.messageInput.placeholder = 'هر چی میخوای بپرس';
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
function getDeepThinkTVHTML() {
|
| 40 |
+
return `
|
| 41 |
+
<div class="deep-think-tv-container">
|
| 42 |
+
<section class="deep-think-tv">
|
| 43 |
+
<div class="screen scanlines gloss">
|
| 44 |
+
<div class="ui">
|
| 45 |
+
<div class="header">
|
| 46 |
+
<div class="topbar">
|
| 47 |
+
<div class="badge"><span class="dot"></span>تفکر عمیق چت باتآلفا</div>
|
| 48 |
+
</div>
|
| 49 |
+
<div class="topic"><span>موضوع:</span><strong id="tv-topic">...</strong></div>
|
| 50 |
+
</div>
|
| 51 |
+
<div class="steps">
|
| 52 |
+
<div class="step active" data-step="analyzing"><span class="mini"></span>تحقیق و بررسی</div>
|
| 53 |
+
</div>
|
| 54 |
+
<div class="progress"><div class="bar" id="tv-bar" style="width:0%"></div></div>
|
| 55 |
+
<div id="tv-log" class="log custom-scrollbar"></div>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
</section>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="final-answer-wrapper"></div>
|
| 61 |
+
`;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export function createDeepThinkPanel(modelBubbleOuterDivElement) {
|
| 65 |
+
const contentArea = modelBubbleOuterDivElement.querySelector('.message-content');
|
| 66 |
+
if (!contentArea || contentArea.querySelector('.deep-think-tv')) return;
|
| 67 |
+
contentArea.innerHTML = getDeepThinkTVHTML();
|
| 68 |
+
const tv = contentArea.querySelector('.deep-think-tv');
|
| 69 |
+
if (document.documentElement.classList.contains('dark')) {
|
| 70 |
+
tv.classList.add('dark');
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
export function updateDeepThinkPanel(data, modelBubbleOuterDivElement) {
|
| 75 |
+
const tv = modelBubbleOuterDivElement.querySelector('.deep-think-tv');
|
| 76 |
+
if (!tv) return;
|
| 77 |
+
|
| 78 |
+
if (data.topic) {
|
| 79 |
+
const topicEl = tv.querySelector('#tv-topic');
|
| 80 |
+
if (topicEl) topicEl.textContent = data.topic;
|
| 81 |
+
}
|
| 82 |
+
if (data.log) {
|
| 83 |
+
const logEl = tv.querySelector('#tv-log');
|
| 84 |
+
if (logEl) {
|
| 85 |
+
const row = document.createElement('div');
|
| 86 |
+
row.className = 'row';
|
| 87 |
+
row.innerHTML = `<div class="icon">✓</div><div>${escapeHTML(data.log)}</div>`;
|
| 88 |
+
logEl.appendChild(row);
|
| 89 |
+
logEl.scrollTop = logEl.scrollHeight;
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
if (data.progress) {
|
| 93 |
+
const barEl = tv.querySelector('#tv-bar');
|
| 94 |
+
if (barEl) barEl.style.width = `${data.progress}%`;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
export function hideDeepThinkPanel(modelBubbleOuterDivElement) {
|
| 99 |
+
const tvContainer = modelBubbleOuterDivElement.querySelector('.deep-think-tv-container');
|
| 100 |
+
const finalAnswerWrapper = modelBubbleOuterDivElement.querySelector('.final-answer-wrapper');
|
| 101 |
+
if (tvContainer) {
|
| 102 |
+
tvContainer.style.transition = 'opacity 0.5s, max-height 0.5s, padding 0.5s, margin 0.5s';
|
| 103 |
+
tvContainer.style.opacity = '0';
|
| 104 |
+
tvContainer.style.maxHeight = '0';
|
| 105 |
+
tvContainer.style.padding = '0';
|
| 106 |
+
tvContainer.style.margin = '0';
|
| 107 |
+
tvContainer.style.overflow = 'hidden';
|
| 108 |
+
}
|
| 109 |
+
if(finalAnswerWrapper) {
|
| 110 |
+
finalAnswerWrapper.classList.add('visible');
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
function getReasoningHUDHTML() {
|
| 115 |
+
return `
|
| 116 |
+
<div class="reasoning-hud-container">
|
| 117 |
+
<section class="reasoning-hud">
|
| 118 |
+
<div class="grid-bg"></div>
|
| 119 |
+
<div class="ui-content">
|
| 120 |
+
<div class="header">
|
| 121 |
+
<div class="badge"><span class="dot"></span>استدلال منطقی</div>
|
| 122 |
+
<div class="topic"><span>موضوع:</span><strong id="reasoning-topic">...</strong></div>
|
| 123 |
+
</div>
|
| 124 |
+
<div class="progress"><div class="bar" id="reasoning-bar" style="width:0%"></div></div>
|
| 125 |
+
<div id="reasoning-log" class="log custom-scrollbar"></div>
|
| 126 |
+
</div>
|
| 127 |
+
</section>
|
| 128 |
+
</div>
|
| 129 |
+
<div class="final-answer-wrapper"></div>
|
| 130 |
+
`;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
export function createReasoningPanel(modelBubbleOuterDivElement) {
|
| 134 |
+
const contentArea = modelBubbleOuterDivElement.querySelector('.message-content');
|
| 135 |
+
if (!contentArea || contentArea.querySelector('.reasoning-hud')) return;
|
| 136 |
+
contentArea.innerHTML = getReasoningHUDHTML();
|
| 137 |
+
const hud = contentArea.querySelector('.reasoning-hud');
|
| 138 |
+
if (document.documentElement.classList.contains('dark')) {
|
| 139 |
+
hud.classList.add('dark');
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
export function updateReasoningPanel(data, modelBubbleOuterDivElement) {
|
| 144 |
+
const hud = modelBubbleOuterDivElement.querySelector('.reasoning-hud');
|
| 145 |
+
if (!hud) return;
|
| 146 |
+
|
| 147 |
+
if (data.topic) {
|
| 148 |
+
const topicEl = hud.querySelector('#reasoning-topic');
|
| 149 |
+
if (topicEl) topicEl.textContent = data.topic;
|
| 150 |
+
}
|
| 151 |
+
if (data.log) {
|
| 152 |
+
const logEl = hud.querySelector('#reasoning-log');
|
| 153 |
+
if (logEl) {
|
| 154 |
+
const row = document.createElement('div');
|
| 155 |
+
row.className = 'row';
|
| 156 |
+
row.innerHTML = `<div class="icon"><svg fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M13 10V3L4 14h7v7l9-11h-7z" /></svg></div><div>${escapeHTML(data.log)}</div>`;
|
| 157 |
+
logEl.appendChild(row);
|
| 158 |
+
logEl.scrollTop = logEl.scrollHeight;
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
if (data.progress) {
|
| 162 |
+
const barEl = hud.querySelector('#reasoning-bar');
|
| 163 |
+
if (barEl) barEl.style.width = `${data.progress}%`;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
export function hideReasoningPanel(modelBubbleOuterDivElement) {
|
| 168 |
+
const hudContainer = modelBubbleOuterDivElement.querySelector('.reasoning-hud-container');
|
| 169 |
+
const finalAnswerWrapper = modelBubbleOuterDivElement.querySelector('.final-answer-wrapper');
|
| 170 |
+
if (hudContainer) {
|
| 171 |
+
hudContainer.style.transition = 'opacity 0.5s, max-height 0.5s, padding 0.5s, margin 0.5s';
|
| 172 |
+
hudContainer.style.opacity = '0';
|
| 173 |
+
hudContainer.style.maxHeight = '0';
|
| 174 |
+
hudContainer.style.padding = '0';
|
| 175 |
+
hudContainer.style.margin = '0';
|
| 176 |
+
hudContainer.style.overflow = 'hidden';
|
| 177 |
+
}
|
| 178 |
+
if(finalAnswerWrapper) {
|
| 179 |
+
finalAnswerWrapper.classList.add('visible');
|
| 180 |
+
}
|
| 181 |
+
}
|