Add sub-question branching + document summary modals
- Source modal now shows LLM-generated document summary (lazy-gen + cached in documents.summary) instead of raw chunk text; toggle reveals matched chunk; "View all chunks" button fetches every chunk of the document via new api/document-chunks.php endpoint - Each sub-question card gets a "Branch ↓" button that pre-fills the query with that sub-question and shows a context panel with the prior brief summary; prior_context + branch_notes are injected into interpretSeed() and synthesise() so the LLM knows where the research is coming from - Upload document summaries generated at synthesis time and attached to upload sources alongside corpus summaries - DB: documents.summary TEXT column added to bnl_corpus on chloe Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../includes/bootstrap.php';
|
||||
|
||||
dbnToolsRequireMethod('GET');
|
||||
dbnToolsRequireAuth();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store');
|
||||
|
||||
try {
|
||||
$documentId = isset($_GET['document_id']) ? (int)$_GET['document_id'] : 0;
|
||||
if ($documentId <= 0) {
|
||||
echo json_encode(['ok' => false, 'error' => 'document_id is required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$ragDb = dbnToolsRagDb();
|
||||
|
||||
$docStmt = $ragDb->prepare("SELECT id, title FROM documents WHERE id = ? LIMIT 1");
|
||||
$docStmt->execute([$documentId]);
|
||||
$doc = $docStmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$doc) {
|
||||
echo json_encode(['ok' => false, 'error' => 'Document not found']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$chunkStmt = $ragDb->prepare("
|
||||
SELECT chunk_index, section_title, content
|
||||
FROM chunks
|
||||
WHERE document_id = ?
|
||||
ORDER BY chunk_index ASC
|
||||
");
|
||||
$chunkStmt->execute([$documentId]);
|
||||
$chunks = [];
|
||||
foreach ($chunkStmt as $row) {
|
||||
$chunks[] = [
|
||||
'chunk_index' => (int)$row['chunk_index'],
|
||||
'section_title' => $row['section_title'] ?? null,
|
||||
'content' => (string)$row['content'],
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'document' => ['id' => (int)$doc['id'], 'title' => (string)$doc['title']],
|
||||
'chunks' => $chunks,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
error_log('DBN document-chunks error: ' . $e->getMessage());
|
||||
echo json_encode(['ok' => false, 'error' => 'Internal error']);
|
||||
}
|
||||
Reference in New Issue
Block a user