File size: 12,086 Bytes
9e27409 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | <!DOCTYPE html>
<!--
====================================================================================
ОПЦИОНАЛЬНЫЙ ФАЙЛ (не обязателен для agent.py).
ВАЖНО ПРО ЛОГИН: внутри кадра (iframe) браузер не передаёт сайту агента его
cookie и изолирует хранилище, поэтому вход в аккаунт агента там НЕ сохраняется.
Используйте этот файл только если приоритет - скрыть чужой адрес, а вход в
аккаунт не нужен. Если логин важен - оставьте стандартную страницу /env/<id>
из agent.py (плавный переход в этом же окне, логин сохраняется).
ЗАЧЕМ ОН НУЖЕН:
Сайт агента (arena.ai) отдаёт заголовок:
Content-Security-Policy: frame-ancestors 'self' https://huggingface.co/ https://*.static.hf.space/
X-Frame-Options: SAMEORIGIN
Это значит: вставить его в iframe можно ТОЛЬКО со страниц доменов huggingface.co
и *.static.hf.space. Со своего домена/VPS/обычного Space (xxx.hf.space) браузер
кадр запретит - тогда agent.py автоматически делает переход в этом же окне.
Если хочется, чтобы посетитель вообще никогда не видел сторонней ссылки и адреса,
нужно поднять маленькую статическую страницу в Hugging Face (Static Space).
У таких страниц адрес вида https://<user>-<space>.static.hf.space/ - он РАЗРЕШЁН
сайтом агента, поэтому кадр внутри него работает.
КАК ПОДНЯТЬ (2 минуты):
1. huggingface.co -> New -> Space -> имя, например "agent-run" -> SDK: Static.
2. В созданном репозитории положите этот файл под именем index.html
(Add file -> Upload files -> выбрать этот файл, переименовав в index.html).
3. Откройте https://<ваш-логин>-agent-run.static.hf.space/ - увидите кнопку
"Uruchom agenta", а агент откроется ВНУТРИ этой же страницы.
НАСТРОЙКА (блок CONFIG ниже в скрипте):
AGENT_URL - адрес агента;
PING_BASE - адрес вашего Flask-приложения из agent.py (для статистики заходов,
необязательно, можно оставить пустым);
DEFAULT_ENV - ID среды из админки (можно передавать ссылкой как ?env=123456).
Заходы будут считаться, если посетитель открыл ссылку с ?env=ID и заполнен PING_BASE.
====================================================================================
-->
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<meta name="robots" content="noindex, nofollow">
<title>Uruchom agenta</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;800&display=swap" rel="stylesheet">
<style>
html, body { margin: 0; padding: 0; width: 100%; height: 100%; font-family: 'Montserrat', sans-serif; background: #0a0a0c; color: #fff; overflow: hidden; -webkit-font-smoothing: antialiased; }
#btn-container { display: flex; justify-content: center; align-items: center; height: 100%; width: 100%; flex-direction: column; gap: 18px; padding: 20px; box-sizing: border-box; text-align: center; }
.action-btn {
background: linear-gradient(45deg, #c8ff00, #aaff00); color: #000; border: none;
padding: 20px 40px; font-size: 1.5rem; font-weight: 800; border-radius: 14px; cursor: pointer;
text-transform: uppercase; box-shadow: 0 8px 30px rgba(200, 255, 0, 0.4);
transition: transform 0.2s, box-shadow 0.2s; letter-spacing: 1.5px; text-decoration: none;
font-family: inherit; max-width: 90vw;
}
.action-btn:hover { transform: scale(1.05); box-shadow: 0 12px 40px rgba(200, 255, 0, 0.6); }
.action-btn:active { transform: scale(0.98); }
#agent-view { position: fixed; inset: 0; display: none; background: #0a0a0c; }
#agent-view.active { display: block; }
#agent-topbar {
position: absolute; top: 0; left: 0; right: 0; height: 46px; z-index: 3;
display: flex; align-items: center; gap: 10px; padding: 0 12px; box-sizing: border-box;
background: linear-gradient(180deg, rgba(10,10,12,0.92), rgba(10,10,12,0));
}
#agent-back {
display: flex; align-items: center; justify-content: center;
height: 34px; padding: 0 14px; border-radius: 999px; cursor: pointer;
border: 1px solid rgba(255,255,255,0.16); background: rgba(0,0,0,0.55); color: #fff;
font-family: inherit; font-size: 0.85rem; font-weight: 600; letter-spacing: 0.4px;
backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); transition: background 0.2s;
}
#agent-back:hover { background: rgba(0,0,0,0.85); }
#agent-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #0a0a0c; display: block; }
#agent-loader {
position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column;
align-items: center; justify-content: center; gap: 18px; background: #0a0a0c;
transition: opacity 0.3s; text-align: center; padding: 24px; box-sizing: border-box;
}
#agent-loader.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(200, 255, 0, 0.18); border-top-color: #c8ff00; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 0.95rem; color: #9a9a9a; letter-spacing: 0.5px; }
#agent-fallback {
position: absolute; inset: 0; z-index: 5; display: none; flex-direction: column;
align-items: center; justify-content: center; gap: 18px; background: #0a0a0c;
text-align: center; padding: 24px; box-sizing: border-box;
}
#agent-fallback.show { display: flex; }
#agent-fallback p { color: #9a9a9a; font-size: 0.95rem; max-width: 420px; margin: 0; line-height: 1.55; }
</style>
</head>
<body>
<div id="btn-container">
<button class="action-btn" onclick="startAgent()">Uruchom agenta</button>
</div>
<div id="agent-view">
<div id="agent-topbar">
<button id="agent-back" onclick="closeAgent()">← Wstecz</button>
</div>
<iframe id="agent-frame" title="Agent" src="about:blank" referrerpolicy="no-referrer" allowfullscreen
allow="clipboard-read; clipboard-write; microphone; camera; autoplay; fullscreen; encrypted-media; geolocation; display-capture"></iframe>
<div id="agent-loader">
<div class="spinner"></div>
<div class="loader-text">Uruchamianie agenta…</div>
</div>
<div id="agent-fallback">
<p>Nie udało się uruchomić agenta w tym oknie. Kliknij poniżej, aby spróbować ponownie.</p>
<button class="action-btn" style="font-size: 1.1rem; padding: 16px 30px;" onclick="startAgent()">Uruchom agenta</button>
<button onclick="closeAgent()" style="background: none; border: none; color: #7a7a7a; font-family: inherit; font-size: 0.9rem; cursor: pointer; text-decoration: underline;">Wróć</button>
</div>
</div>
<script>
(function () {
// ================== CONFIG ==================
var AGENT_URL = 'https://arena.ai/agent'; // адрес агента
var PING_BASE = ''; // например 'https://kgshop-agent.hf.space' (для статистики)
var DEFAULT_ENV = ''; // например '123456' (ID среды из админки)
var SUSPECT_MS = 400; // признак блокировки встраивания
var LOAD_TIMEOUT = 20000;
// ============================================
var params = {};
try {
window.location.search.replace(/^\?/, '').split('&').forEach(function (pair) {
if (!pair) { return; }
var kv = pair.split('=');
params[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1] || '');
});
} catch (e) {}
var ENV_ID = params.env || DEFAULT_ENV;
var startScreen = document.getElementById('btn-container');
var view = document.getElementById('agent-view');
var frameEl = document.getElementById('agent-frame');
var loader = document.getElementById('agent-loader');
var fallback = document.getElementById('agent-fallback');
var startedAt = 0;
var firstLoad = false;
var loadTimer = null;
var openState = false;
var fails = 0;
function ping() {
if (!ENV_ID || !PING_BASE) { return; }
var img = new Image();
img.src = PING_BASE.replace(/\/+$/, '') + '/ping/' + encodeURIComponent(ENV_ID) + '?t=' + Date.now();
}
window.startAgent = function () {
ping();
startScreen.style.display = 'none';
view.classList.add('active');
loader.classList.remove('hidden');
fallback.classList.remove('show');
startedAt = Date.now();
firstLoad = true;
openState = true;
try {
if (window.history && window.history.pushState) {
window.history.pushState({ agentOpen: true }, '');
}
} catch (e) {}
frameEl.setAttribute('src', AGENT_URL);
if (loadTimer) { clearTimeout(loadTimer); }
loadTimer = setTimeout(function () { if (openState) { loader.classList.add('hidden'); } }, LOAD_TIMEOUT);
};
window.closeAgent = function () {
openState = false;
fallback.classList.remove('show');
loader.classList.remove('hidden');
view.classList.remove('active');
startScreen.style.display = 'flex';
try { frameEl.setAttribute('src', 'about:blank'); } catch (e) {}
if (loadTimer) { clearTimeout(loadTimer); loadTimer = null; }
};
frameEl.addEventListener('load', function () {
if (!openState || !firstLoad) { return; }
firstLoad = false;
var elapsed = Date.now() - startedAt;
if (loadTimer) { clearTimeout(loadTimer); loadTimer = null; }
if (elapsed < SUSPECT_MS) { // кадр заблокирован (мгновенная "пустая" загрузка)
fails += 1;
if (fails >= 2) {
// дважды не получилось в кадре - главное, чтобы агент работал
window.location.assign(AGENT_URL);
return;
}
fallback.classList.add('show');
loader.classList.add('hidden');
return;
}
loader.classList.add('hidden');
});
window.addEventListener('popstate', function () {
if (openState) { closeAgent(); }
});
})();
</script>
</body>
</html>
|