Show hlink to artifacts
Browse files- static/index.html +61 -4
static/index.html
CHANGED
|
@@ -1165,8 +1165,9 @@ curl -sL https://huggingface.co/buckets/ml-agent-explorers/efficient-optimizer-c
|
|
| 1165 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1166 |
const MESSAGES_URL = '/api/messages';
|
| 1167 |
const LEADERBOARD_URL = '/api/leaderboard';
|
|
|
|
| 1168 |
const POLL_MS = 30_000;
|
| 1169 |
-
const CACHE_KEY = '
|
| 1170 |
const HANDLE_KEY = 'efficient_optimizer_human_handle';
|
| 1171 |
const FETCH_TIMEOUT_MS = 30_000;
|
| 1172 |
const HANDLE_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,31}$/;
|
|
@@ -1225,6 +1226,7 @@ const FILENAME_RE = /^(\d{8})-(\d{6})_(.+?)(?:_(.+))?\.md$/;
|
|
| 1225 |
// Captures the step count from the same line as the marker. Loose matches like
|
| 1226 |
// "2812 steps" in prose are intentionally ignored.
|
| 1227 |
const LEADERBOARD_RESULT_RE = /\*\*\s*leaderboard\s+result\s*:\s*\*\*[^\n]*?(\d[\d,]*)\s*steps/gi;
|
|
|
|
| 1228 |
const STEPS_MIN = 100;
|
| 1229 |
const STEPS_MAX = 100000;
|
| 1230 |
|
|
@@ -1306,11 +1308,66 @@ function findBestSteps(body) {
|
|
| 1306 |
return matches.length ? Math.min(...matches) : null;
|
| 1307 |
}
|
| 1308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1309 |
function renderMarkdownInline(text) {
|
| 1310 |
if (!text) return '';
|
| 1311 |
-
if (!window.marked) return escapeHtml(text);
|
| 1312 |
-
try {
|
| 1313 |
-
|
|
|
|
|
|
|
| 1314 |
}
|
| 1315 |
|
| 1316 |
function parseMessage(filename, raw) {
|
|
|
|
| 1165 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1166 |
const MESSAGES_URL = '/api/messages';
|
| 1167 |
const LEADERBOARD_URL = '/api/leaderboard';
|
| 1168 |
+
const BUCKET_WEB_URL = 'https://huggingface.co/buckets/ml-agent-explorers/efficient-optimizer-collab';
|
| 1169 |
const POLL_MS = 30_000;
|
| 1170 |
+
const CACHE_KEY = 'efficient_optimizer_cache_v3';
|
| 1171 |
const HANDLE_KEY = 'efficient_optimizer_human_handle';
|
| 1172 |
const FETCH_TIMEOUT_MS = 30_000;
|
| 1173 |
const HANDLE_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,31}$/;
|
|
|
|
| 1226 |
// Captures the step count from the same line as the marker. Loose matches like
|
| 1227 |
// "2812 steps" in prose are intentionally ignored.
|
| 1228 |
const LEADERBOARD_RESULT_RE = /\*\*\s*leaderboard\s+result\s*:\s*\*\*[^\n]*?(\d[\d,]*)\s*steps/gi;
|
| 1229 |
+
const ARTIFACT_REF_RE = /artifacts\/[^\s<>"'`]+/g;
|
| 1230 |
const STEPS_MIN = 100;
|
| 1231 |
const STEPS_MAX = 100000;
|
| 1232 |
|
|
|
|
| 1308 |
return matches.length ? Math.min(...matches) : null;
|
| 1309 |
}
|
| 1310 |
|
| 1311 |
+
function splitArtifactRef(raw) {
|
| 1312 |
+
let path = raw;
|
| 1313 |
+
let suffix = '';
|
| 1314 |
+
while (path.length && /[.,;:!?)}\]]/.test(path[path.length - 1])) {
|
| 1315 |
+
suffix = path[path.length - 1] + suffix;
|
| 1316 |
+
path = path.slice(0, -1);
|
| 1317 |
+
}
|
| 1318 |
+
return { path, suffix };
|
| 1319 |
+
}
|
| 1320 |
+
function artifactHref(path) {
|
| 1321 |
+
const cleanPath = path.replace(/^\/+/, '');
|
| 1322 |
+
const encoded = cleanPath.split('/').map(encodeURIComponent).join('/');
|
| 1323 |
+
const route = cleanPath.endsWith('/') || !cleanPath.split('/').pop().includes('.') ? 'tree' : 'resolve';
|
| 1324 |
+
return `${BUCKET_WEB_URL}/${route}/${encoded}`;
|
| 1325 |
+
}
|
| 1326 |
+
function linkArtifactRefsInHtml(html) {
|
| 1327 |
+
if (!html || !html.includes('artifacts/')) return html;
|
| 1328 |
+
const template = document.createElement('template');
|
| 1329 |
+
template.innerHTML = html;
|
| 1330 |
+
const walker = document.createTreeWalker(template.content, NodeFilter.SHOW_TEXT);
|
| 1331 |
+
const textNodes = [];
|
| 1332 |
+
while (walker.nextNode()) textNodes.push(walker.currentNode);
|
| 1333 |
+
|
| 1334 |
+
for (const node of textNodes) {
|
| 1335 |
+
const parent = node.parentElement;
|
| 1336 |
+
if (!parent || parent.closest('a, code, pre')) continue;
|
| 1337 |
+
const text = node.nodeValue;
|
| 1338 |
+
ARTIFACT_REF_RE.lastIndex = 0;
|
| 1339 |
+
if (!ARTIFACT_REF_RE.test(text)) continue;
|
| 1340 |
+
ARTIFACT_REF_RE.lastIndex = 0;
|
| 1341 |
+
|
| 1342 |
+
const fragment = document.createDocumentFragment();
|
| 1343 |
+
let lastIndex = 0;
|
| 1344 |
+
let match;
|
| 1345 |
+
while ((match = ARTIFACT_REF_RE.exec(text)) !== null) {
|
| 1346 |
+
const raw = match[0];
|
| 1347 |
+
const { path, suffix } = splitArtifactRef(raw);
|
| 1348 |
+
if (!path || path === 'artifacts/') continue;
|
| 1349 |
+
fragment.append(document.createTextNode(text.slice(lastIndex, match.index)));
|
| 1350 |
+
const link = document.createElement('a');
|
| 1351 |
+
link.href = artifactHref(path);
|
| 1352 |
+
link.target = '_blank';
|
| 1353 |
+
link.rel = 'noopener noreferrer';
|
| 1354 |
+
link.textContent = path;
|
| 1355 |
+
fragment.append(link);
|
| 1356 |
+
if (suffix) fragment.append(document.createTextNode(suffix));
|
| 1357 |
+
lastIndex = match.index + raw.length;
|
| 1358 |
+
}
|
| 1359 |
+
fragment.append(document.createTextNode(text.slice(lastIndex)));
|
| 1360 |
+
node.replaceWith(fragment);
|
| 1361 |
+
}
|
| 1362 |
+
return template.innerHTML;
|
| 1363 |
+
}
|
| 1364 |
function renderMarkdownInline(text) {
|
| 1365 |
if (!text) return '';
|
| 1366 |
+
if (!window.marked) return linkArtifactRefsInHtml(escapeHtml(text));
|
| 1367 |
+
try {
|
| 1368 |
+
return linkArtifactRefsInHtml(window.marked.parse(text, { gfm: true, breaks: true, mangle: false, headerIds: false }));
|
| 1369 |
+
}
|
| 1370 |
+
catch { return linkArtifactRefsInHtml(escapeHtml(text)); }
|
| 1371 |
}
|
| 1372 |
|
| 1373 |
function parseMessage(filename, raw) {
|