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
24 changes: 19 additions & 5 deletions app/static/builder/command-builder-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
if (!r.others.length && !ownAgentsOf(b).length && (b.setups || []).some(s => s.key === 'original')) r.others = ['original'];
delete r.other;
if (r.options) delete r.options[key];
return r;
return keepDefaultProvider(r);
}
// The datasets a standard recipe runs: each with each choice, a job each; dataset also accepts one key.
const datasetsOf = r => Array.isArray(r.datasets) ? r.datasets : (r.dataset ? [r.dataset] : []);
Expand Down Expand Up @@ -183,11 +183,14 @@
function createStandard(benchmark = '', other = '') {
const st = standard(), b = (benchmark && standardBase({benchmark})) || st.benchmarks[0];
const r = {version: 1, harness: 'standard', name: 'standard-experiment', title: 'Standard experiment', benchmark: '', datasets: [], others: [],
model_choice: 'any', provider: firstAvailable(providersOf({}), 'openai'), model: bareModel(schema.defaultModel || ''), limit: '', concurrency: '', unsandboxed: false, where: 'local',
model_choice: 'any', provider: '', model: bareModel(schema.defaultModel || ''), limit: '', concurrency: '', unsandboxed: false, where: 'local',
backend: 'local', options: {}};
// a version's ref (key@version) opens that version
const ref = b && (b.versions || []).some(v => v.ref === benchmark) ? benchmark : b && b.key;
return b ? setStandardBenchmark(r, ref, other) : r;
unpicked.add(r);
if (b) setStandardBenchmark(r, ref, other);
if (!r.provider) r.provider = firstAvailable(providersOf({}), 'openai'); // none set serves it
return r;
}
// Keep only options and values the benchmark accepts.
const ownOptions = (b, opts) => Object.fromEntries(Object.entries(opts || {}).filter(([k, v]) => {
Expand Down Expand Up @@ -216,7 +219,7 @@
if (r.bench_options) r.bench_options = ownOptions(b, r.bench_options);
if (r.bench_options && ownAgentsOf(b).length) delete r.bench_options.agent; // each own agent is its own choice
if (was !== b || r.name === 'standard-experiment') { r.name = b.key + '-experiment'; r.title = b.label + ' experiment'; }
return r;
return keepDefaultProvider(r);
}
// A benchmark whose lists name the list they are cut from (``subset_of``): the dataset a list is drawn under, its
// own id for one cut from none. A choice of another list of that dataset takes the place of the one chosen, its task
Expand Down Expand Up @@ -271,6 +274,7 @@
// A saved standard recipe read back: known fields only, each of its type.
function standardFromJSON(raw, notes) {
const r = createStandard(typeof raw.benchmark === 'string' ? raw.benchmark : '');
unpicked.delete(r);
for (const key of ['name', 'title', 'model', 'where', 'model_choice']) if (typeof raw[key] === 'string') r[key] = raw[key];
const sets = Array.isArray(raw.datasets) ? raw.datasets.filter(k => typeof k === 'string') : typeof raw.dataset === 'string' && raw.dataset ? [raw.dataset] : null;
// The builder chooses one list per dataset family; report any saved choices it drops.
Expand Down Expand Up @@ -411,6 +415,16 @@
const needsOf = c => endpointOf(c) ? 'MODEL_' + endpointOf(c) + '_API_URL' : PROVIDER_NEEDS[c] || PROVIDER_NEEDS.custom;
const available = () => ((schema.credentials || {}).available || []).filter(p => PROVIDERS.includes(kindOf(p)));
const firstAvailable = (offered, otherwise) => available().find(p => offered.includes(p)) || otherwise;
// A new standard recipe's provider until the person chooses one: the first set that serves its benchmark and
// participants, chosen again only when a change leaves it unset or unable to serve them. A choice, or a recipe
// read back, keeps its own.
const unpicked = new WeakSet();
function keepDefaultProvider(r) {
if (!unpicked.has(r)) return r;
const offered = providersOf(r), have = available().filter(c => offered.includes(kindOf(c)));
if (have.length && !have.includes(choiceOf(r))) { setChoice(r, have[0]); unpicked.add(r); }
return r;
}
// What each part of a run that calls the model speaks: a Harbor run chats, a benchmark's own scripts their setup's
// apis, an agent of the standard its definition's apis. A provider is offered when it may serve every part. A judge
// speaks chat too, on its own provider or, Same as agent, on the agent's (blockedRole).
Expand All @@ -427,7 +441,7 @@
// The Model step's choice into the recipe: its provider, and for a named endpoint its id.
// a provider that routes no model to several takes no Served by: a pin made for OpenRouter is dropped with it
function setChoice(r, c) {
r.provider = kindOf(c); keepEndpoint(r, {endpoint: endpointOf(c)});
unpicked.delete(r); r.provider = kindOf(c); keepEndpoint(r, {endpoint: endpointOf(c)});
for (const role of SERVED_ROLES) if (kindOf(roleChoiceOf(r, role)) !== 'openrouter' && r.served_by) setServed(r, role, []);
}
// A judge's or user simulator's own provider (recipe.py: judge_provider, simulator_provider), a choice as the Model
Expand Down
26 changes: 11 additions & 15 deletions app/static/builder/command-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,27 +480,22 @@
}
};
// The provider is one whose key (an OpenAI-compatible endpoint: its URL) is set in Settings, each endpoint by its
// name. One is said, nothing to choose; several are a select of those alone; none, every provider. A recipe
// naming one whose key is not set keeps it, marked, until another is chosen.
// name: a select of those alone, at any size; none set, every provider. A recipe naming one whose key is not set
// keeps it, shown as nothing chosen, until another is chosen.
const providerField = (rec, offered) => {
const have = C.available().filter(p => offered.includes(p.split(':')[0])), current = C.choiceOf(rec);
if (have.length === 1 && current === have[0])
return `<div class="nb-field"><span>Provider</span><span class="nb-fixed">${esc(C.labelOf(current))}</span><small>The only one set in Settings.</small></div>`;
const shown = !have.length ? offered : [...have, ...(have.includes(current) ? [] : [current])];
return select('Provider', 'provider', current, shown.map(p => [p, have.length && !have.includes(p) ? C.labelOf(p) + ' · not set in Settings' : C.labelOf(p)]));
return select('Provider', 'provider', current, (have.length ? have : offered).map(p => [p, C.labelOf(p)]), 'Choose a provider');
};
// The standard's, a role's on its line, the same choices; the judge's and the user simulator's are Same as the
// agent, or another that serves chat.
const roleProvider = (rec, role, who) => {
const own = role !== 'model', offered = own ? C.roleProvidersOf() : C.providersOf(rec), agent = C.choiceOf(rec);
const have = C.available().filter(p => offered.includes(p.split(':')[0])), current = own ? (C.ownRole(rec, role) ? C.roleChoiceOf(rec, role) : '') : agent;
// the recipe's own choice stays listed, and shown, when Settings has none of it (a named endpoint, say)
const shown = [...(!have.length ? offered : have), ...(!current || (!have.length ? offered : have).includes(current) ? [] : [current])]
.filter(p => !own || p !== agent);
const name = p => !p ? 'Same as ' + who.toLowerCase().replace('module', 'Module') : have.length && !have.includes(p) ? C.labelOf(p) + ' · not set in Settings' : C.labelOf(p);
const options = (own ? ['', ...shown] : shown).map(p => [p, name(p)]);
if (options.length === 1 && options[0][0] === current) return `<span class="nb-fixed">${esc(options[0][1])}</span>`;
return `<select data-field="${own ? role + '_provider' : 'provider'}" aria-label="Provider, ${esc(own ? role : who.toLowerCase())}">${options.map(([v, t]) => `<option value="${esc(v)}" ${v === current ? 'selected' : ''}>${esc(t)}</option>`).join('')}</select>`;
// only those set; none set, every one that fits. A recipe's own choice not among them shows as none chosen.
const shown = (have.length ? have : offered).filter(p => !own || p !== agent);
const options = (own ? ['', ...shown] : shown).map(p => [p, p ? C.labelOf(p) : 'Same as ' + who.toLowerCase().replace('module', 'Module')]);
const none = !options.some(([v]) => v === current) ? '<option value="" selected hidden data-placeholder>Choose a provider</option>' : '';
return `<select data-field="${own ? role + '_provider' : 'provider'}" aria-label="Provider, ${esc(own ? role : who.toLowerCase())}">${none}${options.map(([v, t]) => `<option value="${esc(v)}" ${v === current ? 'selected' : ''}>${esc(t)}</option>`).join('')}</select>`;
};
// A role's model field, listing its own provider's models (model-picker.js), or its fixed model like the paper.
const modelInput = (rec, role, key, value, placeholder, name) => `<input aria-label="Model, ${esc(name.toLowerCase())}" data-field="${key}" value="${esc(value)}" list="nb-models" data-model-provider="${esc(C.roleChoiceOf(rec, role))}" placeholder="${esc(placeholder)}" autocomplete="off" spellcheck="false">`;
Expand Down Expand Up @@ -1120,7 +1115,8 @@
const atMost = (el, value) => el.max !== '' && value !== '' && Number(value) > Number(el.max) ? Number(el.max) : value;
// after: what sits on the input's line, after it (a model's reasoning)
const field = (label,key,value,{type='text',hint='',list='',min='',max='',placeholder='',declared=false}={}) => { const input = `<input${declared?' class="nb-declared"':''} aria-label="${esc(label)}" data-field="${key}" type="${type}" value="${esc(value)}" ${list?`list="${list}"`:''} ${min!==''?`min="${min}"`:''} ${max!==''?`max="${max}"`:''} ${type==='number'?'step="any"':''} placeholder="${esc(placeholder)}" autocomplete="off" spellcheck="false">`; return `<label class="nb-field">${label}${input}${hint?`<small>${hint}</small>`:''}</label>`; };
const select = (label,key,value,options) => `<label class="nb-field">${label}<select data-field="${key}">${options.map(([v,t])=>`<option value="${esc(v)}" ${v===value?'selected':''}>${esc(t)}</option>`).join('')}</select></label>`;
// placeholder: shown while value is none of the options
const select = (label,key,value,options,placeholder='') => `<label class="nb-field">${label}<select data-field="${key}">${placeholder&&!options.some(([v])=>v===value)?`<option value="" selected hidden data-placeholder>${esc(placeholder)}</option>`:''}${options.map(([v,t])=>`<option value="${esc(v)}" ${v===value?'selected':''}>${esc(t)}</option>`).join('')}</select></label>`;
const fixed = (label,value,whose='official') => `<label class="nb-field ui-field-row"><span class="ui-field-copy">${esc(label)}</span><span class="nb-fixed">${esc(value)} (${whose})</span></label>`;
const note = (title,text) => `<div class="nb-notice"><strong>${title}</strong>${text}</div>`;
function customRows(agent = '') {
Expand Down Expand Up @@ -1480,7 +1476,7 @@
if(p)rec.params[p.key]=p.type==='optional-boolean'?(value==='__default__'?null:value==='true'):value;
else if(d.field==='timeoutMultiplier'){rec.timeoutMultiplier=value;rec.agentMinutes='';}
else if(d.field.startsWith('adapterPath:')){const id=d.field.slice(12);if(String(value).trim())rec.adapterPaths[id]=String(value).trim();else delete rec.adapterPaths[id];}
else if(!d.providerModel&&['model','userModel','evalModel'].includes(d.field)&&/^(openrouter|openai)\//.test(String(value))){rec.provider=C.providerOf(rec,value);rec[d.field]=C.bareModel(value);
else if(!d.providerModel&&['model','userModel','evalModel'].includes(d.field)&&/^(openrouter|openai)\//.test(String(value))){C.setChoice(rec,C.providerOf(rec,value));rec[d.field]=C.bareModel(value);
renderForm();refreshPlan();const f=root.querySelector(`[data-field="${d.field}"]`);if(f){f.focus();f.setSelectionRange(f.value.length,f.value.length);}return;} // the provider the prefix named, and whether it is set
else if(d.field==='provider'){C.setChoice(rec,value);renderForm();refreshPlan();return;}
else if(d.field==='judge_provider'||d.field==='simulator_provider'){C.setRoleChoice(rec,d.field.split('_')[0],value);renderForm();refreshPlan();return;} // its models, levels and Served by follow it // whether it is set in Settings, and the names a runner's models are sent as, follow the provider
Expand Down
20 changes: 20 additions & 0 deletions app/ui_tests/test_command_builder_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ def test_a_new_recipe_starts_on_the_first_provider_set(self):
self.assertEqual(self.on(['openrouter', 'openai', 'custom'], new), ['openrouter', 'openrouter'])
self.assertEqual(self.on(['custom'], new), ['custom', 'custom'])
self.assertEqual(self.on([], new), ['openai', 'openai']) # No selection: infer from the latest observed model.
# a standard recipe: the first set that serves its participants, again as they change; a choice or a saved recipe keeps its own
standard = ("const k=C.standardOthers(C.createStandard('terminal-bench')).find(o=>o.key.startsWith('claude-code')).key;"
"const a=C.createStandard('terminal-bench',k);const b=C.createStandard('terminal-bench','codex@2.2.2');const was=b.provider;C.toggleParticipant(b,'codex@2.2.2');C.toggleParticipant(b,k);"
"const c=C.createStandard('terminal-bench','codex@2.2.2');C.setChoice(c,'openai');C.toggleParticipant(c,'codex@2.2.2');C.toggleParticipant(c,k);"
"const d=C.fromJSON(JSON.stringify({...C.createStandard('terminal-bench','codex@2.2.2'),provider:'openai'}));C.toggleParticipant(d,'codex@2.2.2');C.toggleParticipant(d,k);"
"process.stdout.write(JSON.stringify([C.chosenOf(a),a.provider,was,b.provider,c.provider,d.provider]))")
chosen, *providers = self.on(['openai', 'anthropic'], standard)
self.assertTrue(chosen[0].startswith('claude-code'), chosen)
self.assertEqual(providers, ['anthropic', 'openai', 'anthropic', 'openai', 'openai'])
# one that still serves is kept; a switch drops an OpenRouter pin; a named endpoint alone is chosen with its id
cases = ("const k=C.standardOthers(C.createStandard('terminal-bench')).find(o=>o.key.startsWith('claude-code')).key;"
"const r=C.createStandard('terminal-bench',k);const out=[r.provider];C.toggleParticipant(r,'codex@2.2.2');C.toggleParticipant(r,k);out.push(r.provider);"
"C.toggleParticipant(r,k);C.toggleParticipant(r,'codex@2.2.2');out.push(r.provider,C.chosenOf(r).length);process.stdout.write(JSON.stringify(out))")
self.assertEqual(self.on(['anthropic', 'custom'], cases), ['anthropic', 'custom', 'custom', 1])
pinned = ("const k=C.standardOthers(C.createStandard('terminal-bench')).find(o=>o.key.startsWith('claude-code')).key;"
"const r=C.createStandard('terminal-bench','codex@2.2.2');const was=r.provider;r.served_by={model:['x']};"
"C.toggleParticipant(r,'codex@2.2.2');C.toggleParticipant(r,k);process.stdout.write(JSON.stringify([was,r.provider,r.served_by||null]))")
self.assertEqual(self.on(['openrouter', 'anthropic'], pinned), ['openrouter', 'anthropic', None])
alone = "const r=C.createStandard('terminal-bench');process.stdout.write(JSON.stringify([C.choiceOf(r),C.providerBlocker(r)]))"
self.assertEqual(self.on(['custom:GPU'], alone, endpoints={'GPU': 'GPU box'}), ['custom:GPU', ''])

def test_run_waits_for_a_provider_that_is_set_and_never_switches_one(self):
state = ("const r=C.create();r.agents=['tau3-llm-agent'];" + PIN.replace('%', '%%') + "r.model='x';r.provider=%s;const back=C.fromJSON(JSON.stringify(r));"
Expand Down
5 changes: 2 additions & 3 deletions docs/builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ A provider is *set* when Settings holds its key, or the base URL of a custom pro

| Set in Settings | Model stage | Run |
| --- | --- | --- |
| One | That provider, nothing to choose | Open |
| Several | A choice among them | Open |
| One or more | A list of those alone; a new recipe starts on the first that fits | Open |
| None | Every provider that fits | Disabled until a provider is configured |
| A recipe naming one that is not set | Kept, marked *not set in Settings* | Disabled until another is chosen |
| A recipe naming one that is not set | Kept, the list showing none chosen | Disabled until another is chosen |

A recipe of controls alone needs no key unless the benchmark uses a judge or embedding model.

Expand Down