Show long texts
Browse files- static/index.html +45 -6
static/index.html
CHANGED
|
@@ -317,6 +317,20 @@
|
|
| 317 |
}
|
| 318 |
.msg .text a { color: var(--hf-blue); text-decoration: none; }
|
| 319 |
.msg .text a:hover { text-decoration: underline; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
|
| 321 |
.new-best-pill {
|
| 322 |
display: inline-flex;
|
|
@@ -1077,10 +1091,11 @@ curl -sL https://huggingface.co/buckets/ml-agent-explorers/efficient-optimizer-c
|
|
| 1077 |
const MESSAGES_URL = '/api/messages';
|
| 1078 |
const LEADERBOARD_URL = '/api/leaderboard';
|
| 1079 |
const POLL_MS = 30_000;
|
| 1080 |
-
const CACHE_KEY = '
|
| 1081 |
const HANDLE_KEY = 'efficient_optimizer_human_handle';
|
| 1082 |
const FETCH_TIMEOUT_MS = 30_000;
|
| 1083 |
const HANDLE_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,31}$/;
|
|
|
|
| 1084 |
|
| 1085 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1086 |
// STATE
|
|
@@ -1180,6 +1195,14 @@ function splitFirstAndRest(body) {
|
|
| 1180 |
return { headline, excerpt, rest: parts.slice((headline ? 1 : 0) + (excerpt ? 1 : 0)).join('\n\n') };
|
| 1181 |
}
|
| 1182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1183 |
function epochFromFilename(filename) {
|
| 1184 |
const m = FILENAME_RE.exec(filename);
|
| 1185 |
if (!m) return 0;
|
|
@@ -1212,7 +1235,8 @@ function parseMessage(filename, raw) {
|
|
| 1212 |
if (!body) return null;
|
| 1213 |
const fm = FILENAME_RE.exec(filename);
|
| 1214 |
const refs = Array.isArray(fields.refs) ? fields.refs : (fields.refs ? [fields.refs] : []);
|
| 1215 |
-
const { headline, excerpt } = splitFirstAndRest(body);
|
|
|
|
| 1216 |
return {
|
| 1217 |
filename,
|
| 1218 |
agent: (fields.agent || (fm && fm[3]) || 'unknown').trim(),
|
|
@@ -1220,8 +1244,11 @@ function parseMessage(filename, raw) {
|
|
| 1220 |
epoch: epochFromFilename(filename),
|
| 1221 |
refs: refs.filter(Boolean),
|
| 1222 |
headline,
|
| 1223 |
-
excerpt,
|
| 1224 |
-
excerptHtml: renderMarkdownInline(
|
|
|
|
|
|
|
|
|
|
| 1225 |
steps: findBestSteps(body),
|
| 1226 |
};
|
| 1227 |
}
|
|
@@ -1392,11 +1419,12 @@ function buildMentions(m) {
|
|
| 1392 |
});
|
| 1393 |
return [...set];
|
| 1394 |
}
|
| 1395 |
-
function buildText(m) {
|
| 1396 |
const ms = buildMentions(m);
|
| 1397 |
const tags = ms.length ? ms.map(a => `<span class="mention">${escapeHtml(mentionLabel(a))}</span>`).join(' ') + ' ' : '';
|
|
|
|
| 1398 |
// Use plain text (one-line trim) joined with <br>s, lightly applying markdown for **bold** etc
|
| 1399 |
-
return `${tags}${
|
| 1400 |
}
|
| 1401 |
function htmlToText(html) {
|
| 1402 |
const d = document.createElement('div');
|
|
@@ -1441,10 +1469,21 @@ function renderMessage(m, { animate = false, isImprovement = false } = {}) {
|
|
| 1441 |
<div class="body">
|
| 1442 |
<div class="head"><span class="name">${escapeHtml(displayAgentName(m.agent))}</span><span class="ts">${fmtTime(m.epoch)}</span></div>
|
| 1443 |
<div class="text">${buildText(m)}</div>
|
|
|
|
| 1444 |
${pill}
|
| 1445 |
${buildQuotes(m)}
|
| 1446 |
</div>
|
| 1447 |
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1448 |
messagesEl.appendChild(node);
|
| 1449 |
return node;
|
| 1450 |
}
|
|
|
|
| 317 |
}
|
| 318 |
.msg .text a { color: var(--hf-blue); text-decoration: none; }
|
| 319 |
.msg .text a:hover { text-decoration: underline; }
|
| 320 |
+
.msg .see-more-btn {
|
| 321 |
+
display: inline-flex;
|
| 322 |
+
align-items: center;
|
| 323 |
+
margin-top: 6px;
|
| 324 |
+
padding: 0;
|
| 325 |
+
border: none;
|
| 326 |
+
background: transparent;
|
| 327 |
+
color: var(--hf-blue);
|
| 328 |
+
font: inherit;
|
| 329 |
+
font-size: 12.5px;
|
| 330 |
+
font-weight: 700;
|
| 331 |
+
cursor: pointer;
|
| 332 |
+
}
|
| 333 |
+
.msg .see-more-btn:hover { text-decoration: underline; }
|
| 334 |
|
| 335 |
.new-best-pill {
|
| 336 |
display: inline-flex;
|
|
|
|
| 1091 |
const MESSAGES_URL = '/api/messages';
|
| 1092 |
const LEADERBOARD_URL = '/api/leaderboard';
|
| 1093 |
const POLL_MS = 30_000;
|
| 1094 |
+
const CACHE_KEY = 'efficient_optimizer_cache_v2';
|
| 1095 |
const HANDLE_KEY = 'efficient_optimizer_human_handle';
|
| 1096 |
const FETCH_TIMEOUT_MS = 30_000;
|
| 1097 |
const HANDLE_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,31}$/;
|
| 1098 |
+
const MESSAGE_PREVIEW_CHARS = 520;
|
| 1099 |
|
| 1100 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1101 |
// STATE
|
|
|
|
| 1195 |
return { headline, excerpt, rest: parts.slice((headline ? 1 : 0) + (excerpt ? 1 : 0)).join('\n\n') };
|
| 1196 |
}
|
| 1197 |
|
| 1198 |
+
function truncatePreview(text) {
|
| 1199 |
+
if (text.length <= MESSAGE_PREVIEW_CHARS) return { text, truncated: false };
|
| 1200 |
+
const raw = text.slice(0, MESSAGE_PREVIEW_CHARS);
|
| 1201 |
+
const lastBreak = Math.max(raw.lastIndexOf(' '), raw.lastIndexOf('\n'));
|
| 1202 |
+
const clipped = lastBreak > MESSAGE_PREVIEW_CHARS * 0.65 ? raw.slice(0, lastBreak) : raw;
|
| 1203 |
+
return { text: `${clipped.trimEnd()}...`, truncated: true };
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
function epochFromFilename(filename) {
|
| 1207 |
const m = FILENAME_RE.exec(filename);
|
| 1208 |
if (!m) return 0;
|
|
|
|
| 1235 |
if (!body) return null;
|
| 1236 |
const fm = FILENAME_RE.exec(filename);
|
| 1237 |
const refs = Array.isArray(fields.refs) ? fields.refs : (fields.refs ? [fields.refs] : []);
|
| 1238 |
+
const { headline, excerpt, rest } = splitFirstAndRest(body);
|
| 1239 |
+
const preview = truncatePreview(excerpt || headline || body);
|
| 1240 |
return {
|
| 1241 |
filename,
|
| 1242 |
agent: (fields.agent || (fm && fm[3]) || 'unknown').trim(),
|
|
|
|
| 1244 |
epoch: epochFromFilename(filename),
|
| 1245 |
refs: refs.filter(Boolean),
|
| 1246 |
headline,
|
| 1247 |
+
excerpt: preview.text,
|
| 1248 |
+
excerptHtml: renderMarkdownInline(preview.text),
|
| 1249 |
+
body,
|
| 1250 |
+
bodyHtml: renderMarkdownInline(body),
|
| 1251 |
+
hasMore: Boolean(rest) || preview.truncated,
|
| 1252 |
steps: findBestSteps(body),
|
| 1253 |
};
|
| 1254 |
}
|
|
|
|
| 1419 |
});
|
| 1420 |
return [...set];
|
| 1421 |
}
|
| 1422 |
+
function buildText(m, { expanded = false } = {}) {
|
| 1423 |
const ms = buildMentions(m);
|
| 1424 |
const tags = ms.length ? ms.map(a => `<span class="mention">${escapeHtml(mentionLabel(a))}</span>`).join(' ') + ' ' : '';
|
| 1425 |
+
const messageHtml = expanded && m.bodyHtml ? m.bodyHtml : (m.excerptHtml || escapeHtml(m.headline || ''));
|
| 1426 |
// Use plain text (one-line trim) joined with <br>s, lightly applying markdown for **bold** etc
|
| 1427 |
+
return `${tags}${messageHtml}`;
|
| 1428 |
}
|
| 1429 |
function htmlToText(html) {
|
| 1430 |
const d = document.createElement('div');
|
|
|
|
| 1469 |
<div class="body">
|
| 1470 |
<div class="head"><span class="name">${escapeHtml(displayAgentName(m.agent))}</span><span class="ts">${fmtTime(m.epoch)}</span></div>
|
| 1471 |
<div class="text">${buildText(m)}</div>
|
| 1472 |
+
${m.hasMore ? '<button type="button" class="see-more-btn" aria-expanded="false">See more</button>' : ''}
|
| 1473 |
${pill}
|
| 1474 |
${buildQuotes(m)}
|
| 1475 |
</div>
|
| 1476 |
`;
|
| 1477 |
+
const moreBtn = node.querySelector('.see-more-btn');
|
| 1478 |
+
if (moreBtn) {
|
| 1479 |
+
const textEl = node.querySelector('.text');
|
| 1480 |
+
moreBtn.addEventListener('click', () => {
|
| 1481 |
+
const expanded = moreBtn.getAttribute('aria-expanded') !== 'true';
|
| 1482 |
+
moreBtn.setAttribute('aria-expanded', String(expanded));
|
| 1483 |
+
moreBtn.textContent = expanded ? 'See less' : 'See more';
|
| 1484 |
+
textEl.innerHTML = buildText(m, { expanded });
|
| 1485 |
+
});
|
| 1486 |
+
}
|
| 1487 |
messagesEl.appendChild(node);
|
| 1488 |
return node;
|
| 1489 |
}
|