Wilker commited on
Commit
cdf46fb
·
1 Parent(s): 19a8c26

fix: corrige atualização em tempo real do badge de cota após resposta (variável backend inexistente)

Browse files
Files changed (1) hide show
  1. index.html +26 -6
index.html CHANGED
@@ -700,14 +700,32 @@ function switchMode(mode) {
700
  opt.textContent = `${m.label}${quotaBadge} — ${m.desc}`;
701
  if (m.active) { opt.selected = true; currentModelKey = m.key; }
702
  sel.appendChild(opt);
703
- });
704
- updateModelLabel();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
705
  } catch (err) {
706
- console.error('Erro ao carregar modelos:', err);
707
- }
708
- }
709
 
710
- function onModelChange() {
711
  currentModelKey = document.getElementById('model-select').value;
712
  modelJustChanged = true;
713
  document.getElementById('model-loading-hint').classList.add('show');
@@ -1020,6 +1038,8 @@ async function sendMessage() {
1020
  updateStats(usage.prompt_tokens||0, usage.completion_tokens||0, ms);
1021
  speak(reply);
1022
 
 
 
1023
  if (modelJustChanged) {
1024
  document.getElementById('model-loading-hint').classList.remove('show');
1025
  modelJustChanged = false;
 
700
  opt.textContent = `${m.label}${quotaBadge} — ${m.desc}`;
701
  if (m.active) { opt.selected = true; currentModelKey = m.key; }
702
  sel.appendChild(opt);
703
+ });
704
+ updateModelLabel();
705
+ } catch (err) {
706
+ console.error('Erro ao carregar modelos:', err);
707
+ }
708
+ }
709
+
710
+ // ── Update Quota Badge ────────────────────────────────────────────────────────
711
+ async function updateQuotaBadge(modelKey) {
712
+ try {
713
+ const res = await fetch('/v1/quota');
714
+ const data = await res.json();
715
+ const quota = data.quotas.find(q => q.model === modelKey);
716
+ if (!quota) return;
717
+ const opt = document.querySelector(`option[value="${modelKey}"]`);
718
+ if (!opt) return;
719
+ const label = opt.textContent.split(' — ')[0].trim();
720
+ const rest = opt.textContent.split(' — ')[1] || '';
721
+ const quotaBadge = ` (${quota.used}/${quota.limit})`;
722
+ opt.textContent = `${label}${quotaBadge} — ${rest}`;
723
  } catch (err) {
724
+ console.error('Erro ao atualizar quota:', err);
725
+ }
726
+ }
727
 
728
+ function onModelChange() {
729
  currentModelKey = document.getElementById('model-select').value;
730
  modelJustChanged = true;
731
  document.getElementById('model-loading-hint').classList.add('show');
 
1038
  updateStats(usage.prompt_tokens||0, usage.completion_tokens||0, ms);
1039
  speak(reply);
1040
 
1041
+ updateQuotaBadge(currentModelKey);
1042
+
1043
  if (modelJustChanged) {
1044
  document.getElementById('model-loading-hint').classList.remove('show');
1045
  modelJustChanged = false;