heartcode 0.1.69 → 0.1.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/settings.html CHANGED
@@ -257,6 +257,30 @@
257
257
  .preset b { display: block; }
258
258
  .preset span { color: var(--muted); font-size: 12px; }
259
259
  .preset.on { border-color: var(--accent); background: var(--accent-soft); }
260
+ .preset.cli { position: relative; }
261
+ .preset.cli .mark { position: absolute; top: 10px; right: 10px; width: 15px; height: 15px; color: var(--accent); }
262
+ .preset.cli .mark svg { width: 100%; height: 100%; }
263
+ .preset.off { border-style: dashed; background: none; }
264
+ .preset.off b { color: var(--muted); }
265
+ .preset .get { display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); }
266
+ .preset .get svg { width: 13px; height: 13px; }
267
+ .preset.off:hover .get { filter: brightness(1.15); }
268
+ .preset .get.busy svg { animation: spin 1s linear infinite; }
269
+ .preset .get.ext { color: var(--muted); background: none; padding-left: 0; }
270
+ .preset .bad { color: var(--danger, #c33); }
271
+ .shim { display: block; height: 10px; border-radius: 5px; margin-top: 6px; background: linear-gradient(90deg, var(--line, #8883) 25%, color-mix(in srgb, var(--line, #8883) 40%, transparent) 50%, var(--line, #8883) 75%); background-size: 200% 100%; animation: shim 1.2s linear infinite; }
272
+ .preset.skel { pointer-events: none; }
273
+ .preset.skel .shim:first-child { width: 70%; height: 13px; margin-top: 0; }
274
+ @keyframes shim { from { background-position: 200% 0; } to { background-position: -200% 0; } }
275
+ .cli-bar { display: flex; align-items: center; gap: 12px; margin: 4px 0 10px; font-size: 13px; }
276
+ #cli-form { width: min(980px, calc(100vw - 32px)); }
277
+ .preset.cli .box { position: absolute; top: 10px; right: 10px; width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--line-strong); display: grid; place-items: center; color: transparent; }
278
+ .preset.cli .box .icon { width: 12px; height: 12px; color: inherit; vertical-align: 0; } /* not .preset span's grey */
279
+ .preset.cli .mark.icon { color: var(--accent); }
280
+ .preset.cli.picked { border-color: var(--accent); background: var(--accent-soft); }
281
+ .preset.cli.picked .box { background: var(--accent); border-color: var(--accent); color: #fff; }
282
+ .preset.cli.had { opacity: .6; cursor: default; }
283
+ .cli-log { max-height: 120px; overflow: auto; font: 11px/1.4 ui-monospace, monospace; color: var(--faint); white-space: pre-wrap; margin-top: 8px; }
260
284
 
261
285
  /* Providers & models: every provider's models in one list, full width; it fills the screen's height and scrolls inside */
262
286
  .head-actions { display: flex; gap: 8px; align-items: center; }
@@ -290,7 +314,7 @@
290
314
  .mrow.flash { animation: flash 1.6s ease-out; }
291
315
  @keyframes flash { from { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); } to { background: none; box-shadow: none; } }
292
316
  .mrow .id { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
293
- .rows > .mrow, .rows > .mwrap { height: 40px; } /* one height: a long list only draws what's in view */
317
+ .rows > .mwrap { height: 40px; content-visibility: auto; contain-intrinsic-size: auto 40px; } /* thousands of rows: the browser lays out only the ones in view */
294
318
  .mwrap .mrow { height: 100%; }
295
319
  .mrow .can { display: inline; margin-left: 12px; color: var(--muted); font-family: var(--sans); font-size: 11.5px; } /* on the name's line: one line a model */
296
320
  .mrow .add { color: var(--accent); font-size: 12.5px; font-weight: 600; white-space: nowrap; opacity: .55; transition: opacity .12s; }
@@ -454,7 +478,7 @@
454
478
  .pill .again:hover:not(:disabled) { color: var(--text); }
455
479
  .pill.on { border-color: var(--accent); background: var(--accent-soft); }
456
480
  .pill.on .again { border-left-color: color-mix(in srgb, var(--accent) 40%, transparent); }
457
- .mt-h, .mtable li { display: grid; grid-template-columns: 14px 16px 28px minmax(120px, 1fr) 80px 148px 52px 26px 26px 26px 44px 44px 44px 94px 74px 104px; /* the last: Test · Request · Edit · ✕, as wide as they are */ align-items: center; column-gap: 4px; padding: 8px 12px; }
481
+ .mt-h, .mtable li { display: grid; grid-template-columns: 14px 16px 28px minmax(120px, 1fr) 100px 148px 52px 26px 26px 26px 44px 44px 44px 94px 74px 104px; /* the last: Test · Request · Edit · ✕, as wide as they are */ align-items: center; column-gap: 4px; padding: 8px 12px; }
458
482
  .mt-h button.mid, .mtable .mid { text-align: center; }
459
483
  @media (min-width: 861px) and (max-width: 1400px) { .mt-h, .mtable li { padding-left: 6px; padding-right: 6px; } .mt, .mt-h.mt-hpick { min-width: 1012px; } } /* a small laptop (1280): narrower rows */
460
484
  .mt-h > :nth-child(15), .mtable .try { padding-left: 12px; } /* Works?: a little room after the right-aligned price */
@@ -478,6 +502,8 @@
478
502
  .mtable li:first-child .n { color: var(--accent); }
479
503
  .mtable .m { font-family: var(--mono); font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
480
504
  .mtable .p { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
505
+ .picon { width: 13px; height: 13px; margin-right: 5px; vertical-align: -2px; color: var(--faint); }
506
+ .picon.cli { color: var(--accent); }
481
507
  .mtable .yes { color: var(--ok); }
482
508
  /* Helper: a switch (can #1 start it for side jobs?), then what it's good at, as pills */
483
509
  .hp { display: flex; align-items: center; gap: 4px; min-width: 0; }
@@ -576,6 +602,7 @@
576
602
  .mt-set { display: flex; align-items: center; gap: 8px; min-width: 0; }
577
603
  .mt-setl { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
578
604
  .mt-setl .icon { width: 14px; height: 14px; color: var(--faint); }
605
+ .mt-sets.few .mt-setl .lt { display: inline !important; } /* only the time limits: room for their names */
579
606
  .mt-div { width: 1px; height: 22px; background: var(--line-strong); margin: 0 4px; } /* between the fail-over settings and the helpers' */
580
607
  .mt-mode-sets .h-order select { height: 34px; }
581
608
  .mt-mode-sets .seg { height: 34px; }
@@ -847,6 +874,9 @@
847
874
  .mtable li .acts .ib.k-info { color: var(--c-slate); }
848
875
  .mtable li .acts .ib.k-edit { color: var(--c-violet); }
849
876
  .mtable li .acts .ib.k-del { color: var(--c-red); }
877
+ /* every dialog: at most 80% of the screen each way (its own width may be less); what doesn't fit scrolls inside */
878
+ dialog { max-width: 80vw !important; max-height: 80vh !important; max-height: 80dvh !important; }
879
+ dialog .actions:last-child:not(#p-added) { position: sticky; bottom: -24px; margin-bottom: -24px; padding-bottom: 24px; background: var(--panel); z-index: 1; } /* its buttons stay in view while the rest scrolls */
850
880
  </style>
851
881
  </head>
852
882
  <body>
@@ -876,7 +906,7 @@
876
906
  <section class="page" id="page-providers">
877
907
  <div class="head">
878
908
  <div><h1>Providers</h1><p class="lead">Click a model to add it to the list, or tick several. HeartCode tries the list in order: #1 first, the next when one fails.</p></div>
879
- <div class="head-actions"><button id="p-mine" type="button"></button><button class="primary" id="p-open">+ Add a provider</button></div>
909
+ <div class="head-actions"><button id="p-mine" type="button"></button><button id="cli-open" type="button" title="Claude Code, Codex, opencode, Copilot, Cursor… on this machine">+ Add CLIs</button><button class="primary" id="p-open">+ Add a provider</button></div>
880
910
  </div>
881
911
  <div class="steps" id="steps"></div>
882
912
  <div class="work" id="p-work" hidden>
@@ -885,8 +915,11 @@
885
915
  <input type="checkbox" id="pick-shown" aria-label="select every model shown">
886
916
  <input type="search" id="m-search" placeholder="Search all models…">
887
917
  <label class="free-only" title="only the models their provider lists at $0 (a provider whose list has no prices can't say)"><input type="checkbox" id="free-only">Free only</label>
918
+ <label class="free-only" title="only the providers that are on (their switch): the ones off are hidden"><input type="checkbox" id="on-only">On only</label>
919
+ <select id="m-kind" aria-label="which providers to show" title="all of them, only the API providers, or only the coding CLIs"><option value="all">All</option><option value="api">Providers only</option><option value="cli">CLIs only</option></select>
888
920
  <select id="m-sort" aria-label="sort the models"><option value="name">Sort by name</option><option value="price">Sort by price (free first)</option></select>
889
921
  <button class="small ghost" id="fold-all" type="button">Collapse all</button>
922
+ <button class="small ghost" id="on-all" type="button" title="switch every provider on or off (off: kept, but HeartCode skips its models)"></button>
890
923
  <button class="small" id="dev-all" type="button" title="ask models.dev what each listed model can do: tool calls, context, thinking, images">Get from models.dev</button>
891
924
  </div>
892
925
  <div class="job-slot" data-where="catalog"></div>
@@ -1110,21 +1143,32 @@
1110
1143
  </dialog>
1111
1144
  <dialog id="p-form" aria-labelledby="p-title">
1112
1145
  <h2 id="p-title">Add a provider</h2>
1113
- <p class="sub">Pick one to fill in its address, or type any OpenAI-compatible API below.</p>
1146
+ <p class="sub">Pick one to fill in its address, or type any OpenAI-compatible API below. A coding CLI (Claude Code, Codex…)? Use <b>+ Add CLIs</b>.</p>
1114
1147
  <div class="presets" id="presets"></div>
1115
1148
  <div class="row" style="margin-top:6px">
1116
1149
  <div class="grow"><label class="f" for="p-name">Name</label><input type="text" id="p-name" placeholder="openrouter, groq, work…"></div>
1117
1150
  <div class="grow" style="flex:2"><label class="f" for="p-url">Base URL</label><input type="text" id="p-url" placeholder="https://openrouter.ai/api/v1"></div>
1118
1151
  </div>
1152
+ <div id="p-keys">
1119
1153
  <label class="f" for="p-key">API key <span class="muted" id="p-keynote" style="font-weight:normal"></span></label>
1120
1154
  <input type="password" id="p-key" autocomplete="off" placeholder="paste it here (none for a server on this machine, like Ollama)">
1121
1155
  <div class="hint">Kept in config.json on this machine. This page only shows its first and last characters.</div>
1156
+ </div>
1157
+ <div class="hint" id="p-clinote" hidden></div>
1122
1158
  <div id="p-more" hidden>
1123
1159
  <label class="opt" style="margin-top:16px"><div class="t"><b>Load its model list</b><span>On: its models are asked from the provider. Off: never asked; only the models added by name show (the box next to its name).</span></div><span class="sw"><input type="checkbox" id="p-list-on"><i></i></span></label>
1124
1160
  <div class="actions" id="p-added"></div>
1125
1161
  </div>
1126
1162
  <div class="actions"><button class="danger" id="p-delete" hidden>Delete provider</button><span class="spacer"></span><button id="p-cancel">Cancel</button><button class="primary" id="p-save">Add provider</button></div>
1127
1163
  </dialog>
1164
+ <dialog id="cli-form" aria-labelledby="cli-title">
1165
+ <h2 id="cli-title">Add coding CLIs</h2>
1166
+ <p class="sub">Tick the ones you want: each is added as a provider with its models. A CLI works on your messages with its own tools and its own sign-in (no key). Not installed? Click Install.</p>
1167
+ <div class="cli-bar"><button class="small ghost" id="cli-all" type="button"></button><span class="muted" id="cli-count"></span></div>
1168
+ <div class="presets" id="cli-tiles"></div>
1169
+ <pre class="cli-log" id="cli-log" hidden></pre>
1170
+ <div class="actions"><button id="cli-cancel" type="button">Cancel</button><button class="primary" id="cli-add" type="button" disabled>Add CLIs</button></div>
1171
+ </dialog>
1128
1172
  <dialog id="c-form" aria-labelledby="c-title">
1129
1173
  <h2 id="c-title">Add a server</h2>
1130
1174
  <p class="sub">The command that starts it on this machine, or the URL of a remote one (a sign-in page opens if it needs one). Its name comes from the command; its flags can be ticked on and off in the list.</p>
@@ -1271,6 +1315,15 @@ const ICON = {
1271
1315
  image: 'M3 5h18v14H3zM8.5 11a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zM21 15l-5-5L5 19',
1272
1316
  bulb: 'M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7V16h8v-1.3A7 7 0 0 0 12 2z',
1273
1317
  }
1318
+ // before a provider's name: a terminal for a coding CLI (cli://), a server for an API
1319
+ const provIcon = (name) => {
1320
+ const cli = /^cli:\/\//i.test(S?.providers.find((p) => p.name === name)?.baseUrl ?? '')
1321
+ const el = ic(cli ? 'terminal' : 'server', `picon${cli ? ' cli' : ''}`)
1322
+ el.title = cli ? 'a coding CLI' : 'an API provider'
1323
+ el.removeAttribute('aria-hidden')
1324
+ el.setAttribute('aria-label', el.title)
1325
+ return el
1326
+ }
1274
1327
  const ic = (name, cls = '') => {
1275
1328
  const el = document.createElement('span')
1276
1329
  el.className = `icon ${cls}`.trim()
@@ -1608,10 +1661,99 @@ function drawPresets() {
1608
1661
  if (!editing && (!$('p-name').value || PRESETS.some(([n]) => n === $('p-name').value))) $('p-name').value = name
1609
1662
  $('p-url').value = url
1610
1663
  drawPresets()
1664
+ drawCliNote()
1611
1665
  $('p-key').focus()
1612
1666
  } }, h('b', { textContent: label }), h('span', { textContent: what }))))
1613
1667
  }
1614
- $('p-url').oninput = drawPresets
1668
+ $('p-url').oninput = () => (drawPresets(), drawCliNote())
1669
+
1670
+ // The coding CLIs (src/clis.js), added on their own dialog (+ Add CLIs): tick any number, then one click
1671
+ // adds each as a provider at cli://<its name>; one that isn't installed installs from here (its log shown
1672
+ // as it goes, ticked once it's in), then is signed in to in a terminal
1673
+ let CLIS = null
1674
+ let cliPoll = null
1675
+ const CLI_PICKS = new Set()
1676
+ let cliTouched = false // ticks changed by hand: installed ones aren't ticked again by themselves
1677
+ const cliAdded = (id) => (S?.providers ?? []).some((p) => new RegExp(`^cli://${id}(/|$)`, 'i').test(p.baseUrl ?? ''))
1678
+ function loadClis() {
1679
+ api('/api/clis').then((list) => {
1680
+ const was = new Map((CLIS ?? []).map((k) => [k.id, k.installed]))
1681
+ CLIS = list
1682
+ for (const k of list) if (k.installed && !cliAdded(k.id) && (!cliTouched || was.get(k.id) === false)) CLI_PICKS.add(k.id) // ticked: what's here, and one just installed
1683
+ drawClis()
1684
+ if ($('p-form').open) drawCliNote()
1685
+ clearTimeout(cliPoll)
1686
+ if (list.some((k) => k.installing || k.pending) && $('cli-form').open) cliPoll = setTimeout(loadClis, list.some((k) => k.installing) ? 1500 : 700) // an install's log; versions still being asked
1687
+ }, (e) => toast(e.message, true))
1688
+ }
1689
+ // the provider dialog with a cli:// address (editing one, or typed): no key field, how to sign in instead
1690
+ function drawCliNote() {
1691
+ const cli = /^cli:\/\/([^/]+)/i.exec($('p-url').value.trim())?.[1]
1692
+ const k = CLIS?.find((x) => x.id === cli)
1693
+ $('p-keys').hidden = Boolean(cli)
1694
+ $('p-clinote').hidden = !cli
1695
+ $('p-clinote').textContent = cli ? `No key: ${k?.title ?? cli} uses its own sign-in. Not signed in yet? Run "${k?.login ?? cli}" in a terminal first.` : ''
1696
+ }
1697
+ function drawClis() {
1698
+ const busy = CLIS?.find((x) => x.installing || x.error)
1699
+ $('cli-log').hidden = !busy?.log && !busy?.error
1700
+ if (busy) $('cli-log').textContent = busy.error ? `${busy.title}: ${busy.error}` : `Installing ${busy.title}…\n${busy.log.slice(-1500)}`
1701
+ if (busy) $('cli-log').scrollTop = 1e9
1702
+ for (const id of [...CLI_PICKS]) if (cliAdded(id) || !CLIS?.find((k) => k.id === id)?.installed) CLI_PICKS.delete(id)
1703
+ const free = (CLIS ?? []).filter((k) => k.installed && !cliAdded(k.id))
1704
+ const n = CLI_PICKS.size
1705
+ $('cli-add').disabled = !n
1706
+ $('cli-add').textContent = n ? `Add ${n} CLI${n === 1 ? '' : 's'}` : 'Add CLIs'
1707
+ $('cli-all').hidden = !free.length
1708
+ $('cli-all').textContent = free.every((k) => CLI_PICKS.has(k.id)) ? 'Untick all' : `Tick all installed (${free.length})`
1709
+ $('cli-count').textContent = CLIS ? `${CLIS.filter((k) => k.installed).length} of ${CLIS.length} installed${CLIS.some((k) => cliAdded(k.id)) ? ` · ${CLIS.filter((k) => cliAdded(k.id)).length} added already` : ''}` : ''
1710
+ if (!CLIS) return put($('cli-tiles'), Array.from({ length: 15 }, () => h('div', { className: 'preset skel' }, h('i', { className: 'shim' }), h('i', { className: 'shim', style: 'width:45%' })))) // loading
1711
+ const order = [...CLIS].sort((a, b) => b.installed - a.installed) // installed first; the rest to install
1712
+ put($('cli-tiles'), order.map((k) => {
1713
+ const had = cliAdded(k.id)
1714
+ const picked = CLI_PICKS.has(k.id)
1715
+ return h('button', { type: 'button', className: 'preset cli' + (k.installed ? '' : ' off') + (picked ? ' picked' : '') + (had ? ' had' : ''), 'aria-pressed': k.installed && !had ? String(picked) : undefined, title: had ? `${k.title}: added already` : k.installed ? `${k.title} ${k.version}` : k.install ? `click to install: ${k.install}` : `install it yourself: ${k.commands?.[0] ?? k.page}${k.needs ? ` (needs ${k.needs})` : ''}`, onclick: () => {
1716
+ if (had) return
1717
+ if (k.installed) {
1718
+ cliTouched = true
1719
+ picked ? CLI_PICKS.delete(k.id) : CLI_PICKS.add(k.id)
1720
+ return drawClis()
1721
+ }
1722
+ if (k.installing) return
1723
+ if (!k.install) return window.open(k.page, '_blank', 'noopener')
1724
+ if (!confirm(`Install ${k.title}?\n\nThis runs: ${k.install}`)) return
1725
+ api('/api/cli/install', { id: k.id }).then(loadClis, (e) => toast(e.message, true))
1726
+ } }, ...(k.installed
1727
+ ? [h('b', { textContent: k.title }), had ? h('span', { textContent: 'added' }) : k.pending ? h('i', { className: 'shim', style: 'width:40%' }) : h('span', { textContent: k.version ? `v${k.version}` : 'installed' }), had ? ic('check', 'mark') : h('span', { className: 'box' }, ic('check'))]
1728
+ : [h('b', { textContent: k.title }), k.installing ? h('span', { className: 'get busy' }, ic('refresh'), 'Installing…')
1729
+ : k.error ? h('span', { className: 'get bad' }, ic('refresh'), 'Failed · try again')
1730
+ : k.install ? h('span', { className: 'get' }, ic('download'), 'Install')
1731
+ : h('span', { className: 'get ext' }, ic('link'), 'Get it')])) // nothing here can install it: its page
1732
+ }))
1733
+ }
1734
+ $('cli-open').onclick = () => {
1735
+ cliTouched = false
1736
+ drawClis()
1737
+ $('cli-form').showModal()
1738
+ loadClis()
1739
+ }
1740
+ $('cli-cancel').onclick = () => $('cli-form').close()
1741
+ $('cli-all').onclick = () => {
1742
+ const free = CLIS.filter((k) => k.installed && !cliAdded(k.id))
1743
+ cliTouched = true
1744
+ if (free.every((k) => CLI_PICKS.has(k.id))) CLI_PICKS.clear()
1745
+ else for (const k of free) CLI_PICKS.add(k.id)
1746
+ drawClis()
1747
+ }
1748
+ $('cli-add').onclick = async () => {
1749
+ const ids = [...CLI_PICKS]
1750
+ const r = await act('/api/clis/add', { ids })
1751
+ if (!r) return
1752
+ $('cli-form').close()
1753
+ CLI_PICKS.clear()
1754
+ for (const p of r.providers) if (ids.some((id) => new RegExp(`^cli://${id}(/|$)`, 'i').test(p.baseUrl ?? ''))) loadModels(p.name, true) // their models, side by side
1755
+ toast(`added ${ids.length} CLI${ids.length === 1 ? '' : 's'}: their models are loading`)
1756
+ }
1615
1757
 
1616
1758
  const MODELS = {} // provider → { list } | { error } | { loading }
1617
1759
  const filters = {}
@@ -1629,10 +1771,10 @@ function loadModels(name, again = false) {
1629
1771
  show()
1630
1772
  api('/api/models', { name })
1631
1773
  .then(({ models, details }) => (MODELS[name] = { list: models, details: details ?? {} }), (e) => ((MODELS[name] = { error: e.message }), listLoads.failed++))
1632
- .then(() => (listLoads.done++, show(), S && drawProviders(S)))
1774
+ .then(() => (listLoads.done++, show(), redraw()))
1633
1775
  }
1634
1776
  const useModel = (provider, model) => act('/api/model', { provider, model }, `HeartCode now uses ${provider} · ${model}`)
1635
- const saveOrder = (list, done, opts = {}) => act('/api/order', { list, ...opts }, done)
1777
+ const saveOrder = (list, done, opts = {}) => act('/api/order', { list: list.map(({ provider, model }) => ({ provider, model })), ...opts }, done) // only what the server keeps: a whole row each (tests, models.dev…) made a long list too big to send
1636
1778
 
1637
1779
  let editing = null
1638
1780
  function openForm(p = null) {
@@ -1647,12 +1789,14 @@ function openForm(p = null) {
1647
1789
  // editing: what used to crowd its header
1648
1790
  $('p-more').hidden = $('p-delete').hidden = !p
1649
1791
  $('presets').hidden = Boolean(p)
1792
+ if (!CLIS) loadClis() // a CLI's title and sign-in command, for its note
1650
1793
  $('p-form').querySelector('.sub').hidden = Boolean(p)
1651
1794
  if (p) {
1652
1795
  $('p-list-on').checked = p.list
1653
1796
  put($('p-added'), p.added.length ? [h('span', { className: 'muted', style: 'font-size:13px', textContent: `${p.added.length} model${p.added.length === 1 ? '' : 's'} added by name` }), h('button', { className: 'small danger', textContent: 'Forget them', onclick: () => ($('p-form').close(), clearAdded(p)) })] : [])
1654
1797
  }
1655
1798
  drawPresets()
1799
+ drawCliNote()
1656
1800
  $('p-form').showModal()
1657
1801
  ;(p ? $('p-url') : $('p-name')).focus()
1658
1802
  }
@@ -1685,61 +1829,109 @@ $('c-what').addEventListener('keydown', (e) => e.key === 'Enter' && $('c-add').c
1685
1829
  for (const id of ['p-name', 'p-url', 'p-key']) $(id).addEventListener('keydown', (e) => e.key === 'Enter' && $('p-save').click())
1686
1830
 
1687
1831
  // model names in a natural order: "glm-5.2" before "glm-5.10", case doesn't matter
1832
+ // --- The Providers page: every provider's models, to pick from ---
1833
+ // One state, one way to draw it. What's shown comes from the filters (search, Free only, On only,
1834
+ // All / Providers only / CLIs only); the list is built again only when that changes, and what changes
1835
+ // often (your list, the ticks, the folds) is marked on the rows already there, so it stays where you
1836
+ // scrolled it. Every click on the list goes through one handler (catalogEvents), by what was clicked.
1688
1837
  const byName = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare // one collator: thousands of names sort fast
1689
- let modelQuery = ''
1690
- // the models under each provider: by name, or by what its list says they cost (cheapest first; no price: last)
1691
1838
  // The page's own choices (sorts, folds, the provider ranking), kept in ~/.heart (the browser's
1692
1839
  // storage isn't: the page's address has a new port each time)
1693
1840
  const savePref = (key, value) => api('/api/prefs', { key, value }).catch((e) => toast(`not kept: ${e.message}`, true))
1694
- let catSort = 'name'
1695
- // only the models their provider lists at $0 (what its own list says: the price shown under each)
1696
- let freeOnly = false
1841
+ let modelQuery = '' // the search
1842
+ let catSort = 'name' // the models under each provider: by name, or by what its list says they cost (cheapest first; no price: last)
1843
+ let freeOnly = false // only the models their provider lists at $0
1844
+ let onOnly = false // only the providers switched on
1845
+ let catKind = 'all' // all, only the API providers (api), or only the coding CLIs (cli)
1846
+ const FOLDED = new Set() // providers folded (kept); a search shows them open while it's typed
1847
+ const TICKED = new Set() // the ticked models, "provider/model" (kept while you search or filter)
1697
1848
  const isFree = (d) => Boolean(d?.price) && !d.price.input && !d.price.output
1698
- $('free-only').onchange = (e) => {
1699
- freeOnly = e.target.checked
1700
- savePref('freeOnly', freeOnly)
1701
- if (S) drawProviders(S)
1702
- }
1703
- $('m-sort').onchange = (e) => {
1704
- catSort = e.target.value
1705
- savePref('catSort', catSort)
1706
- if (S) drawProviders(S)
1707
- }
1849
+ const isCli = (p) => /^cli:\/\//i.test(p.baseUrl ?? '')
1850
+ const TOP = /auto|free|default/i // models with these anywhere in the name come first under each provider (routers, free ones, the default)
1708
1851
  const costOf = (d) => (d?.price ? (d.price.input ?? 0) + (d.price.output ?? 0) : Infinity)
1709
- // Providers folded on the page (kept: savePref). Typing a search opens them all, until you fold or
1710
- // unfold one (or all) again.
1711
- let searchOpen = false
1712
- const FOLDED = new Set()
1852
+ const splitKey = (k) => ({ provider: k.slice(0, k.indexOf('/')), model: k.slice(k.indexOf('/') + 1) })
1853
+
1854
+ // What the filters show: [{ p, m, ids, own }] (own: models of yours it doesn't list), the providers
1855
+ // that are on first, each one's models with auto/free/default first, then by name or price
1856
+ function catView(s = S) {
1857
+ if (!s) return []
1858
+ const q = modelQuery.trim().toLowerCase()
1859
+ return [...s.providers].sort((a, b) => Boolean(a.off) - Boolean(b.off)).flatMap((p) => {
1860
+ if (onOnly && p.off) return []
1861
+ if (catKind !== 'all' && (catKind === 'cli') !== isCli(p)) return []
1862
+ const m = MODELS[p.name] ?? { loading: true }
1863
+ const listed = m.list ?? []
1864
+ const has = new Set(listed)
1865
+ const extra = [...new Set([...p.added, ...s.order.filter((t) => t.provider === p.name).map((t) => t.model)])].filter((id) => !has.has(id))
1866
+ const ids = [...listed, ...extra]
1867
+ .filter((id) => (!q || id.toLowerCase().includes(q)) && (!freeOnly || isFree(m.details?.[id])))
1868
+ .sort((a, b) => TOP.test(b) - TOP.test(a) || (catSort === 'price' && costOf(m.details?.[a]) - costOf(m.details?.[b])) || byName(a, b))
1869
+ if ((q || freeOnly) && !ids.length) return [] // searching or free only: the providers with one
1870
+ return [{ p, m, ids, own: new Set(extra.filter((id) => !p.added.includes(id))) }]
1871
+ })
1872
+ }
1873
+ // drawn again at the next frame (many lists arriving at once: drawn once)
1874
+ let redrawing = 0
1875
+ const redraw = () => S && !redrawing && (redrawing = requestAnimationFrame(() => ((redrawing = 0), drawProviders(S))))
1876
+
1877
+ // the providers ticked: those with a model ticked (a provider's own box ticks all of its models shown)
1878
+ const selProviders = () => [...new Set([...TICKED].map((k) => splitKey(k).provider))].filter((n) => S?.providers.some((p) => p.name === n))
1879
+ const offOf = (names) => S.providers.filter((p) => names.includes(p.name))
1880
+ const switchProviders = (names, on) => act('/api/provider/on', { names, on }, `${names.length === 1 ? names[0] : `${names.length} providers`} ${on ? 'on' : 'off'}${on ? '' : ': HeartCode skips their models'}`)
1881
+ // the top button: the ticked providers when some are, else all; off while any of them is on
1882
+ function onAllLabel() {
1883
+ const sel = selProviders()
1884
+ const anyOn = (sel.length ? offOf(sel) : S?.providers ?? []).some((p) => !p.off)
1885
+ $('on-all').textContent = sel.length ? `Turn ${sel.length} selected ${anyOn ? 'off' : 'on'}` : anyOn ? 'Turn all off' : 'Turn all on'
1886
+ $('on-all').title = sel.length ? `switch the ${sel.length} selected provider${sel.length === 1 ? '' : 's'} ${anyOn ? 'off' : 'on'}` : 'switch every provider on or off (off: kept, but HeartCode skips its models)'
1887
+ $('on-all').hidden = !S?.providers.length
1888
+ }
1889
+ $('on-all').onclick = () => {
1890
+ const sel = selProviders()
1891
+ if (sel.length) return switchProviders(sel, !offOf(sel).some((p) => !p.off))
1892
+ const on = !S?.providers.some((p) => !p.off)
1893
+ act('/api/provider/on', { on }, on ? 'every provider is on' : 'every provider is off: HeartCode skips their models until you turn one on')
1894
+ }
1895
+ // the folds, on the sections there (nothing built again); a search shows them all open
1713
1896
  function applyFolds() {
1714
- $('fold-all').textContent = allFolded() ? 'Expand all' : 'Collapse all'
1897
+ const view = catView()
1898
+ const searching = Boolean(modelQuery.trim())
1715
1899
  for (const sec of $('p-list').querySelectorAll('section[data-provider]')) {
1716
- const folded = FOLDED.has(sec.dataset.provider) && !(searchOpen && modelQuery.trim())
1900
+ const folded = FOLDED.has(sec.dataset.provider) && !searching
1717
1901
  sec.classList.toggle('collapsed', folded)
1718
1902
  sec.querySelector('.fold')?.setAttribute('aria-expanded', String(!folded))
1719
1903
  }
1720
- for (const box of $('p-list').querySelectorAll('.rows')) box._v?.draw() // the ones now open
1721
- }
1722
- // A fold by hand during a search starts from what's shown (the ones it opened stay open).
1723
- function settle() {
1724
- if (searchOpen && modelQuery.trim()) for (const sec of $('p-list').querySelectorAll('section[data-provider]')) FOLDED.delete(sec.dataset.provider)
1725
- searchOpen = false
1726
- }
1727
- const folds = () => (applyFolds(), savePref('folded', [...FOLDED])) // a fold changed: shown and kept
1728
- const fold = (name) => (settle(), FOLDED.has(name) ? FOLDED.delete(name) : FOLDED.add(name), folds())
1729
- // one button: collapse them all, or (all collapsed) expand them all
1730
- const allFolded = () => Boolean(S?.providers.length) && S.providers.every((p) => FOLDED.has(p.name))
1731
- $('fold-all').onclick = () => (settle(), allFolded() ? FOLDED.clear() : S?.providers.forEach((p) => FOLDED.add(p.name)), folds())
1904
+ $('fold-all').textContent = view.length && view.every((x) => FOLDED.has(x.p.name)) ? 'Expand all' : 'Collapse all'
1905
+ $('fold-all').hidden = !view.length
1906
+ onAllLabel()
1907
+ }
1908
+ const fold = (name) => (FOLDED.has(name) ? FOLDED.delete(name) : FOLDED.add(name), savePref('folded', [...FOLDED]), applyFolds())
1909
+ $('fold-all').onclick = () => {
1910
+ const view = catView()
1911
+ const all = view.every((x) => FOLDED.has(x.p.name))
1912
+ for (const x of view) all ? FOLDED.delete(x.p.name) : FOLDED.add(x.p.name)
1913
+ savePref('folded', [...FOLDED])
1914
+ applyFolds()
1915
+ }
1916
+ // the filters: each kept, and the list drawn again
1917
+ const filter = (id, key, set) => ($(id).onchange = (e) => (set(e.target), savePref(key, e.target.type === 'checkbox' ? e.target.checked : e.target.value), redraw()))
1918
+ filter('free-only', 'freeOnly', (el) => (freeOnly = el.checked))
1919
+ filter('on-only', 'onOnly', (el) => (onOnly = el.checked))
1920
+ filter('m-kind', 'catKind', (el) => (catKind = el.value))
1921
+ filter('m-sort', 'catSort', (el) => (catSort = el.value))
1922
+ $('m-search').oninput = (e) => ((modelQuery = e.target.value), redraw())
1923
+ // select every model shown (folded ones too: the filters decide what's shown), or none
1732
1924
  $('pick-shown').onchange = (e) => {
1733
- for (const [provider, ids] of SHOWN) for (const id of ids) e.target.checked ? pickedOf(provider).add(id) : PICKED_CAT.get(provider)?.delete(id)
1925
+ for (const x of catView()) for (const id of x.ids) e.target.checked ? TICKED.add(`${x.p.name}/${id}`) : TICKED.delete(`${x.p.name}/${id}`)
1734
1926
  drawPicks()
1735
1927
  }
1736
1928
  $('p-mine').onclick = () => (location.hash = 'models')
1737
1929
  // models.dev fetched again (your models' profiles too), then every listed provider's models with it
1738
1930
  $('dev-all').onclick = async () => {
1739
- if (!(await lookUp())) return
1931
+ if (!(await lookUp(null, { models: true }))) return // models.dev only: no rankings, no helpers marked
1740
1932
  S?.providers.filter((p) => p.list).forEach((p) => loadModels(p.name, true))
1741
1933
  }
1742
- $('m-search').oninput = (e) => ((modelQuery = e.target.value), (searchOpen = true), S && drawProviders(S), applyFolds())
1934
+
1743
1935
  // A model's tooltip: its full name and what's known about it (from the provider, HeartCode's price
1744
1936
  // list and its own test), and what a click does. Shown on hover and on keyboard focus.
1745
1937
  // a token count, short: 1M, 1.05M (two decimals, not rounded up to 1.1M), 131k
@@ -1774,7 +1966,7 @@ const MEANS = {
1774
1966
  }
1775
1967
  // What a test came to, in a word: works, its status code (402, 429…), empty, no answer or failed;
1776
1968
  // null while it runs or before it's tested
1777
- const outcome = (r) => (!r || r.going ? null : r.ok ? 'works' : r.status ? String(r.status) : /nothing/.test(r.error) ? 'empty' : /within/.test(r.error) ? 'no answer' : 'failed')
1969
+ const outcome = (r) => (!r || r.going ? null : r.ok ? 'works' : r.status ? String(r.status) : r.kind === 'empty' || (!r.kind && /nothing/.test(r.error)) ? 'empty' : r.kind === 'timeout' || (!r.kind && /within/.test(r.error)) ? 'no answer' : 'failed') // kind: said by the server (older results: their words)
1778
1970
  // The Works? cell: the last result (cut short, all of it on hover) and Test.
1779
1971
  function triedCell(t) {
1780
1972
  const r = TRIES[keyOf(t)]
@@ -1805,11 +1997,6 @@ for (const ev of ['pointerup', 'pointercancel']) addEventListener(ev, () => {
1805
1997
  if (drawAfterPress) (drawAfterPress = false), setTimeout(mineSoon, 0) // after the click it finishes
1806
1998
  }, true)
1807
1999
  let drawAfterPress = false
1808
- addEventListener('pointerdown', () => (pressed = true), true)
1809
- for (const ev of ['pointerup', 'pointercancel']) addEventListener(ev, () => {
1810
- pressed = false
1811
- if (drawAfterPress) (drawAfterPress = false), setTimeout(mineSoon, 0) // after the click it finishes
1812
- }, true)
1813
2000
  const mineSoon = () => {
1814
2001
  if (mineFrame) return
1815
2002
  const later = testingAll ? Math.max(0, mineLast + 400 - Date.now()) : 0
@@ -1861,7 +2048,8 @@ function showRun(run) {
1861
2048
  job('test-all')
1862
2049
  if (run?.over && afterTests) {
1863
2050
  afterTests = null
1864
- setAuto(true, $('h-auto'))
2051
+ if (working()) setAuto(true, $('h-auto'))
2052
+ else toast('none of them answered: no helpers picked (Works? says why, on hover)', true) // not the dialog again
1865
2053
  } else if (!run?.over) afterTests = null // never started
1866
2054
  if (run?.over) toast(`${run.stopping ? `stopped after ${run.done} of ${run.total}: ` : ''}${run.good} of ${run.done} work${run.good === run.done ? '' : `; ${run.done - run.good} don't (Works? says why, on hover)`}`, run.good < run.done)
1867
2055
  } else
@@ -1877,15 +2065,17 @@ function showRun(run) {
1877
2065
 
1878
2066
  // models.dev looked up again: one model (its Retry), or all of yours with their rankings (Update model info)
1879
2067
  const retry = (t) => h('button', { className: 'small', textContent: 'Retry', title: 'look it up in models.dev again', onclick: (e) => (e.stopPropagation(), lookUp(t)) })
1880
- async function lookUp(t) {
1881
- job('models.dev', { where: ['catalog', 'table'], what: t ? `Looking up ${t.model} in models.dev` : 'Updating the models: models.dev and LMArena', detail: t ? 'context, tool calls, thinking, images' : 'context, tool calls, thinking, images, price; scores' })
2068
+ // models: all of them, from models.dev only (the Providers page's button)
2069
+ async function lookUp(t, { models = false } = {}) {
2070
+ const full = !t && !models // Update model info: rankings too, and helpers marked
2071
+ job('models.dev', { where: ['catalog', 'table'], what: t ? `Looking up ${t.model} in models.dev` : full ? 'Updating the models: models.dev and LMArena' : 'Getting the models from models.dev', detail: full ? 'context, tool calls, thinking, images, price; scores' : 'context, tool calls, thinking, images' })
1882
2072
  if (!t) (lookingUp = true), mineSoon()
1883
- const [r, scored] = await Promise.all([act('/api/models-dev', t ? { provider: t.provider, model: t.model } : {}), t ? null : act('/api/rankings', {})])
2073
+ const [r, scored] = await Promise.all([act('/api/models-dev', t ? { provider: t.provider, model: t.model } : {}), full ? act('/api/rankings', {}) : null])
1884
2074
  if (!t) (lookingUp = false), mineSoon()
1885
2075
  job('models.dev')
1886
2076
  // all of them: the helpers marked from what's known now (Automatic: picked again by the server;
1887
2077
  // My picks: added to yours, what you picked stays)
1888
- const marked = !t && r && !S.helpersAuto ? await api('/api/helpers/mark', {}).catch((e) => (toast(e.message, true), null)) : null
2078
+ const marked = full && r && !S.helpersAuto ? await api('/api/helpers/mark', {}).catch((e) => (toast(e.message, true), null)) : null
1889
2079
  if (marked) Object.assign(S, { helpers: marked.helpers, helpersAuto: marked.helpersAuto }), drawMine(S)
1890
2080
  if (r) toast(t ? (r.found ? `${t.model}: found in models.dev` : `${t.model}: still not in models.dev`) : `models.dev: ${r.found} of ${r.of} found${scored ? ' · rankings updated' : ''}${marked?.marked ? ` · ${marked.marked} model${marked.marked === 1 ? '' : 's'} marked as helpers` : ''}`)
1891
2081
  return r
@@ -2019,24 +2209,28 @@ function drawProviders(s) {
2019
2209
  ].map(([t, d, cls], i) => h('div', { className: 'step ' + cls }, h('span', { className: 'num', textContent: cls === 'done' ? '✓' : i + 1 }), h('div', {}, h('b', { textContent: t }), d))))
2020
2210
  $('steps').hidden = order.length > 0 // the first start only
2021
2211
  $('p-work').hidden = none
2022
- // your list, at the top: how many, and the way to its page (the order, what to do when one fails)
2212
+ // your list, at the top: how many, and the way to its page
2023
2213
  const shown = shownOrder()
2024
2214
  $('p-mine').hidden = !shown.length
2025
2215
  $('p-mine').textContent = `Models (${shown.length}) →`
2026
2216
  $('p-mine').title = shown.length ? `HeartCode uses ${shown[0].provider} · ${shown[0].model}. Open Models: the order, and what happens when one fails` : ''
2027
- fillHeight()
2028
-
2029
- // every provider's models, A to Z; one click adds it (the first one becomes #1). Built
2030
- // again only when what it lists changes (a provider, its models, the search); a change to your
2031
- // list only updates the rows it touches (markCatalog), so the list stays where you scrolled it
2032
- // (but one of yours a provider doesn't list gets a row of its own).
2033
- const unlisted = order.filter((t) => !(MODELS[t.provider]?.list ?? []).includes(t.model)).map(keyOf).sort()
2034
- const shape = JSON.stringify([s.providers, s.providers.map((p) => (MODELS[p.name]?.list ?? []).length + (MODELS[p.name]?.error ?? '') + ((MODELS[p.name] ?? { loading: true }).loading ? 'loading' : '')), modelQuery.trim(), catSort, freeOnly, unlisted])
2035
- if (shape !== catalogShape) (buildCatalog(s), applyFolds())
2036
- catalogShape = shape
2037
- markCatalog()
2038
- $('m-search').placeholder = `Search ${Object.values(MODELS).reduce((n, m) => n + (m.list?.length ?? 0), 0) || 'all'} models…`
2039
2217
  for (const el of document.querySelectorAll('[data-count="n-providers"]')) el.textContent = s.providers.length || ''
2218
+ // each provider's models: asked for once (its list switched off: never; switched on again: now)
2219
+ for (const p of s.providers) {
2220
+ if (!p.list) MODELS[p.name] = { list: [], details: {}, off: true }
2221
+ else loadModels(p.name, MODELS[p.name]?.off)
2222
+ }
2223
+ for (const k of [...TICKED]) if (!s.providers.some((p) => p.name === splitKey(k).provider)) TICKED.delete(k) // a provider deleted: its ticks go
2224
+ const view = catView(s)
2225
+ // built again only when what's shown changed; the rest is marked on the rows there
2226
+ const stamp = JSON.stringify([view.map((x) => [x.p.name, x.p.off, x.p.baseUrl, x.p.key, x.p.added, x.m.loading ?? false, x.m.error ?? '', x.m.off ?? false, x.m.list?.length ?? 0, x.ids.join('\n')]), catKind, onOnly, freeOnly])
2227
+ if (stamp !== catStamp) buildCatalog(view, s)
2228
+ catStamp = stamp
2229
+ markCatalog(s)
2230
+ applyFolds()
2231
+ drawPicks(view)
2232
+ $('m-search').placeholder = `Search ${Object.values(MODELS).reduce((n, m) => n + (m.list?.length ?? 0), 0) || 'all'} models…`
2233
+ fillHeight()
2040
2234
  }
2041
2235
  // Your models: pick one up (anywhere on it with a mouse, by its ⋮⋮ on a touch screen) and the
2042
2236
  // others move aside as it goes; let go and it's saved, already in its place (no jump when the
@@ -2119,7 +2313,6 @@ function sortable(v, onMove) {
2119
2313
  }
2120
2314
 
2121
2315
  // --- the models on the left: rows that read your list when clicked or hovered (S.order, now) ---
2122
- let catalogShape = null
2123
2316
  // where a model is in your list (undefined: not in it); looked up, not searched (thousands of rows ask)
2124
2317
  let places = { of: null, at: null }
2125
2318
  const placeOf = (provider, id) => {
@@ -2129,16 +2322,12 @@ const placeOf = (provider, id) => {
2129
2322
  // A model's row on the left: scrolled to and lit up for a moment (one just added by name).
2130
2323
  function showRow(provider, id, said) {
2131
2324
  toast(said)
2132
- const list = $('p-list')
2133
- const box = [...list.querySelectorAll(`section[data-provider="${CSS.escape(provider)}"] .rows`)].find((b) => b._ids)
2134
- const i = box?._ids.indexOf(id) ?? -1
2135
- if (i < 0) return
2136
- const at = box.getBoundingClientRect().top - list.getBoundingClientRect().top + list.scrollTop + i * CAT_ROW
2137
- if (at < list.scrollTop + 120 || at + CAT_ROW > list.scrollTop + list.clientHeight) list.scrollTop = at - list.clientHeight / 2
2138
- box._v.draw()
2139
- const el = box._v.shown.get(i)
2140
- const row = el?.matches('.mrow') ? el : el?.querySelector('.mrow')
2141
- if (!row) return
2325
+ const sec = [...$('p-list').querySelectorAll('section[data-provider]')].find((x) => x.dataset.provider === provider)
2326
+ const w = sec && [...sec.querySelectorAll('.mwrap')].find((r) => r.dataset.model === id)
2327
+ if (!w) return
2328
+ if (FOLDED.has(provider)) fold(provider)
2329
+ w.scrollIntoView({ block: 'center' })
2330
+ const row = w.querySelector('.mrow')
2142
2331
  row.classList.remove('flash')
2143
2332
  void row.offsetWidth // restart the animation
2144
2333
  row.classList.add('flash')
@@ -2250,8 +2439,8 @@ $('hellos-close').onclick = () => $('hellos').close()
2250
2439
  $('hellos').addEventListener('close', () => (hellos = null))
2251
2440
  // the ticks: the ones that answered, only
2252
2441
  $('hellos-ok').onclick = () => {
2253
- PICKED_CAT.clear()
2254
- for (const t of hellos?.list ?? []) if (answered(t.r)) pickedOf(t.provider).add(t.model)
2442
+ TICKED.clear()
2443
+ for (const t of hellos?.list ?? []) if (answered(t.r)) TICKED.add(keyOf(t))
2255
2444
  $('hellos').close()
2256
2445
  drawPicks()
2257
2446
  }
@@ -2264,127 +2453,173 @@ async function clearAdded(p) {
2264
2453
  if (inList.length && !(await saveOrder(S.order.filter((t) => !inList.includes(t))))) return
2265
2454
  act('/api/provider/added', { name: p.name, all: true }, `${p.name}: the models added by name are forgotten`)
2266
2455
  }
2267
- const CAT_ROW = 40 // a model's row: its name, and what it can do beside it
2268
- // The models ticked (provider → Set of ids): kept while you search, so ones ticked for one search
2269
- // and the next are added (or taken off) together. SHOWN: each provider's models shown now (the
2270
- // search's matches).
2271
- const PICKED_CAT = new Map()
2272
- const SHOWN = new Map()
2273
- const pickedOf = (name) => PICKED_CAT.get(name) ?? PICKED_CAT.set(name, new Set()).get(name)
2274
- // The ticked models (every provider's) and what to do with them, on the bar over the list: all the
2275
- // shown ones ticked (or none), added to your list, taken off it. The tick boxes drawn now (rows and
2276
- // each provider's) follow.
2277
- function drawPicks() {
2456
+ let catStamp = null
2457
+ // The list: a section per provider (its header, then a row per model). Where you scrolled stays.
2458
+ function buildCatalog(view, s) {
2459
+ const list = $('p-list')
2460
+ const at = list.scrollTop
2461
+ if (!view.length) {
2462
+ put(list, h('div', { className: 'cat-note', textContent: !s.providers.length ? '' : modelQuery.trim() ? `No model matches "${modelQuery.trim()}".` : freeOnly ? "No provider lists a model at $0. (A provider whose list has no prices can't say what's free: Free only leaves those out.)" : catKind === 'cli' ? 'No coding CLI here: + Add CLIs, or untick On only.' : catKind === 'api' ? 'No API provider here: + Add a provider, or untick On only.' : 'Every provider is off. Turn one on (Turn all on), or untick On only.' }))
2463
+ return
2464
+ }
2465
+ put(list, view.map(({ p, m, ids, own }) => h('section', { 'data-provider': p.name, className: p.off ? 'off' : '' },
2466
+ h('div', { className: 'prov-h', 'data-act': 'fold' },
2467
+ h('button', { className: 'fold', type: 'button', textContent: '▾', 'aria-label': `fold ${p.name}`, 'aria-expanded': 'true', 'data-act': 'fold' }),
2468
+ ids.length ? h('input', { type: 'checkbox', className: 'pick-all', 'aria-label': `select ${p.name}'s models`, title: `select all of ${p.name}'s models shown (or none)` }) : null,
2469
+ h('label', { className: 'sw', title: p.off ? `switched off: HeartCode skips ${p.name}'s models. Switch it on` : `switch ${p.name} off: HeartCode skips its models (nothing is deleted)` },
2470
+ h('input', { type: 'checkbox', className: 'p-on', checked: !p.off, 'aria-label': `${p.name} on` }), h('i')),
2471
+ h('div', { className: 'who' },
2472
+ h('span', { className: 'name' }, provIcon(p.name), p.name),
2473
+ p.off ? h('span', { className: 'tag', textContent: 'off' }) : null,
2474
+ m.off ? h('span', { className: 'tag', textContent: 'list off', title: "its list isn't loaded: add a model by its name, in the box on the right" }) : m.loading ? h('span', { className: 'tag', textContent: 'loading…' }) : m.error ? h('span', { className: 'tag err', textContent: "can't list its models", title: m.error }) : h('span', { className: 'tag', textContent: `${m.list.length} model${m.list.length === 1 ? '' : 's'}` }),
2475
+ h('span', { className: 'tag inlist', hidden: true }),
2476
+ h('span', { className: 'meta mono', textContent: p.baseUrl, title: `${p.baseUrl} · key ${p.key || 'none'}` })),
2477
+ h('form', { className: 'by-name' },
2478
+ h('input', { type: 'text', name: 'name', placeholder: 'model name(s)', 'aria-label': `add models to ${p.name} by their names`, title: `a model's exact name, or several separated by commas: added to ${p.name} (not to the list: click one to put it there), also ones ${p.name} doesn't list` }),
2479
+ h('button', { className: 'small', textContent: 'Add' })),
2480
+ h('button', { className: 'small', type: 'button', textContent: 'Edit', title: 'its address and key, its model list, delete it', 'data-act': 'edit' })),
2481
+ ids.length ? h('div', { className: 'rows' }, ids.map((id) => h('div', { className: 'mwrap', 'data-model': id },
2482
+ h('input', { type: 'checkbox', className: 'pick', 'aria-label': `select ${id}` }),
2483
+ h('button', { className: 'mrow', type: 'button', 'data-act': 'toggle' },
2484
+ h('span', { className: 'id', title: id }, id, canCell(m.details?.[id], S.order[placeOf(p.name, id)])),
2485
+ isFree(m.details?.[id]) ? h('span', { className: 'tag ok', textContent: 'free', title: `${p.name}'s model list says $0` }) : null,
2486
+ own.has(id) ? h('span', { className: 'tag', textContent: 'not in its list' }) : p.added.includes(id) ? h('span', { className: 'tag', textContent: 'added by name' }) : null,
2487
+ h('span', { className: 'tail' })),
2488
+ h('button', { className: 'small try', type: 'button', textContent: 'Test', title: `send ${id} "Hello" and see what was sent and what came back`, 'data-act': 'test' }),
2489
+ p.added.includes(id) ? h('button', { className: 'forget', type: 'button', textContent: '✕', title: 'forget this model', 'aria-label': `forget ${id}`, 'data-act': 'forget' }) : null))) : null,
2490
+ m.error ? h('div', { className: 'cat-note', style: 'color:var(--err)' }, `can't list its models: ${shortError(m.error)} `, h('button', { className: 'small', type: 'button', textContent: 'Try again', 'data-act': 'reload' }), h('div', { className: 'muted', style: 'margin-top:4px', textContent: 'Or add a model by its name, in the box above.' })) : null,
2491
+ m.off && !ids.length ? h('div', { className: 'cat-note', textContent: 'Its list is off: add a model by its name, in the box above.' }) : null,
2492
+ m.loading ? h('div', { className: 'cat-note', textContent: 'Loading its models…' }) : null)))
2493
+ list.scrollTop = at
2494
+ }
2495
+ // Your list on the rows there: its place (#2 fallback, in use, + Add), and how many each provider has in it
2496
+ function markCatalog(s = S) {
2497
+ const shownAt = new Map(shownOrder().map((t, i) => [keyOf(t), i]))
2498
+ const now = inUse()
2499
+ const count = new Map()
2500
+ for (const t of s.order) count.set(t.provider, (count.get(t.provider) ?? 0) + 1)
2501
+ for (const sec of $('p-list').querySelectorAll('section[data-provider]')) {
2502
+ const name = sec.dataset.provider
2503
+ const off = isOff(name)
2504
+ const n = count.get(name) ?? 0
2505
+ const tag = sec.querySelector('.inlist')
2506
+ tag.hidden = !n
2507
+ tag.textContent = `${n} in the list${now?.provider === name ? ' · in use' : ''}`
2508
+ for (const w of sec.querySelectorAll('.mwrap')) {
2509
+ const id = w.dataset.model
2510
+ const k = `${name}/${id}`
2511
+ const mine = placeOf(name, id) !== undefined
2512
+ const at = shownAt.get(k)
2513
+ const tail = mine && off ? ['tag', 'in the list · off'] : now && keyOf(now) === k ? ['tag brand', `#${at + 1} in use`] : at !== undefined ? ['tag brand', `#${at + 1} fallback`] : ['add', s.order.length ? '+ Add' : 'Use']
2514
+ const el = w.querySelector('.tail')
2515
+ if (el.className !== `tail ${tail[0]}` || el.textContent !== tail[1]) (el.className = `tail ${tail[0]}`), (el.textContent = tail[1])
2516
+ w.querySelector('.mrow').classList.toggle('taken', mine)
2517
+ w.querySelector('.mrow').title = mine ? `click: take ${id} off the list` : `click: add ${id} to the list`
2518
+ }
2519
+ }
2520
+ }
2521
+ // The ticks on the rows and boxes there, and the bar under the list: what's ticked, and what to do with it
2522
+ function drawPicks(view = catView()) {
2278
2523
  if (!S) return
2279
- const all = [...PICKED_CAT].flatMap(([provider, ids]) => [...ids].map((model) => ({ provider, model })))
2280
- const shown = [...SHOWN].flatMap(([provider, ids]) => ids.map((model) => ({ provider, model })))
2281
- const isPicked = (t) => Boolean(PICKED_CAT.get(t.provider)?.has(t.model))
2282
- const toAdd = all.filter((t) => placeOf(t.provider, t.model) === undefined)
2283
- const toTake = all.filter((t) => placeOf(t.provider, t.model) !== undefined)
2284
- for (const box of $('p-list').querySelectorAll('input.pick')) box.checked = Boolean(PICKED_CAT.get(box.closest('section').dataset.provider)?.has(box.dataset.model))
2285
- for (const box of $('p-list').querySelectorAll('input.pick-all')) {
2286
- const ids = SHOWN.get(box.dataset.provider) ?? []
2287
- const n = ids.filter((id) => PICKED_CAT.get(box.dataset.provider)?.has(id)).length
2288
- box.checked = n > 0 && n === ids.length
2289
- box.indeterminate = n > 0 && n < ids.length
2524
+ for (const sec of $('p-list').querySelectorAll('section[data-provider]')) {
2525
+ let n = 0
2526
+ const rows = sec.querySelectorAll('.mwrap')
2527
+ for (const w of rows) {
2528
+ const on = TICKED.has(`${sec.dataset.provider}/${w.dataset.model}`)
2529
+ w.querySelector('.pick').checked = on
2530
+ n += on
2531
+ }
2532
+ const box = sec.querySelector('.pick-all')
2533
+ if (box) (box.checked = n > 0 && n === rows.length), (box.indeterminate = n > 0 && n < rows.length)
2290
2534
  }
2535
+ const shown = view.flatMap((x) => x.ids.map((id) => `${x.p.name}/${id}`))
2536
+ const n = shown.filter((k) => TICKED.has(k)).length
2291
2537
  const top = $('pick-shown')
2292
- const n = shown.filter(isPicked).length
2293
2538
  top.checked = n > 0 && n === shown.length
2294
2539
  top.indeterminate = n > 0 && n < shown.length
2295
2540
  top.disabled = !shown.length
2296
- top.title = top.checked ? 'unselect every model shown' : `select every model shown (${shown.length}${modelQuery.trim() ? ': the matches' : ''})`
2541
+ top.title = top.checked ? 'unselect every model shown' : `select every model shown (${shown.length})`
2542
+ const all = [...TICKED].map(splitKey)
2543
+ const toAdd = all.filter((t) => placeOf(t.provider, t.model) === undefined)
2544
+ const toTake = all.filter((t) => placeOf(t.provider, t.model) !== undefined)
2545
+ const sel = selProviders()
2546
+ const on = offOf(sel).filter((p) => !p.off).map((p) => p.name)
2547
+ const off = offOf(sel).filter((p) => p.off).map((p) => p.name)
2548
+ const prov = (k) => `${k} provider${k === 1 ? '' : 's'}`
2297
2549
  const take = () => {
2298
- const off = new Set(toTake.map(keyOf))
2299
- const rest = S.order.filter((t) => !off.has(keyOf(t)))
2550
+ const gone = new Set(toTake.map(keyOf))
2551
+ const rest = S.order.filter((t) => !gone.has(keyOf(t)))
2300
2552
  if (!confirm(`Take ${toTake.length} model${toTake.length === 1 ? '' : 's'} off the list?${!rest.length ? ' None is left then: HeartCode has no model to use until one is chosen.' : keyOf(rest[0]) !== keyOf(S.order[0]) ? ` HeartCode then uses ${rest[0].provider} · ${rest[0].model}.` : ''}`)) return
2301
- PICKED_CAT.clear()
2553
+ TICKED.clear()
2302
2554
  saveOrder(rest, `${toTake.length} removed`)
2303
2555
  }
2304
2556
  const was = $('picks').hidden
2305
2557
  $('picks').hidden = !all.length
2306
2558
  put($('picks'),
2307
- h('span', { className: 'n', textContent: `${all.length} selected` }),
2308
- h('button', { className: 'small ghost', textContent: 'Clear', onclick: () => (PICKED_CAT.clear(), drawPicks()) }),
2559
+ h('span', { className: 'n', textContent: `${all.length} selected${all.length > n ? ` (${all.length - n} not shown)` : ''}` }),
2560
+ h('button', { className: 'small ghost', textContent: 'Clear', onclick: () => (TICKED.clear(), drawPicks()) }),
2309
2561
  h('button', { className: 'small', textContent: `Test ${all.length}`, title: 'send each ticked model "Hello" and see which answer', onclick: () => helloAll(all) }),
2562
+ on.length ? h('button', { className: 'small', textContent: `Turn off ${prov(on.length)}`, title: `switch off: ${on.join(', ')}`, onclick: () => switchProviders(on, false) }) : null,
2563
+ off.length ? h('button', { className: 'small', textContent: `Turn on ${prov(off.length)}`, title: `switch on: ${off.join(', ')}`, onclick: () => switchProviders(off, true) }) : null,
2310
2564
  toTake.length ? h('button', { className: 'small danger', textContent: `Remove ${toTake.length} from the list`, onclick: take }) : null,
2311
- toAdd.length ? h('button', { className: 'small primary', textContent: `Add ${toAdd.length} to the list`, onclick: () => (PICKED_CAT.clear(), saveOrder([...S.order, ...toAdd], `${toAdd.length} added: the list has ${S.order.length + toAdd.length} models`)) }) : null)
2565
+ toAdd.length ? h('button', { className: 'small primary', textContent: `Add ${toAdd.length} to the list`, onclick: () => (TICKED.clear(), saveOrder([...S.order, ...toAdd], `${toAdd.length} added: the list has ${S.order.length + toAdd.length} models`)) }) : null)
2566
+ onAllLabel()
2312
2567
  if (was !== $('picks').hidden) fillHeight() // the list gives it room
2313
2568
  }
2314
- function buildCatalog(s) {
2315
- const q = modelQuery.trim()
2316
- SHOWN.clear()
2317
- put($('p-list'), s.providers.map((p) => {
2318
- if (!p.list) MODELS[p.name] = { list: [], details: {}, off: true } // its list switched off: never asked for
2319
- else loadModels(p.name, MODELS[p.name]?.off)
2320
- const m = MODELS[p.name] ?? { loading: true }
2321
- // and the models added by name (and any of yours it doesn't list), marked as yours
2322
- const listed = new Set(m.list ?? [])
2323
- const yours = [...new Set([...p.added, ...s.order.filter((t) => t.provider === p.name).map((t) => t.model)])].filter((id) => !listed.has(id))
2324
- const ids = [...listed, ...yours].sort((a, b) => (catSort === 'price' && costOf(m.details?.[a]) - costOf(m.details?.[b])) || byName(a, b)).filter((id) => id.toLowerCase().includes(q.toLowerCase()) && (!freeOnly || isFree(m.details?.[id])))
2325
- const row = (id, own) =>
2326
- h('button', { className: 'mrow', 'data-provider': p.name, 'data-model': id, onclick: () => (placeOf(p.name, id) === undefined ? addModel(p.name, id) : removeMine(p.name, id)) },
2327
- h('span', { className: 'id', title: id }, id, canCell(m.details?.[id], S.order[placeOf(p.name, id)])),
2328
- isFree(m.details?.[id]) ? h('span', { className: 'tag ok', textContent: 'free', title: `${p.name}'s model list says $0` }) : null,
2329
- own ? h('span', { className: 'tag', textContent: 'not in its list' }) : p.added.includes(id) ? h('span', { className: 'tag', textContent: 'added by name' }) : null,
2330
- rowTail(p.name, id))
2331
- // its tick box (to add or take off several at once), and one you added: ✕ forgets it (it leaves your list too)
2332
- const tick = (id) => h('input', { type: 'checkbox', className: 'pick', checked: pickedOf(p.name).has(id), 'data-model': id, 'aria-label': `select ${id}`, onchange: (e) => (e.target.checked ? pickedOf(p.name).add(id) : pickedOf(p.name).delete(id), drawPicks()) })
2333
- const item = (id) => h('div', { className: 'mwrap' }, tick(id), row(id),
2334
- h('button', { className: 'small try', textContent: 'Test', title: `send ${id} "Hello" and see what was sent and what came back`, onclick: () => hello(p.name, id) }),
2335
- !p.added.includes(id) ? null :
2336
- h('button', { className: 'forget', textContent: '✕', title: 'forget this model', 'aria-label': `forget ${id}`, onclick: async () => {
2337
- if (placeOf(p.name, id) !== undefined && !confirm(`Forget ${id}? It leaves the list too.`)) return
2338
- if (placeOf(p.name, id) !== undefined) await saveOrder(S.order.filter((t) => t.provider !== p.name || t.model !== id), `${id} removed`)
2339
- act('/api/provider/added', { name: p.name, model: id, remove: true }, `forgot ${id}`)
2340
- } }))
2341
- // models by their names (several, comma-separated), under this provider only: not into the list
2342
- // (a click on one puts it there); one it has already: said, and shown
2343
- const addByName = (e) => {
2344
- e.preventDefault()
2345
- const box = e.target.elements.name
2346
- const ids = [...new Set(box.value.split(',').map((x) => x.trim()).filter(Boolean))]
2347
- if (!ids.length) return
2348
- const add = ids.filter((id) => !listed.has(id) && !yours.includes(id))
2349
- if (!add.length) return showRow(p.name, ids[0], ids.length === 1 ? `${p.name} already has ${ids[0]}: click it to add it to the list` : `${p.name} already has all ${ids.length}`)
2350
- box.value = ''
2351
- act('/api/provider/added', { name: p.name, models: add }, `${add.length === 1 ? add[0] : `${add.length} models`} added to ${p.name}${add.length < ids.length ? ` (${ids.length - add.length} it had already)` : ''}: click one to put it in the list`)
2569
+ // Every click and change on the list, by what it was on
2570
+ ;(() => {
2571
+ const list = $('p-list')
2572
+ const where = (el) => ({ sec: el.closest('section[data-provider]'), w: el.closest('.mwrap') })
2573
+ const provOf = (sec) => S.providers.find((p) => p.name === sec?.dataset.provider)
2574
+ list.addEventListener('change', (e) => {
2575
+ const { sec, w } = where(e.target)
2576
+ if (!sec) return
2577
+ const name = sec.dataset.provider
2578
+ if (e.target.matches('.pick')) {
2579
+ const k = `${name}/${w.dataset.model}`
2580
+ e.target.checked ? TICKED.add(k) : TICKED.delete(k)
2581
+ drawPicks()
2582
+ } else if (e.target.matches('.pick-all')) {
2583
+ for (const r of sec.querySelectorAll('.mwrap')) e.target.checked ? TICKED.add(`${name}/${r.dataset.model}`) : TICKED.delete(`${name}/${r.dataset.model}`)
2584
+ drawPicks()
2585
+ } else if (e.target.matches('.p-on')) act('/api/provider/on', { name, on: e.target.checked }, e.target.checked ? `${name} is on` : `${name} is off: HeartCode skips its models`)
2586
+ })
2587
+ list.addEventListener('click', async (e) => {
2588
+ const { sec, w } = where(e.target)
2589
+ if (!sec) return
2590
+ const name = sec.dataset.provider
2591
+ const id = w?.dataset.model
2592
+ const act_ = e.target.closest('[data-act]')?.dataset.act
2593
+ if (e.target.closest('input, label, form, .cat-note button') && act_ !== 'reload') return // their own (change, submit)
2594
+ if (act_ === 'fold') return fold(name)
2595
+ if (act_ === 'edit') return openForm(provOf(sec))
2596
+ if (act_ === 'reload') return loadModels(name, true)
2597
+ if (act_ === 'test') return hello(name, id)
2598
+ if (act_ === 'toggle') return placeOf(name, id) === undefined ? addModel(name, id) : removeMine(name, id)
2599
+ if (act_ === 'forget') {
2600
+ const mine = placeOf(name, id) !== undefined
2601
+ if (mine && !confirm(`Forget ${id}? It leaves the list too.`)) return
2602
+ if (mine && !(await saveOrder(S.order.filter((t) => t.provider !== name || t.model !== id), `${id} removed`))) return
2603
+ act('/api/provider/added', { name, model: id, remove: true }, `forgot ${id}`)
2352
2604
  }
2353
- if (q && !ids.length) return null // searching: only the providers with a match
2354
- if (freeOnly && !ids.length) return null // free only: the providers with a free one
2355
- return h('section', { 'data-provider': p.name, className: p.off ? 'off' : '' },
2356
- // the header folds it (a click on it, or its arrow; not on its buttons and switch)
2357
- h('div', { className: 'prov-h', onclick: (e) => !e.target.closest('button:not(.fold), input, label, a') && fold(p.name) },
2358
- h('button', { className: 'fold', type: 'button', textContent: '▾', 'aria-label': `fold ${p.name}`, 'aria-expanded': 'true' }),
2359
- ids.length ? h('input', { type: 'checkbox', className: 'pick-all', 'data-provider': p.name, 'aria-label': `select ${p.name}'s models`, title: `select all of ${p.name}'s models shown (or none)`, onchange: (e) => (ids.forEach((id) => (e.target.checked ? pickedOf(p.name).add(id) : pickedOf(p.name).delete(id))), drawPicks()) }) : null,
2360
- h('label', { className: 'sw', title: p.off ? `switched off: HeartCode skips ${p.name}'s models. Switch it on` : `switch ${p.name} off: HeartCode skips its models (nothing is deleted)` },
2361
- h('input', { type: 'checkbox', checked: !p.off, 'aria-label': `${p.name} on`, onchange: (e) => act('/api/provider/on', { name: p.name, on: e.target.checked }, e.target.checked ? `${p.name} is on` : `${p.name} is off: HeartCode skips its models`) }),
2362
- h('i')),
2363
- h('div', { className: 'who' },
2364
- h('span', { className: 'name', textContent: p.name }),
2365
- p.off ? h('span', { className: 'tag', textContent: 'off' }) : null,
2366
- m.off ? h('span', { className: 'tag', textContent: 'list off', title: "its list isn't loaded: add a model by its name, in the box on the right" }) : m.loading ? h('span', { className: 'tag', textContent: 'loading…' }) : m.error ? h('span', { className: 'tag err', textContent: "can't list its models", title: m.error }) : h('span', { className: 'tag', textContent: `${m.list.length} model${m.list.length === 1 ? '' : 's'}` }),
2367
- h('span', { className: 'tag inlist' }),
2368
- h('span', { className: 'meta mono', textContent: p.baseUrl, title: `${p.baseUrl} · key ${p.key || 'none'}` })),
2369
- h('form', { className: 'by-name', onsubmit: addByName },
2370
- h('input', { type: 'text', name: 'name', placeholder: 'model name(s)', 'aria-label': `add models to ${p.name} by their names`, title: `a model's exact name, or several separated by commas: added to ${p.name} (not to the list: click one to put it there), also ones ${p.name} doesn't list` }),
2371
- h('button', { className: 'small', textContent: 'Add' })),
2372
- h('button', { className: 'small', textContent: 'Edit', title: 'its address and key, its model list, delete it', onclick: () => openForm(p) })),
2373
- // what's listed first; loading and errors under it (the models already shown stay where they are)
2374
- (() => {
2375
- if (!ids.length) return null
2376
- SHOWN.set(p.name, ids)
2377
- const box = h('div', { className: 'rows' })
2378
- box._ids = ids
2379
- box._v = virtual(box, { count: ids.length, height: CAT_ROW, row: (i) => item(ids[i]), scroller: $('p-list') })
2380
- return box
2381
- })(),
2382
- m.error ? h('div', { className: 'cat-note', style: 'color:var(--err)' }, `can't list its models: ${shortError(m.error)} `, h('button', { className: 'small', textContent: 'Try again', onclick: () => loadModels(p.name, true) }), h('div', { className: 'muted', style: 'margin-top:4px', textContent: "Or add a model by its name, in the box above." })) : null,
2383
- m.off && !ids.length ? h('div', { className: 'cat-note', textContent: "Its list is off: add a model by its name, in the box above." }) : null,
2384
- m.loading ? h('div', { className: 'cat-note', textContent: 'Loading its models…' }) : null)
2385
- }))
2386
- if (freeOnly && !$('p-list').querySelector('section')) put($('p-list'), h('div', { className: 'cat-note', textContent: "No provider lists a model at $0. (A provider whose model list has no prices can't say what's free: Free only leaves those out.)" }))
2387
- }
2605
+ })
2606
+ // models by their names (several, comma-separated), under this provider only: not into the list
2607
+ // (a click on one puts it there); one it has already: said, and shown
2608
+ list.addEventListener('submit', (e) => {
2609
+ e.preventDefault()
2610
+ const { sec } = where(e.target)
2611
+ const p = provOf(sec)
2612
+ if (!p) return
2613
+ const box = e.target.elements.name
2614
+ const ids = [...new Set(box.value.split(',').map((x) => x.trim()).filter(Boolean))]
2615
+ if (!ids.length) return
2616
+ const has = new Set([...(MODELS[p.name]?.list ?? []), ...p.added])
2617
+ const add = ids.filter((id) => !has.has(id))
2618
+ if (!add.length) return showRow(p.name, ids[0], ids.length === 1 ? `${p.name} already has ${ids[0]}: click it to add it to the list` : `${p.name} already has all ${ids.length}`)
2619
+ box.value = ''
2620
+ act('/api/provider/added', { name: p.name, models: add }, `${add.length === 1 ? add[0] : `${add.length} models`} added to ${p.name}${add.length < ids.length ? ` (${ids.length - add.length} it had already)` : ''}: click one to put it in the list`)
2621
+ })
2622
+ })()
2388
2623
  // --- Your models page: the list as a table; sorted by several columns at once (each a tie-break
2389
2624
  // for the ones before it), the sort kept in this browser ---
2390
2625
  const can = (t) => ({ tools: t.tested ? t.tested.mode === 'tools' : t.known?.tools !== false, thinking: Boolean(t.tested ? t.tested.thinking : t.known?.thinking), images: Boolean(t.tested ? t.tested.vision : t.known?.images) })
@@ -2631,8 +2866,8 @@ function drawMine(s) {
2631
2866
  // about: its tooltip, in plain words (the label is its first line)
2632
2867
  const cell = (icon, label, about, ...control) => h('label', { className: 'mt-set', title: `${label}\n${about}` }, h('span', { className: 'mt-setl' }, ic(icon), h('span', { className: 'lt', textContent: label })), h('span', { className: 'mt-setc' }, ...control))
2633
2868
  // a whole number setting (seconds), with its limits from the server (SPEED_LIMITS)
2634
- const LIMITS = { replyStart: [5, 600], replyIdle: [10, 1800] }
2635
- // a time limit saved; the ones that depend on it (Give up, Stalled, Tests wait) may move to fit: said
2869
+ const LIMITS = s.limits
2870
+ // a time limit saved; the one that depends on it (Give up, Stalled) may move to fit: said
2636
2871
  // for longer, and the boxes that moved flash
2637
2872
  const saveTime = async (name, v, said) => {
2638
2873
  const r = await act('/api/setting', { name, value: v })
@@ -2648,25 +2883,26 @@ function drawMine(s) {
2648
2883
  saveTime(name, v, said(v))
2649
2884
  } })
2650
2885
  const secsCell = (icon, label, name, about, unit, said) => cell(icon, label, about, num(name, label, said), h('span', { className: 'unit', textContent: unit }))
2651
- const settings = h('div', { className: 'mt-sets', inert: busy },
2886
+ const single = order.length < 2 // one model: only the time limits (nothing to switch to, no helpers)
2887
+ const settings = h('div', { className: `mt-sets${single ? ' few' : ''}`, inert: busy },
2652
2888
  h('div', { className: 'mt-mode-sets' },
2653
- cell('swap', 'If one fails', 'What happens when a model errors, doesn\'t answer in time, or is rate-limited.\n\nSwitch model: another of your models takes over at once (the best-ranked one not tried yet).\nRetry it first: when the model is only busy or briefly down (a rate limit, an outage), the same one is tried again, up to the number of tries set here; any other error switches at once.',
2889
+ !single && cell('swap', 'If one fails', 'What happens when a model errors, doesn\'t answer in time, or is rate-limited.\n\nSwitch model: another of your models takes over at once (the best-ranked one not tried yet).\nRetry it first: when the model is only busy or briefly down (a rate limit, an outage), the same one is tried again, up to the number of tries set here; any other error switches at once.',
2654
2890
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
2655
2891
  [['failure', 'switch model'], ['retries', 'retry it first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
2656
2892
  ro.on === 'retries' ? h('input', { type: 'number', className: 'tries', 'aria-label': 'tries', title: 'Tries\nHow many times in all the same model is tried when it\'s busy or briefly down, before another model takes over.', min: 1, max: 20, value: ro.retries, onchange: (e) => saveOrder(S.order, 'saved', { retries: Number(e.target.value) }) }) : null),
2657
- secsCell('clock', 'Give up', 'replyStart', "How long a model gets to start answering.\n\nAfter HeartCode asks, the first word, thought or tool call must come within this many seconds. If nothing comes, the model counts as failed and another one takes over.\n\nRaise it if your providers are slow but do answer (fewer switches). Lower it to move on faster from models that hang.\nStalled and Tests wait are never shorter than this: they move up with it.", 's', (v) => `a model that hasn't started answering in ${v}s counts as failed`),
2893
+ secsCell('clock', 'Give up', 'replyStart', "How long a model gets to start answering.\n\nAfter HeartCode asks, the first word, thought or tool call must come within this many seconds. If nothing comes, the model counts as failed and another one takes over.\n\nRaise it if your providers are slow but do answer (fewer switches). Lower it to move on faster from models that hang.\nStalled is never shorter than this: it moves up with it.", 's', (v) => `a model that hasn't started answering in ${v}s counts as failed`),
2658
2894
  secsCell('pause', 'Stalled', 'replyIdle', "How long a reply may go quiet once it has started.\n\nA model that keeps sending (text or thinking) is never cut off, however long it takes. One that sends nothing at all for this many seconds counts as stalled: it's asked again, or another model takes over.\n\nAt least as long as Give up (a pause mid-reply has the same causes as a slow start).", 's', (v) => `a reply silent for ${v}s counts as stalled`),
2659
- cell('hourglass', 'Tests wait', "Only for the Test buttons on this page, not for real work.\n\nHow long each model gets to answer a short test message. No answer by then shows as \"no answer\" in Works?.\n\nAt least as long as Give up, so a test doesn't call a model broken that real work would still wait for.",
2895
+ cell('hourglass', 'Tests wait', "Only for the Test buttons on this page, not for real work.\n\nHow long each model gets to answer a short test message. No answer by then shows as \"no answer\" in Works?.\n\nShorter than Give up: a slow model may show \"no answer\" here and still work in real use.",
2660
2896
  h('input', { type: 'number', className: 'tries', 'data-name': 'testTimeout', min: 1, max: 600, step: 1, value: S.settings.testTimeout, 'aria-label': 'Test timeout in seconds', onchange: (e) => {
2661
2897
  const v = Math.round(Number(e.target.value))
2662
2898
  if (!(v >= 1 && v <= 600)) return (e.target.value = S.settings.testTimeout), toast('a whole number of seconds, 1 to 600', true)
2663
2899
  saveTime('testTimeout', v, `tests wait ${v} second${v === 1 ? '' : 's'} for an answer`)
2664
2900
  } }), h('span', { className: 'unit', textContent: 's' })),
2665
- cell('send', 'New message', 'Which model a new message goes to first.\n\n#1: always the top of the list.\nLast working: the one that answered last (useful while #1 keeps failing).',
2901
+ !single && cell('send', 'New message', 'Which model a new message goes to first.\n\n#1: always the top of the list.\nLast working: the one that answered last (useful while #1 keeps failing).',
2666
2902
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
2667
2903
  [['first', '#1'], ['stay', 'last working']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.next === v })))),
2668
- h('span', { className: 'mt-div', 'aria-hidden': 'true' }),
2669
- chooser))
2904
+ !single && h('span', { className: 'mt-div', 'aria-hidden': 'true' }),
2905
+ !single && chooser))
2670
2906
 
2671
2907
  // --- beside the filters: what's shown · what you do with it (the sorts show in the column heads) ---
2672
2908
  const line = h('div', { className: 'mt-line' },
@@ -2722,7 +2958,7 @@ function drawMine(s) {
2722
2958
  else (results.fails++, (results[o] = (results[o] ?? 0) + 1))
2723
2959
  }
2724
2960
  put($('mt'),
2725
- order.length > 1 ? settings : null,
2961
+ order.length ? settings : null, // the time limits count with one model too (Give up: how long it gets to start)
2726
2962
  order.length
2727
2963
  ? h('div', { className: 'mt-tools' },
2728
2964
  h('div', { className: 'mt-row', inert: busy }, filterBarOf(order, results), line),
@@ -2848,13 +3084,14 @@ const working = () => S.order.filter((t) => TRIES[keyOf(t)]?.ok && !TRIES[keyOf(
2848
3084
  let afterTests = null
2849
3085
  function testFirst() {
2850
3086
  const n = (x) => x.toLocaleString()
2851
- const paid = S.order.filter((t) => t.price && (t.price.input > 0 || t.price.output > 0)).length
2852
- const unknown = S.order.filter((t) => !t.price).length
2853
- $('h-test-cost').textContent = `Test all sends each of the ${n(S.order.length)} models a short message. ${paid ? `${n(paid)} of them aren't free: each charges for its few tokens. ` : ''}${unknown ? `${n(unknown)} have no price we know of, and may charge too. ` : ''}When it's done, helpers are picked from the ones that worked.`
3087
+ const order = shownOrder() // as Test all: a provider switched off isn't tested
3088
+ const paid = order.filter((t) => t.price && (t.price.input > 0 || t.price.output > 0)).length
3089
+ const unknown = order.filter((t) => !t.price).length
3090
+ $('h-test-cost').textContent = `Test all sends each of the ${n(order.length)} models a short message. ${paid ? `${n(paid)} of them aren't free: each charges for its few tokens. ` : ''}${unknown ? `${n(unknown)} have no price we know of, and may charge too. ` : ''}When it's done, helpers are picked from the ones that worked.`
2854
3091
  $('h-test-go').onclick = () => {
2855
3092
  $('h-test').close()
2856
3093
  afterTests = 'auto'
2857
- tryAll(S.order)
3094
+ tryAll(order)
2858
3095
  }
2859
3096
  $('h-test-no').onclick = () => $('h-test').close()
2860
3097
  $('h-test').showModal()
@@ -2908,7 +3145,7 @@ function tableRow(t, at, pick, row = at) {
2908
3145
  h('span', { className: 'n', textContent: `#${row + 1}`, title: row !== at ? `#${at + 1} in the list HeartCode uses (Save list to use the order shown)` : '' }),
2909
3146
  h('span', { className: 'm' }, h('span', { className: 'name', textContent: t.model, title: t.model + (t.record ? `\nTrack record (recent work): ${t.record.done} done, ${t.record.failed} failed` : '') }), tag,
2910
3147
  t.record?.poor ? h('span', { className: 'tag warn', textContent: '⚠', 'aria-label': 'failing', title: `Failing: it failed most of its recent work (${t.record.failed} failed, ${t.record.done} done: handed over, reviews that said no, broken replies). HeartCode picks it last and doesn't start a message with it while another can. Turn off "Learn from each model's track record" in Settings to use your order only.` }) : null),
2911
- h('span', { className: 'p', textContent: isOff(t.provider) ? `${t.provider} · off` : t.provider, title: t.provider }),
3148
+ h('span', { className: 'p', title: t.provider }, provIcon(t.provider), isOff(t.provider) ? `${t.provider} · off` : t.provider),
2912
3149
  helperCell(t, at),
2913
3150
  h('span', { className: 'num', textContent: ctx ? `${t.tested?.sure === false ? '~' : ''}${kTok(ctx)}` : '–', title: ctx ? `${ctx.toLocaleString()} tokens${t.tested?.sure === false ? ' (assumed: the server and models.dev don\'t say)' : ''}` : '' }),
2914
3151
  yes(c.tools), yes(c.thinking), yes(c.images),
@@ -2922,27 +3159,11 @@ function tableRow(t, at, pick, row = at) {
2922
3159
  h('button', { type: 'button', className: 'small ghost ib k-del', disabled: busy, title: 'Remove it from the list (it stays under its provider)', 'aria-label': `remove ${t.model}`, onclick: () => removeMine(t.provider, t.model) }, ic('trash'))))
2923
3160
  }
2924
3161
 
2925
- // your list changed: the rows and counts it touches, in place
2926
- function markCatalog() {
2927
- for (const r of $('p-list').querySelectorAll('.mrow')) {
2928
- const at = placeOf(r.dataset.provider, r.dataset.model)
2929
- r.classList.toggle('taken', at !== undefined)
2930
- r.lastElementChild.replaceWith(rowTail(r.dataset.provider, r.dataset.model))
2931
- }
2932
- for (const sec of $('p-list').querySelectorAll('section[data-provider]')) {
2933
- const n = S.order.filter((t) => t.provider === sec.dataset.provider).length
2934
- const tag = sec.querySelector('.inlist')
2935
- tag.hidden = !n
2936
- tag.textContent = `${n} in the list${inUse()?.provider === sec.dataset.provider ? ' · in use' : ''}`
2937
- }
2938
- drawPicks()
2939
- }
2940
-
2941
3162
  function drawUsing(s) {
2942
3163
  const o = s.order.filter((t) => !isOff(t.provider))
2943
3164
  $('using').hidden = page() === 'providers' // there it's on the page itself
2944
3165
  const first = inUse() ?? o[0]
2945
- put($('using'), o.length ? [h('span', { className: 'k', textContent: 'HeartCode uses' }), h('b', { textContent: first.model, title: first !== o[0] ? `${o[0].model} (#1) failed most of its recent work, so messages start with ${first.model} until it does better` : '' }), h('span', { className: 'k', textContent: `${first.provider}${first !== o[0] ? ' · #1 is failing' : ''}${o.length > 1 ? ` · ${o.length - 1} fallback${o.length > 2 ? 's' : ''}` : ''}` })] : s.order.length ? [h('span', { className: 'k', textContent: 'The providers of all the models are switched off' }), h('a', { href: '#providers', textContent: 'Switch one on' })] : [h('span', { className: 'k', textContent: 'No model chosen yet' }), h('a', { href: '#providers', textContent: 'Choose one' })])
3166
+ put($('using'), o.length ? [h('span', { className: 'k', textContent: 'HeartCode uses' }), h('b', { textContent: first.model, title: first !== o[0] ? `${o[0].model} (#1) failed most of its recent work, so messages start with ${first.model} until it does better` : '' }), h('span', { className: 'k' }, provIcon(first.provider), `${first.provider}${first !== o[0] ? ' · #1 is failing' : ''}${o.length > 1 ? ` · ${o.length - 1} fallback${o.length > 2 ? 's' : ''}` : ''}`)] : s.order.length ? [h('span', { className: 'k', textContent: 'The providers of all the models are switched off' }), h('a', { href: '#providers', textContent: 'Switch one on' })] : [h('span', { className: 'k', textContent: 'No model chosen yet' }), h('a', { href: '#providers', textContent: 'Choose one' })])
2946
3167
  }
2947
3168
 
2948
3169
  // --- General ---
@@ -2974,8 +3195,14 @@ function drawGeneral(s) {
2974
3195
  }
2975
3196
  $('g-effort').onchange = (e) => act('/api/setting', { name: 'effort', value: e.target.value }, 'effort saved')
2976
3197
  $('g-context').onchange = (e) => act('/api/setting', { name: 'context', value: e.target.value.trim() ? Number(e.target.value) : null }, 'context window saved')
2977
- // Voice: this machine (whisper-cli and a ggml model) or a provider's transcription API, a model and a
2978
- // language: kept as config's "voice" ({ provider, model, language }; nothing set: this machine).
3198
+ // Voice: Hex, whisper-cli or OpenAI's API (nothing set: Hex when it's ready, else whisper-cli), a model
3199
+ // and a language: kept as config's "voice" ({ engine, model, language }).
3200
+ const VOICE = {
3201
+ '': ['Automatic', 'On this computer: Hex when it\'s installed with its Labs › Transcribe files on, else whisper-cli and a model.', 'Empty: the engine\'s own (Hex: your dictation model; whisper: the best in ~/.whisper-models).', 'auto'],
3202
+ hex: ['Hex', 'The Hex app on this computer, with your Hex dictation model: private, free, fast. Needs Hex\'s Labs › Transcribe files (hex labs on transcribe-files).', 'A model id from hex model list. Empty: the one Hex uses.', 'Hex\'s'],
3203
+ whisper: ['whisper-cli', 'whisper.cpp on this computer: private, free, slower. Needs whisper-cli and a model file.', 'A whisper model file (ggml-….bin). Empty: the best one in ~/.whisper-models.', 'auto'],
3204
+ openai: ['OpenAI API', 'Sent to OpenAI to turn into text, with your OpenAI provider\'s key: paid, fast.', 'Its speech-to-text model, like whisper-1 or gpt-4o-transcribe.', 'whisper-1'],
3205
+ }
2979
3206
  function voiceNow() {
2980
3207
  try {
2981
3208
  return S?.voice ? JSON.parse(S.voice) : {}
@@ -2985,25 +3212,24 @@ function voiceNow() {
2985
3212
  }
2986
3213
  function drawVoice(s) {
2987
3214
  const v = voiceNow()
2988
- const names = (s.providers ?? []).map((p) => p.name)
2989
- put($('v-src'), h('option', { value: '', textContent: 'This machine (whisper-cli)' }), names.map((n) => h('option', { value: n, textContent: `${n} (its transcription API)` })))
2990
- $('v-src').value = v.provider && names.includes(v.provider) ? v.provider : ''
2991
- const remote = Boolean($('v-src').value)
2992
- $('v-src-about').textContent = remote ? 'Sent to that provider to turn into text: fast, needs its key.' : 'Runs on this computer: private, free, slower. Needs whisper-cli and a model.'
2993
- $('v-model-about').textContent = remote ? 'Its speech-to-text model, like whisper-large-v3 (Groq) or whisper-1 (OpenAI).' : 'A whisper model file (ggml-….bin). Empty: the best one in ~/.whisper-models.'
2994
- $('v-lang-about').textContent = remote ? 'The language spoken, like en or bn. Empty: worked out from the speech.' : 'The language spoken, like en or bn; auto works it out. Empty: English.'
2995
- $('v-model').placeholder = remote ? 'whisper-large-v3' : 'auto'
2996
- $('v-lang').placeholder = remote ? 'auto' : 'en'
3215
+ put($('v-src'), Object.entries(VOICE).map(([v, [label]]) => h('option', { value: v, textContent: label })))
3216
+ $('v-src').value = VOICE[v.engine] ? v.engine : ''
3217
+ const [, about, model, ph] = VOICE[$('v-src').value]
3218
+ $('v-src-about').textContent = about
3219
+ $('v-model-about').textContent = model
3220
+ $('v-lang-about').textContent = 'The language spoken, like en or bn; auto works it out. Empty: English (OpenAI: worked out).'
3221
+ $('v-model').placeholder = ph
3222
+ $('v-lang').placeholder = 'en'
2997
3223
  for (const [id, k] of [['v-model', 'model'], ['v-lang', 'language']]) if (document.activeElement !== $(id)) $(id).value = v[k] ?? ''
2998
3224
  }
2999
3225
  function saveVoice(what) {
3000
- const v = { provider: $('v-src').value || undefined, model: $('v-model').value.trim() || undefined, language: $('v-lang').value.trim() || undefined }
3226
+ const v = { engine: $('v-src').value || undefined, model: $('v-model').value.trim() || undefined, language: $('v-lang').value.trim() || undefined }
3001
3227
  const set = Object.fromEntries(Object.entries(v).filter(([, x]) => x !== undefined))
3002
3228
  act('/api/voice', { text: Object.keys(set).length ? JSON.stringify(set) : '' }, what)
3003
3229
  }
3004
3230
  $('v-src').onchange = (e) => {
3005
3231
  $('v-model').value = '' // a local model's path means nothing to a provider, and the other way round
3006
- saveVoice(`voice: ${e.target.value || 'this machine'}`)
3232
+ saveVoice(`voice: ${VOICE[e.target.value][0]}`)
3007
3233
  }
3008
3234
  $('v-model').onchange = () => saveVoice('voice model saved')
3009
3235
  $('v-lang').onchange = () => saveVoice('voice language saved')
@@ -3643,8 +3869,7 @@ let sbLines = [] // [{ left:[id…], right:[id…] }]
3643
3869
  let sbDrag = null // the chip being dragged: { id, from: 'palette' | { line, side, idx } }
3644
3870
  let sbSaveTimer = null
3645
3871
  const SB_DEFAULT = () => [
3646
- { left: ['provider', 'model'], right: ['mode', 'thinking', 'images'] },
3647
- { left: ['ctx', 'tps', 'autocompact'], right: ['background', 'permissions', 'worktree', 'cost'] },
3872
+ { left: ['provider', 'model', 'ctx', 'tps'], right: ['mode', 'thinking', 'autocompact', 'background', 'worktree', 'permissions', 'cost'] },
3648
3873
  ]
3649
3874
  const sbLabel = (id) => (SB_ITEMS.find((i) => i.id === id) || {}).label || id
3650
3875
  const sbSample = (id) => (SB_ITEMS.find((i) => i.id === id) || {}).sample || id
@@ -3748,7 +3973,7 @@ function sbSave() {
3748
3973
  function render(s) {
3749
3974
  $('version').textContent = s.version ? `v${s.version}` : ''
3750
3975
  $('update-note').hidden = !s.update
3751
- if (s.update) $('update-note').innerHTML = `⬆ <b>${s.update}</b> is out · type <code>/update</code> in HeartCode`
3976
+ if (s.update) $('update-note').replaceChildren('⬆ ', h('b', { textContent: s.update }), ' is out · type ', h('code', { textContent: '/update' }), ' in HeartCode') // the registry's text: never as HTML
3752
3977
  if (s.prefs) {
3753
3978
  // the page's choices, as kept (also changed on another page: shown here too)
3754
3979
  const p = s.prefs
@@ -3756,6 +3981,10 @@ function render(s) {
3756
3981
  $('m-sort').value = catSort
3757
3982
  freeOnly = p.freeOnly === true
3758
3983
  $('free-only').checked = freeOnly
3984
+ onOnly = p.onOnly === true
3985
+ $('on-only').checked = onOnly
3986
+ catKind = ['api', 'cli'].includes(p.catKind) ? p.catKind : 'all'
3987
+ $('m-kind').value = catKind
3759
3988
  FOLDED.clear()
3760
3989
  for (const n of Array.isArray(p.folded) ? p.folded : []) FOLDED.add(n)
3761
3990
  const flip = (x) => (['provider', 'works'].includes(x.key) ? { ...x, dir: x.dir === 'up' ? 'down' : 'up' } : x) // an older page's sort: these two ran the other way
@@ -3825,6 +4054,7 @@ if (token) {
3825
4054
  gotResult(key, result)
3826
4055
  })
3827
4056
  events.addEventListener('testrun', (e) => showRun(JSON.parse(e.data)))
4057
+ events.addEventListener('clis', () => $('cli-form').open && loadClis()) // an install finished
3828
4058
  events.addEventListener('helpers', (e) => ((S.helpers = JSON.parse(e.data).helpers), drawMine(S))) // picked for you again, after a test run
3829
4059
  // many at once (thousands of models added): taken in once a frame, the table drawn once
3830
4060
  const news = new Map()