diff --git a/api/endpoints/agent.php b/api/endpoints/agent.php index f7ee21b..f768250 100644 --- a/api/endpoints/agent.php +++ b/api/endpoints/agent.php @@ -37,11 +37,18 @@ function get_agent_by_key(string $key): ?array { return $rows[0] ?? null; } -function update_agent_seen(string $agentId, string $status = 'online'): void { - JarvisDB::query( - 'UPDATE registered_agents SET last_seen = NOW(), status = ? WHERE agent_id = ?', - [$status, $agentId] - ); +function update_agent_seen(string $agentId, string $status = 'online', ?string $version = null): void { + if ($version !== null) { + JarvisDB::query( + 'UPDATE registered_agents SET last_seen = NOW(), status = ?, version = ? WHERE agent_id = ?', + [$status, $version, $agentId] + ); + } else { + JarvisDB::query( + 'UPDATE registered_agents SET last_seen = NOW(), status = ? WHERE agent_id = ?', + [$status, $agentId] + ); + } } // ── Auth (all actions except register) ─────────────────────────────────────── @@ -104,7 +111,7 @@ switch ($agentAction) { // ── HEARTBEAT ──────────────────────────────────────────────────────────── case 'heartbeat': - update_agent_seen($agent['agent_id']); + update_agent_seen($agent['agent_id'], 'online', trim($data['version'] ?? '') ?: null); // Return any pending commands for this agent $commands = JarvisDB::query(