Files
html/api/agent-avatar-unified.php

71 lines
2.4 KiB
PHP

<?php
// V28 V83 Unified Avatar Endpoint - Opus WIRE doctrine #14 amendee
// Merges 3 files WITHOUT modifying sources (V1 URL + V2 unified + V75 emoji)
// Priority: V2 > V75 > V1 per agent
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$action = $_GET['action'] ?? 'unified';
$agent = $_GET['agent'] ?? '';
$v1 = @json_decode(@file_get_contents('/var/www/html/api/agent-avatars.json'), true) ?: [];
$v2 = @json_decode(@file_get_contents('/var/www/html/api/agent-avatars-v2.json'), true) ?: [];
$v75 = @json_decode(@file_get_contents('/var/www/html/api/agent-avatars-v75.json'), true) ?: [];
// Merge with priority V2 > V75 > V1
$unified = [];
foreach ($v1 as $k => $v) { $unified[$k] = ['source' => 'v1_url', 'data' => $v]; }
foreach ($v75 as $k => $v) { $unified[$k] = ['source' => 'v75_emoji', 'data' => $v]; }
foreach ($v2 as $k => $v) { $unified[$k] = ['source' => 'v2_unified', 'data' => $v]; }
if ($action === 'unified') {
// Summary
$by_source = ['v1_url' => 0, 'v75_emoji' => 0, 'v2_unified' => 0];
foreach ($unified as $v) { $by_source[$v['source']]++; }
echo json_encode([
'ok' => true,
'unified_count' => count($unified),
'sources' => [
'v1_url' => count($v1),
'v75_emoji' => count($v75),
'v2_unified' => count($v2),
],
'by_source_winning' => $by_source,
'priority' => 'v2_unified > v75_emoji > v1_url',
'doctrine' => '14_amendee_amelioration_sans_casse',
'files_preserved' => true,
'ts' => date('c'),
], JSON_PRETTY_PRINT);
exit;
}
if ($action === 'get' && $agent) {
if (!isset($unified[$agent])) {
// Try case-insensitive
$lower = strtolower($agent);
foreach ($unified as $k => $v) {
if (strtolower($k) === $lower) {
echo json_encode(['ok' => true, 'agent' => $k, 'unified' => $v]);
exit;
}
}
http_response_code(404);
echo json_encode(['error' => 'agent not found', 'agent' => $agent]);
exit;
}
echo json_encode(['ok' => true, 'agent' => $agent, 'unified' => $unified[$agent]]);
exit;
}
if ($action === 'list') {
// Just names
echo json_encode([
'ok' => true,
'count' => count($unified),
'names' => array_keys($unified),
]);
exit;
}
echo json_encode(['error' => 'unknown action', 'actions' => ['unified', 'get', 'list']]);