diff --git a/api/redact.php b/api/redact.php index ae6acd5..4126347 100644 --- a/api/redact.php +++ b/api/redact.php @@ -5,8 +5,15 @@ require_once __DIR__ . '/../includes/LegalTools.php'; dbnToolsRequireMethod('POST'); dbnToolsRequireAuth(); -$ftUid = dbnToolsFreeTierCheck('redact'); + +// Determine engine and its credit cost before the pre-flight credit check $input = dbnToolsJsonInput(400000); +$_validEngines = ['azure_mini', 'azure_full']; +$_engine = in_array((string)($input['engine'] ?? ''), $_validEngines, true) + ? (string)$input['engine'] : 'azure_mini'; +$_engineCredits = $_engine === 'azure_full' ? 2 : 1; + +$ftUid = dbnToolsFreeTierCheckAmount('redact', $_engineCredits); dbnToolsWithChargedTelemetry('redact', '', $ftUid, function () use ($input): array { $text = dbnToolsInjectDocContent($input, dbnToolsString($input, 'text', 128000, false)); @@ -17,7 +24,7 @@ dbnToolsWithChargedTelemetry('redact', '', $ftUid, function () use ($input): arr $region = dbnToolsNormalizeRegion($input['region'] ?? 'nordic'); $language = dbnToolsNormalizeLanguage($input['language'] ?? 'en'); - $validEngines = ['azure_mini', 'azure_full', 'gpu', 'regex']; + $validEngines = ['azure_mini', 'azure_full']; $engine = in_array((string)($input['engine'] ?? ''), $validEngines, true) ? (string)$input['engine'] : 'azure_mini'; @@ -67,4 +74,4 @@ dbnToolsWithChargedTelemetry('redact', '', $ftUid, function () use ($input): arr $text, $mode, $region, $language, $aliases, $engine, $outputFormat, $keepOfficials, $exemptNames, $redactTypes ); -}); +}, $_engineCredits); diff --git a/api/save-to-corpus.php b/api/save-to-corpus.php index 9698200..c3d3c9d 100644 --- a/api/save-to-corpus.php +++ b/api/save-to-corpus.php @@ -35,6 +35,13 @@ $tags = json_encode( JSON_UNESCAPED_UNICODE ); +$rawSourceDocIds = $input['source_doc_ids'] ?? null; +$sourceDocIdArr = is_array($rawSourceDocIds) + ? $rawSourceDocIds + : (is_string($rawSourceDocIds) ? array_filter(array_map('trim', explode(',', $rawSourceDocIds))) : []); +$firstSourceDocId = (int)(reset($sourceDocIdArr) ?: 0); +$sourceUrl = $firstSourceDocId > 0 ? "corpus-doc:{$firstSourceDocId}" : null; + if ($title === '') { dbnToolsError('title is required.', 400, 'bad_request'); } @@ -71,10 +78,10 @@ $wordCount = str_word_count($content); $ins = $db->prepare(" INSERT INTO client_documents (client_id, corpus_id, title, source_type, content, category, - tags, import_method, source_tool, word_count, status) - VALUES (?, ?, ?, 'text', ?, 'tool-output', ?, 'tool_output', ?, ?, 'pending') + tags, import_method, source_tool, source_url, word_count, status) + VALUES (?, ?, ?, 'text', ?, 'tool-output', ?, 'tool_output', ?, ?, ?, 'pending') "); -$ins->execute([$clientId, $corpusId, $title, $content, $tags, $sourceTool, $wordCount]); +$ins->execute([$clientId, $corpusId, $title, $content, $tags, $sourceTool, $sourceUrl, $wordCount]); $docId = (int)$db->lastInsertId(); try { diff --git a/assets/css/doc-picker.css b/assets/css/doc-picker.css index 1ef3313..0690b3c 100644 --- a/assets/css/doc-picker.css +++ b/assets/css/doc-picker.css @@ -270,3 +270,23 @@ transition: border-color 0.15s, color 0.15s; } .audio-corpus-upload:hover { border-color: var(--dbn-accent, #00205B); color: var(--dbn-accent, #00205B); } + + +/* ── Redacted document badge ─────────────────────────────────────────────── */ + +.doc-item__badge { + display: inline-block; + margin-left: 0.45em; + padding: 0.1em 0.45em; + border-radius: 4px; + font-size: 0.72rem; + font-weight: 600; + vertical-align: middle; + line-height: 1.4; +} + +.doc-item__badge--redact { + background: #ede8f7; + color: #5b35a8; + border: 1px solid rgba(91, 53, 168, 0.2); +} diff --git a/assets/css/tools.css b/assets/css/tools.css index 0baae97..774a013 100644 --- a/assets/css/tools.css +++ b/assets/css/tools.css @@ -2266,6 +2266,38 @@ p { cursor: progress; } +@keyframes redact-spin { + to { transform: rotate(360deg); } +} + +.redact-working { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 12px; + padding: 32px 16px; + border: 1px solid var(--line); + border-radius: 8px; + background: #fbfcfe; +} + +.redact-working p { + margin: 0; + color: var(--muted); + font-size: 0.92rem; +} + +.redact-working__spinner { + display: block; + width: 22px; + height: 22px; + border: 3px solid var(--line); + border-top-color: var(--teal); + border-radius: 50%; + animation: redact-spin 0.9s linear infinite; +} + /* ── Feedback widget ──────────────────────────────────────────── */ .feedback-widget { margin-top: 1.5rem; diff --git a/assets/js/corpus-save.js b/assets/js/corpus-save.js index 92a9c52..8543f04 100644 --- a/assets/js/corpus-save.js +++ b/assets/js/corpus-save.js @@ -41,6 +41,7 @@ } function bodyFor(kind, payload) { + const sourceDocIds = (payload.sourceDocIds || '').split(',').map(s => s.trim()).filter(Boolean); if (window.DBN_DASHBOARD) { return JSON.stringify({ title: payload.title, @@ -48,6 +49,7 @@ source_tool: payload.tool || 'dashboard-save', tags: payload.tags, kind, + ...(sourceDocIds.length ? { source_doc_ids: sourceDocIds } : {}), }); } return JSON.stringify({ @@ -55,6 +57,7 @@ content: payload.content, source_tool: payload.tool || '', tags: payload.tags, + ...(sourceDocIds.length ? { source_doc_ids: sourceDocIds } : {}), }); } @@ -74,9 +77,10 @@ } _pendingBtn = btn; - dlg.dataset.pendingContent = content; - dlg.dataset.pendingTool = btn.dataset.tool || ''; - dlg.dataset.pendingKind = 'tool_output'; + dlg.dataset.pendingContent = content; + dlg.dataset.pendingTool = btn.dataset.tool || ''; + dlg.dataset.pendingKind = 'tool_output'; + dlg.dataset.pendingSourceDocIds = btn.dataset.sourceDocIds || ''; titleIn.value = btn.dataset.suggestedTitle || ''; tagsIn.value = ''; @@ -90,12 +94,13 @@ e.preventDefault(); dlg.close(); - const btn = _pendingBtn; - const content = dlg.dataset.pendingContent || ''; - const tool = dlg.dataset.pendingTool || ''; - const kind = dlg.dataset.pendingKind || 'tool_output'; - const title = titleIn.value.trim(); - const tags = tagsIn.value.trim(); + const btn = _pendingBtn; + const content = dlg.dataset.pendingContent || ''; + const tool = dlg.dataset.pendingTool || ''; + const kind = dlg.dataset.pendingKind || 'tool_output'; + const sourceDocIds = dlg.dataset.pendingSourceDocIds || ''; + const title = titleIn.value.trim(); + const tags = tagsIn.value.trim(); if (!title || !content) return; @@ -109,7 +114,7 @@ method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, - body: bodyFor(kind, { title, content, tool, tags }), + body: bodyFor(kind, { title, content, tool, tags, sourceDocIds }), }); const data = await resp.json().catch(() => ({})); @@ -146,6 +151,7 @@ delete dlg.dataset.pendingContent; delete dlg.dataset.pendingTool; delete dlg.dataset.pendingKind; + delete dlg.dataset.pendingSourceDocIds; }); function showToast(msg, isError) { diff --git a/assets/js/doc-picker.js b/assets/js/doc-picker.js index e6ed2db..9853ed4 100644 --- a/assets/js/doc-picker.js +++ b/assets/js/doc-picker.js @@ -97,10 +97,13 @@ .toLocaleDateString(undefined, { dateStyle: 'medium' })); } catch (_) {} } + var redactBadge = doc.source_tool === 'redact' + ? '✂ Redacted' + : ''; return '
Redacting document…
${highlightRedactedText(lastRedactedText)}${inventoryHtml}${upgradeBtn}${dlRow}`;
diff --git a/includes/LegalTools.php b/includes/LegalTools.php
index f19e483..25acb3a 100644
--- a/includes/LegalTools.php
+++ b/includes/LegalTools.php
@@ -1120,7 +1120,7 @@ PROMPT;
// Build officials note
$officialsNote = '';
if ($keepOfficials) {
- $officialsNote = "\n\nOFFICIALS — for persons identified as JUDGE, EXPERT_WITNESS, or CASEWORKER in an official capacity: do NOT replace their name with a plain bracket tag. Instead use the format [ROLE: Name], e.g. [JUDGE: Andersen] or [EXPERT_WITNESS: Dr. Larsen]. Their name must remain visible inside the tag.";
+ $officialsNote = "\n\nOFFICIALS — for persons identified as JUDGE, ATTORNEY, EXPERT_WITNESS, or CASEWORKER in an official capacity: do NOT replace their name with a plain bracket tag. Instead use the format [ROLE: Name], e.g. [JUDGE: Andersen], [ATTORNEY: Skretting] or [EXPERT_WITNESS: Dr. Larsen]. Their name must remain visible inside the tag.";
}
$allowedTypesNote = '';
@@ -1363,7 +1363,7 @@ PROMPT;
private function applyGenericTags(string $text): string
{
// Collapse contextual role tags (e.g. [FATHER], [JUDGE: Andersen], [CHILD_1]) → [PERSON]
- $text = preg_replace('/\[(?:FATHER|MOTHER|CHILD(?:_\d+)?|GRANDPARENT|SIBLING|ATTORNEY|JUDGE(?::\s*[^\]]+)?|CASEWORKER(?::\s*[^\]]+)?|EXPERT_WITNESS(?::\s*[^\]]+)?|PERSON(?:_\d+)?)\]/u', '[PERSON]', $text) ?? $text;
+ $text = preg_replace('/\[(?:FATHER|MOTHER|CHILD(?:_\d+)?|GRANDPARENT|SIBLING|ATTORNEY(?::\s*[^\]]+)?|JUDGE(?::\s*[^\]]+)?|CASEWORKER(?::\s*[^\]]+)?|EXPERT_WITNESS(?::\s*[^\]]+)?|PERSON(?:_\d+)?)\]/u', '[PERSON]', $text) ?? $text;
return $text;
}
@@ -1382,7 +1382,7 @@ PROMPT;
// Replace named role tags (keeping consistent mapping per unique tag)
$text = preg_replace_callback(
- '/\[(FATHER|MOTHER|CHILD(?:_\d+)?|GRANDPARENT|SIBLING|ATTORNEY|JUDGE(?::\s*[^\]]+)?|CASEWORKER(?::\s*[^\]]+)?|EXPERT_WITNESS(?::\s*[^\]]+)?|PERSON(?:_\d+)?)\]/u',
+ '/\[(FATHER|MOTHER|CHILD(?:_\d+)?|GRANDPARENT|SIBLING|ATTORNEY(?::\s*[^\]]+)?|JUDGE(?::\s*[^\]]+)?|CASEWORKER(?::\s*[^\]]+)?|EXPERT_WITNESS(?::\s*[^\]]+)?|PERSON(?:_\d+)?)\]/u',
function (array $m) use (&$nameCursor, &$personMap, $norwegianNames): string {
$key = $m[1];
if (!isset($personMap[$key])) {
diff --git a/includes/PricingCatalog.php b/includes/PricingCatalog.php
index 60bd70b..9169f06 100644
--- a/includes/PricingCatalog.php
+++ b/includes/PricingCatalog.php
@@ -133,7 +133,7 @@ final class PricingCatalog
'translate' => 1,
'korrespond_refine' => 1,
'timeline' => 2,
- 'redact' => 2,
+ 'redact' => 1, // minimum (gpt-4o-mini); azure_full overrides to 2 in api/redact.php
'barnevernet' => 3,
'advocate' => 3,
'korrespond' => 3,
diff --git a/redact.php b/redact.php
index 338111e..e9d577f 100644
--- a/redact.php
+++ b/redact.php
@@ -19,10 +19,8 @@ require_once __DIR__ . '/includes/layout.php';
Engine
-
-
- Azure engines use your BNL Azure credits. GPU runs the local LiteLLM proxy. Regex-only is instant and free but finds no names or organisations.
+gpt-4o-mini: 1 credit — fast, handles most documents well. gpt-4o: 2 credits — higher accuracy for complex or multi-person cases.
Drop up to 5 files here, or
+Drop one file here, or
PDF, DOCX, TXT — text extracted in memory, never stored