Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/static/builder/command-builder-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@
// another page and coming back finds the recipe as it was left. Pure halves:
// the page owns the storage. A draft does not come back when the page was
// opened for something else - a prefill from a run, or a run's own recipe.
const OPENED_FOR = ['run','like','dataset','model','agent','n_tasks','standard','other'];
const OPENED_FOR = ['run','like','saved','dataset','model','agent','n_tasks','standard','other'];
function packDraft(state) {
return JSON.stringify({version: 1, at: new Date().toISOString(), recipe: state.recipe, step: state.step, steps: STEPS.length, first: 'benchmark', tab: state.tab, saved: state.saved || ''});
}
Expand Down
1 change: 1 addition & 0 deletions app/static/builder/command-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
let opened = '', savedId = ''; // savedId: the saved recipe this page holds, which a save updates (renames)
if (schema.loadRecipe) { try { recipe = C.fromJSON(schema.loadRecipe); step = REVIEW; opened = 'Opened the recipe of run “' + schema.loadRun + '”. Run gives it a new name.'; } catch (e) { opened = 'This run’s recipe cannot be read: ' + e.message; } }
else if (schema.loadLike) { const o = C.fromJob(schema.loadLike); recipe = o.recipe; step = REVIEW; opened = o.notes.join(' '); }
else if (schema.loadSaved) { try { recipe = C.fromJSON(schema.loadSaved.recipe); savedId = schema.loadSaved.id; step = REVIEW; opened = 'Loaded “' + schema.loadSaved.name + '”.'; } catch (e) { opened = 'This saved recipe cannot be read: ' + e.message; } }
// An unsupported draft opens nothing; its rejection is shown as a toast.
else { let d = null; try { d = C.unpackDraft(localStorage.getItem(draftKey), query); } catch {} if (d && d.recipe) { recipe = d.recipe; step = d.step; tab = d.tab; savedId = d.saved; } else if (d && d.gone) opened = d.gone; }
const saveDraft = () => { try { localStorage.setItem(draftKey, C.packDraft({recipe, step, tab, saved: savedId})); } catch {} };
Expand Down
19 changes: 19 additions & 0 deletions app/static/builder/recipes.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* The Recipes page: one row per saved recipe; Info and Delete in one dialog (the Launches page's, runs/launches.css). */
.rcp-head { justify-content: space-between; align-items: center; }
.rcp-name { overflow-wrap: anywhere; } /* a name wraps, never cut */
.rcp-warn { display: flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 12.5px; color: var(--patch_failed_tests); cursor: help; }
.rcp-warn .ic { width: 14px; height: 14px; }
.rcp-val { display: block; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* the whole value is its tooltip */
#recipes td[data-col="name"] { white-space: normal; }
dialog.std-how.launch-delete.wide { width: min(56rem, calc(100vw - 32px)); }
.launch-delete .rcp-problems { list-style: none; padding: 0; margin: 12px 0 0; }
.rcp-problems li { display: flex; gap: 8px; align-items: baseline; padding: 6px 10px; margin-top: 4px; border-radius: 8px; font-size: 13px;
background: color-mix(in srgb, var(--patch_failed_tests) 12%, var(--surface)); }
.rcp-problems .ic { width: 14px; height: 14px; color: var(--patch_failed_tests); align-self: center; }
.rcp-step h3 em { font-style: normal; margin-right: 8px; }
.rcp-row { display: grid; grid-template-columns: minmax(7rem, 12rem) 1fr; gap: 12px; padding: 4px 0; border-top: 1px solid var(--border-soft); }
.rcp-row small { color: var(--text-dim); }
.rcp-row span { overflow-wrap: anywhere; }
.rcp-json { max-height: 22rem; overflow: auto; margin: 4px 0 0; padding: 10px 12px; border: 1px solid var(--border-soft); border-radius: 8px;
background: var(--surface-2); font-size: 12px; line-height: 1.5; }
@media (max-width: 640px) { .rcp-row { grid-template-columns: 1fr; gap: 0; } }
102 changes: 102 additions & 0 deletions app/static/builder/recipes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* The Recipes page (templates/builder/recipes.html): each saved recipe step by step, and what the builder's own
check of a loaded recipe says this Nullius cannot run of it - the recipe core's for a Harbor recipe (fromJSON,
validate, providerBlocker), the compile of its Review step for a standard one, done by the server for the page. */
(function () {
'use strict';
const STEPS = ['benchmark', 'runner', 'dataset', 'agent', 'model', 'limits', 'where'];
// {rows: [[step, title, value]], problems: [[step, message]]}; a recipe the core cannot read is its one problem.
function described(C, raw, compiled) {
let r;
const benchmark = typeof raw.benchmark === 'string' ? raw.benchmark : '';
try { r = C.fromJSON(raw); } catch (e) { return {rows: [], benchmark, problems: [[C.STEP.runner, e.message]]}; }
const out = C.isStandard(r) ? compiled || {review: [], errors: []} : {review: C.review(r), errors: C.validate(r).errors};
const blocked = C.providerBlocker(r);
return {rows: out.review, benchmark, problems: [...out.errors.map(e => [e.step, e.message]), ...(blocked ? [[C.STEP.model, blocked]] : [])]};
}
// A step's cell: the values of its review rows, in order; with none (a recipe its check stopped early), the benchmark it names.
const cell = (C, d, key) => d.rows.length ? d.rows.filter(([s]) => s === C.STEP[key]).map(([, , v]) => v).join(' · ') : key === 'benchmark' ? d.benchmark : '';
const said = (C, problems) => problems.map(([s, m]) => C.STEPS[s] + ': ' + m).join('\n');
// The first free name of a copy of `name`, among `taken`.
function copyName(name, taken) {
for (let n = 1; ; n++) { const t = name + (n === 1 ? ' (copy)' : ' (copy ' + n + ')'); if (!taken.includes(t)) return t; }
}
if (typeof module === 'object' && module.exports) { module.exports = {described, cell, said, copyName, STEPS}; return; }

const page = JSON.parse(document.getElementById('rcp-data').textContent), schema = page.schema;
const C = window.NulliusRecipe(schema), byId = Object.fromEntries(page.recipes.map(x => [x.id, x]));
const esc = s => String(s).replace(/[&<>"']/g, c => ({'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'})[c]);
const notify = (m, error = false) => window.nulliusNotify(m, {error});
// A write's notice survives the reload that shows its result.
const KEY = 'nullius.recipes.said';
const reload = m => { try { sessionStorage.setItem(KEY, m); } catch {} location.reload(); };
try { const m = sessionStorage.getItem(KEY); sessionStorage.removeItem(KEY); if (m) notify(m); } catch {}
const call = async (url, method, body) => {
const res = await nulliusFetch(url, {method, headers: {'Content-Type': 'application/json', 'X-CSRF-Token': schema.csrf}, body: JSON.stringify(body)});
const j = await res.json().catch(() => ({}));
if (!res.ok || j.ok === false) throw Error(j.error || 'HTTP ' + res.status);
return j;
};

// The cells, before the table toolkit reads the rows (tables.js wires them once the page is read).
const info = {};
for (const tr of document.querySelectorAll('#recipes tbody tr')) {
const item = byId[tr.dataset.recipe], d = info[item.id] = described(C, item.recipe, page.compiled[item.id]);
for (const key of STEPS) { const span = tr.querySelector(`[data-col="${key}"] .rcp-val`), v = cell(C, d, key); span.textContent = v; span.title = v; }
if (d.problems.length) { const w = tr.querySelector('.rcp-warn'); w.hidden = false; w.title = said(C, d.problems); }
tr.dataset.search = [item.name, ...STEPS.map(k => cell(C, d, k))].join(' ');
}

const dialog = document.getElementById('rcp-dialog');
let opener = null;
const show = (html, wide) => { dialog.innerHTML = html; dialog.classList.toggle('wide', wide); dialog.showModal(); };
dialog.addEventListener('close', () => opener?.focus());
dialog.addEventListener('click', e => { // the backdrop, not the dialog's own padding
const r = dialog.getBoundingClientRect();
if (e.target === dialog && (e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom)) dialog.close();
});
const head = (t, x) => `<div class="std-how-head"><h2 id="rcp-dialog-h">${esc(t)}</h2>${x ? '<button type="button" class="std-how-x" data-close aria-label="Close"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 3.5l9 9M12.5 3.5l-9 9"/></svg></button>' : ''}</div>`;
function details(item) {
const d = info[item.id], shown = STEPS.map(k => C.STEP[k]);
const warn = d.problems.length ? `<ul class="rcp-problems">${d.problems.map(([s, m]) => `<li><svg class="ic" aria-hidden="true"><use href="#i-alert"/></svg><span><b>${esc(C.STEPS[s])}</b> ${esc(m)}</span></li>`).join('')}</ul>` : '';
const steps = shown.map((s, n) => `<section class="rcp-step"><h3><em>0${n + 1}</em>${esc(C.STEPS[s])}</h3>${d.rows.filter(([i]) => i === s).map(([, t, v]) => `<div class="rcp-row"><small>${esc(t)}</small><span>${esc(v)}</span></div>`).join('')}</section>`).join('');
show(head(item.name, true) + warn + steps + `<h3 class="rcp-json-h">JSON</h3><pre class="rcp-json">${esc(JSON.stringify(item.recipe, null, 2))}</pre>`, true);
}
function ask(item) {
show(head('Delete recipe ' + item.name) + `<div class="launch-delete-acts"><button type="button" class="btn ghost" data-close autofocus>Keep it</button><button type="button" class="btn danger" data-delete="${esc(item.id)}">Delete recipe</button></div>`, false);
}
function download(item) {
const url = URL.createObjectURL(new Blob([JSON.stringify(item.recipe, null, 2) + '\n'], {type: 'application/json'})), a = document.createElement('a');
a.href = url; a.download = (item.recipe.name || 'recipe') + '.json'; a.click(); setTimeout(() => URL.revokeObjectURL(url), 1000);
}
document.addEventListener('click', async e => {
const b = e.target.closest('[data-act], [data-close], [data-delete], #rcp-import');
if (!b || b.getAttribute('aria-disabled') === 'true') return;
const item = byId[b.closest('[data-recipe]')?.dataset.recipe];
if (b.dataset.close !== undefined) return dialog.close();
if (b.dataset.act === 'info') { opener = b; return details(item); }
if (b.dataset.act === 'delete') { opener = b; return ask(item); }
if (b.dataset.act === 'export') return download(item);
try {
if (b.dataset.act === 'duplicate') {
const name = copyName(item.name, page.recipes.map(x => x.name));
await call('/new-run/recipes', 'POST', {recipe: {...item.recipe, title: name}});
reload('Saved “' + name + '”.');
} else if (b.dataset.delete) {
await call('/new-run/recipes/' + encodeURIComponent(b.dataset.delete), 'DELETE', {});
reload('Deleted “' + byId[b.dataset.delete].name + '”.');
} else if (b.id === 'rcp-import') document.getElementById('rcp-file').click();
} catch (err) { notify((b.dataset.delete ? 'Not deleted: ' : 'Not saved: ') + err.message, true); }
});
document.getElementById('rcp-file').addEventListener('change', async e => {
const file = e.target.files[0];
e.target.value = '';
if (!file) return;
let body;
try { body = JSON.parse(await file.text()); } catch { return notify('Not imported: ' + file.name + ' is not JSON.', true); }
try {
const j = await call('/new-run/recipes/import', 'POST', body), n = j.added.length;
const skipped = j.skipped.map(x => '“' + x.name + '”');
reload([n ? 'Imported ' + n + ' recipe' + (n > 1 ? 's' : '') + '.' : '', skipped.length ? 'Already saved: ' + skipped.join(', ') + '.' : ''].filter(Boolean).join(' '));
} catch (err) { notify(err.message, true); }
});
})();
1 change: 1 addition & 0 deletions app/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ input[type=text].invalid:focus { box-shadow: inset 0 0 0 1px var(--bad); }
background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
border-radius: 8px; padding: .65rem .85rem; font-size: .85rem; margin-bottom: 1rem;
}
.page-title + .alert { margin-top: 1rem; } /* the gap the controls row leaves when a table shows */
.alert .mono { color: var(--text); }
.alert.error {
background: color-mix(in srgb, var(--agent_error) 12%, var(--surface));
Expand Down
4 changes: 4 additions & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<symbol id="i-disk" viewBox="0 0 24 24"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 13h18M7 16h.01M10.5 16h.01"/></symbol>
<symbol id="i-cloud-down" viewBox="0 0 24 24"><path d="M4.4 15.3A7 7 0 1 1 15.7 8h1.8a4.5 4.5 0 0 1 2.4 8.3M12 12v9M8.5 17.5 12 21l3.5-3.5"/></symbol>
<symbol id="i-launches" viewBox="0 0 24 24"><path d="M12 3c3 2 4.5 5 4.5 9l-2 4h-5l-2-4C7.5 8 9 5 12 3zM7.5 12 5 15v3l4.5-2M16.5 12l2.5 3v3l-4.5-2M11 19.5l1 1.5 1-1.5"/><circle cx="12" cy="10" r="1.5"/></symbol>
<symbol id="i-recipe" viewBox="0 0 24 24"><rect x="5" y="3" width="14" height="18" rx="2"/><path d="M9 8h6M9 12h6M9 16h3.5"/></symbol>
<symbol id="i-copy" viewBox="0 0 24 24"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M15 9V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h3"/></symbol>
<symbol id="i-export" viewBox="0 0 24 24"><path d="M12 15V4M7 9l5-5 5 5M4 20h16"/></symbol>
<symbol id="i-dollar" viewBox="0 0 24 24"><path d="M12 3v18M16.5 7.5C15.9 6 14.2 5 12 5c-2.5 0-4.5 1.3-4.5 3.3 0 4.4 9 2.4 9 6.9 0 2-2 3.3-4.5 3.3-2.2 0-3.9-1-4.5-2.5"/></symbol>
<symbol id="i-refresh" viewBox="0 0 24 24"><path d="M20 12a8 8 0 1 1-2.7-6M20 4v5h-5"/></symbol>
<symbol id="i-close" viewBox="0 0 24 24"><path d="M9 7l-5 5 5 5M4 12h12M18 5v14"/></symbol>
Expand Down Expand Up @@ -213,6 +216,7 @@
<div class="nav-label">Manage</div>
<a class="nav-item {{ 'on' if ep.startswith('workspace') }}" href="{{ url_for('workspaces_page') }}" data-label="Workspaces" aria-label="Workspaces"><svg class="ic"><use href="#i-ws"/></svg><span class="lbl">Workspaces</span></a>
<a class="nav-item {{ 'on' if ep == 'launches_page' }}" href="{{ url_for('launches_page') }}" data-label="Launches" aria-label="Launches"><svg class="ic"><use href="#i-launches"/></svg><span class="lbl">Launches</span></a>
<a class="nav-item {{ 'on' if ep == 'recipes_page' }}" href="{{ url_for('recipes_page') }}" data-label="Recipes" aria-label="Recipes"><svg class="ic"><use href="#i-recipe"/></svg><span class="lbl">Recipes</span></a>
<a class="nav-item {{ 'on' if ep.startswith('settings') }}" href="{{ url_for('settings_page') }}" data-label="Settings" aria-label="Settings"><svg class="ic"><use href="#i-gear"/></svg><span class="lbl">Settings</span></a>
</div>
</nav>
Expand Down
48 changes: 48 additions & 0 deletions app/templates/builder/recipes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% from '_tables.html' import table, cell, greyed %}
{% extends "base.html" %}
{% block title %}Recipes — Nullius{% endblock %}
{% block crumb %}/ recipes{% endblock %}
{% block head %}<link rel="stylesheet" href="{{ url_for('static', filename='catalogue/catalogue.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='runs/launches.css') }}">{# its dialog #}
<link rel="stylesheet" href="{{ url_for('static', filename='builder/recipes.css') }}">
<script src="{{ url_for('static', filename='tables.js') }}"></script>{% endblock %}
{#- A recipe's row: its step cells and its search are filled by builder/recipes.js. #}
{% macro recipe_tr(x) %} data-recipe="{{ x.id }}"{% endmacro %}

{% block body %}
{% set local, why = builder_data.local, builder_data.recipesWhy %}
<div class="page-title rcp-head"><h1>Recipes</h1>
<button type="button" class="btn sm" id="rcp-import"{% if not local %} aria-disabled="true" title="{{ why }}"{% endif %}><svg class="ic" aria-hidden="true"><use href="#i-import"/></svg>Import</button>
<input type="file" accept=".json,application/json" id="rcp-file" hidden aria-label="Import a recipe JSON file"></div>

{% if recipes %}
{#- a column per step of the run builder, 01 to 07, by its key in command-builder-core.js (STEP) #}
{% set cols = [dict(key='name', label='Name', sticky=true, menu=false, width='expand'), dict(key='benchmark', label='Benchmark'), dict(key='runner', label='Runner'),
dict(key='dataset', label='Dataset'), dict(key='agent', label='Agent'), dict(key='model', label='Model'), dict(key='limits', label='Limits'),
dict(key='where', label='Where'), dict(key='saved', label='Saved', type='num', align='left'), dict(key='actions', label='Actions', blank=true)] %}
{% call(x, c) table('recipes', cols, recipes, recipe_tr, search='Search by name, benchmark or agent', columns=true, empty='No recipe matches.', noun='recipes') %}
{%- if c.key == 'name' %}{% call cell(c, sort=x.name) %}<span class="rcp-name">{{ x.name }}</span>
<span class="rcp-warn" hidden><svg class="ic" aria-hidden="true"><use href="#i-alert"/></svg>Cannot run here</span>{% endcall %}
{%- elif c.key == 'saved' %}{% call cell(c, sort=x.saved[:19]|replace('-', '')|replace(':', '')|replace('T', ''), class='mono faint nowrap') %}{{ x.saved[:16]|replace('T', ' ') }}{% endcall %}
{%- elif c.key == 'actions' %}{% call cell(c, class='acts-col') %}
<a class="icon-btn" href="{{ url_for('new_run', saved=x.id) }}" aria-label="Open {{ x.name }} in the run builder" title="Open in the run builder"><svg class="ic"><use href="#i-newrun"/></svg></a>
<button type="button" class="icon-btn" data-act="info" aria-haspopup="dialog" aria-label="Info: {{ x.name }}" title="Info"><svg class="ic"><use href="#i-info"/></svg></button>
{%- if local %}<button type="button" class="icon-btn" data-act="duplicate" aria-label="Duplicate {{ x.name }}" title="Duplicate"><svg class="ic"><use href="#i-copy"/></svg></button>
{%- else %}{{ greyed('Duplicate ' ~ x.name, 'Duplicate', why, 'dup-' ~ x.id, icon='copy', class='icon-btn') }}{% endif %}
<button type="button" class="icon-btn" data-act="export" aria-label="Export {{ x.name }}" title="Export JSON"><svg class="ic"><use href="#i-export"/></svg></button>
{%- if local %}<button type="button" class="icon-btn danger" data-act="delete" aria-haspopup="dialog" aria-label="Delete {{ x.name }}" title="Delete recipe"><svg class="ic"><use href="#i-trash"/></svg></button>
{%- else %}{{ greyed('Delete ' ~ x.name, 'Delete recipe', why, 'del-' ~ x.id) }}{% endif %}
{% endcall %}
{%- else %}{% call cell(c) %}<span class="rcp-val"></span>{% endcall %}
{%- endif %}
{% endcall %}
{% else %}
<div class="alert">No saved recipe yet.{% if local %} <a href="{{ url_for('new_run') }}">Build one <span aria-hidden="true">→</span></a>{% endif %}</div>
{% endif %}
<dialog class="std-how launch-delete" id="rcp-dialog" aria-labelledby="rcp-dialog-h"></dialog>
<script id="rcp-data" type="application/json">{{ dict(schema=builder_data, recipes=recipes, compiled=compiled)|tojson }}</script>
{% endblock %}
{% block scripts %}
<script src="{{ url_for('static', filename='builder/command-builder-core.js') }}"></script>
<script src="{{ url_for('static', filename='builder/recipes.js') }}"></script>
{% endblock %}
Loading
Loading