$validActions] ); } if ($docId <= 0) { dbnToolsError('doc_id must be a positive integer.', 400, 'missing_doc_id'); } $root = dbnToolsAiPortalRoot(); $graphFile = $root . '/lib/ai/GraphClient.php'; $agentFile = $root . '/lib/ai/LegalGraphAgent.php'; if (!is_file($graphFile) || !is_file($agentFile)) { dbnToolsError('Graph backend not installed.', 503, 'graph_unavailable'); } require_once $graphFile; require_once $agentFile; try { $config = file_exists('/etc/bnl/config.php') ? include '/etc/bnl/config.php' : []; $host = (string)($config['falkordb']['host'] ?? dbnToolsEnv('DBN_FALKORDB_HOST', '10.0.2.10')); $port = (int) ($config['falkordb']['port'] ?? (int)dbnToolsEnv('DBN_FALKORDB_PORT', '6379')); $pass = (string)($config['falkordb']['password'] ?? dbnToolsEnv('DBN_FALKORDB_PASSWORD', '')); $client = new GraphClient($host, $port, $pass); $agent = new LegalGraphAgent($client); $results = match ($action) { 'cites' => $agent->cites($docId, $limit), 'cited_by' => $agent->citedBy($docId, $limit), 'implements' => $agent->implements($docId, $limit), 'chain' => $agent->chain($docId, $depth), }; } catch (Throwable $e) { dbnToolsRespond([ 'ok' => true, 'action' => $action, 'doc_id' => $docId, 'count' => 0, 'results' => [], 'warning' => 'Graph backend unavailable: ' . $e->getMessage(), ]); } dbnToolsRespond([ 'ok' => true, 'action' => $action, 'doc_id' => $docId, 'count' => count($results), 'results' => $results, ]);