feat(tools): converge two-tier Quick/Pro selector onto .no fork
Port the dobetterlegal-tools two-tier quality stack to dobetternorge.no: QUALITY_TIERS registry + resolveTier (ToolModels), dbnToolsResolveToolRun (bootstrap), tier read+charge in the 6 analytical endpoints, Quick/Pro UI + payload.tier on the 6 tool pages/JS, and the bounded corpusContextForSummarize RAG fix (per-passage trim + total budget + reranker_enabled). Back-compat: requests without `tier` keep legacy engine behavior. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -767,6 +767,50 @@ function dbnToolsIsFreeTier(): bool
|
||||
&& !empty($_SESSION['dbn_tools_sso_uid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Current free-tier SSO user id, or 0 for CaveauAI / non-SSO sessions.
|
||||
* Lets an endpoint resolve a quality tier (subscription gate) BEFORE charging,
|
||||
* without reaching into the session directly. Mirrors the uid the check/deduct
|
||||
* helpers use.
|
||||
*/
|
||||
function dbnToolsFreeTierUid(): int
|
||||
{
|
||||
return dbnToolsIsFreeTier() ? (int)$_SESSION['dbn_tools_sso_uid'] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the model + credit gate for a tool run. When the request carries a `tier`
|
||||
* param, honour the Quick/Pro quality tier (subscription-gated, server-priced); otherwise
|
||||
* fall back to the legacy engine-selector behaviour. Runs the credit gate (exits 402/429
|
||||
* if over limit) and returns the context an endpoint needs to run + deduct.
|
||||
*
|
||||
* @return array{tier:string,engine:string,credits:?int,ftUid:int,metadata:array}
|
||||
*/
|
||||
function dbnToolsResolveToolRun(string $tool, array $input, string $legacyDefaultEngine = 'azure_mini'): array
|
||||
{
|
||||
if (isset($input['tier'])) {
|
||||
$res = ToolModels::resolveTier(dbnToolsFreeTierUid(), $tool, (string)$input['tier']);
|
||||
$ftUid = dbnToolsFreeTierCheckAmount($tool, $res['credits']);
|
||||
return [
|
||||
'tier' => $res['tier'],
|
||||
'engine' => $res['engine'],
|
||||
'credits' => $res['credits'],
|
||||
'ftUid' => $ftUid,
|
||||
'metadata' => ['tier' => $res['tier'], 'engine' => $res['engine']],
|
||||
];
|
||||
}
|
||||
|
||||
$ftUid = dbnToolsFreeTierCheck($tool);
|
||||
$engine = ToolModels::engineForUser($ftUid, (string)($input['engine'] ?? $legacyDefaultEngine));
|
||||
return [
|
||||
'tier' => '',
|
||||
'engine' => $engine,
|
||||
'credits' => null,
|
||||
'ftUid' => $ftUid,
|
||||
'metadata' => [],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforce credit + tier gate before a tool call.
|
||||
* Exits with JSON 402/429 if the user is over limit or out of credits.
|
||||
|
||||
Reference in New Issue
Block a user