0fcfed1a86
dbnToolsString was called with required=true (default), so it aborted before dbnToolsInjectDocContent could inject content from the doc picker. Now passes required=false and validates after injection so doc-only submissions work in timeline, redact, ask, and summarize. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.8 KiB
PHP
66 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../includes/LegalTools.php';
|
|
require_once __DIR__ . '/../includes/CaseResults.php';
|
|
require_once __DIR__ . '/../includes/ToolModels.php';
|
|
|
|
dbnToolsRequireMethod('POST');
|
|
dbnToolsRequireAuth();
|
|
$ftUid = dbnToolsFreeTierCheck('timeline');
|
|
$ftRemaining = dbnToolsFreeTierDeduct($ftUid, 'timeline');
|
|
if ($ftRemaining >= 0) { header('X-Credits-Remaining: ' . $ftRemaining); }
|
|
$input = dbnToolsJsonInput(400000);
|
|
$language = dbnToolsNormalizeLanguage($input['language'] ?? 'en');
|
|
|
|
dbnToolsWithTelemetry('timeline', $language, function () use ($input, $language, $ftUid): array {
|
|
$text = dbnToolsInjectDocContent($input, dbnToolsString($input, 'text', 128000, false));
|
|
if (mb_strlen(trim($text), 'UTF-8') < 10) {
|
|
dbnToolsAbort('Paste text, upload a file, or select a document before running.', 422, 'empty_text');
|
|
}
|
|
|
|
$validEngines = ['azure_mini', 'azure_full', 'gpu'];
|
|
$engine = in_array((string)($input['engine'] ?? ''), $validEngines, true)
|
|
? (string)$input['engine'] : 'azure_mini';
|
|
$engine = ToolModels::engineForUser($ftUid, $engine);
|
|
|
|
$validFocus = ['all', 'deadlines', 'hearings', 'cps'];
|
|
$focus = in_array((string)($input['focus'] ?? ''), $validFocus, true)
|
|
? (string)$input['focus'] : 'all';
|
|
|
|
$confidenceFilter = (string)($input['confidence_filter'] ?? '') === 'high_medium'
|
|
? 'high_medium' : 'all';
|
|
|
|
$includeRelative = ($input['include_relative'] ?? true) !== false;
|
|
$includeBackground = ($input['include_background'] ?? true) !== false;
|
|
$userNotes = dbnToolsString($input, 'user_notes', 2000, false);
|
|
|
|
// Optional: prepend the user's case-context chunks so the timeline includes events
|
|
// referenced in their uploaded case documents.
|
|
$useMyCase = !empty($input['use_my_case']);
|
|
if ($useMyCase) {
|
|
$caseBlock = dbnToolsCaseContext(true, $text, 5);
|
|
if ($caseBlock !== '') {
|
|
$text = $text . "\n\n" . $caseBlock;
|
|
}
|
|
}
|
|
|
|
$result = (new DbnLegalToolsService())->timeline($text, $language, $engine, $focus, $confidenceFilter, $includeRelative, $includeBackground, $userNotes);
|
|
|
|
// Persist for paid users (silently no-op for free)
|
|
if ($ftUid > 0) {
|
|
$ownerId = CaseStore::caseResolveClientId($ftUid);
|
|
$resultId = CaseResults::save($ftUid, $ownerId, 'timeline', $input, $result, [
|
|
'used_case_context' => $useMyCase ? 1 : 0,
|
|
'case_doc_ids' => dbnToolsLastCaseDocIds(),
|
|
'model' => $engine,
|
|
'latency_ms' => (int)($result['latency_ms'] ?? 0),
|
|
'credits_charged' => FreeTier::cost('timeline'),
|
|
]);
|
|
if ($resultId > 0) {
|
|
$result['result_id'] = $resultId;
|
|
}
|
|
}
|
|
return $result;
|
|
});
|