diff --git a/api/document-chunks.php b/api/document-chunks.php index fdc375c..87274b2 100644 --- a/api/document-chunks.php +++ b/api/document-chunks.php @@ -18,7 +18,13 @@ try { $ragDb = dbnToolsRagDb(); - $docStmt = $ragDb->prepare("SELECT id, title FROM documents WHERE id = ? LIMIT 1"); + $docStmt = $ragDb->prepare(" + SELECT d.id, d.title, ds.summary AS ai_summary, ds.summary_model + FROM documents d + LEFT JOIN doc_summaries ds ON ds.document_id = d.id + WHERE d.id = ? + LIMIT 1 + "); $docStmt->execute([$documentId]); $doc = $docStmt->fetch(PDO::FETCH_ASSOC); if (!$doc) { @@ -44,7 +50,12 @@ try { echo json_encode([ 'ok' => true, - 'document' => ['id' => (int)$doc['id'], 'title' => (string)$doc['title']], + 'document' => [ + 'id' => (int)$doc['id'], + 'title' => (string)$doc['title'], + 'ai_summary' => $doc['ai_summary'] ?? null, + 'summary_model' => $doc['summary_model'] ?? null, + ], 'chunks' => $chunks, ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);