heartcode 0.1.63 → 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
@@ -209,6 +209,7 @@
209
209
  button:active:not(:disabled) { transform: translateY(1px); }
210
210
  button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
211
211
  button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.07); }
212
+ button.primary.attn { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); } /* the order shown isn't saved yet */
212
213
  button.danger { color: var(--err); }
213
214
  button.danger:hover:not(:disabled) { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
214
215
  button.small { padding: 4px 10px; font-size: 12.5px; }
@@ -256,6 +257,30 @@
256
257
  .preset b { display: block; }
257
258
  .preset span { color: var(--muted); font-size: 12px; }
258
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; }
259
284
 
260
285
  /* Providers & models: every provider's models in one list, full width; it fills the screen's height and scrolls inside */
261
286
  .head-actions { display: flex; gap: 8px; align-items: center; }
@@ -289,7 +314,7 @@
289
314
  .mrow.flash { animation: flash 1.6s ease-out; }
290
315
  @keyframes flash { from { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); } to { background: none; box-shadow: none; } }
291
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; }
292
- .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 */
293
318
  .mwrap .mrow { height: 100%; }
294
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 */
295
320
  .mrow .add { color: var(--accent); font-size: 12.5px; font-weight: 600; white-space: nowrap; opacity: .55; transition: opacity .12s; }
@@ -453,7 +478,7 @@
453
478
  .pill .again:hover:not(:disabled) { color: var(--text); }
454
479
  .pill.on { border-color: var(--accent); background: var(--accent-soft); }
455
480
  .pill.on .again { border-left-color: color-mix(in srgb, var(--accent) 40%, transparent); }
456
- .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; }
457
482
  .mt-h button.mid, .mtable .mid { text-align: center; }
458
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 */
459
484
  .mt-h > :nth-child(15), .mtable .try { padding-left: 12px; } /* Works?: a little room after the right-aligned price */
@@ -477,6 +502,8 @@
477
502
  .mtable li:first-child .n { color: var(--accent); }
478
503
  .mtable .m { font-family: var(--mono); font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
479
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); }
480
507
  .mtable .yes { color: var(--ok); }
481
508
  /* Helper: a switch (can #1 start it for side jobs?), then what it's good at, as pills */
482
509
  .hp { display: flex; align-items: center; gap: 4px; min-width: 0; }
@@ -490,11 +517,8 @@
490
517
  .mtable li .hp .jp:active:not(:disabled) { transform: scale(.95); }
491
518
  .mtable li .hp .jp:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
492
519
  .mtable li .hp .jp.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); }
493
- .mtable li .hp .jp.sug { border-style: dashed; border-color: var(--accent); color: var(--accent); }
494
- .mtable li .hp.off .jp:not(.sug) { opacity: .6; }
495
- /* the helper suggestions, waiting for a yes: beside the list's buttons */
496
- .hsug { display: inline-flex; align-items: center; gap: 6px; padding: 2px 3px 2px 10px; border: 1px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--text); white-space: nowrap; }
497
- .hsug .ic { color: var(--accent); }
520
+ .mtable li .hp.off .jp { opacity: .6; }
521
+ /* the helpers' part of the list's buttons (Clear helpers) */
498
522
  .hbar { display: contents; }
499
523
  .mtable li .hp .jp.saving, .hp .saving .sw { opacity: .55; animation: hp-pulse .9s ease-in-out infinite alternate; pointer-events: none; } /* its save on its way */
500
524
  @keyframes hp-pulse { to { opacity: .25; } }
@@ -578,6 +602,7 @@
578
602
  .mt-set { display: flex; align-items: center; gap: 8px; min-width: 0; }
579
603
  .mt-setl { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
580
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 */
581
606
  .mt-div { width: 1px; height: 22px; background: var(--line-strong); margin: 0 4px; } /* between the fail-over settings and the helpers' */
582
607
  .mt-mode-sets .h-order select { height: 34px; }
583
608
  .mt-mode-sets .seg { height: 34px; }
@@ -849,6 +874,9 @@
849
874
  .mtable li .acts .ib.k-info { color: var(--c-slate); }
850
875
  .mtable li .acts .ib.k-edit { color: var(--c-violet); }
851
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 */
852
880
  </style>
853
881
  </head>
854
882
  <body>
@@ -878,7 +906,7 @@
878
906
  <section class="page" id="page-providers">
879
907
  <div class="head">
880
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>
881
- <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>
882
910
  </div>
883
911
  <div class="steps" id="steps"></div>
884
912
  <div class="work" id="p-work" hidden>
@@ -887,8 +915,11 @@
887
915
  <input type="checkbox" id="pick-shown" aria-label="select every model shown">
888
916
  <input type="search" id="m-search" placeholder="Search all models…">
889
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>
890
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>
891
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>
892
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>
893
924
  </div>
894
925
  <div class="job-slot" data-where="catalog"></div>
@@ -906,7 +937,7 @@
906
937
 
907
938
  <!-- Notifications -->
908
939
  <section class="page" id="page-notify">
909
- <div class="head"><div><h1>Notifications</h1><p class="lead">A phone message when HeartCode finishes a task, fails, or needs an answer: no need to watch it work.</p></div></div>
940
+ <div class="head"><div><h1>Notifications</h1><p class="lead">A sound, a desktop notification or a phone message when HeartCode finishes a task, fails, or needs an answer: no need to watch it work. All off until switched on.</p></div></div>
910
941
  <div class="cols">
911
942
  <div class="stack">
912
943
  <div class="card">
@@ -914,10 +945,15 @@
914
945
  <p class="sub">Through a private bot: only its owner gets its messages.</p>
915
946
  <div id="tg-setup"></div>
916
947
  </div>
948
+ <div class="card">
949
+ <h2>On this computer</h2>
950
+ <p class="sub">While HeartCode runs in a terminal here (not <span class="mono">-p</span>: the program that started it tells you). Its own sound: a heartbeat.</p>
951
+ <div id="al-setup"></div>
952
+ </div>
917
953
  </div>
918
954
  <div class="stack">
919
955
  <div class="card">
920
- <h2>When to send one</h2>
956
+ <h2>When to send one to Telegram</h2>
921
957
  <p class="sub">Each on its own. A running HeartCode follows changes right away.</p>
922
958
  <div id="tg-events"></div>
923
959
  </div>
@@ -1107,21 +1143,32 @@
1107
1143
  </dialog>
1108
1144
  <dialog id="p-form" aria-labelledby="p-title">
1109
1145
  <h2 id="p-title">Add a provider</h2>
1110
- <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>
1111
1147
  <div class="presets" id="presets"></div>
1112
1148
  <div class="row" style="margin-top:6px">
1113
1149
  <div class="grow"><label class="f" for="p-name">Name</label><input type="text" id="p-name" placeholder="openrouter, groq, work…"></div>
1114
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>
1115
1151
  </div>
1152
+ <div id="p-keys">
1116
1153
  <label class="f" for="p-key">API key <span class="muted" id="p-keynote" style="font-weight:normal"></span></label>
1117
1154
  <input type="password" id="p-key" autocomplete="off" placeholder="paste it here (none for a server on this machine, like Ollama)">
1118
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>
1119
1158
  <div id="p-more" hidden>
1120
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>
1121
1160
  <div class="actions" id="p-added"></div>
1122
1161
  </div>
1123
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>
1124
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>
1125
1172
  <dialog id="c-form" aria-labelledby="c-title">
1126
1173
  <h2 id="c-title">Add a server</h2>
1127
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>
@@ -1268,6 +1315,15 @@ const ICON = {
1268
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',
1269
1316
  bulb: 'M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7V16h8v-1.3A7 7 0 0 0 12 2z',
1270
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
+ }
1271
1327
  const ic = (name, cls = '') => {
1272
1328
  const el = document.createElement('span')
1273
1329
  el.className = `icon ${cls}`.trim()
@@ -1293,7 +1349,7 @@ const BUTTON_ICONS = [
1293
1349
  // card titles: their icon and color
1294
1350
  const TITLE_ICONS = [
1295
1351
  [/^permissions/i, 'shield', 'green'], [/^terminal colors/i, 'palette', 'pink'], [/^behavior/i, 'toggle', 'blue'], [/^model$/i, 'cpu', 'violet'], [/^voice/i, 'mic', 'amber'],
1296
- [/^external tools/i, 'tool', 'slate'], [/^web search/i, 'globe', 'teal'], [/^telegram/i, 'send', 'blue'], [/^when to send/i, 'bell', 'amber'], [/^servers/i, 'server', 'teal'],
1352
+ [/^external tools/i, 'tool', 'slate'], [/^web search/i, 'globe', 'teal'], [/^telegram/i, 'send', 'blue'], [/^when to send/i, 'bell', 'amber'], [/^on this computer/i, 'monitor', 'green'], [/^servers/i, 'server', 'teal'],
1297
1353
  [/^install from/i, 'download', 'violet'], [/^the run's log/i, 'file', 'gray'], [/^requests logged/i, 'activity', 'blue'], [/^requests$/i, 'activity', 'blue'], [/^lines/i, 'layout', 'slate'],
1298
1354
  [/^items/i, 'list', 'slate'], [/^show the status bar/i, 'layout', 'slate'],
1299
1355
  ]
@@ -1605,10 +1661,99 @@ function drawPresets() {
1605
1661
  if (!editing && (!$('p-name').value || PRESETS.some(([n]) => n === $('p-name').value))) $('p-name').value = name
1606
1662
  $('p-url').value = url
1607
1663
  drawPresets()
1664
+ drawCliNote()
1608
1665
  $('p-key').focus()
1609
1666
  } }, h('b', { textContent: label }), h('span', { textContent: what }))))
