Add premium My Case MVP

This commit is contained in:
2026-05-23 10:17:34 +02:00
parent e0aeefc73e
commit 83fc71414f
33 changed files with 1275 additions and 148 deletions
+15 -5
View File
@@ -421,7 +421,7 @@ function dbnmDb(): PDO
/**
* True when the current session belongs to an SSO user (Google login).
* All SSO sessions go through the credit + tier system (free, light, pro, pro_plus).
* All SSO sessions go through the credit + tier system (free, plus, pro).
* False for CaveauAI client sessions, which bypass all credit checks.
*
* Note: name is historical — paid SSO users are also subject to the credit gate.
@@ -497,18 +497,22 @@ function dbnToolsCurrentTier(): string
*/
function dbnToolsCaseContext(bool $useMyCase, string $query, int $k = 5): string
{
if (!$useMyCase) return '';
if (!dbnToolsIsFreeTier()) return '';
if (!$useMyCase) { $GLOBALS['dbn_last_case_doc_ids'] = []; return ''; }
if (!dbnToolsIsFreeTier()) { $GLOBALS['dbn_last_case_doc_ids'] = []; return ''; }
$userId = (int)($_SESSION['dbn_tools_sso_uid'] ?? 0);
if ($userId <= 0) return '';
if ($userId <= 0) { $GLOBALS['dbn_last_case_doc_ids'] = []; return ''; }
require_once __DIR__ . '/FreeTier.php';
$tier = FreeTier::tier($userId);
if (!in_array($tier, ['light', 'pro', 'pro_plus'], true)) return '';
if (!FreeTier::isPaidTier($tier)) { $GLOBALS['dbn_last_case_doc_ids'] = []; return ''; }
require_once __DIR__ . '/CaseStore.php';
$effective = CaseStore::caseResolveClientId($userId);
$chunks = CaseStore::caseHybridSearch($effective, $query, $k);
$GLOBALS['dbn_last_case_doc_ids'] = array_values(array_unique(array_map(
static fn($c) => (int)($c['doc_id'] ?? 0),
$chunks
)));
// Audit log: who ran what against whose case
try {
@@ -528,6 +532,12 @@ function dbnToolsCaseContext(bool $useMyCase, string $query, int $k = 5): string
return CaseStore::formatChunksForPrompt($chunks);
}
/** Returns the case_document ids retrieved by the most recent dbnToolsCaseContext() call in this request. */
function dbnToolsLastCaseDocIds(): array
{
return is_array($GLOBALS['dbn_last_case_doc_ids'] ?? null) ? $GLOBALS['dbn_last_case_doc_ids'] : [];
}
/** Read /etc/bnl/intersite.php for the HMAC secret shared between dobetternorge.no and tools.dobetternorge.no. */
function dbnToolsIntersiteSecret(): string
{