This commit is contained in:
Your Name
2026-10-23 09:26:49 +08:00
parent 14abf67d0d
commit 3f15786491
34 changed files with 2866 additions and 225 deletions
@@ -11,7 +11,7 @@ use think\facade\Cache;
/** Short-lived evidence only. The caller must re-authorize and aggregate before lookup. */
final class AiContextCompactionCache
{
public static function remember(string $scope, string $profile, string $source, callable $produce): array
public static function remember(string $scope, string $profile, string $source, callable $produce, ?callable $shouldAbort = null): array
{
$config = config('prescription_ai') ?: [];
$ttl = max(0, min(600, (int) ($config['context_compaction_cache_ttl'] ?? 300)));
@@ -28,6 +28,7 @@ final class AiContextCompactionCache
}
}
$result = $produce();
if ($shouldAbort !== null && $shouldAbort()) throw new \RuntimeException('Context operation cancelled');
if ($scope !== '' && $ttl > 0 && self::valid($result, strlen($source))) {
try {
Cache::set($key, $result, $ttl);