1610
1667
  }
1611
- $('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
+ }
1612
1757
 
1613
1758
  const MODELS = {} // provider → { list } | { error } | { loading }
1614
1759
  const filters = {}
@@ -1626,10 +1771,10 @@ function loadModels(name, again = false) {
1626
1771
  show()
1627
1772
  api('/api/models', { name })
1628
1773
  .then(({ models, details }) => (MODELS[name] = { list: models, details: details ?? {} }), (e) => ((MODELS[name] = { error: e.message }), listLoads.failed++))
1629
- .then(() => (listLoads.done++, show(), S && drawProviders(S)))
1774
+ .then(() => (listLoads.done++, show(), redraw()))
1630
1775
  }
1631
1776
  const useModel = (provider, model) => act('/api/model', { provider, model }, `HeartCode now uses ${provider} · ${model}`)
1632
- 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
1633
1778
 
1634
1779
  let editing = null
1635
1780
  function openForm(p = null) {
@@ -1644,12 +1789,14 @@ function openForm(p = null) {
1644
1789
  // editing: what used to crowd its header
1645
1790
  $('p-more').hidden = $('p-delete').hidden = !p
1646
1791
  $('presets').hidden = Boolean(p)
1792
+ if (!CLIS) loadClis() // a CLI's title and sign-in command, for its note
1647
1793
  $('p-form').querySelector('.sub').hidden = Boolean(p)
1648
1794
  if (p) {
1649
1795
  $('p-list-on').checked = p.list
1650
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)) })] : [])
1651
1797
  }
1652
1798
  drawPresets()
1799
+ drawCliNote()
1653
1800
  $('p-form').showModal()
1654
1801
  ;(p ? $('p-url') : $('p-name')).focus()
1655
1802
  }
@@ -1682,61 +1829,109 @@ $('c-what').addEventListener('keydown', (e) => e.key === 'Enter' && $('c-add').c
1682
1829
  for (const id of ['p-name', 'p-url', 'p-key']) $(id).addEventListener('keydown', (e) => e.key === 'Enter' && $('p-save').click())
1683
1830
 
1684
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.
1685
1837
  const byName = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare // one collator: thousands of names sort fast
1686
- let modelQuery = ''
1687
- // the models under each provider: by name, or by what its list says they cost (cheapest first; no price: last)
1688
1838
  // The page's own choices (sorts, folds, the provider ranking), kept in ~/.heart (the browser's
1689
1839
  // storage isn't: the page's address has a new port each time)
1690
1840
  const savePref = (key, value) => api('/api/prefs', { key, value }).catch((e) => toast(`not kept: ${e.message}`, true))
1691
- let catSort = 'name'
1692
- // only the models their provider lists at $0 (what its own list says: the price shown under each)
1693
- 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)
1694
1848
  const isFree = (d) => Boolean(d?.price) && !d.price.input && !d.price.output
1695
- $('free-only').onchange = (e) => {
1696
- freeOnly = e.target.checked
1697
- savePref('freeOnly', freeOnly)
1698
- if (S) drawProviders(S)
1699
- }
1700
- $('m-sort').onchange = (e) => {
1701
- catSort = e.target.value
1702
- savePref('catSort', catSort)
1703
- if (S) drawProviders(S)
1704
- }
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)
1705
1851
  const costOf = (d) => (d?.price ? (d.price.input ?? 0) + (d.price.output ?? 0) : Infinity)
1706
- // Providers folded on the page (kept: savePref). Typing a search opens them all, until you fold or
1707
- // unfold one (or all) again.
1708
- let searchOpen = false
1709
- 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
1710
1896
  function applyFolds() {
1711
- $('fold-all').textContent = allFolded() ? 'Expand all' : 'Collapse all'
1897
+ const view = catView()
1898
+ const searching = Boolean(modelQuery.trim())
1712
1899
  for (const sec of $('p-list').querySelectorAll('section[data-provider]')) {
1713
- const folded = FOLDED.has(sec.dataset.provider) && !(searchOpen && modelQuery.trim())
1900
+ const folded = FOLDED.has(sec.dataset.provider) && !searching
1714
1901
  sec.classList.toggle('collapsed', folded)
1715
1902
  sec.querySelector('.fold')?.setAttribute('aria-expanded', String(!folded))
1716
1903
  }
1717
- for (const box of $('p-list').querySelectorAll('.rows')) box._v?.draw() // the ones now open
1718
- }
1719
- // A fold by hand during a search starts from what's shown (the ones it opened stay open).
1720
- function settle() {
1721
- if (searchOpen && modelQuery.trim()) for (const sec of $('p-list').querySelectorAll('section[data-provider]')) FOLDED.delete(sec.dataset.provider)
1722
- searchOpen = false
1723
- }
1724
- const folds = () => (applyFolds(), savePref('folded', [...FOLDED])) // a fold changed: shown and kept
1725
- const fold = (name) => (settle(), FOLDED.has(name) ? FOLDED.delete(name) : FOLDED.add(name), folds())
1726
- // one button: collapse them all, or (all collapsed) expand them all
1727
- const allFolded = () => Boolean(S?.providers.length) && S.providers.every((p) => FOLDED.has(p.name))
1728
- $('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
1729
1924
  $('pick-shown').onchange = (e) => {
1730
- 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}`)
1731
1926
  drawPicks()
1732
1927
  }
1733
1928
  $('p-mine').onclick = () => (location.hash = 'models')
1734
1929
  // models.dev fetched again (your models' profiles too), then every listed provider's models with it
1735
1930
  $('dev-all').onclick = async () => {
1736
- if (!(await lookUp())) return
1931
+ if (!(await lookUp(null, { models: true }))) return // models.dev only: no rankings, no helpers marked
1737
1932
  S?.providers.filter((p) => p.list).forEach((p) => loadModels(p.name, true))
1738
1933
  }
1739
- $('m-search').oninput = (e) => ((modelQuery = e.target.value), (searchOpen = true), S && drawProviders(S), applyFolds())
1934
+
1740
1935
  // A model's tooltip: its full name and what's known about it (from the provider, HeartCode's price
1741
1936
  // list and its own test), and what a click does. Shown on hover and on keyboard focus.
1742
1937
  // a token count, short: 1M, 1.05M (two decimals, not rounded up to 1.1M), 131k
@@ -1771,7 +1966,7 @@ const MEANS = {
1771
1966
  }
1772
1967
  // What a test came to, in a word: works, its status code (402, 429…), empty, no answer or failed;
1773
1968
  // null while it runs or before it's tested
1774
- 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)
1775
1970
  // The Works? cell: the last result (cut short, all of it on hover) and Test.
1776
1971
  function triedCell(t) {
1777
1972
  const r = TRIES[keyOf(t)]
@@ -1802,11 +1997,6 @@ for (const ev of ['pointerup', 'pointercancel']) addEventListener(ev, () => {
1802
1997
  if (drawAfterPress) (drawAfterPress = false), setTimeout(mineSoon, 0) // after the click it finishes
1803
1998
  }, true)
1804
1999
  let drawAfterPress = false
1805
- addEventListener('pointerdown', () => (pressed = true), true)
1806
- for (const ev of ['pointerup', 'pointercancel']) addEventListener(ev, () => {
1807
- pressed = false
1808
- if (drawAfterPress) (drawAfterPress = false), setTimeout(mineSoon, 0) // after the click it finishes
1809
- }, true)
1810
2000
  const mineSoon = () => {
1811
2001
  if (mineFrame) return
1812
2002
  const later = testingAll ? Math.max(0, mineLast + 400 - Date.now()) : 0
@@ -1857,10 +2047,9 @@ function showRun(run) {
1857
2047
  for (const [key, r] of Object.entries(TRIES)) if (r.going) r.before ? (TRIES[key] = r.before) : delete TRIES[key] // stopped before it: as it was
1858
2048
  job('test-all')
1859
2049
  if (run?.over && afterTests) {
1860
- const then = afterTests
1861
2050
  afterTests = null
1862
- if (then === 'suggest') suggestNow()
1863
- else 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
1864
2053
  } else if (!run?.over) afterTests = null // never started
1865
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)
1866
2055
  } else
@@ -1876,13 +2065,19 @@ function showRun(run) {
1876
2065
 
1877
2066
  // models.dev looked up again: one model (its Retry), or all of yours with their rankings (Update model info)
1878
2067
  const retry = (t) => h('button', { className: 'small', textContent: 'Retry', title: 'look it up in models.dev again', onclick: (e) => (e.stopPropagation(), lookUp(t)) })
1879
- async function lookUp(t) {
1880
- 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' })
1881
2072
  if (!t) (lookingUp = true), mineSoon()
1882
- 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])
1883
2074
  if (!t) (lookingUp = false), mineSoon()
1884
2075
  job('models.dev')
1885
- 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' : ''}`)
2076
+ // all of them: the helpers marked from what's known now (Automatic: picked again by the server;
2077
+ // My picks: added to yours, what you picked stays)
2078
+ const marked = full && r && !S.helpersAuto ? await api('/api/helpers/mark', {}).catch((e) => (toast(e.message, true), null)) : null
2079
+ if (marked) Object.assign(S, { helpers: marked.helpers, helpersAuto: marked.helpersAuto }), drawMine(S)
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` : ''}`)
1886
2081
  return r
