feat: redesign UI section Cles API IA - recherche, carte defaut, cartes depliables, footer sticky (#104)
This commit is contained in:
@@ -82,6 +82,24 @@ function renderCapabilityList(caps) {
|
||||
return box;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render only the *enabled* capabilities as colored tags (#104). Used by the
|
||||
* config panel where a compact read-only summary reads better than checkboxes.
|
||||
*/
|
||||
function renderCapabilityBadges(caps) {
|
||||
const box = document.createElement('div');
|
||||
box.className = 'ai-caps-badges';
|
||||
if (!caps) return box;
|
||||
AI_CAPABILITY_KEYS.forEach((key) => {
|
||||
if (!caps[key]) return;
|
||||
const item = document.createElement('span');
|
||||
item.className = 'ai-cap-badge';
|
||||
item.textContent = t(`ai.cap_${key}`);
|
||||
box.appendChild(item);
|
||||
});
|
||||
return box;
|
||||
}
|
||||
|
||||
/** Accent-insensitive, case-insensitive normalization for model search. */
|
||||
function _normalizeText(value) {
|
||||
return String(value || '')
|
||||
@@ -1019,6 +1037,7 @@ export {
|
||||
AI_CAPABILITY_KEYS,
|
||||
getModelCapabilities,
|
||||
renderCapabilityList,
|
||||
renderCapabilityBadges,
|
||||
_buildPickerUI as buildAIPickerUI,
|
||||
refreshAIPickers,
|
||||
PICKER_SLOT_CLASS,
|
||||
|
||||
+129
-39
@@ -6,7 +6,7 @@ import { syncVaultSelectors, setSelectedVaultContext, refreshSidebarForContext,
|
||||
import { escapeHtml, safeCreateIcons } from './utils.js';
|
||||
import { showToast, closeHeaderMenu, closeMobileSidebar } from './ui.js';
|
||||
import { t, setLocale, getLocale } from './i18n.js';
|
||||
import { getModelCapabilities, renderCapabilityList, refreshAIPickers } from './ai.js';
|
||||
import { getModelCapabilities, renderCapabilityBadges, refreshAIPickers } from './ai.js';
|
||||
|
||||
let _recentTimestampTimer = null;
|
||||
let _recentFilesCache = [];
|
||||
@@ -766,6 +766,11 @@ function initConfigModal() {
|
||||
if (saveAIKeysBtn) saveAIKeysBtn.addEventListener("click", saveAIKeys);
|
||||
const testAIKeysBtn = document.getElementById("cfg-test-ai-keys");
|
||||
if (testAIKeysBtn) testAIKeysBtn.addEventListener("click", testAIKeys);
|
||||
// Provider search filter (#104)
|
||||
const aiProviderSearch = document.getElementById("cfg-ai-search");
|
||||
if (aiProviderSearch) {
|
||||
aiProviderSearch.addEventListener("input", () => filterAIProviders(aiProviderSearch.value));
|
||||
}
|
||||
// Tool & connected-source keys (#103)
|
||||
const saveToolKeysBtn = document.getElementById("cfg-save-tool-keys");
|
||||
if (saveToolKeysBtn) saveToolKeysBtn.addEventListener("click", saveToolKeys);
|
||||
@@ -1510,7 +1515,7 @@ function updateRegexPreview() {
|
||||
}
|
||||
|
||||
|
||||
// ── AI Keys management ──
|
||||
// ── AI Keys management (#104 — accordion redesign) ──
|
||||
const AI_KEY_MAP = {
|
||||
"cfg-deepseek-key": "DEEPSEEK_API_KEY",
|
||||
"cfg-openrouter-key": "OPENROUTER_API_KEY",
|
||||
@@ -1522,57 +1527,140 @@ const AI_KEY_MAP = {
|
||||
};
|
||||
const AI_PROVIDER_NAMES = ["deepseek","openrouter","gemini","nvidia","qwencloud","xiaomi","mistral"];
|
||||
|
||||
function _ensureAIKeyUI() {
|
||||
for (const [inputId] of Object.entries(AI_KEY_MAP)) {
|
||||
const input = document.getElementById(inputId);
|
||||
if (!input) continue;
|
||||
const row = input.closest(".config-row");
|
||||
if (!row || row.dataset.enhanced) continue;
|
||||
row.dataset.enhanced = "1";
|
||||
row.style.cssText += "display:flex;align-items:center;gap:8px;flex-wrap:wrap;";
|
||||
const badge = document.createElement("span");
|
||||
badge.id = inputId.replace("-key", "-badge");
|
||||
badge.style.cssText = "font-size:11px;padding:2px 8px;border-radius:10px;white-space:nowrap;";
|
||||
row.appendChild(badge);
|
||||
const delBtn = document.createElement("button");
|
||||
delBtn.type = "button";
|
||||
delBtn.id = inputId.replace("-key", "-delete");
|
||||
delBtn.className = "config-btn-secondary";
|
||||
delBtn.style.cssText = "font-size:11px;padding:4px 10px;color:var(--danger,#e74c3c);border-color:var(--danger,#e74c3c);cursor:pointer;display:none;";
|
||||
delBtn.textContent = "\u00d7 Supprimer";
|
||||
delBtn.addEventListener("click", () => deleteAIKey(inputId));
|
||||
row.appendChild(delBtn);
|
||||
// Display metadata for the provider accordion cards (#104).
|
||||
const AI_PROVIDER_META = {
|
||||
deepseek: { name: "DeepSeek", placeholder: "sk-..." },
|
||||
openrouter: { name: "OpenRouter", placeholder: "sk-or-..." },
|
||||
gemini: { name: "Gemini", placeholder: "AIza..." },
|
||||
nvidia: { name: "NVIDIA", placeholder: "nvapi-..." },
|
||||
qwencloud: { name: "QwenCloud", placeholder: "sk-..." },
|
||||
xiaomi: { name: "Xiaomi", placeholder: "xm-..." },
|
||||
mistral: { name: "Mistral", placeholder: "sk-..." },
|
||||
};
|
||||
|
||||
function _renderAIProviderCards() {
|
||||
const host = document.getElementById("cfg-ai-providers");
|
||||
if (!host) return;
|
||||
host.innerHTML = "";
|
||||
for (const p of AI_PROVIDER_NAMES) {
|
||||
const meta = AI_PROVIDER_META[p] || { name: p, placeholder: "sk-..." };
|
||||
const card = el("div", { class: "ai-provider-card", "data-provider": p });
|
||||
|
||||
// Header row (div + role=button so the per-provider delete button can
|
||||
// live inside without nesting two interactive elements).
|
||||
const head = el("div", {
|
||||
class: "ai-provider-head",
|
||||
role: "button",
|
||||
tabindex: "0",
|
||||
"aria-expanded": "false",
|
||||
});
|
||||
head.appendChild(el("span", { class: "ai-provider-logo", "aria-hidden": "true" }, [document.createTextNode(meta.name.charAt(0))]));
|
||||
head.appendChild(el("span", { class: "ai-provider-name" }, [document.createTextNode(meta.name)]));
|
||||
head.appendChild(el("span", { class: "ai-provider-badge", id: `cfg-${p}-badge` }));
|
||||
const delBtn = el("button", {
|
||||
type: "button",
|
||||
class: "ai-provider-delete",
|
||||
id: `cfg-${p}-delete`,
|
||||
title: t("config.ai_delete_key_title"),
|
||||
});
|
||||
delBtn.style.display = "none";
|
||||
delBtn.appendChild(icon("trash-2", 14));
|
||||
delBtn.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
deleteAIKey(`cfg-${p}-key`);
|
||||
});
|
||||
head.appendChild(delBtn);
|
||||
const chevron = icon("chevron-down", 16);
|
||||
chevron.classList.add("ai-provider-chevron");
|
||||
head.appendChild(chevron);
|
||||
|
||||
const toggle = () => _toggleAICard(card);
|
||||
head.addEventListener("click", toggle);
|
||||
head.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); toggle(); }
|
||||
});
|
||||
|
||||
// Collapsible body: API key (60%) + model (40%), labels above inputs.
|
||||
const body = el("div", { class: "ai-provider-body hidden" });
|
||||
const fields = el("div", { class: "ai-provider-fields" });
|
||||
|
||||
const keyField = el("div", { class: "ai-field ai-field-key" });
|
||||
keyField.appendChild(el("label", { class: "ai-field-label", for: `cfg-${p}-key` }, [document.createTextNode(`${meta.name} API Key`)]));
|
||||
const keyInput = document.createElement("input");
|
||||
keyInput.type = "password";
|
||||
keyInput.id = `cfg-${p}-key`;
|
||||
keyInput.className = "config-input";
|
||||
keyInput.placeholder = meta.placeholder;
|
||||
keyInput.autocomplete = "off";
|
||||
keyField.appendChild(keyInput);
|
||||
|
||||
const modelField = el("div", { class: "ai-field ai-field-model" });
|
||||
modelField.appendChild(el("label", { class: "ai-field-label", for: `cfg-${p}-model` }, [document.createTextNode(t("config.ai_model"))]));
|
||||
const modelSel = document.createElement("select");
|
||||
modelSel.id = `cfg-${p}-model`;
|
||||
modelSel.className = "config-select";
|
||||
modelSel.innerHTML = '<option value="">-- Modele --</option>';
|
||||
modelField.appendChild(modelSel);
|
||||
|
||||
fields.appendChild(keyField);
|
||||
fields.appendChild(modelField);
|
||||
body.appendChild(fields);
|
||||
|
||||
card.appendChild(head);
|
||||
card.appendChild(body);
|
||||
host.appendChild(card);
|
||||
}
|
||||
safeCreateIcons();
|
||||
}
|
||||
|
||||
function _toggleAICard(card) {
|
||||
const open = card.classList.toggle("open");
|
||||
const body = card.querySelector(".ai-provider-body");
|
||||
if (body) body.classList.toggle("hidden", !open);
|
||||
const head = card.querySelector(".ai-provider-head");
|
||||
if (head) head.setAttribute("aria-expanded", open ? "true" : "false");
|
||||
}
|
||||
|
||||
/** Filter the provider accordion cards by the section search input (#104). */
|
||||
export function filterAIProviders(query) {
|
||||
const host = document.getElementById("cfg-ai-providers");
|
||||
const emptyMsg = document.getElementById("cfg-ai-providers-empty");
|
||||
if (!host) return;
|
||||
const q = _sidebarNorm(query);
|
||||
let visible = 0;
|
||||
host.querySelectorAll(".ai-provider-card").forEach((card) => {
|
||||
const p = card.dataset.provider;
|
||||
const meta = AI_PROVIDER_META[p] || { name: p };
|
||||
const match = !q || _sidebarNorm(meta.name).includes(q) || p.includes(q);
|
||||
card.style.display = match ? "" : "none";
|
||||
if (match) visible++;
|
||||
});
|
||||
if (emptyMsg) emptyMsg.classList.toggle("hidden", visible > 0);
|
||||
}
|
||||
|
||||
function _setAIKeyBadge(inputId, hasKey) {
|
||||
const badge = document.getElementById(inputId.replace("-key", "-badge"));
|
||||
const delBtn = document.getElementById(inputId.replace("-key", "-delete"));
|
||||
const provider = inputId.replace("-key", "");
|
||||
const badge = document.getElementById(`${provider}-badge`);
|
||||
const delBtn = document.getElementById(`${provider}-delete`);
|
||||
if (badge) {
|
||||
if (hasKey) {
|
||||
badge.textContent = "\u2713 Configur\u00e9";
|
||||
badge.style.background = "var(--success-bg, #27ae6022)";
|
||||
badge.style.color = "var(--success, #27ae60)";
|
||||
badge.style.border = "1px solid var(--success, #27ae60)";
|
||||
} else {
|
||||
badge.textContent = "Non configur\u00e9";
|
||||
badge.style.background = "var(--muted-bg, #ffffff10)";
|
||||
badge.style.color = "var(--text-muted, #888)";
|
||||
badge.style.border = "1px solid var(--border, #444)";
|
||||
}
|
||||
badge.textContent = hasKey
|
||||
? "\u2713 " + t("config.ai_status_configured")
|
||||
: t("config.ai_status_not_configured");
|
||||
badge.classList.toggle("configured", !!hasKey);
|
||||
}
|
||||
if (delBtn) delBtn.style.display = hasKey ? "inline-block" : "none";
|
||||
if (delBtn) delBtn.style.display = hasKey ? "inline-flex" : "none";
|
||||
}
|
||||
|
||||
async function loadAIKeys() {
|
||||
_ensureAIKeyUI();
|
||||
_renderAIProviderCards();
|
||||
try {
|
||||
const data = await api("/api/config/ai-keys");
|
||||
for (const [inputId, envName] of Object.entries(AI_KEY_MAP)) {
|
||||
const input = document.getElementById(inputId);
|
||||
const val = data[envName] || "";
|
||||
if (input) {
|
||||
input.placeholder = val || (inputId.includes("gemini") ? "AIza..." : inputId.includes("openrouter") ? "sk-or-..." : "sk-...");
|
||||
const meta = AI_PROVIDER_META[inputId.replace("-key", "")] || {};
|
||||
input.placeholder = val || meta.placeholder || "sk-...";
|
||||
}
|
||||
_setAIKeyBadge(inputId, !!val);
|
||||
}
|
||||
@@ -1626,7 +1714,7 @@ async function _renderConfigModelCaps(provider, model) {
|
||||
if (!provider || !model) return;
|
||||
const caps = await getModelCapabilities(provider, model);
|
||||
if (!caps) return;
|
||||
host.appendChild(renderCapabilityList(caps));
|
||||
host.appendChild(renderCapabilityBadges(caps));
|
||||
}
|
||||
|
||||
async function saveAIKeys() {
|
||||
@@ -1830,6 +1918,8 @@ export {
|
||||
initProfile,
|
||||
switchSidebarTab,
|
||||
populateVersions,
|
||||
loadAIKeys,
|
||||
saveAIKeys,
|
||||
};
|
||||
|
||||
// Populate every version display (header badge, About modal, help guide footer)
|
||||
|
||||
Reference in New Issue
Block a user