1 Commits

Author SHA1 Message Date
pewdiepie-archdaemon 9c1affe9f5 fix: make agent loopback base port env-configurable (#2752)
_COOKBOOK_BASE was hardcoded to http://localhost:7000 with no env-var
override anywhere in the codebase. Tools that do an internal HTTP
loopback (app_api, trigger_research, cookbook state read/write) silently
fail with "All connection attempts failed" whenever the running uvicorn
isn't on port 7000 — which is most non-default deployments and any
side-by-side multi-instance setup. The misleading "Task triggered"
message from manage_tasks during a research request hides that the
underlying research never starts.

Resolution order, lowest to highest priority:
  1. Fallback http://127.0.0.1:7000 (preserves legacy default).
  2. APP_PORT — derive http://127.0.0.1:$APP_PORT (matches docker-compose
     which already reads APP_PORT).
  3. ODYSSEUS_INTERNAL_BASE — explicit override (e.g. behind a TLS proxy
     where loopback isn't 127.0.0.1).

127.0.0.1 instead of "localhost" avoids IPv6/DNS ambiguity for a
strictly-local call.

No API or schema change. Defaults preserved: existing setups on port
7000 are unaffected.

Caught by #2752.
2026-06-05 12:16:47 +09:00
3 changed files with 17 additions and 103 deletions
+15 -1
View File
@@ -2479,7 +2479,21 @@ async def do_manage_calendar(content: str, owner: Optional[str] = None) -> Dict:
# Cookbook routes loopback. The agent's tool calls run in-process but
# need to reach admin-gated cookbook routes; we ride the per-process
# internal token so require_admin lets us through. See core/middleware.py.
_COOKBOOK_BASE = "http://localhost:7000"
#
# Resolution order:
# 1. ODYSSEUS_INTERNAL_BASE — explicit override (e.g. behind a TLS proxy).
# 2. APP_PORT — derive http://127.0.0.1:$APP_PORT (matches docker-compose).
# 3. Fallback http://127.0.0.1:7000 — preserves legacy default.
#
# 127.0.0.1 (not "localhost") avoids IPv6/DNS ambiguity for a strictly-local
# call. Without this, tools that loop back (app_api, trigger_research,
# cookbook state read/write) fail with "All connection attempts failed"
# whenever the running uvicorn isn't on 7000 — which is most non-default
# deployments and any side-by-side multi-instance setup.
_COOKBOOK_BASE = os.environ.get(
"ODYSSEUS_INTERNAL_BASE",
f"http://127.0.0.1:{os.environ.get('APP_PORT', '7000')}",
)
def _internal_headers(owner: Optional[str] = None) -> Dict[str, str]:
+2 -78
View File
@@ -1783,9 +1783,6 @@ function _renderNotes() {
contentHtml += `<div class="note-checkbox${doneClass}" data-note-id="${note.id}" data-idx="${i}" style="padding-left:${indent * 16}px">
<span class="note-check-dot" title="Mark done"></span>
<span class="note-check-text">${_linkify(item.text)}</span>
<button class="note-checkbox-agent" data-note-id="${note.id}" data-idx="${i}" title="Solve this todo with the agent">
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 8V4H8"/><rect x="4" y="8" width="16" height="12" rx="2"/><path d="M2 14h2M20 14h2M15 13v2M9 13v2"/></svg>
</button>
<button class="note-checkbox-rm" data-note-id="${note.id}" data-idx="${i}" title="Delete item">
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
</button>
@@ -2137,7 +2134,7 @@ function _bindCardEvents(body) {
// Click empty area of checklist preview (not on checkbox/X) — edit
body.querySelectorAll('.note-checklist-preview').forEach(el => {
el.addEventListener('click', (e) => {
if (e.target.closest('.note-checkbox, .note-checkbox-rm, .note-checkbox-agent, .note-cl-quickadd, input')) return;
if (e.target.closest('.note-checkbox, .note-checkbox-rm, .note-cl-quickadd, input')) return;
e.stopPropagation();
tapToEditOrSelect(el.closest('.note-card'));
});
@@ -2163,7 +2160,7 @@ function _bindCardEvents(body) {
// title / content preview triggered edit, so padding + empty gutters were
// dead zones that felt broken on mobile.
if (_isNotesMobileMode() && !_selectMode) {
const _INTERACTIVE = 'button, a, input, label, .note-card-color-dot, .note-checkbox, .note-checkbox-rm, .note-checkbox-agent, .note-cl-quickadd, .note-agent-tag, .note-card-pin, .note-card-corner-trash, .note-card-corner-menu, .note-card-corner-unarchive, .note-card-edit-corner, .note-card-reminder, .note-card-cb';
const _INTERACTIVE = 'button, a, input, label, .note-card-color-dot, .note-checkbox, .note-checkbox-rm, .note-cl-quickadd, .note-agent-tag, .note-card-pin, .note-card-corner-trash, .note-card-corner-menu, .note-card-corner-unarchive, .note-card-edit-corner, .note-card-reminder, .note-card-cb';
body.querySelectorAll('.note-card').forEach(card => {
card.addEventListener('click', (e) => {
if (e.target.closest(_INTERACTIVE)) return;
@@ -2483,19 +2480,6 @@ function _bindCardEvents(body) {
});
});
// Per-item agent solve (hover button next to the X). Scoped to one todo
// item — uses the note title as context if present, but only the single
// item's text as the work. Mirrors the per-note _agentSolveNote pattern.
body.querySelectorAll('.note-checkbox-agent').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
if (_selectMode) return;
const noteId = btn.dataset.noteId;
const idx = parseInt(btn.dataset.idx);
_agentSolveTodoItem(noteId, idx);
});
});
// Quick-add new checklist item (hover input at bottom of todo cards)
body.querySelectorAll('.note-cl-quickadd-input').forEach(input => {
input.addEventListener('click', (e) => e.stopPropagation());
@@ -4386,66 +4370,6 @@ async function _agentSolveNote(id) {
}
}
// Per-item version of _agentSolveNote. Scoped to a single checklist item;
// the note title (if any) is included as context, but only this one item's
// text is the work the agent is asked to do. agent_session_id is set on the
// PARENT note (latest-wins) so the Agent tag still surfaces the most recent
// run from this note — same UX as a per-note solve.
async function _agentSolveTodoItem(noteId, idx) {
const note = _notes.find(n => n.id === noteId);
if (!note || !Array.isArray(note.items)) return;
const item = note.items[idx];
const itemText = (item && (item.text || '').trim()) || '';
if (!itemText) {
uiModule.showToast('Nothing to solve — item is empty');
return;
}
const titleCtx = (note.title || '').trim();
const prompt = titleCtx
? `Context (from note "${titleCtx}").\n\nHelp me with this todo: ${itemText}`
: `Help me with this todo: ${itemText}`;
try {
const dc = await (await fetch(`${API_BASE}/api/default-chat`, { credentials: 'same-origin' })).json();
if (!dc.endpoint_url || !dc.model) { uiModule.showError('No default chat model configured'); return; }
const label = itemText.slice(0, 40);
const csFd = new FormData();
csFd.append('name', 'Agent: ' + label);
csFd.append('endpoint_url', dc.endpoint_url);
csFd.append('model', dc.model);
if (dc.endpoint_id) csFd.append('endpoint_id', dc.endpoint_id);
csFd.append('skip_validation', 'true');
const csRes = await fetch(`${API_BASE}/api/session`, { method: 'POST', credentials: 'same-origin', body: csFd });
if (!csRes.ok) { uiModule.showError('Could not create agent session'); return; }
const sess = await csRes.json();
const sid = sess.id;
const n = _notes.find(x => x.id === noteId);
if (n) n.agent_session_id = sid;
_renderNotes();
_patchNote(noteId, { agent_session_id: sid }).catch(() => {});
const fd = new FormData();
fd.append('message', prompt);
fd.append('session', sid);
fd.append('mode', 'agent');
fetch(`${API_BASE}/api/chat_stream`, { method: 'POST', credentials: 'same-origin', body: fd })
.then(async (res) => {
if (!res.ok || !res.body) return;
const reader = res.body.getReader();
while (true) { const { done } = await reader.read(); if (done) break; }
if (window.sessionModule && window.sessionModule.markStreamComplete) {
try { window.sessionModule.markStreamComplete(sid); } catch {}
}
})
.catch(() => {});
uiModule.showToast('Agent working on this item — tap the Agent tag when ready');
} catch (e) {
uiModule.showError('Agent failed: ' + (e.message || e));
}
}
async function _copyNote(noteId, btnEl) {
const note = _notes.find(n => n.id === noteId);
if (!note) return false;
-24
View File
@@ -32126,30 +32126,6 @@ body.notes-mobile-mode.notes-drag-mode .note-card-pin.active {
.note-checkbox:hover .note-checkbox-rm { opacity: 0.55; }
.note-checkbox-rm:hover { opacity: 1 !important; color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.note-card-selectmode .note-checkbox-rm { display: none; }
/* Per-item "solve with agent" button mirrors .note-checkbox-rm visually
so the two hover-actions on a todo item read as a pair. Sits to the left
of the X (DOM order = agent then X), both pushed to the right via the
shared margin-left:auto pattern. */
.note-checkbox-agent {
flex: 0 0 auto;
background: transparent;
border: none;
color: var(--fg);
opacity: 0;
cursor: pointer;
padding: 2px;
border-radius: 3px;
display: flex;
align-items: center;
justify-content: center;
margin-left: auto;
margin-right: 0;
transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.note-checkbox:hover .note-checkbox-agent { opacity: 0.55; }
.note-checkbox-agent:hover { opacity: 1 !important; color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.note-card-selectmode .note-checkbox-agent { display: none; }
.note-check-dot {
width: 16px;
height: 16px;