1887
2082
  }
1888
2083
 
@@ -2014,24 +2209,28 @@ function drawProviders(s) {
2014
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))))
2015
2210
  $('steps').hidden = order.length > 0 // the first start only
2016
2211
  $('p-work').hidden = none
2017
- // 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
2018
2213
  const shown = shownOrder()
2019
2214
  $('p-mine').hidden = !shown.length
2020
2215
  $('p-mine').textContent = `Models (${shown.length}) →`
2021
2216
  $('p-mine').title = shown.length ? `HeartCode uses ${shown[0].provider} · ${shown[0].model}. Open Models: the order, and what happens when one fails` : ''
2022
- fillHeight()
2023
-
2024
- // every provider's models, A to Z; one click adds it (the first one becomes #1). Built
2025
- // again only when what it lists changes (a provider, its models, the search); a change to your
2026
- // list only updates the rows it touches (markCatalog), so the list stays where you scrolled it
2027
- // (but one of yours a provider doesn't list gets a row of its own).
2028
- const unlisted = order.filter((t) => !(MODELS[t.provider]?.list ?? []).includes(t.model)).map(keyOf).sort()
2029
- 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])
2030
- if (shape !== catalogShape) (buildCatalog(s), applyFolds())
2031
- catalogShape = shape
2032
- markCatalog()
2033
- $('m-search').placeholder = `Search ${Object.values(MODELS).reduce((n, m) => n + (m.list?.length ?? 0), 0) || 'all'} models…`
2034
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()
2035
2234
  }
2036
2235
  // Your models: pick one up (anywhere on it with a mouse, by its ⋮⋮ on a touch screen) and the
2037
2236
  // others move aside as it goes; let go and it's saved, already in its place (no jump when the
@@ -2114,7 +2313,6 @@ function sortable(v, onMove) {
2114
2313
  }
2115
2314
 
2116
2315
  // --- the models on the left: rows that read your list when clicked or hovered (S.order, now) ---
2117
- let catalogShape = null
2118
2316
  // where a model is in your list (undefined: not in it); looked up, not searched (thousands of rows ask)
2119
2317
  let places = { of: null, at: null }
2120
2318
  const placeOf = (provider, id) => {
@@ -2124,16 +2322,12 @@ const placeOf = (provider, id) => {
2124
2322
  // A model's row on the left: scrolled to and lit up for a moment (one just added by name).
2125
2323
  function showRow(provider, id, said) {
2126
2324
  toast(said)
2127
- const list = $('p-list')
2128
- const box = [...list.querySelectorAll(`section[data-provider="${CSS.escape(provider)}"] .rows`)].find((b) => b._ids)
2129
- const i = box?._ids.indexOf(id) ?? -1
2130
- if (i < 0) return
2131
- const at = box.getBoundingClientRect().top - list.getBoundingClientRect().top + list.scrollTop + i * CAT_ROW
2132
- if (at < list.scrollTop + 120 || at + CAT_ROW > list.scrollTop + list.clientHeight) list.scrollTop = at - list.clientHeight / 2
2133
- box._v.draw()
2134
- const el = box._v.shown.get(i)
2135
- const row = el?.matches('.mrow') ? el : el?.querySelector('.mrow')
2136
- 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')
2137
2331
  row.classList.remove('flash')
2138
2332
  void row.offsetWidth // restart the animation
2139
2333
  row.classList.add('flash')
@@ -2151,7 +2345,7 @@ const addModel = (provider, id) => {
2151
2345
  // a provider switched off: its models stay in your list, but HeartCode skips them; the one in use is
2152
2346
  // the first of a provider that's on
2153
2347
  const isOff = (name) => Boolean(S?.providers.find((p) => p.name === name)?.off)
2154
- const inUse = () => S.order.find((t) => !isOff(t.provider))
2348
+ const inUse = () => S.order.find((t) => !isOff(t.provider) && !t.record?.poor) ?? S.order.find((t) => !isOff(t.provider)) // #1 failing (its track record): the first that isn't (client.js)
2155
2349
  // Your models as shown: none of a provider that's switched off (they come back when it's on again)
2156
2350
  const shownOrder = () => S.order.filter((t) => !isOff(t.provider))
2157
2351
  // An order saved from what's shown: the models of a provider that's off keep their places in yours
@@ -2245,8 +2439,8 @@ $('hellos-close').onclick = () => $('hellos').close()
2245
2439
  $('hellos').addEventListener('close', () => (hellos = null))
2246
2440
  // the ticks: the ones that answered, only
2247
2441
  $('hellos-ok').onclick = () => {
2248
- PICKED_CAT.clear()
2249
- 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))
2250
2444
  $('hellos').close()
2251
2445
  drawPicks()
2252
2446
  }
@@ -2259,127 +2453,173 @@ async function clearAdded(p) {
2259
2453
  if (inList.length && !(await saveOrder(S.order.filter((t) => !inList.includes(t))))) return
2260
2454
  act('/api/provider/added', { name: p.name, all: true }, `${p.name}: the models added by name are forgotten`)
2261
2455
  }
2262
- const CAT_ROW = 40 // a model's row: its name, and what it can do beside it
2263
- // The models ticked (provider → Set of ids): kept while you search, so ones ticked for one search
2264
- // and the next are added (or taken off) together. SHOWN: each provider's models shown now (the
2265
- // search's matches).
2266
- const PICKED_CAT = new Map()
2267
- const SHOWN = new Map()
2268
- const pickedOf = (name) => PICKED_CAT.get(name) ?? PICKED_CAT.set(name, new Set()).get(name)
2269
- // The ticked models (every provider's) and what to do with them, on the bar over the list: all the
2270
- // shown ones ticked (or none), added to your list, taken off it. The tick boxes drawn now (rows and
2271
- // each provider's) follow.
2272
- 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()) {
2273
2523
  if (!S) return
2274
- const all = [...PICKED_CAT].flatMap(([provider, ids]) => [...ids].map((model) => ({ provider, model })))
2275
- const shown = [...SHOWN].flatMap(([provider, ids]) => ids.map((model) => ({ provider, model })))
2276
- const isPicked = (t) => Boolean(PICKED_CAT.get(t.provider)?.has(t.model))
2277
- const toAdd = all.filter((t) => placeOf(t.provider, t.model) === undefined)
2278
- const toTake = all.filter((t) => placeOf(t.provider, t.model) !== undefined)
2279
- for (const box of $('p-list').querySelectorAll('input.pick')) box.checked = Boolean(PICKED_CAT.get(box.closest('section').dataset.provider)?.has(box.dataset.model))
2280
- for (const box of $('p-list').querySelectorAll('input.pick-all')) {
2281
- const ids = SHOWN.get(box.dataset.provider) ?? []
2282
- const n = ids.filter((id) => PICKED_CAT.get(box.dataset.provider)?.has(id)).length
2283
- box.checked = n > 0 && n === ids.length
2284
- 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)
2285
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
2286
2537
  const top = $('pick-shown')
2287
- const n = shown.filter(isPicked).length
2288
2538
  top.checked = n > 0 && n === shown.length
2289
2539
  top.indeterminate = n > 0 && n < shown.length
2290
2540
  top.disabled = !shown.length
2291
- 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'}`
2292
2549
  const take = () => {
2293
- const off = new Set(toTake.map(keyOf))
2294
- 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)))
2295
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
2296
- PICKED_CAT.clear()
2553
+ TICKED.clear()
2297
2554
  saveOrder(rest, `${toTake.length} removed`)
2298
2555
  }
