/**
* Session Inspector — right panel with full state rendering
*/
let inspectorEl;
export function initInspector() {
inspectorEl = document.getElementById('inspector');
clearInspector();
}
export function clearInspector() {
if (!inspectorEl) return;
inspectorEl.innerHTML = '
No session selected
';
}
export function updateInspector(session) {
if (!inspectorEl || !session) return;
inspectorEl.innerHTML = '';
// Header
inspectorEl.appendChild(buildSection('Session', `
ID
${session.session_id.substring(0, 16)}...
Status
${session.status}
Turns
${session.turn_count}
Created
${formatTime(session.created_at)}
Updated
${formatTime(session.updated_at)}
`));
// Current Task
if (session.current_task) {
const task = session.current_task;
let taskHtml = `
Objective
${escapeHtml(task.objective)}
Status
${task.status}
Step
${task.current_step_index + 1} / ${(task.plan || []).length}
`;
// Facts
if (task.facts_extracted && task.facts_extracted.length > 0) {
taskHtml += 'Facts:';
for (const f of task.facts_extracted.slice(-8)) {
taskHtml += `- ${escapeHtml(f)}
`;
}
taskHtml += '
';
}
// Constraints
if (task.constraints && task.constraints.length > 0) {
taskHtml += 'Constraints:';
for (const c of task.constraints) {
taskHtml += `- ${escapeHtml(c)}
`;
}
taskHtml += '
';
}
inspectorEl.appendChild(buildSection('Current Task', taskHtml));
// Plan
if (task.plan && task.plan.length > 0) {
let planHtml = '';
for (let i = 0; i < task.plan.length; i++) {
const step = task.plan[i];
const stepStatus = step.status || 'pending';
const isActive = i === task.current_step_index && task.status === 'executing';
const stepClass = isActive ? 'active' : (stepStatus === 'completed' ? 'completed' : stepStatus === 'failed' ? 'failed' : '');
planHtml += `
${escapeHtml(step.description)}
${step.tools_used && step.tools_used.length > 0 ? `
${step.tools_used.map(t => `${escapeHtml(t)}`).join('')}
` : ''}
${step.result_summary ? `
${escapeHtml(step.result_summary.substring(0, 200))}
` : ''}
`;
}
planHtml += '
';
inspectorEl.appendChild(buildSection('Execution Plan', planHtml));
}
}
// Completed tasks
if (session.completed_tasks && session.completed_tasks.length > 0) {
let html = '';
for (const t of session.completed_tasks) {
html += `- ${t}
`;
}
html += '
';
inspectorEl.appendChild(buildSection(`Completed (${session.completed_tasks.length})`, html));
}
}
function buildSection(title, innerHtml) {
const section = document.createElement('div');
section.className = 'inspector-section';
section.innerHTML = `${title}
${innerHtml}`;
return section;
}
function formatTime(isoStr) {
if (!isoStr) return '—';
try {
return new Date(isoStr).toLocaleTimeString('en-US', { hour12: false });
} catch {
return isoStr;
}
}
function escapeHtml(str) {
if (!str) return '';
return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');
}