mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
2f5e7b5a00
Both endpoints tried to require a non-existent includes/auth.php and call AuthMiddleware::requireAuth() — auth is already handled by api.php before any endpoint file runs. This caused 500 errors on /api/metrics (which blocked agent sparklines) and /api/suggestions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
// Proactive suggestions endpoint — returns time-based command suggestions
|
|
require_once __DIR__ . '/../config.php';
|
|
header('Content-Type: application/json');
|
|
|
|
$hour = (int)date('G');
|
|
$dow = (int)date('w'); // 0=Sun, 6=Sat
|
|
|
|
// Find intents used 3+ times at this hour and day-of-week
|
|
$rows = JarvisDB::query(
|
|
"SELECT intent_name, hit_count FROM usage_patterns
|
|
WHERE hour=? AND dow=? AND hit_count >= 3
|
|
ORDER BY hit_count DESC LIMIT 3",
|
|
[$hour, $dow]
|
|
) ?? [];
|
|
|
|
// Map intents to friendly suggestion prompts
|
|
$intentPrompts = [
|
|
'network_scan' => 'Run a network scan?',
|
|
'jellyfin_now_playing' => 'Check what\'s playing on Jellyfin?',
|
|
'jellyfin_library' => 'Check the Jellyfin library?',
|
|
'ha_scene' => 'Activate a home scene?',
|
|
'planner:briefing' => 'Get your daily briefing?',
|
|
'vm_suggestions' => 'Check VM resource usage?',
|
|
'jellyfin_pause' => 'Pause Jellyfin?',
|
|
'focus_mode' => 'Switch to focus mode?',
|
|
'show_panels' => 'Show all panels?',
|
|
];
|
|
|
|
$suggestions = [];
|
|
foreach ($rows as $r) {
|
|
$intent = $r['intent_name'];
|
|
if (isset($intentPrompts[$intent])) {
|
|
$suggestions[] = [
|
|
'intent' => $intent,
|
|
'prompt' => $intentPrompts[$intent],
|
|
'hit_count' => (int)$r['hit_count'],
|
|
];
|
|
}
|
|
}
|
|
|
|
echo json_encode(['suggestions' => $suggestions, 'hour' => $hour, 'dow' => $dow]);
|