diff --git a/static/js/core/agents.js b/static/js/core/agents.js index 95e5f46..37789e7 100644 --- a/static/js/core/agents.js +++ b/static/js/core/agents.js @@ -658,22 +658,30 @@ async function refreshAgentDevices(agentId) { console.log('Agent data received:', data); if (data.agent && data.agent.interfaces) { - const devices = data.agent.interfaces.devices || []; + // Agent stores SDR devices in interfaces.sdr_devices (matching local mode) + const devices = data.agent.interfaces.sdr_devices || data.agent.interfaces.devices || []; console.log(`Found ${devices.length} devices on agent`); - populateDeviceSelect(devices); - // Update SDR type dropdown if device has sdr_type - if (devices.length > 0 && devices[0].sdr_type) { + // Auto-select SDR type if devices found + if (devices.length > 0) { + const firstType = devices[0].sdr_type || 'rtlsdr'; const sdrTypeSelect = document.getElementById('sdrTypeSelect'); if (sdrTypeSelect) { - sdrTypeSelect.value = devices[0].sdr_type; + sdrTypeSelect.value = firstType; } } + + // Directly populate device dropdown for agent mode + // (Don't use onSDRTypeChanged since currentDeviceList is template-scoped) + populateDeviceSelect(devices); } else { - console.warn('No interfaces found in agent data'); + console.warn('No interfaces found in agent data:', data); + // Show empty devices + populateDeviceSelect([]); } } catch (error) { console.error('Failed to refresh agent devices:', error); + populateDeviceSelect([]); } } diff --git a/static/js/modes/bluetooth.js b/static/js/modes/bluetooth.js index f6b3cee..2972c0c 100644 --- a/static/js/modes/bluetooth.js +++ b/static/js/modes/bluetooth.js @@ -650,10 +650,17 @@ const BluetoothMode = (function() { async function checkScanStatus() { try { - const response = await fetch('/api/bluetooth/scan/status'); - const data = await response.json(); + const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local'; + const endpoint = isAgentMode + ? `/controller/agents/${currentAgent}/bluetooth/status` + : '/api/bluetooth/scan/status'; - if (data.is_scanning) { + const response = await fetch(endpoint); + const responseData = await response.json(); + // Handle agent response format (may be nested in 'result') + const data = isAgentMode && responseData.result ? responseData.result : responseData; + + if (data.is_scanning || data.running) { setScanning(true); startEventStream(); } diff --git a/static/js/modes/wifi.js b/static/js/modes/wifi.js index 231ac3f..5dd2920 100644 --- a/static/js/modes/wifi.js +++ b/static/js/modes/wifi.js @@ -571,12 +571,19 @@ const WiFiMode = (function() { async function checkScanStatus() { try { - const response = await fetch(`${CONFIG.apiBase}/scan/status`); + const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local'; + const endpoint = isAgentMode + ? `/controller/agents/${currentAgent}/wifi/status` + : `${CONFIG.apiBase}/scan/status`; + + const response = await fetch(endpoint); if (!response.ok) return; - const status = await response.json(); + const data = await response.json(); + // Handle agent response format (may be nested in 'result') + const status = isAgentMode && data.result ? data.result : data; - if (status.is_scanning) { + if (status.is_scanning || status.running) { setScanning(true, status.scan_mode); if (status.scan_mode === 'deep') { startEventStream(); diff --git a/templates/index.html b/templates/index.html index c27c90d..3fe1508 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3447,13 +3447,22 @@ } function checkStatus() { - fetch('/status') + const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local'; + const endpoint = isAgentMode + ? `/controller/agents/${currentAgent}/pager/status` + : '/status'; + + fetch(endpoint) .then(r => r.json()) .then(data => { - if (data.running !== isRunning) { - setRunning(data.running); - if (data.running && !eventSource) { - startStream(); + // Handle agent response format (may be nested in 'result') + const statusData = isAgentMode && data.result ? data.result : data; + const running = statusData.running; + + if (running !== isRunning) { + setRunning(running); + if (running && !eventSource) { + startStream(isAgentMode); } } })