feat: proper confirmation-resume flow + per-user tool policy
Fixes the broken confirmation gate where users had no way to approve
or deny a blocked tool call in the web UI.
Changes:
- orchestrator_engine.py: add OrchestrateCheckpoint dataclass, extract
loop into _run_from_contents(), add resume() function
- openai_orchestrator.py: same treatment — _run_from_messages(), resume()
- routers/orchestrator.py: POST /{job_id}/confirm and /deny endpoints,
separate _checkpoints store, _resume_job() + _finalize_job() helpers,
"awaiting_confirmation" job status with pending_confirmation payload
- auth_utils.py: get_tool_policy() and save_tool_policy() helpers reading
home/{user}/tool_policy.json (allow/deny lists)
- routers/orchestrator.py: loads tool_policy per user and passes
confirm_allow/confirm_deny to both engines
- app.js: poll loop handles awaiting_confirmation — shows Confirm/Deny
buttons inline, resumes polling after user action
- settings.html + settings.py: Tool Permissions section with allow/deny
textareas, POST /settings/tool-policy route
- style.css: .confirm-gate, .confirm-btn, .deny-btn styles
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1192,6 +1192,37 @@
|
||||
: '⚡ working…';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (job.status === 'awaiting_confirmation') {
|
||||
const pc = job.pending_confirmation || {};
|
||||
const toolNames = (pc.tools || []).map(t => t.name).join(', ');
|
||||
thinkingDiv.className = 'message assistant';
|
||||
thinkingDiv.innerHTML = `<div class="confirm-gate">
|
||||
<p>${escapeHtml(pc.message || 'Confirm this action?')}</p>
|
||||
<p class="confirm-tools">Tool${(pc.tools||[]).length !== 1 ? 's' : ''}: <code>${escapeHtml(toolNames)}</code></p>
|
||||
<div class="confirm-actions">
|
||||
<button class="confirm-btn">Confirm</button>
|
||||
<button class="deny-btn">Deny</button>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
const confirmed = await new Promise(resolve => {
|
||||
thinkingDiv.querySelector('.confirm-btn').onclick = () => resolve(true);
|
||||
thinkingDiv.querySelector('.deny-btn').onclick = () => resolve(false);
|
||||
});
|
||||
|
||||
thinkingDiv.className = 'message assistant thinking';
|
||||
thinkingDiv.textContent = confirmed ? '⚡ confirmed — continuing…' : '⚡ denied — finishing…';
|
||||
|
||||
const action = confirmed ? 'confirm' : 'deny';
|
||||
const resumeRes = await fetch(`/orchestrate/${job_id}/${action}`, {
|
||||
method: 'POST',
|
||||
signal: activeController.signal,
|
||||
});
|
||||
if (!resumeRes.ok) throw new Error(`Resume failed: HTTP ${resumeRes.status}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user