2299
2556
  const was = $('picks').hidden
2300
2557
  $('picks').hidden = !all.length
2301
2558
  put($('picks'),
2302
- h('span', { className: 'n', textContent: `${all.length} selected` }),
2303
- 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()) }),
2304
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,
2305
2564
  toTake.length ? h('button', { className: 'small danger', textContent: `Remove ${toTake.length} from the list`, onclick: take }) : null,
2306
- 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()
2307
2567
  if (was !== $('picks').hidden) fillHeight() // the list gives it room
2308
2568
  }
2309
- function buildCatalog(s) {
2310
- const q = modelQuery.trim()
2311
- SHOWN.clear()
2312
- put($('p-list'), s.providers.map((p) => {
2313
- if (!p.list) MODELS[p.name] = { list: [], details: {}, off: true } // its list switched off: never asked for
2314
- else loadModels(p.name, MODELS[p.name]?.off)
2315
- const m = MODELS[p.name] ?? { loading: true }
2316
- // and the models added by name (and any of yours it doesn't list), marked as yours
2317
- const listed = new Set(m.list ?? [])
2318
- const yours = [...new Set([...p.added, ...s.order.filter((t) => t.provider === p.name).map((t) => t.model)])].filter((id) => !listed.has(id))
2319
- 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])))
2320
- const row = (id, own) =>
2321
- 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)) },
2322
- h('span', { className: 'id', title: id }, id, canCell(m.details?.[id], S.order[placeOf(p.name, id)])),
2323
- isFree(m.details?.[id]) ? h('span', { className: 'tag ok', textContent: 'free', title: `${p.name}'s model list says $0` }) : null,
2324
- own ? h('span', { className: 'tag', textContent: 'not in its list' }) : p.added.includes(id) ? h('span', { className: 'tag', textContent: 'added by name' }) : null,
2325
- rowTail(p.name, id))
2326
- // its tick box (to add or take off several at once), and one you added: ✕ forgets it (it leaves your list too)
2327
- 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()) })
2328
- const item = (id) => h('div', { className: 'mwrap' }, tick(id), row(id),
2329
- 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) }),
2330
- !p.added.includes(id) ? null :
2331
- h('button', { className: 'forget', textContent: '✕', title: 'forget this model', 'aria-label': `forget ${id}`, onclick: async () => {
2332
- if (placeOf(p.name, id) !== undefined && !confirm(`Forget ${id}? It leaves the list too.`)) return
2333
- if (placeOf(p.name, id) !== undefined) await saveOrder(S.order.filter((t) => t.provider !== p.name || t.model !== id), `${id} removed`)
2334
- act('/api/provider/added', { name: p.name, model: id, remove: true }, `forgot ${id}`)
2335
- } }))
2336
- // a model by its name, into your list; one it has already: said, and shown
2337
- const addByName = (e) => {
2338
- e.preventDefault()
2339
- const box = e.target.elements.name
2340
- const id = box.value.trim()
2341
- if (!id) return
2342
- const at = placeOf(p.name, id)
2343
- if (at !== undefined) return showRow(p.name, id, `${id} is already in the list (#${at + 1})`)
2344
- if (listed.has(id) || yours.includes(id)) return showRow(p.name, id, `${p.name} already has ${id}: click it to add it`)
2345
- box.value = ''
2346
- addModel(p.name, id)
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}`)
2347
2604
  }
2348
- if (q && !ids.length) return null // searching: only the providers with a match
2349
- if (freeOnly && !ids.length) return null // free only: the providers with a free one
2350
- return h('section', { 'data-provider': p.name, className: p.off ? 'off' : '' },
2351
- // the header folds it (a click on it, or its arrow; not on its buttons and switch)
2352
- h('div', { className: 'prov-h', onclick: (e) => !e.target.closest('button:not(.fold), input, label, a') && fold(p.name) },
2353
- h('button', { className: 'fold', type: 'button', textContent: '▾', 'aria-label': `fold ${p.name}`, 'aria-expanded': 'true' }),
2354
- 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,
2355
- 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)` },
2356
- 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`) }),
2357
- h('i')),
2358
- h('div', { className: 'who' },
2359
- h('span', { className: 'name', textContent: p.name }),
2360
- p.off ? h('span', { className: 'tag', textContent: 'off' }) : null,
2361
- 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'}` }),
2362
- h('span', { className: 'tag inlist' }),
2363
- h('span', { className: 'meta mono', textContent: p.baseUrl, title: `${p.baseUrl} · key ${p.key || 'none'}` })),
2364
- h('form', { className: 'by-name', onsubmit: addByName },
2365
- h('input', { type: 'text', name: 'name', placeholder: 'model name', 'aria-label': `add a model to ${p.name} by its name`, title: `a model's exact name: added to the list, also one ${p.name} doesn't list` }),
2366
- h('button', { className: 'small', textContent: 'Add' })),
2367
- h('button', { className: 'small', textContent: 'Edit', title: 'its address and key, its model list, delete it', onclick: () => openForm(p) })),
2368
- // what's listed first; loading and errors under it (the models already shown stay where they are)
2369
- (() => {
2370
- if (!ids.length) return null
2371
- SHOWN.set(p.name, ids)
2372
- const box = h('div', { className: 'rows' })
2373
- box._ids = ids
2374
- box._v = virtual(box, { count: ids.length, height: CAT_ROW, row: (i) => item(ids[i]), scroller: $('p-list') })
2375
- return box
2376
- })(),
2377
- 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,
2378
- 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,
2379
- m.loading ? h('div', { className: 'cat-note', textContent: 'Loading its models…' }) : null)
2380
- }))
2381
- 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.)" }))
2382
- }
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
+ })()
2383
2623
  // --- Your models page: the list as a table; sorted by several columns at once (each a tie-break
2384
2624
  // for the ones before it), the sort kept in this browser ---
2385
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) })
@@ -2434,7 +2674,6 @@ $('pr-save').onclick = () => {
2434
2674
  RANK = [...list, ...RANK.filter((n) => !list.includes(n))] // providers not in your list now keep their place for later
2435
2675
  savePref('rank', RANK)
2436
2676
  $('pr').close()
2437
- if (S.helperOrder === 'provider') api('/api/helper-order', { by: 'provider', rank: RANK }).catch((e) => toast(e.message, true)) // helpers by the new ranking
2438
2677
  setSort(SORT.some((x) => x.key === 'provider') ? SORT : [{ key: 'provider', dir: 'down' }, ...SORT]) // sorted by it now
2439
2678
  }
2440
2679
  const firstDir = (key) => COLS[key].first // up: A to Z, low to high
