Files
zyt/artifacts/prescription-ai-runtime/check_source_shape.php
T
2026-09-10 15:19:17 +08:00

35 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/check_queue.php';
$secret = (string) config('prescription_analysis.encryption_key', '');
if ($secret === '') {
$secret = trim((string) file_get_contents(root_path('runtime') . 'prescription_ai_private/snapshot.key'));
}
$cipher = new \app\common\service\prescriptionai\PrescriptionAiCipher($secret);
$batch = \think\facade\Db::name('prescription_ai_batch')->where('id', 1)->where('prescription_id', 7556)->find();
$context = $cipher->decrypt($batch['context_cipher'], 'context');
$types = $hosts = $missing = [];
$sendable = [];
foreach ($context['files'] as $file) {
$type = (string) ($file['type'] ?? 'unknown');
$types[$type] = ($types[$type] ?? 0) + 1;
$host = (string) (parse_url((string) ($file['url'] ?? ''), PHP_URL_HOST) ?: '(none)');
$hosts[$host] = ($hosts[$host] ?? 0) + 1;
if ($file['status'] !== 'restricted' && !empty($file['url'])) { $sendable[] = $file; }
}
$normalization = [];
foreach (array_chunk($sendable, 3) as $files) {
$wire = array_map(static fn (array $f): array => ['type' => $f['type'], 'url' => $f['url'], 'transfer_method' => 'remote_url'], $files);
$value = (new ReflectionMethod(\app\common\service\DifyChatService::class, 'normalizeFiles'))->invoke(null, $wire, 3);
$normalization[] = ['input' => count($wire), 'kept' => count($value['kept']), 'over_limit' => count($value['dropped'])];
}
foreach ($context['missing'] ?? [] as $item) {
$code = (string) ($item['code'] ?? 'unknown');
$missing[$code] = ($missing[$code] ?? 0) + 1;
}
echo json_encode(['source_shape_only' => [
'attachment_types' => $types, 'attachment_hosts' => $hosts, 'missing_codes' => $missing,
'attachment_batch_normalization' => $normalization,
'max_files' => config('prescription_ai.max_files'), 'timeout' => config('prescription_ai.timeout'),
]], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), PHP_EOL;