Files
zyt/artifacts/private_ai_synthetic_status_20261027.php
T
2026-10-27 14:03:35 +08:00

28 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
ini_set('display_errors','0'); ini_set('log_errors','0');
header('Content-Type: application/json');
if (PHP_SAPI !== 'cgi-fcgi' || ($_SERVER['REMOTE_ADDR'] ?? '') !== '127.0.0.1'
|| ($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST' || (int)($_SERVER['CONTENT_LENGTH'] ?? 0) !== 0) {
http_response_code(403); echo '{"ok":false}'; exit;
}
try {
$root=dirname(__DIR__).'/server'; require $root.'/vendor/autoload.php';
$app=new \think\App($root.'/'); require_once $root.'/vendor/topthink/framework/src/helper.php';
$app->env->load($root.'/.env');
$app->config->set(require $root.'/config/prescription_ai.php','prescription_ai');
$matches=[];
foreach (glob($root.'/runtime/ai-synthetic-runtime-20261027/controls/*.json') ?: [] as $file) {
if (hash_file('sha256',$file)==='d1a87c46e302a5579d23d04af01f763dc4847ef7fe06babda738b6e8cf07b483') $matches[]=$file;
}
if(count($matches)!==1) {echo '{"ok":false,"error_code":"SYNTHETIC_PIN_NOT_UNIQUE"}';exit;}
$file=$matches[0]; $before=hash_file('sha256',$file);
$s=json_decode((string)file_get_contents($file),true,64,JSON_THROW_ON_ERROR);
if(($s['upstream']['profile']??'')!=='openai' || !str_starts_with($s['upstream']['user']??'','synthetic-runtime-20261027-')
|| empty($s['cancel_requested']) || !empty($s['upstream_terminal_confirmed'])) throw new \RuntimeException();
$identity=array_intersect_key($s['upstream'],array_flip(['profile','user','task_id','workflow_run_id','generation']));
$r=\app\common\service\DifyWorkflowRunStatus::lookup($identity,1000);
echo json_encode(['ok'=>($r['ok']??false)===true,'status'=>$r['status']??null,
'error_code'=>$r['error_code']??null,'status_lookup_count'=>1,'original_control_unchanged'=>hash_file('sha256',$file)===$before]);
} catch(\Throwable $ignored) {echo '{"ok":false,"error_code":"SYNTHETIC_STATUS_FAILED"}';}