@@ -2563,6 +2802,8 @@ function drawMine(s) {
2563
2802
  const shown = filtering() ? order.filter((t) => passes(t)) : order
2564
2803
  const view = sorted(shown)
2565
2804
  const filtered = shown.length !== order.length
2805
+ // sorted, and the order shown isn't the list's (test times changed since it was saved…): said on Save list
2806
+ const drift = SORT.length > 0 && !filtered && view.some((t, i) => t !== order[i])
2566
2807
  for (const k of PICKED) if (placeOf(...k.split(/\/(.*)/s)) === undefined) PICKED.delete(k) // gone from the list
2567
2808
  const n = (x) => x.toLocaleString()
2568
2809
 
@@ -2606,25 +2847,18 @@ function drawMine(s) {
2606
2847
  $('mt-lead').textContent = 'The models HeartCode uses: #1 answers; when a model fails, another takes over (the best-ranked one not tried yet). Hover a setting to see what it does.'
2607
2848
  const busy = locked()
2608
2849
  $('mt-actions').inert = false // Save list works at any time; the rest wait while something runs (below)
2609
- // the order helpers are picked in when #1 starts them: your list's, or your provider ranking's
2610
- const helperOrder = (by) => api('/api/helper-order', { by, rank: RANK }).then((r) => ((S.helperOrder = r.helperOrder), drawMine(S)), (e) => toast(e.message, true))
2611
2850
  // who chooses the helpers: HeartCode (from the tests and the rankings, again when those change) or you
2612
- const chooser = h('label', { className: 'h-order', title: 'Helpers\nWho picks the helpers: the models #1 can hand side jobs to (looking at a screenshot, a review, a part of the plan).\n\nAutomatic: HeartCode picks them, and what each is for, from the tests and the rankings, and picks again when those change.\nManual: you switch them on, and pick their jobs, in the Helper column.' },
2851
+ const chooser = h('label', { className: 'h-order', title: 'Helpers\nWho picks the helpers: the models #1 can hand side jobs to (looking at a screenshot, a review, a part of the plan).\n\nAutomatic: HeartCode picks them, and what each is good at, from the tests and the rankings (again when those change). A job goes to the fastest helper that\'s good at it; if that one can\'t do it, the best-ranked of the others takes over.\nMy picks: you switch them on, and pick their jobs, in the Helper column. A job goes to the best-ranked one good at it; if it can\'t, the next.' },
2613
2852
  h('span', { className: 'mt-setl' }, ic('sparkles'), h('span', { className: 'lt', textContent: 'Helpers' })),
2614
2853
  h('select', { id: 'h-auto', onchange: (e) => setAuto(e.target.value === 'auto', e.target) },
2615
- [['auto', 'Automatic'], ['manual', 'Manual']].map(([v, t]) => h('option', { value: v, textContent: t, selected: (S.helpersAuto ? 'auto' : 'manual') === v }))))
2616
- const orderBy = h('span', { className: 'h-order', title: 'Used\nWhich helper #1 takes first when several fit a job.\n\nBy score: the best-ranked in public rankings (the default).\nIn list order: the first in your list.\nBy provider: by your provider ranking (Order providers).' }, h('span', { className: 'mt-setl' }, ic('bars'), h('span', { className: 'lt', textContent: 'Used' })),
2617
- h('div', { className: 'seg', role: 'radiogroup', 'aria-label': 'The order helpers are used in' },
2618
- [['own', 'in list order', 'when #1 starts a helper, it takes the first one that fits the job, in the list\'s order'], ['provider', 'by provider', 'when #1 starts a helper, it takes them by the provider ranking (Order providers), each provider\'s in the list\'s order. The list itself stays as it is'], ['score', 'by score', 'when #1 starts a helper, it takes the best ranked first: its best place in LMArena\'s public rankings for coding, web apps, long real tasks and hard prompts (Update model info). Models not ranked come after, in the list\'s order']].map(([v, t, about]) =>
2619
- h('label', { className: (S.helperOrder ?? 'score') === v ? 'on' : '', title: about },
2620
- h('input', { type: 'radio', name: 'helper-order', checked: (S.helperOrder ?? 'score') === v, disabled: v === 'provider' && !order.some((t) => t.provider !== order[0]?.provider), onchange: () => helperOrder(v) }), t))))
2854
+ [['auto', 'Automatic'], ['manual', 'My picks']].map(([v, t]) => h('option', { value: v, textContent: t, selected: (S.helpersAuto ? 'auto' : 'manual') === v }))))
2621
2855
  put($('mt-actions'),
2622
2856
  ((why) => h('span', { title: why ?? '' }, h('button', { className: 'small', textContent: 'Order providers', disabled: Boolean(why), title: why ? '' : 'drag the providers into order; the Provider column sorts by it', onclick: openRanking })))( // disabled: why, on a span (a disabled button shows no tooltip in every browser)
2623
2857
  !order.some((t) => t.provider !== order[0]?.provider) ? 'All the models are from one provider: nothing to order' : null),
2624
2858
  h('button', { className: 'small', textContent: 'Update model info', disabled: !order.length, title: `what each model can do (context, tools, thinking, images, price) from models.dev, and its places in LMArena's public rankings (coding, web apps, vision${S.rankings ? `; rankings from ${new Date(S.rankings.fetched).toLocaleDateString()}` : ''})`, onclick: () => lookUp() }),
2625
2859
  h('button', { className: 'small', textContent: filtered ? `Test ${n(shown.length)}` : 'Test all', disabled: testingAll || !shown.length, title: `send ${filtered ? 'the models shown' : 'each model'} a short message to see which really answer, and how fast`, onclick: () => tryAll(filtered ? shown : order) }),
2626
2860
  // always there: the list as it's shown (sorted, filtered), saved whenever
2627
- h('button', { className: 'small primary', textContent: filtered ? `Use only these ${n(view.length)}` : 'Save list', disabled: !view.length, title: filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : 'save the list as shown: HeartCode uses them in this order (#1 first)', onclick: saveList }))
2861
+ h('button', { className: 'small primary' + (drift ? ' attn' : ''), textContent: filtered ? `Use only these ${n(view.length)}` : drift ? 'Save this order' : 'Save list', disabled: !view.length, title: (drift ? `The order shown isn't the one HeartCode uses: its #1 is ${order[0].model}, here at row ${view.indexOf(order[0]) + 1} (sorted ${dirText(SORT[0].key, SORT[0].dir)}). ` : '') + (filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : 'save the list as shown: HeartCode uses them in this order (#1 first)'), onclick: saveList }))
2628
2862
  for (const b of $('mt-actions').children) if (!b.classList.contains('primary')) b.inert = busy // all but Save list wait while something runs
2629
2863
 
2630
2864
  // --- row 2, the list's settings: when a model fails (left), the helpers (right); an icon and a short label each ---
@@ -2632,8 +2866,8 @@ function drawMine(s) {
2632
2866
  // about: its tooltip, in plain words (the label is its first line)
2633
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))
2634
2868
  // a whole number setting (seconds), with its limits from the server (SPEED_LIMITS)
2635
- const LIMITS = { replyStart: [5, 600], replyIdle: [10, 1800] }
2636
- // 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
2637
2871
  // for longer, and the boxes that moved flash
2638
2872
  const saveTime = async (name, v, said) => {
2639
2873
  const r = await act('/api/setting', { name, value: v })
@@ -2649,25 +2883,26 @@ function drawMine(s) {
2649
2883
  saveTime(name, v, said(v))
2650
2884
  } })
2651
2885
  const secsCell = (icon, label, name, about, unit, said) => cell(icon, label, about, num(name, label, said), h('span', { className: 'unit', textContent: unit }))
2652
- 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 },
2653
2888
  h('div', { className: 'mt-mode-sets' },
2654
- 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.',
2655
2890
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
2656
2891
  [['failure', 'switch model'], ['retries', 'retry it first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
2657
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),
2658
- 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`),
2659
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`),
2660
- 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.",
2661
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) => {
2662
2897
  const v = Math.round(Number(e.target.value))
2663
2898
  if (!(v >= 1 && v <= 600)) return (e.target.value = S.settings.testTimeout), toast('a whole number of seconds, 1 to 600', true)
2664
2899
  saveTime('testTimeout', v, `tests wait ${v} second${v === 1 ? '' : 's'} for an answer`)
2665
2900
  } }), h('span', { className: 'unit', textContent: 's' })),
2666
- 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).',
2667
2902
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
2668
2903
  [['first', '#1'], ['stay', 'last working']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.next === v })))),
2669
- h('span', { className: 'mt-div', 'aria-hidden': 'true' }),
2670
- chooser, orderBy))
2904
+ !single && h('span', { className: 'mt-div', 'aria-hidden': 'true' }),
2905
+ !single && chooser))
2671
2906
 
2672
2907
  // --- beside the filters: what's shown · what you do with it (the sorts show in the column heads) ---
