.json $tenant = getenv('CODEB_TENANT') ?: 'https://'; $apiKey = getenv('CODEB_API_KEY'); $outDir = getenv('OUT_DIR') ?: './codeb-transcripts'; if (!$apiKey) { fwrite(STDERR, "CODEB_API_KEY not set\n"); exit(2); } if (!is_dir($outDir)) mkdir($outDir, 0755, true); function get(string $url, string $apiKey): string { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey], CURLOPT_TIMEOUT => 30, ]); $body = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($body === false || $code >= 400) throw new RuntimeException("HTTP $code fetching $url"); return $body; } $idx = json_decode(get("$tenant/signal.ashx?list-transcripts=1", $apiKey), true); $items = $idx['items'] ?? []; echo "[list] ", count($items), " transcripts\n"; foreach ($items as $it) { $f = $it['file'] ?? ''; if (!$f) continue; $doc = get("$tenant/signal.ashx?get-transcript=" . urlencode($f), $apiKey); file_put_contents(rtrim($outDir, '/') . "/$f", $doc); $parsed = json_decode($doc, true); $turns = isset($parsed['_transcriptTurns']) ? count($parsed['_transcriptTurns']) : 0; echo "[fetch] $f turns=$turns\n"; }