mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-15 17:25:26 -04:00
Merge remote-tracking branch 'origin/dev'
This commit is contained in:
+111
-11
@@ -13,6 +13,10 @@ let modalEl = null;
|
||||
|
||||
function el(id) { return document.getElementById(id); }
|
||||
function esc(s) { return uiModule.esc(s); }
|
||||
function safeRasterDataUrl(raw) {
|
||||
const value = String(raw || '').trim();
|
||||
return /^data:image\/(?:png|jpe?g|gif|webp);base64,[a-z0-9+/=\s]+$/i.test(value) ? value : '';
|
||||
}
|
||||
|
||||
/* ── Tab switching ── */
|
||||
const ADMIN_TABS = new Set(['services', 'integrations', 'tools', 'users', 'system']);
|
||||
@@ -1554,6 +1558,7 @@ async function initResearchSearchSettings() {
|
||||
/* ── Agent Settings (AI tab) ── */
|
||||
async function initAgentSettings() {
|
||||
var toolsInput = el('set-agentMaxTools');
|
||||
var roundsInput = el('set-agentMaxRounds');
|
||||
var msg = el('set-agentMsg');
|
||||
if (!toolsInput) return;
|
||||
|
||||
@@ -1561,23 +1566,41 @@ async function initAgentSettings() {
|
||||
var res = await fetch('/api/auth/settings', { credentials: 'same-origin' });
|
||||
var settings = await res.json();
|
||||
if (settings.agent_max_tool_calls) toolsInput.value = settings.agent_max_tool_calls;
|
||||
if (roundsInput && settings.agent_max_rounds) roundsInput.value = settings.agent_max_rounds;
|
||||
} catch (e) {}
|
||||
|
||||
// Clamp + coerce a raw input to an int in [lo, hi]; falls back to `dflt`
|
||||
// when blank/non-numeric. Mirrors the server-side validation.
|
||||
function clampInt(raw, lo, hi, dflt) {
|
||||
var n = parseInt(raw, 10);
|
||||
if (isNaN(n)) return dflt;
|
||||
return Math.max(lo, Math.min(n, hi));
|
||||
}
|
||||
|
||||
async function save() {
|
||||
var val = parseInt(toolsInput.value, 10) || 0;
|
||||
var tools = clampInt(toolsInput.value, 0, 1000, 0);
|
||||
var rounds = roundsInput ? clampInt(roundsInput.value, 1, 200, 20) : null;
|
||||
toolsInput.value = tools; // reflect the clamped value
|
||||
if (roundsInput) roundsInput.value = rounds;
|
||||
var payload = { agent_max_tool_calls: tools };
|
||||
if (rounds != null) payload.agent_max_rounds = rounds;
|
||||
try {
|
||||
await fetch('/api/auth/settings', { method: 'POST', credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ agent_max_tool_calls: val })
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
msg.textContent = val > 0 ? 'Limit: ' + val + ' tool calls per message' : 'Unlimited';
|
||||
msg.textContent = (tools > 0 ? 'Limit: ' + tools + ' tool calls' : 'Unlimited tool calls') +
|
||||
(rounds != null ? ' · ' + rounds + ' steps/message' : '');
|
||||
msg.style.color = 'var(--fg)';
|
||||
} catch (e) { msg.textContent = 'Failed to save'; msg.style.color = 'var(--red)'; }
|
||||
}
|
||||
|
||||
toolsInput.addEventListener('change', save);
|
||||
if (roundsInput) roundsInput.addEventListener('change', save);
|
||||
var cur = parseInt(toolsInput.value, 10) || 0;
|
||||
msg.textContent = cur > 0 ? 'Limit: ' + cur + ' tool calls per message' : 'Unlimited';
|
||||
var curR = roundsInput ? (parseInt(roundsInput.value, 10) || 20) : null;
|
||||
msg.textContent = (cur > 0 ? 'Limit: ' + cur + ' tool calls' : 'Unlimited tool calls') +
|
||||
(curR != null ? ' · ' + curR + ' steps/message' : '');
|
||||
}
|
||||
|
||||
/* ═══════════════════════════════════════════
|
||||
@@ -2069,15 +2092,16 @@ function initAccount() {
|
||||
const r = await fetch('/api/auth/2fa/setup', { method: 'POST', credentials: 'same-origin' });
|
||||
if (!r.ok) { const d = await r.json(); throw new Error(d.detail || 'Failed'); }
|
||||
const setup = await r.json();
|
||||
const qrCode = safeRasterDataUrl(setup.qr_code);
|
||||
// Show QR code + manual secret + verify input
|
||||
tfaContent.innerHTML = `
|
||||
<div style="text-align:center;margin-bottom:12px;">
|
||||
<img src="${setup.qr_code}" alt="QR Code" style="border-radius:8px;max-width:200px;">
|
||||
${qrCode ? `<img src="${esc(qrCode)}" alt="QR Code" style="border-radius:8px;max-width:200px;">` : ''}
|
||||
</div>
|
||||
<div style="font-size:11px;opacity:0.5;text-align:center;margin-bottom:8px;">
|
||||
Scan with your authenticator app, or enter manually:
|
||||
</div>
|
||||
<div style="font-family:monospace;font-size:12px;text-align:center;padding:6px;background:var(--bg);border:1px solid var(--border);border-radius:4px;margin-bottom:12px;word-break:break-all;user-select:all;cursor:text;">${setup.secret}</div>
|
||||
<div style="font-family:monospace;font-size:12px;text-align:center;padding:6px;background:var(--bg);border:1px solid var(--border);border-radius:4px;margin-bottom:12px;word-break:break-all;user-select:all;cursor:text;">${esc(setup.secret)}</div>
|
||||
<input id="tfa-verify-code" type="text" placeholder="Enter 6-digit code to verify" autocomplete="one-time-code" inputmode="numeric" maxlength="8" style="width:100%;padding:8px;background:var(--bg);border:1px solid var(--border);border-radius:4px;color:var(--fg);font-family:inherit;font-size:13px;box-sizing:border-box;text-align:center;letter-spacing:3px;margin-bottom:6px;">
|
||||
<div class="settings-row" style="justify-content:flex-end;">
|
||||
<span id="tfa-msg" style="font-size:11px;margin-right:auto;"></span>
|
||||
@@ -4424,6 +4448,68 @@ async function initUnifiedIntegrations() {
|
||||
|
||||
// ── MCP form — full management view ──
|
||||
async function showMcpForm(editId) {
|
||||
// Toggle an in-flight loading state on a button (disabled + dimmed + label).
|
||||
function _setBtnLoading(btn, loading, label) {
|
||||
if (!btn) return;
|
||||
btn.disabled = loading;
|
||||
btn.style.opacity = loading ? '0.6' : '';
|
||||
btn.style.cursor = loading ? 'progress' : '';
|
||||
if (label != null) btn.textContent = label;
|
||||
}
|
||||
function _showMcpPasteback(id) {
|
||||
const msg = el('uf-mcp-msg'); if (!msg) return;
|
||||
if (el('uf-mcp-pasteback')) return; // already shown
|
||||
msg.innerHTML =
|
||||
'Authorize in the opened tab. If the redirect fails (remote access), paste the resulting URL here: ' +
|
||||
'<input id="uf-mcp-pasteback" class="settings-input" placeholder="http://localhost:7000/api/mcp/oauth/callback?code=..." style="margin-top:4px">' +
|
||||
'<button class="admin-btn-sm" id="uf-mcp-paste-go" style="margin-top:4px">Submit</button>';
|
||||
const pasteGo = el('uf-mcp-paste-go');
|
||||
if (pasteGo) pasteGo.addEventListener('click', async () => {
|
||||
const cb = el('uf-mcp-pasteback').value.trim();
|
||||
if (!cb) return;
|
||||
const pf = new FormData(); pf.append('callback_url', cb);
|
||||
_setBtnLoading(pasteGo, true, 'Submitting…');
|
||||
try {
|
||||
await fetch(`/api/mcp/oauth/exchange/${id}`, { method: 'POST', credentials: 'same-origin', body: pf });
|
||||
} finally {
|
||||
_setBtnLoading(pasteGo, false, 'Submit');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Drives the OAuth flow: waits for the auth_url (discovery+DCR may lag),
|
||||
// opens it once, then resolves on connected/error.
|
||||
async function _handleMcpAuth(id, initialAuthUrl, tries = 90) {
|
||||
let opened = false;
|
||||
const openAuth = (u) => { if (!opened && u) { opened = true; window.open(u, '_blank', 'noopener'); _showMcpPasteback(id); } };
|
||||
openAuth(initialAuthUrl);
|
||||
const msg = el('uf-mcp-msg');
|
||||
let fails = 0;
|
||||
for (let i = 0; i < tries; i++) {
|
||||
await new Promise(res => setTimeout(res, 2000));
|
||||
try {
|
||||
const r = await fetch('/api/mcp/servers', { credentials: 'same-origin' });
|
||||
if (!r.ok) throw new Error('HTTP ' + r.status);
|
||||
const list = await r.json();
|
||||
fails = 0;
|
||||
const s = Array.isArray(list) ? list.find(x => x.id === id) : null;
|
||||
if (!s) continue;
|
||||
if (s.auth_url) openAuth(s.auth_url);
|
||||
if (s.status === 'connected') {
|
||||
if (msg) msg.textContent = `Connected (${s.tool_count || 0} tools)`;
|
||||
await renderList(); return;
|
||||
}
|
||||
if (s.status === 'error') {
|
||||
if (msg) msg.textContent = `Failed: ${s.error || 'unknown'}`; return;
|
||||
}
|
||||
} catch (e) {
|
||||
// Tolerate a single blip, but surface persistent failures instead of
|
||||
// silently polling until timeout.
|
||||
if (++fails >= 5 && msg) msg.textContent = `Status check failing (${e.message || 'network error'}) — still retrying…`;
|
||||
}
|
||||
}
|
||||
if (msg) msg.textContent = 'Authorization timed out. Reconnect from the server list to retry.';
|
||||
}
|
||||
if (editId && editId !== 'new') {
|
||||
// Show management view for existing server
|
||||
formEl.innerHTML = '<div class="admin-card" style="margin-top:8px"><span style="opacity:0.5;font-size:11px">Loading...</span></div>';
|
||||
@@ -4501,7 +4587,7 @@ async function initUnifiedIntegrations() {
|
||||
<h2 style="font-size:13px">Add MCP Server</h2>
|
||||
<div class="settings-col">
|
||||
<div class="settings-row"><label class="settings-label">Name</label><input id="uf-mcp-name" class="settings-input" placeholder="Server name"></div>
|
||||
<div class="settings-row"><label class="settings-label">Transport</label><select id="uf-mcp-transport" class="settings-input"><option value="stdio">stdio</option><option value="sse">SSE</option></select></div>
|
||||
<div class="settings-row"><label class="settings-label">Transport</label><select id="uf-mcp-transport" class="settings-input"><option value="stdio">stdio</option><option value="sse">SSE</option><option value="http">Streamable HTTP</option></select></div>
|
||||
<div id="uf-mcp-stdio-fields" style="display:flex;flex-direction:column;gap:6px;">
|
||||
<div class="settings-row"><label class="settings-label">Command</label><input id="uf-mcp-cmd" class="settings-input" placeholder="npx"></div>
|
||||
<div class="settings-row"><label class="settings-label">Args</label><input id="uf-mcp-args" class="settings-input" placeholder='["-y", "@modelcontextprotocol/server-filesystem"]'></div>
|
||||
@@ -4514,9 +4600,12 @@ async function initUnifiedIntegrations() {
|
||||
</div>
|
||||
</div>`;
|
||||
el('uf-mcp-transport').addEventListener('change', () => {
|
||||
const sse = el('uf-mcp-transport').value === 'sse';
|
||||
el('uf-mcp-stdio-fields').style.display = sse ? 'none' : 'flex';
|
||||
el('uf-mcp-sse-fields').style.display = sse ? 'flex' : 'none';
|
||||
const v = el('uf-mcp-transport').value;
|
||||
const isUrl = (v === 'sse' || v === 'http');
|
||||
el('uf-mcp-stdio-fields').style.display = isUrl ? 'none' : 'flex';
|
||||
el('uf-mcp-sse-fields').style.display = isUrl ? 'flex' : 'none';
|
||||
const urlInput = el('uf-mcp-url');
|
||||
if (urlInput) urlInput.placeholder = (v === 'http') ? 'https://mcp.example.com/mcp' : 'http://localhost:3001/sse';
|
||||
});
|
||||
el('uf-mcp-cancel').addEventListener('click', () => { formEl.style.display = 'none'; });
|
||||
el('uf-mcp-save').addEventListener('click', async () => {
|
||||
@@ -4534,14 +4623,25 @@ async function initUnifiedIntegrations() {
|
||||
} else {
|
||||
fd.append('url', el('uf-mcp-url').value);
|
||||
}
|
||||
const saveBtn = el('uf-mcp-save'), cancelBtn = el('uf-mcp-cancel');
|
||||
const _origLabel = saveBtn.textContent;
|
||||
_setBtnLoading(saveBtn, true, 'Saving…'); if (cancelBtn) cancelBtn.disabled = true;
|
||||
try {
|
||||
const r = await fetch('/api/mcp/servers', { method: 'POST', credentials: 'same-origin', body: fd });
|
||||
if (r.ok) {
|
||||
const data = await r.json().catch(() => ({}));
|
||||
if (r.ok && data.needs_auth) {
|
||||
el('uf-mcp-msg').textContent = 'Preparing authorization…';
|
||||
_handleMcpAuth(data.id, data.auth_url);
|
||||
} else if (r.ok && (data.connected || data.status === 'connected')) {
|
||||
el('uf-mcp-msg').textContent = `Connected (${data.tool_count || 0} tools)`;
|
||||
formEl.style.display = 'none'; await renderList();
|
||||
} else if (r.ok) {
|
||||
el('uf-mcp-msg').textContent = 'Saved'; formEl.style.display = 'none'; await renderList();
|
||||
} else {
|
||||
el('uf-mcp-msg').textContent = `Failed (${r.status})`;
|
||||
}
|
||||
} catch (_) { el('uf-mcp-msg').textContent = 'Failed'; }
|
||||
finally { _setBtnLoading(saveBtn, false, _origLabel); if (cancelBtn) cancelBtn.disabled = false; }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user