2673
2908
  const line = h('div', { className: 'mt-line' },
@@ -2707,7 +2942,7 @@ function drawMine(s) {
2707
2942
  lastPicked = i
2708
2943
  drawMine(S)
2709
2944
  }
2710
- const tableV = table && virtual(table, { count: view.length, height: TABLE_ROW, row: (i) => tableRow(view[i], order.indexOf(view[i]), (e) => pick(i, e)), scroller: window })
2945
+ const tableV = table && virtual(table, { count: view.length, height: TABLE_ROW, row: (i) => tableRow(view[i], order.indexOf(view[i]), (e) => pick(i, e), i), scroller: window })
2711
2946
  if (tableV) tableV.items = view.length
2712
2947
  // typing in a filter: the box is put back in the redrawn page, still with the focus and the caret
2713
2948
  const typing = filterBar?.contains(document.activeElement) ? document.activeElement : null
@@ -2723,7 +2958,7 @@ function drawMine(s) {
2723
2958
  else (results.fails++, (results[o] = (results[o] ?? 0) + 1))
2724
2959
  }
2725
2960
  put($('mt'),
2726
- 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)
2727
2962
  order.length
2728
2963
  ? h('div', { className: 'mt-tools' },
2729
2964
  h('div', { className: 'mt-row', inert: busy }, filterBarOf(order, results), line),
@@ -2785,8 +3020,6 @@ const priceOf = (t) => (t.price?.input == null && t.price?.output == null ? '–
2785
3020
  // A click saves at once, in the background: only that row's cell is redrawn, and the button clicked
2786
3021
  // shows it's saving. MINE: your latest picks while saves are on their way (each save sends them all,
2787
3022
  // one after another, so quick clicks don't undo each other).
2788
- // HSUG: suggestions not taken yet ({ key: [jobs] }), shown dashed until you take or dismiss them.
2789
- let HSUG = null
2790
3023
  let MINE = null
2791
3024
  let saving = Promise.resolve()
2792
3025
  let unsaved = 0
@@ -2820,66 +3053,56 @@ function saveHelpers(next, marks = [], done) {
2820
3053
  function setHelper(k, jobs, mark) {
2821
3054
  const next = { ...helpers() }
2822
3055
  jobs ? (next[k] = jobs) : delete next[k]
2823
- if (HSUG?.[k] && jobs) {
2824
- const left = HSUG[k].filter((j) => !jobs.includes(j))
2825
- left.length ? (HSUG[k] = left) : delete HSUG[k]
2826
- if (!Object.keys(HSUG).length) HSUG = null
2827
- }
2828
3056
  saveHelpers(next, [`${k}|${mark}`])
2829
3057
  }
2830
3058
  function helperCell(t, at) {
2831
3059
  const k = keyOf(t)
2832
3060
  const jobs = helpers()[k]
2833
- const sug = HSUG?.[k] ?? []
2834
3061
  const busy = locked()
2835
3062
  return h('span', { className: 'hp' + (jobs ? '' : ' off') },
2836
3063
  h('span', { className: SAVING.has(`${k}|on`) ? 'saving' : '', title: jobs ? 'a helper: #1 can start it for side jobs (click: not a helper)' : Object.keys(helpers()).length ? 'not a helper (click: #1 can start it for side jobs)' : 'no helpers ticked: #1 can start any model in the list (click: only ticked ones)' },
2837
3064
  sw({ checked: Boolean(jobs), disabled: busy, 'aria-label': `${t.model} is a helper`, onchange: (e) => setHelper(k, e.target.checked ? (jobs ?? []) : null, 'on') })),
2838
3065
  Object.entries(S.jobs ?? {}).map(([j, [label, , covers]]) => {
2839
3066
  const has = Boolean(jobs?.includes(j))
2840
- const sugd = !has && sug.includes(j)
2841
- const pill = h('button', { type: 'button', className: 'jp' + (has ? ' on' : sugd ? ' sug' : '') + (SAVING.has(`${k}|${j}`) ? ' saving' : ''), disabled: busy, 'aria-pressed': String(has), 'aria-label': `${label}: ${covers}`, onclick: () => setHelper(k, has ? jobs.filter((x) => x !== j) : [...(jobs ?? []), j], j) }, ic(JOB_ICON[j]))
3067
+ const pill = h('button', { type: 'button', className: 'jp' + (has ? ' on' : '') + (SAVING.has(`${k}|${j}`) ? ' saving' : ''), disabled: busy, 'aria-pressed': String(has), 'aria-label': `${label}: ${covers}`, onclick: () => setHelper(k, has ? jobs.filter((x) => x !== j) : [...(jobs ?? []), j], j) }, ic(JOB_ICON[j]))
2842
3068
  // what the pill means, and what a click does here
2843
3069
  return withTip(pill, () => [
2844
3070
  at === 0 ? h('div', { className: 'tcover', textContent: '#1 answers; as a helper it\'s started when another model is answering.' }) : null,
2845
- h('div', { className: 'tjob', textContent: `${label}${has ? ' · picked' : sugd ? ' · suggested' : ''}` }),
3071
+ h('div', { className: 'tjob', textContent: `${label}${has ? ' · picked' : ''}` }),
2846
3072
  h('div', { className: 'tcover', textContent: covers }),
2847
- sugd ? h('div', { className: 'tcover', textContent: `Suggested from ${SUGGEST_WHY[j]}.` }) : null,
2848
3073
  S.helpersAuto && has ? h('div', { className: 'tcover', textContent: 'Chosen automatically, from the rankings and the tests.' }) : null,
2849
- h('div', { className: 'thint', textContent: (has ? `Click: ${t.model} isn't picked for this any more` : `Click: #1 gives these jobs to ${t.model}${jobs ? '' : ' (it becomes a helper)'}`) + (S.helpersAuto ? ' · from then on: Manual' : '') }),
3074
+ h('div', { className: 'thint', textContent: (has ? `Click: ${t.model} isn't picked for this any more` : `Click: #1 gives these jobs to ${t.model}${jobs ? '' : ' (it becomes a helper)'}`) + (S.helpersAuto ? ' · from then on: My picks' : '') }),
2850
3075
  ])
2851
3076
  }))
2852
3077
  }
2853
3078
  // each job's icon (its name and what it covers: the tooltip)
2854
3079
  const JOB_ICON = { ui: 'monitor', code: 'code', hard: 'mountain', quick: 'zap' }
2855
- // what each pill's suggestions go by (said in its tooltip)
2856
- const SUGGEST_WHY = { ui: 'its place in the top half of the web-app ranking (LMArena)', code: 'its place in the top half of the coding ranking (LMArena)', hard: 'it thinks with a context of 128k or more, or its place in the top half of the ranking for long real tasks or the hardest prompts (LMArena)', quick: 'its test: as fast as the middle one or faster (or nothing else fits it)' }
2857
3080
  // Helpers are picked from the models that answered their test: how many did
2858
3081
  const working = () => S.order.filter((t) => TRIES[keyOf(t)]?.ok && !TRIES[keyOf(t)].going).length
2859
3082
  // No test yet: ask before testing them all (each gets a short message, which a paid model charges for);
2860
- // then: what to do once the run is over ('suggest', or nothing: picked for you does it itself)
3083
+ // then the helpers are picked for you (Automatic) from the ones that worked
2861
3084
  let afterTests = null
2862
- function testFirst(then) {
3085
+ function testFirst() {
2863
3086
  const n = (x) => x.toLocaleString()
2864
- const paid = S.order.filter((t) => t.price && (t.price.input > 0 || t.price.output > 0)).length
2865
- const unknown = S.order.filter((t) => !t.price).length
2866
- $('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 ${then === 'suggest' ? 'suggested' : '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.`
2867
3091
  $('h-test-go').onclick = () => {
2868
3092
  $('h-test').close()
2869
- afterTests = then
2870
- tryAll(S.order)
3093
+ afterTests = 'auto'
3094
+ tryAll(order)
2871
3095
  }
2872
3096
  $('h-test-no').onclick = () => $('h-test').close()
2873
3097
  $('h-test').showModal()
2874
3098
  }
2875
3099
  // Picked for you (HeartCode makes them from what's known, again whenever that changes) or by you
2876
3100
  async function setAuto(on, select) {
2877
- if (on && !working()) return (select.value = 'manual'), testFirst('auto') // nothing to pick from yet
3101
+ if (on && !working()) return (select.value = 'manual'), testFirst() // nothing to pick from yet
2878
3102
  select.disabled = true
2879
3103
  try {
2880
3104
  const r = await api('/api/helpers/auto', { on })
2881
3105
  Object.assign(S, { helpers: r.helpers, helpersAuto: r.helpersAuto })
2882
- HSUG = null
2883
3106
  drawMine(S)
2884
3107
  } catch (e) {
2885
3108
  toast(e.message, true)
@@ -2889,37 +3112,14 @@ async function setAuto(on, select) {
2889
3112
  }
2890
3113
  }
2891
3114
 
2892
- // Suggest helpers: the server's picks, beside yours (nothing saved until you take them)
2893
- async function suggestNow(b) {
2894
- if (b) b.disabled = true
2895
- const r = await api('/api/helpers/suggest', {}).catch((x) => (toast(x.message, true), null))
2896
- if (b) b.disabled = false
2897
- if (!r) return
2898
- HSUG = Object.keys(r.suggest).length ? r.suggest : null
2899
- if (!HSUG) return toast(working() ? 'Nothing more to suggest' : 'No model worked in the test: nothing to pick from', !working())
2900
- drawMine(S) // shown dashed in the Helper column, in the list as it is: nothing filtered
2901
- }
2902
- // The toolbar's helpers part: suggestions waiting (take all · dismiss), or Suggest helpers and Clear
2903
- // helpers. Each saves at once, its own button saying so.
3115
+ // The toolbar's helpers part: Clear helpers, saved at once, its button saying so.
2904
3116
  function drawHelperBar() {
2905
3117
  helperBar ??= h('span', { className: 'hbar' })
2906
3118
  const order = S.order
2907
3119
  const n = Object.keys(helpers()).length
2908
3120
  const busy = (b) => Object.assign(b, { disabled: true, textContent: 'Saving…' }) // its icon and label give way
2909
3121
  put(helperBar,
2910
- HSUG ? h('span', { className: 'hsug', title: 'shown dashed in the Helper column: click one to take just that' }, ic('sparkles'),
2911
- h('span', { textContent: `${Object.keys(HSUG).length} suggested` }),
2912
- h('button', { className: 'small primary', textContent: 'Take all', onclick: (e) => {
2913
- busy(e.currentTarget)
2914
- const next = { ...helpers() }
2915
- const took = Object.keys(HSUG)
2916
- for (const [k, jobs] of Object.entries(HSUG)) next[k] = [...new Set([...(next[k] ?? []), ...jobs])]
2917
- HSUG = null
2918
- saveHelpers(next, [], `${took.length} model${took.length === 1 ? ' is a helper' : 's are helpers'} now`).then(() => drawMine(S))
2919
- } }),
2920
- h('button', { className: 'small ghost', textContent: 'Dismiss', onclick: () => ((HSUG = null), drawMine(S)) })) : null,
2921
- !HSUG && !S.helpersAuto ? h('button', { className: 'small', title: working() ? `suggest helpers from the ${working()} models that answered their test (their provider switched on), each with what it's good at that it doesn't have yet (from the rankings, its test, thinking and context): marked dashed in the Helper column, to take or not; the list isn't filtered` : 'suggest helpers: the models are tested first (helpers are picked from the ones that answer)', onclick: (e) => (working() ? suggestNow(e.currentTarget) : testFirst('suggest')), 'aria-label': 'Suggest helpers' }, ic('sparkles'), h('span', { className: 'lt', textContent: 'Suggest helpers' })) : null,
2922
- !HSUG && n ? h('button', { className: 'small ghost', 'aria-label': 'Clear helpers', title: `Clear helpers: no model a helper (${n} now): #1 can then start any model again, as before`, onclick: (e) => {
3122
+ n ? h('button', { className: 'small ghost', 'aria-label': 'Clear helpers', title: `Clear helpers: no model a helper (${n} now): #1 can then start any model again, as before`, onclick: (e) => {
2923
3123
  if (!confirm(`Clear the ${n} helper${n === 1 ? '' : 's'}? #1 can then start any model again, as before.`)) return
2924
3124
  busy(e.currentTarget)
2925
3125
  saveHelpers({}, [], 'no helpers: #1 can start any model again').then(() => drawMine(S))
@@ -2927,7 +3127,8 @@ function drawHelperBar() {
2927
3127
  return helperBar
2928
3128
  }
2929
3129
 
2930
- function tableRow(t, at, pick) {
3130
+ // at: its place in the list; row: its row as shown (sorted or filtered: 1, 2, 3… down the page)
3131
+ function tableRow(t, at, pick, row = at) {
2931
3132
  const c = can(t)
2932
3133
  const ctx = COLS.context.get(t)
2933
3134
  const picked = PICKED.has(keyOf(t))
@@ -2941,9 +3142,10 @@ function tableRow(t, at, pick) {
2941
3142
  return h('li', { className: 'in' + (picked ? ' picked' : '') + (isOff(t.provider) ? ' off' : ''), 'data-key': `${t.provider}/${t.model}`, title: isOff(t.provider) ? `${t.provider} is switched off: HeartCode skips this model until it's on` : '' },
2942
3143
  h('span', { className: 'grip', textContent: '⋮⋮', 'aria-hidden': 'true' }),
2943
3144
  h('input', { type: 'checkbox', checked: picked, disabled: busy, 'aria-label': `select ${t.model}`, title: 'select (Shift: and every row up to the last one selected)', onclick: (e) => (e.preventDefault(), pick(e)) }),
2944
- h('span', { className: 'n', textContent: `#${at + 1}`, title: SORT.length || filtering() ? 'its place in the list' : '' }),
2945
- h('span', { className: 'm' }, h('span', { className: 'name', textContent: t.model, title: t.model }), tag),
2946
- h('span', { className: 'p', textContent: isOff(t.provider) ? `${t.provider} · off` : t.provider, title: t.provider }),
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)` : '' }),
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,
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),
3148
+ h('span', { className: 'p', title: t.provider }, provIcon(t.provider), isOff(t.provider) ? `${t.provider} · off` : t.provider),
2947
3149
  helperCell(t, at),
2948
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)' : ''}` : '' }),
2949
3151
  yes(c.tools), yes(c.thinking), yes(c.images),
@@ -2957,32 +3159,17 @@ function tableRow(t, at, pick) {
2957
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'))))
2958
3160
  }
2959
3161
 
2960
- // your list changed: the rows and counts it touches, in place
2961
- function markCatalog() {
2962
- for (const r of $('p-list').querySelectorAll('.mrow')) {
2963
- const at = placeOf(r.dataset.provider, r.dataset.model)
2964
- r.classList.toggle('taken', at !== undefined)
2965
- r.lastElementChild.replaceWith(rowTail(r.dataset.provider, r.dataset.model))
2966
- }
2967
- for (const sec of $('p-list').querySelectorAll('section[data-provider]')) {
2968
- const n = S.order.filter((t) => t.provider === sec.dataset.provider).length
2969
- const tag = sec.querySelector('.inlist')
2970
- tag.hidden = !n
2971
- tag.textContent = `${n} in the list${inUse()?.provider === sec.dataset.provider ? ' · in use' : ''}`
2972
- }
2973
- drawPicks()
2974
- }
2975
-
2976
3162
  function drawUsing(s) {
2977
3163
  const o = s.order.filter((t) => !isOff(t.provider))
2978
3164
  $('using').hidden = page() === 'providers' // there it's on the page itself
2979
- put($('using'), o.length ? [h('span', { className: 'k', textContent: 'HeartCode uses' }), h('b', { textContent: o[0].model }), h('span', { className: 'k', textContent: `${o[0].provider}${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' })])
3165
+ const first = inUse() ?? o[0]
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' })])
2980
3167
  }
2981
3168
 
2982
3169
  // --- General ---
2983
3170
  const PERM_INFO = { all: ['Everything', 'Edits files and runs commands without asking'], commands: ['Edits only', 'Edits files; asks before running commands'], ask: ['Ask first', 'Asks before every edit and command'] }
2984
3171
  const THEME_INFO = { dark: ["The terminal's background", ['#1f2328', '#d4d4d8', '#ff6b9d', '#7aa2f7']], light: ['White background', ['#fafbfc', '#24292f', '#d6336c', '#0969da']], midnight: ['Deep blue background', ['#1a1b26', '#c0caf5', '#ff7ab2', '#7aa2f7']], mono: ['No colors: bold and dim', ['#000000', '#bbbbbb', '#ffffff', '#777777']] }
2985
- const TOGGLE_INFO = { autoCompact: 'Compact long conversations', director: 'Let the model set things up', format: 'Format files after edits', lsp: 'Language server checks', updateCheck: 'Check for updates', mouse: 'HeartCode takes the mouse' }
3172
+ const TOGGLE_INFO = { autoCompact: 'Compact long conversations', director: 'Let the model set things up', format: 'Format files after edits', lsp: 'Language server checks', updateCheck: 'Check for updates', trackRecord: "Learn from each model's track record", mouse: 'HeartCode takes the mouse' }
2986
3173
  function choices(id, list, cur, name) {
2987
3174
  put($(id), list.map(([v, title, desc, colors]) => h('label', { className: 'choice' + (v === cur ? ' on' : '') },
2988
3175
  h('input', { type: 'radio', name: id, checked: v === cur, onchange: () => act('/api/setting', { name, value: v }, `${title}: saved`) }),
@@ -3008,8 +3195,14 @@ function drawGeneral(s) {
3008
3195
  }
3009
3196
  $('g-effort').onchange = (e) => act('/api/setting', { name: 'effort', value: e.target.value }, 'effort saved')
3010
3197
  $('g-context').onchange = (e) => act('/api/setting', { name: 'context', value: e.target.value.trim() ? Number(e.target.value) : null }, 'context window saved')
3011
- // Voice: this machine (whisper-cli and a ggml model) or a provider's transcription API, a model and a
3012
- // 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
+ }
3013
3206
  function voiceNow() {
3014
3207
  try {
3015
3208
  return S?.voice ? JSON.parse(S.voice) : {}
@@ -3019,25 +3212,24 @@ function voiceNow() {
3019
3212
  }
3020
3213
  function drawVoice(s) {
3021
3214
  const v = voiceNow()
3022
- const names = (s.providers ?? []).map((p) => p.name)
3023
- put($('v-src'), h('option', { value: '', textContent: 'This machine (whisper-cli)' }), names.map((n) => h('option', { value: n, textContent: `${n} (its transcription API)` })))
3024
- $('v-src').value = v.provider && names.includes(v.provider) ? v.provider : ''
3025
- const remote = Boolean($('v-src').value)
3026
- $('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.'
3027
- $('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.'
3028
- $('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.'
3029
- $('v-model').placeholder = remote ? 'whisper-large-v3' : 'auto'
3030
- $('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'
3031
3223
  for (const [id, k] of [['v-model', 'model'], ['v-lang', 'language']]) if (document.activeElement !== $(id)) $(id).value = v[k] ?? ''
3032
3224
  }
3033
3225
  function saveVoice(what) {
3034
- 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 }
3035
3227
  const set = Object.fromEntries(Object.entries(v).filter(([, x]) => x !== undefined))
3036
3228
  act('/api/voice', { text: Object.keys(set).length ? JSON.stringify(set) : '' }, what)
3037
3229
  }
3038
3230
  $('v-src').onchange = (e) => {
3039
3231
  $('v-model').value = '' // a local model's path means nothing to a provider, and the other way round
3040
- saveVoice(`voice: ${e.target.value || 'this machine'}`)
3232
+ saveVoice(`voice: ${VOICE[e.target.value][0]}`)
3041
3233
  }
3042
3234
  $('v-model').onchange = () => saveVoice('voice model saved')
3043
3235
  $('v-lang').onchange = () => saveVoice('voice language saved')
@@ -3138,6 +3330,21 @@ function drawNotify(s) {
3138
3330
  h('div', { className: 't' }, h('b', { textContent: label }), h('span', { textContent: TG_EVENT_INFO[k] ?? '' })),
3139
3331
  sw({ checked: t.events?.[k] !== false, disabled: !t.connected, 'aria-label': label, onchange: (e) => act('/api/telegram/set', { event: k, value: e.target.checked }, `${label}: ${e.target.checked ? 'on' : 'off'}`) }))))
3140
3332
  }
3333
+ // --- On this computer: a sound and/or a desktop notification, and which events (alert.js) ---
3334
+ function drawAlerts(s) {
3335
+ const a = s.alerts ?? { events: {} }
3336
+ const on = a.sound || a.popup
3337
+ const row = (k, title, about) => h('label', { className: 'opt' }, h('div', { className: 't' }, h('b', { textContent: title }), h('span', { textContent: about })),
3338
+ sw({ checked: a[k], 'aria-label': title, onchange: (e) => act('/api/alerts/set', { [k]: e.target.checked }, `${title}: ${e.target.checked ? 'on' : 'off'}`) }))
3339
+ put($('al-setup'),
3340
+ row('sound', 'Play a sound', 'A heartbeat: rising when done, falling when it failed, twice when it waits for you.'),
3341
+ row('popup', 'Show a desktop notification', 'The task and how it ended, in the corner of the screen.'),
3342
+ ...Object.entries({ done: 'A task finished', failed: 'A task failed', waiting: 'HeartCode is waiting for an answer' }).map(([k, label]) => h('div', { className: 'opt' + (on ? '' : ' tg-off') }, // a div: in a label, a click on the row would press Try it
3343
+ tile(...({ done: ['check', 'green'], failed: ['x', 'red'], waiting: ['clock', 'amber'] }[k])),
3344
+ h('div', { className: 't' }, h('b', { textContent: label })),
3345
+ h('button', { className: 'small ghost', type: 'button', textContent: 'Try it', title: a.popup ? 'Plays its sound and shows its notification' : 'Plays its sound', onclick: () => act('/api/alerts/test', { event: k }) }),
3346
+ sw({ checked: a.events?.[k] !== false, disabled: !on, 'aria-label': label, onchange: (e) => act('/api/alerts/set', { event: k, value: e.target.checked }, `${label}: ${e.target.checked ? 'on' : 'off'}`) }))))
3347
+ }
3141
3348
  const TG_EVENT_INFO = {
3142
3349
  done: 'The task, how long it took, and the answer.',
3143
3350
  failed: 'The task and the error.',
@@ -3183,15 +3390,16 @@ async function clearAll() {
3183
3390
  toast(`deleted: logs on disk now ${bytes(r.size.total)}`)
3184
3391
  }
3185
3392
  // The kinds of log: requests (their own viewer), then the text logs (choices.logKinds)
3186
- const logKindsOf = (s) => ({ requests: { label: 'Requests', about: 'each request to a model and its reply or error: which failed, which worked, which fallback answered' }, ...s.choices.logKinds })
3393
+ const logKindsOf = (s) => ({ requests: { label: 'Requests', about: 'each request to a model and its reply or error: which failed, which worked, which fallback answered', ...s.choices.logSamples?.requests }, ...s.choices.logKinds })
3187
3394
  function drawLogging(s) {
3188
3395
  drawDisk()
3189
3396
  const on = s.settings.logs
3190
- put($('l-kinds'), Object.entries(logKindsOf(s)).map(([k, { label, about }]) => h('label', { className: 'opt' },
3397
+ // hover: what its lines look like and how much room it takes (choices: LOG_SAMPLES in log.js)
3398
+ put($('l-kinds'), Object.entries(logKindsOf(s)).map(([k, { label, about, size, short, example }]) => h('label', { className: 'opt', title: `${label}\n${about[0].toUpperCase() + about.slice(1)}.${example ? `\n\nWhat it looks like:\n${example}` : ''}${size ? `\n\nSpace: ${size}.` : ''}` },
3191
3399
  h('div', { className: 't' }, h('b', { textContent: label }), h('span', { textContent: about[0].toUpperCase() + about.slice(1) }),
3192
- h('span', { className: 'file', textContent: k === 'requests' ? 'requests/<run>/ · a file per request' : `runs/<run>/${k}.log` }),
3400
+ h('span', { className: 'file', textContent: `${k === 'requests' ? 'requests/<run>/ · a file per request' : `runs/<run>/${k}.log`}${short ? ` · ${short}` : ''}` }),
3193
3401
  k === 'requests' ? h('select', { disabled: !on.requests, 'aria-label': 'how much of each request', onchange: (e) => act('/api/setting', { name: 'logDetail', value: e.target.value }, 'saved: from the next request') },
3194
- [['full', 'Everything: what was sent and what came back'], ['summary', 'Only a summary: model, result, error, timings, tokens']].map(([v, l]) => h('option', { value: v, textContent: l, selected: s.settings.logDetail === v }))) : null),
3402
+ [['full', 'Everything: what was sent and what came back (~20 kB+ a request)'], ['summary', 'Only a summary: model, result, error, timings, tokens (~1 kB a request)']].map(([v, l]) => h('option', { value: v, textContent: l, selected: s.settings.logDetail === v }))) : null),
3195
3403
  sw({ checked: on[k], 'aria-label': label, onchange: (e) => act('/api/log-kind', { kind: k, on: e.target.checked }, `${label}: ${e.target.checked ? 'logged from now on' : 'off'}`) }))))
3196
3404
  $('l-alloff').disabled = !Object.values(on).some(Boolean)
3197
3405
  $('l-where').textContent = s.logs.runs.replace(/[\\/]runs$/, '')
@@ -3661,8 +3869,7 @@ let sbLines = [] // [{ left:[id…], right:[id…] }]
3661
3869
  let sbDrag = null // the chip being dragged: { id, from: 'palette' | { line, side, idx } }
3662
3870
  let sbSaveTimer = null
3663
3871
  const SB_DEFAULT = () => [
3664
- { left: ['provider', 'model'], right: ['mode', 'thinking', 'images'] },
3665
- { left: ['ctx', 'tps', 'autocompact'], right: ['background', 'permissions', 'worktree', 'cost'] },
3872
+ { left: ['provider', 'model', 'ctx', 'tps'], right: ['mode', 'thinking', 'autocompact', 'background', 'worktree', 'permissions', 'cost'] },
3666
3873
  ]
3667
3874
  const sbLabel = (id) => (SB_ITEMS.find((i) => i.id === id) || {}).label || id
3668
3875
  const sbSample = (id) => (SB_ITEMS.find((i) => i.id === id) || {}).sample || id
@@ -3766,7 +3973,7 @@ function sbSave() {
3766
3973
  function render(s) {
3767
3974
  $('version').textContent = s.version ? `v${s.version}` : ''
3768
3975
  $('update-note').hidden = !s.update
3769
- 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
3770
3977
  if (s.prefs) {
3771
3978
  // the page's choices, as kept (also changed on another page: shown here too)
3772
3979
  const p = s.prefs
@@ -3774,6 +3981,10 @@ function render(s) {
3774
3981
  $('m-sort').value = catSort
3775
3982
  freeOnly = p.freeOnly === true
3776
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
3777
3988
  FOLDED.clear()
3778
3989
  for (const n of Array.isArray(p.folded) ? p.folded : []) FOLDED.add(n)
3779
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
@@ -3792,6 +4003,7 @@ function render(s) {
3792
4003
  drawGeneral(s)
3793
4004
  drawStatusBar(s)
3794
4005
  drawNotify(s)
4006
+ drawAlerts(s)
3795
4007
  drawLogging(s)
3796
4008
  if (REQS) drawReqs()
3797
4009
  drawPrompts(s)
@@ -3842,6 +4054,7 @@ if (token) {
3842
4054
  gotResult(key, result)
3843
4055
  })
3844
4056
  events.addEventListener('testrun', (e) => showRun(JSON.parse(e.data)))
4057
+ events.addEventListener('clis', () => $('cli-form').open && loadClis()) // an install finished
3845
4058
  events.addEventListener('helpers', (e) => ((S.helpers = JSON.parse(e.data).helpers), drawMine(S))) // picked for you again, after a test run
3846
4059
  // many at once (thousands of models added): taken in once a frame, the table drawn once
3847
4060
  const news = new Map()