heartcode 0.1.35 → 0.1.37
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/CHANGELOG.md +25 -0
- package/README.md +7 -2
- package/bin/heart.js +1 -1
- package/bin/heartcode.js +5 -5
- package/package.json +1 -1
- package/src/log.js +1 -1
- package/src/settings.html +475 -92
- package/src/settings.js +7 -3
- package/src/ui.js +27 -10
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
What changed in each version of HeartCode, newest first.
|
|
4
4
|
|
|
5
|
+
## 0.1.37 (2026-11-02)
|
|
6
|
+
|
|
7
|
+
- Settings page, Your models: filters (search, provider, test result with counts, context, tools,
|
|
8
|
+
thinking, images, free) that combine and are kept. Filtered, **Use these N** makes the models shown
|
|
9
|
+
the only ones HeartCode uses, in the order shown (asked first; the others stay under Providers);
|
|
10
|
+
Test N shown tests just them; dragging works while filtered. The page laid out in full-width rows:
|
|
11
|
+
the list's settings in three cells, filters on one line, what's shown and the list's actions on
|
|
12
|
+
one line, the column names (or the selection's actions) sticky above aligned rows.
|
|
13
|
+
- The whole settings page with icons and colors: each part's icon on its own color in the sidebar
|
|
14
|
+
and on its title, buttons with icons colored by what they do, card titles with icons, less room
|
|
15
|
+
around pages and cards, General's cards packed in two columns, rows' actions as icon buttons,
|
|
16
|
+
Providers one line a model.
|
|
17
|
+
- Saving the list builds the page's state once, not three times (the server skips its own writes);
|
|
18
|
+
a sort or filter changed on the page isn't undone by an older state.
|
|
19
|
+
- Contexts with two decimals (1.05M, not rounded up to 1.1M), on the page and in the status bar;
|
|
20
|
+
the exact count on hover. Checked against models.dev for every model: the data is right.
|
|
21
|
+
- Logs are kept 3 days by default instead of 30 (Advanced → Logs changes it).
|
|
22
|
+
|
|
23
|
+
## 0.1.36 (2026-11-02)
|
|
24
|
+
|
|
25
|
+
- Voice: Space in an empty box (or /voice) starts listening at once, no second key; what you say
|
|
26
|
+
shows in the box as you speak, and Enter sends it, all of it as one message. Keys wait while the
|
|
27
|
+
last part is transcribed (an Enter then sent only the part heard so far, and the rest stayed in
|
|
28
|
+
the box). Esc cancels; Space pauses and goes on. While a task works, it's sent as typed then.
|
|
29
|
+
|
|
5
30
|
## 0.1.35 (2026-11-02)
|
|
6
31
|
|
|
7
32
|
- Settings page, Your list: every column sorts by the value it shows, ↑ smallest first and ↓
|
package/README.md
CHANGED
|
@@ -126,11 +126,16 @@ On **Models → Your list**:
|
|
|
126
126
|
1. **Sort them by context and abilities.** Click the *Abilities* column, then *Context*: the
|
|
127
127
|
models that can do the most come first, the biggest context window first among those (each
|
|
128
128
|
column clicked breaks the ties of the ones before; click one again to reverse it, a third time to
|
|
129
|
-
drop it). Click **Save
|
|
129
|
+
drop it). Click **Save list** to keep it.
|
|
130
130
|
2. **Rearrange a bit more.** Drag a row to move it. #1 is the one HeartCode uses; the others are
|
|
131
131
|
its fallbacks, tried in order.
|
|
132
132
|
3. **Test them** (optional): **Test all** sends each a short message and shows which really answer.
|
|
133
133
|
Each test waits up to 10 seconds; the **Timeout** box next to it changes that.
|
|
134
|
+
4. **Filter them** (optional): by name, provider, test result (works, doesn't, not tested, or one
|
|
135
|
+
error like 402), context, tools, thinking, images or free. **Test all** then tests only the ones
|
|
136
|
+
shown, and **Use these N** makes them the models HeartCode uses, in the order you see (the others
|
|
137
|
+
stay under Providers). Filter to the working ones, sort by Works?, Use these: HeartCode uses your
|
|
138
|
+
working models, fastest first.
|
|
134
139
|
|
|
135
140
|
If a model says *not found* in models.dev, **Retry** looks it up again, or **Set up** tells
|
|
136
141
|
HeartCode what it can do.
|
|
@@ -141,7 +146,7 @@ HeartCode what it can do.
|
|
|
141
146
|
with [@BotFather](https://t.me/BotFather), paste its token, press Start in the bot, and
|
|
142
147
|
HeartCode finds your chat.
|
|
143
148
|
- **Advanced → Logs**: a log of each run, and each request with its reply, in files of their own.
|
|
144
|
-
Logs older than
|
|
149
|
+
Logs older than 3 days are deleted (you can change that).
|
|
145
150
|
|
|
146
151
|
### 7. Back to HeartCode
|
|
147
152
|
|
package/bin/heart.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// Logs, when they're switched on (the settings page: Logging): each run's log in
|
|
12
12
|
// ~/.heart/logs/runs/<day-month-year-hour-min-sec>/, a file per tab ("log": true in config.json);
|
|
13
13
|
// each request to a model in ~/.heart/logs/requests/<same>/, a file per request ("logRequests").
|
|
14
|
-
// Kept for logDays days (
|
|
14
|
+
// Kept for logDays days (3 unless changed). HEART_LOG=/path/file.log logs this run in that one file
|
|
15
15
|
// anyway; HEART_LOG=off: no run log.
|
|
16
16
|
import fs from 'node:fs'
|
|
17
17
|
import os from 'node:os'
|
package/bin/heartcode.js
CHANGED
|
@@ -104,7 +104,7 @@ const SECTIONS = [
|
|
|
104
104
|
]],
|
|
105
105
|
['settings', [
|
|
106
106
|
['/toggle_thinking', "show or collapse the model's thinking"],
|
|
107
|
-
['/voice', 'say your message
|
|
107
|
+
['/voice', 'say your message (or Space in an empty box): it shows in the box as you speak, Enter sends it, Esc cancels'],
|
|
108
108
|
]],
|
|
109
109
|
['session', [
|
|
110
110
|
['/resume', 'continue an earlier session in this folder'],
|
|
@@ -155,7 +155,7 @@ function keysHelp(keys = {}) {
|
|
|
155
155
|
const forAct = (a) => Object.entries(keys).filter(([, v]) => v === a).map(([k]) => pretty(k)).join(' / ')
|
|
156
156
|
const tabs = /(^|,)alt\+[1-9]/.test(Object.keys(keys).join(','))
|
|
157
157
|
const rows = [
|
|
158
|
-
['Space', '
|
|
158
|
+
['Space', 'voice: listens at once, Enter sends what you said (in an empty box)'],
|
|
159
159
|
['Enter', 'send · while it works, queue the message (commands like /help, /cost, /select_model run at once)'],
|
|
160
160
|
['Option/Shift/Ctrl+Enter', 'new line in the box'],
|
|
161
161
|
['Esc', 'stop the task (press twice to confirm)'],
|
|
@@ -198,7 +198,7 @@ const ARGS = {
|
|
|
198
198
|
// Terminal.app can't report Shift+Enter; Option+Enter works there ("Use Option as Meta key").
|
|
199
199
|
const NEWLINE_KEY = process.env.TERM_PROGRAM === 'Apple_Terminal' ? 'Option+Enter' : 'Shift+Enter'
|
|
200
200
|
|
|
201
|
-
const kTokens = (n) => (n >= 1e6 ? `${
|
|
201
|
+
const kTokens = (n) => (n >= 1e6 ? `${Number((n / 1e6).toFixed(2))}M` : n >= 1000 ? `${(n / 1000).toFixed(n >= 10_000 ? 0 : 1)}k` : String(n)) // 1.05M, not rounded up to 1.1M
|
|
202
202
|
|
|
203
203
|
const mask = (k) => (k ? (k.length > 12 ? `${k.slice(0, 4)}…${k.slice(-4)}` : '…') : c.dim('no key'))
|
|
204
204
|
|
|
@@ -1644,9 +1644,9 @@ async function slash(app, line, working = false) {
|
|
|
1644
1644
|
case 'btw':
|
|
1645
1645
|
return app.btw(line.trim().replace(/^\/btw\b/, '').trim(), working)
|
|
1646
1646
|
case 'voice': {
|
|
1647
|
-
if (working) return ui.dictateIn() //
|
|
1647
|
+
if (working) return ui.dictateIn() // as Space does while it works: sent when you press Enter
|
|
1648
1648
|
const text = await ui.dictate()
|
|
1649
|
-
if (text)
|
|
1649
|
+
if (text) ui.ahead.push(text) // sent: the next prompt takes it, as if typed
|
|
1650
1650
|
return
|
|
1651
1651
|
}
|
|
1652
1652
|
case 'toggle_thinking':
|
package/package.json
CHANGED
package/src/log.js
CHANGED
|
@@ -20,7 +20,7 @@ export const runLog = { on: Boolean(LOG_FILE || (LOG_DIR && (!AUTO || process.en
|
|
|
20
20
|
// Where the logs go: bin/heart.js says (the system's temp folder with --temp)
|
|
21
21
|
export const LOGS = path.resolve(process.env.HEART_LOGS || path.join(process.env.HEART_HOME || path.join(os.homedir(), '.heart'), 'logs'))
|
|
22
22
|
export const REQUESTS = path.join(LOGS, 'requests')
|
|
23
|
-
export const DAYS =
|
|
23
|
+
export const DAYS = 3 // how long logs are kept, unless config.json's logDays says otherwise
|
|
24
24
|
const STAMP = process.env.HEART_LOG_STAMP || stamp()
|
|
25
25
|
|
|
26
26
|
export function stamp(d = new Date()) {
|
package/src/settings.html
CHANGED
|
@@ -256,9 +256,9 @@
|
|
|
256
256
|
.mrow.flash { animation: flash 1.6s ease-out; }
|
|
257
257
|
@keyframes flash { from { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); } to { background: none; box-shadow: none; } }
|
|
258
258
|
.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; }
|
|
259
|
-
.rows > .mrow, .rows > .mwrap { height:
|
|
259
|
+
.rows > .mrow, .rows > .mwrap { height: 40px; } /* one height: a long list only draws what's in view */
|
|
260
260
|
.mwrap .mrow { height: 100%; }
|
|
261
|
-
.mrow .can { display:
|
|
261
|
+
.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 */
|
|
262
262
|
.mrow .add { color: var(--accent); font-size: 12.5px; font-weight: 600; white-space: nowrap; opacity: .55; transition: opacity .12s; }
|
|
263
263
|
.mwrap:hover .mrow .add, .mrow:focus-visible .add { opacity: 1; }
|
|
264
264
|
.mrow.taken .id { color: var(--muted); }
|
|
@@ -370,10 +370,10 @@
|
|
|
370
370
|
.mt-top .chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); border-radius: 8px; padding: 1px 3px 1px 9px; margin: 2px 4px 2px 0; color: var(--text); font-size: 12.5px; }
|
|
371
371
|
.mt-top .chip button { border: 0; background: none; padding: 0 4px; font-size: 12px; color: var(--muted); }
|
|
372
372
|
.mt-scroll { overflow-x: auto; }
|
|
373
|
-
.mt { min-width:
|
|
373
|
+
.mt { min-width: 1080px; }
|
|
374
374
|
.mt-h input[type=checkbox], .mtable input[type=checkbox] { width: 15px; height: 15px; margin: 0; accent-color: var(--brand); cursor: pointer; }
|
|
375
375
|
.mtable li.picked { background: var(--brand-soft); }
|
|
376
|
-
.mt-rules { display: flex; align-items: center; flex-wrap: wrap; gap: 10px
|
|
376
|
+
.mt-rules { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 24px; padding: 12px 18px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
|
|
377
377
|
.mt-rules .rule { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
|
|
378
378
|
.mt-rules select { width: auto; height: 32px; padding: 4px 30px 4px 10px; }
|
|
379
379
|
.mt-rules input { width: 64px; height: 32px; }
|
|
@@ -392,8 +392,10 @@
|
|
|
392
392
|
.pill .again:hover:not(:disabled) { color: var(--text); }
|
|
393
393
|
.pill.on { border-color: var(--accent); background: var(--accent-soft); }
|
|
394
394
|
.pill.on .again { border-left-color: color-mix(in srgb, var(--accent) 40%, transparent); }
|
|
395
|
-
.mt-h, .mtable li { display: grid; grid-template-columns:
|
|
396
|
-
.
|
|
395
|
+
.mt-h, .mtable li { display: grid; grid-template-columns: 14px 18px 44px minmax(240px, 1fr) 110px 62px 52px 70px 58px 116px 84px 132px; /* the last: Test · Request · Edit · ✕, as wide as they are */ align-items: center; column-gap: 6px; padding: 8px 18px; }
|
|
396
|
+
.mt-h button.mid, .mtable .mid { text-align: center; }
|
|
397
|
+
.mt-h > :nth-child(11), .mtable .try { padding-left: 12px; } /* Works?: a little room after the right-aligned price */
|
|
398
|
+
.mtable li .acts { justify-content: flex-start; }
|
|
397
399
|
.mt-h { border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 500; color: var(--faint); padding-top: 10px; padding-bottom: 10px; background: var(--panel2); }
|
|
398
400
|
.mt-h button { display: inline; border: 0; background: none !important; padding: 0; font: inherit; color: inherit; text-align: left; white-space: nowrap; transform: none !important; }
|
|
399
401
|
.mt-h button.num { text-align: right; }
|
|
@@ -477,6 +479,63 @@
|
|
|
477
479
|
#mt.sorting { opacity: .55; transition: opacity .1s; pointer-events: none; }
|
|
478
480
|
button.sorting::after { content: ''; display: inline-block; width: 9px; height: 9px; margin-left: 6px; vertical-align: -1px; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
|
|
479
481
|
.sort-live { color: var(--warn); }
|
|
482
|
+
/* Your models: the header's buttons, the list's settings, the toolbar (sticky), the table */
|
|
483
|
+
.mt-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
484
|
+
/* Your models: the settings (three cells across), the toolbar (sticky), the table */
|
|
485
|
+
.mt-sets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
|
|
486
|
+
.mt-set { display: flex; flex-direction: column; gap: 6px; padding: 14px 18px; border-left: 1px solid var(--line); min-width: 0; }
|
|
487
|
+
.mt-set:first-child { border-left: 0; }
|
|
488
|
+
.mt-setl { font-size: 12px; font-weight: 600; color: var(--muted); }
|
|
489
|
+
.mt-setc { display: flex; align-items: center; gap: 8px; }
|
|
490
|
+
.mt-setc select { flex: 1; width: 100%; min-width: 0; height: 34px; }
|
|
491
|
+
.mt-setc input[type=number] { width: 96px; height: 34px; }
|
|
492
|
+
.mt-setc input.tries { width: 64px; }
|
|
493
|
+
.mt-setc .unit { color: var(--muted); font-size: 13px; }
|
|
494
|
+
.mt-sets + .mt-tools { border-radius: 0; }
|
|
495
|
+
.mt-line { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; padding: 0 18px 12px; }
|
|
496
|
+
.mt-status { flex: 1 1 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; min-height: 30px; font-size: 13px; color: var(--muted); }
|
|
497
|
+
.mt-do { display: flex; align-items: center; gap: 8px; flex: none; }
|
|
498
|
+
.mt-hpick .mt-pickbar { grid-column: 3 / -1; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
|
|
499
|
+
.mt-hpick { background: var(--brand-soft); }
|
|
500
|
+
.mt-h.mt-hpick .mt-pickbar button { display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--panel) !important; color: var(--text); font-size: 12.5px; font-weight: 500; }
|
|
501
|
+
.mt-h.mt-hpick .mt-pickbar button:hover { background: var(--hover) !important; }
|
|
502
|
+
.mt-h.mt-hpick .mt-pickbar button.danger { color: var(--err); }
|
|
503
|
+
.mt-h.mt-hpick .mt-pickbar button.ghost { border-color: transparent; background: transparent !important; color: var(--muted); }
|
|
504
|
+
.mt-h.mt-hpick .mt-pickbar b { margin-right: 4px; }
|
|
505
|
+
.mt-tools { position: sticky; top: 0; z-index: 6; background: var(--panel); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
|
|
506
|
+
.mt-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 14px 18px 10px; }
|
|
507
|
+
.f-search { position: relative; flex: 1 1 0; min-width: 170px; display: block; } /* the room the others leave: one line */
|
|
508
|
+
.f-search .f-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-52%); color: var(--faint); font-size: 16px; pointer-events: none; }
|
|
509
|
+
.mt-filters .f-text { width: 100%; height: 34px; padding-left: 32px; }
|
|
510
|
+
.mt-filters select { height: 34px; width: auto; padding-top: 0; padding-bottom: 0; line-height: 32px; }
|
|
511
|
+
.mt-filters select.on { border-color: var(--accent); background-color: color-mix(in srgb, var(--accent-soft) 50%, var(--input)); }
|
|
512
|
+
.f-togs { display: inline-flex; gap: 6px; flex-wrap: wrap; }
|
|
513
|
+
.mt-status .count b { color: var(--text); }
|
|
514
|
+
.mt-status .chip { display: inline-flex; align-items: center; gap: 2px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); border-radius: 999px; padding: 2px 4px 2px 10px; color: var(--text); font-size: 12.5px; }
|
|
515
|
+
.mt-status .chip.sort { border-color: var(--line-strong); background: var(--panel2); }
|
|
516
|
+
.mt-status .chip button { border: 0; background: none; padding: 0 5px; font-size: 11px; color: var(--muted); border-radius: 999px; }
|
|
517
|
+
.mt-status .chip button:hover { color: var(--text); background: var(--hover); }
|
|
518
|
+
.mt-tools .mt-outcomes { border-bottom: 0; border-top: 1px solid var(--line); padding: 9px 18px; }
|
|
519
|
+
.mt-hwrap { overflow: hidden; border-top: 1px solid var(--line); }
|
|
520
|
+
.mt-hwrap .mt-h { border-bottom: 0; }
|
|
521
|
+
.mt-outcomes .label { margin-right: 4px; }
|
|
522
|
+
.pill.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
|
|
523
|
+
.mt-tools .job-slot:not(:empty) { border-top: 1px solid var(--line); }
|
|
524
|
+
.mtable .m { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
525
|
+
.mtable .m .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
526
|
+
.mtable .tag { flex: none; font: 600 10.5px var(--sans); padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); background: none; line-height: 1.5; }
|
|
527
|
+
.mtable .tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
|
|
528
|
+
.mtable button.tag:hover { background: var(--hover); }
|
|
529
|
+
.mtable .price { white-space: nowrap; font-size: 12.5px; }
|
|
530
|
+
.mtable .acts { display: flex; justify-content: flex-end; gap: 4px; }
|
|
531
|
+
.mtable li .acts button { padding-left: 8px; padding-right: 8px; background: transparent; border-color: transparent; color: var(--muted); }
|
|
532
|
+
.mtable li .acts button:hover:not(:disabled) { background: var(--hover); border-color: var(--line-strong); color: var(--text); }
|
|
533
|
+
.mtable li .acts button.danger:hover:not(:disabled) { color: var(--err); }
|
|
534
|
+
.f-tog { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; font-size: 13px; cursor: pointer; user-select: none; }
|
|
535
|
+
.f-tog:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 60%, var(--panel)); }
|
|
536
|
+
.f-tog input { margin: 0; accent-color: var(--brand); }
|
|
537
|
+
.mt-filters .f-count { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
|
|
538
|
+
.mt-filters.on .f-count { color: var(--text); font-weight: 600; }
|
|
480
539
|
.test-wait { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
|
|
481
540
|
.test-wait input { width: 64px; height: 28px; padding: 2px 8px; font-size: 12.5px; text-align: right; }
|
|
482
541
|
.ws-url { display: flex; gap: 8px; margin-top: 10px; }
|
|
@@ -555,6 +614,12 @@
|
|
|
555
614
|
nav a.on::before { display: none; } /* a strip of tabs: the highlighted one is enough */
|
|
556
615
|
nav a .count, .using, .nav-group { display: none; }
|
|
557
616
|
.theme-btn { top: 10px; right: 12px; }
|
|
617
|
+
.mt-tools { position: static; } /* a phone: too tall to stay in sight, it scrolls with the page */
|
|
618
|
+
.mt-sets { grid-template-columns: minmax(0, 1fr); }
|
|
619
|
+
.mt-set { border-left: 0; border-top: 1px solid var(--line); }
|
|
620
|
+
.mt-set:first-child { border-top: 0; }
|
|
621
|
+
.mt-do { width: 100%; }
|
|
622
|
+
.mt-do button { flex: 1; }
|
|
558
623
|
main { padding: 20px 16px 60px; }
|
|
559
624
|
.steps { grid-template-columns: 1fr; }
|
|
560
625
|
.choices, .choices.three { grid-template-columns: 1fr; }
|
|
@@ -615,6 +680,62 @@
|
|
|
615
680
|
.opt.tg-off { opacity: .5; }
|
|
616
681
|
.imp-row .imp-label { font-weight: 500; font-family: var(--mono); font-size: 12.5px; flex: none; }
|
|
617
682
|
.imp-row .imp-desc { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
683
|
+
|
|
684
|
+
/* ===== The look: icons, a color for each part, room used (no empty bands) ===== */
|
|
685
|
+
:root {
|
|
686
|
+
--c-blue: #2563eb; --c-violet: #7c3aed; --c-amber: #b45309; --c-teal: #0f766e; --c-pink: #db2777; --c-slate: #475569; --c-gray: #6b7280; --c-green: #15803d; --c-red: #dc2626;
|
|
687
|
+
}
|
|
688
|
+
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) {
|
|
689
|
+
--c-blue: #60a5fa; --c-violet: #a78bfa; --c-amber: #fbbf24; --c-teal: #2dd4bf; --c-pink: #f472b6; --c-slate: #94a3b8; --c-gray: #9ca3af; --c-green: #4ade80; --c-red: #f87171;
|
|
690
|
+
} }
|
|
691
|
+
:root[data-theme=dark] { --c-blue: #60a5fa; --c-violet: #a78bfa; --c-amber: #fbbf24; --c-teal: #2dd4bf; --c-pink: #f472b6; --c-slate: #94a3b8; --c-gray: #9ca3af; --c-green: #4ade80; --c-red: #f87171; }
|
|
692
|
+
.icon { width: 16px; height: 16px; flex: none; display: inline-block; vertical-align: -3px; }
|
|
693
|
+
.icon svg { width: 100%; height: 100%; display: block; }
|
|
694
|
+
/* a tile: an icon on its color, soft */
|
|
695
|
+
.tile { display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 7px; color: var(--tc, var(--c-slate)); background: color-mix(in srgb, var(--tc, var(--c-slate)) 14%, transparent); }
|
|
696
|
+
.tile .icon { width: 15px; height: 15px; }
|
|
697
|
+
.tile.lg { width: 38px; height: 38px; border-radius: 10px; }
|
|
698
|
+
.tile.lg .icon { width: 20px; height: 20px; }
|
|
699
|
+
[data-tone=blue] { --tc: var(--c-blue); } [data-tone=violet] { --tc: var(--c-violet); } [data-tone=amber] { --tc: var(--c-amber); } [data-tone=teal] { --tc: var(--c-teal); }
|
|
700
|
+
[data-tone=pink] { --tc: var(--c-pink); } [data-tone=slate] { --tc: var(--c-slate); } [data-tone=gray] { --tc: var(--c-gray); } [data-tone=green] { --tc: var(--c-green); } [data-tone=red] { --tc: var(--c-red); }
|
|
701
|
+
/* the sidebar: each part with its tile */
|
|
702
|
+
nav a { padding: 6px 10px; }
|
|
703
|
+
nav a .tile { width: 24px; height: 24px; }
|
|
704
|
+
nav a:not(.on) .tile { filter: saturate(.75); }
|
|
705
|
+
nav a.on .tile { background: var(--tc); color: var(--panel); }
|
|
706
|
+
/* the page: less room around it; its title with its tile */
|
|
707
|
+
main { padding-top: 22px; }
|
|
708
|
+
.head { margin-bottom: 16px; align-items: center; }
|
|
709
|
+
.head h1 { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
|
|
710
|
+
.page > .head:first-child { padding-right: 54px; } /* the theme button sits up there */
|
|
711
|
+
.mcp-row { align-items: flex-start; }
|
|
712
|
+
.mcp-row > .tile { margin-top: 2px; }
|
|
713
|
+
.subtabs { margin-bottom: 14px; }
|
|
714
|
+
.card:not(.mt-card):not(.reqs-card):not(.work > .card) { padding: 16px 18px 18px; } /* the ones that set their own (edge to edge) keep it */
|
|
715
|
+
.card > h2:first-child, .card > .card-h, h2[data-ic] { display: flex; align-items: center; gap: 9px; }
|
|
716
|
+
/* buttons: their icon, colored by what they do */
|
|
717
|
+
button .icon { width: 15px; height: 15px; margin-left: -2px; }
|
|
718
|
+
button.small .icon { width: 14px; height: 14px; }
|
|
719
|
+
button .icon.k-save, button .icon.k-add { color: var(--c-green); }
|
|
720
|
+
button.primary .icon { color: inherit; }
|
|
721
|
+
button .icon.k-test { color: var(--c-blue); }
|
|
722
|
+
button .icon.k-del { color: var(--c-red); }
|
|
723
|
+
button .icon.k-refresh { color: var(--c-amber); }
|
|
724
|
+
button .icon.k-edit { color: var(--c-violet); }
|
|
725
|
+
button .icon.k-info { color: var(--c-slate); }
|
|
726
|
+
button:disabled .icon { opacity: .55; }
|
|
727
|
+
/* General: the cards packed in two columns, no gaps under the short ones */
|
|
728
|
+
.settings-col { display: block; columns: 2; column-gap: 16px; }
|
|
729
|
+
.settings-col > .card { break-inside: avoid; display: block; width: 100%; margin: 0 0 16px; }
|
|
730
|
+
.settings-col > .card.wide { column-span: all; }
|
|
731
|
+
@media (max-width: 1280px) { .settings-col { columns: 1; } }
|
|
732
|
+
/* Your models: a row's actions as icon buttons */
|
|
733
|
+
.mtable li .acts .ib { width: 30px; height: 28px; padding: 0; justify-content: center; }
|
|
734
|
+
.mtable li .acts .ib .icon { margin: 0; width: 15px; height: 15px; }
|
|
735
|
+
.mtable li .acts .ib.k-test { color: var(--c-blue); }
|
|
736
|
+
.mtable li .acts .ib.k-info { color: var(--c-slate); }
|
|
737
|
+
.mtable li .acts .ib.k-edit { color: var(--c-violet); }
|
|
738
|
+
.mtable li .acts .ib.k-del { color: var(--c-red); }
|
|
618
739
|
</style>
|
|
619
740
|
</head>
|
|
620
741
|
<body>
|
|
@@ -665,7 +786,7 @@
|
|
|
665
786
|
|
|
666
787
|
<!-- Your models: all at once, sortable -->
|
|
667
788
|
<section class="page" id="page-models">
|
|
668
|
-
<div class="head"><div><h1>Your models</h1><p class="lead">
|
|
789
|
+
<div class="head"><div><h1>Your models</h1><p class="lead">HeartCode uses #1, and the next one when it fails. Filter, sort or drag, then Save list.</p></div><div class="mt-actions" id="mt-actions"></div></div>
|
|
669
790
|
<div class="card mt-card" id="mt"></div>
|
|
670
791
|
</section>
|
|
671
792
|
|
|
@@ -718,7 +839,7 @@
|
|
|
718
839
|
<label for="l-days"><b>Keep logs for</b></label>
|
|
719
840
|
<input type="number" id="l-days" min="1" max="3650" step="1" value="30">
|
|
720
841
|
<span>days</span>
|
|
721
|
-
<span class="muted">Older ones (both kinds) are deleted when HeartCode starts, and right away when you change this.
|
|
842
|
+
<span class="muted">Older ones (both kinds) are deleted when HeartCode starts, and right away when you change this. 3 days unless you change it.</span>
|
|
722
843
|
</div>
|
|
723
844
|
</div>
|
|
724
845
|
<div class="card reqs-card">
|
|
@@ -767,7 +888,7 @@
|
|
|
767
888
|
</div>
|
|
768
889
|
<div class="card">
|
|
769
890
|
<h2>Voice input</h2>
|
|
770
|
-
<p class="sub">Press Space in an empty input box (or type /voice)
|
|
891
|
+
<p class="sub">Press Space in an empty input box (or type /voice) and talk: your words show in the box as you speak, and Enter sends them. Esc cancels.</p>
|
|
771
892
|
<div class="setting">
|
|
772
893
|
<label class="t" for="v-src"><b>Transcribe with</b><span id="v-src-about"></span></label>
|
|
773
894
|
<select id="v-src"></select>
|
|
@@ -981,6 +1102,115 @@ const h = (tag, props = {}, ...kids) => {
|
|
|
981
1102
|
el.append(...kids.flat(Infinity).filter((x) => x != null && x !== false))
|
|
982
1103
|
return el
|
|
983
1104
|
}
|
|
1105
|
+
// Icons: simple line drawings (24×24, drawn with the text's color), no files or fonts to load.
|
|
1106
|
+
const ICON = {
|
|
1107
|
+
list: 'M8 6h13M8 12h13M8 18h13M3.5 6h.01M3.5 12h.01M3.5 18h.01',
|
|
1108
|
+
sliders: 'M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6',
|
|
1109
|
+
bell: 'M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9M10.3 21a1.94 1.94 0 0 0 3.4 0',
|
|
1110
|
+
sparkles: 'M12 3l1.9 5.8L20 11l-6.1 2.2L12 19l-1.9-5.8L4 11l6.1-2.2zM19 3v4M17 5h4',
|
|
1111
|
+
plug: 'M9 2v6M15 2v6M6 8h12v4a6 6 0 0 1-12 0zM12 18v4',
|
|
1112
|
+
message: 'M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM8 9h8M8 13h5',
|
|
1113
|
+
wrench: 'M14.7 6.3a4 4 0 0 0-5.4 5.4L3 18v3h3l6.3-6.3a4 4 0 0 0 5.4-5.4l-2.6 2.6-2.4-.6-.6-2.4z',
|
|
1114
|
+
save: 'M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2zM17 21v-8H7v8M7 3v5h8',
|
|
1115
|
+
play: 'M7 4l13 8-13 8z',
|
|
1116
|
+
refresh: 'M21 12a9 9 0 1 1-2.6-6.4L21 8M21 3v5h-5',
|
|
1117
|
+
plus: 'M12 5v14M5 12h14',
|
|
1118
|
+
trash: 'M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6M10 11v6M14 11v6',
|
|
1119
|
+
pencil: 'M17 3l4 4L7 21H3v-4z',
|
|
1120
|
+
search: 'M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM21 21l-4.3-4.3',
|
|
1121
|
+
x: 'M18 6L6 18M6 6l12 12',
|
|
1122
|
+
check: 'M20 6L9 17l-5-5',
|
|
1123
|
+
bars: 'M4 20V10M10 20V4M16 20v-7M22 20H2',
|
|
1124
|
+
download: 'M12 3v12M7 10l5 5 5-5M5 21h14',
|
|
1125
|
+
eye: 'M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12zM12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6z',
|
|
1126
|
+
send: 'M22 2L11 13M22 2l-7 20-4-9-9-4z',
|
|
1127
|
+
shield: 'M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z',
|
|
1128
|
+
palette: 'M12 3a9 9 0 1 0 0 18c1 0 1.5-.8 1.5-1.5 0-1.5 1-2 2.5-2H18a3 3 0 0 0 3-3c0-5-4-8.5-9-8.5zM7.5 11h.01M10 7h.01M15 7h.01',
|
|
1129
|
+
toggle: 'M7 7h10a5 5 0 0 1 0 10H7A5 5 0 0 1 7 7zM7 9.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5z',
|
|
1130
|
+
cpu: 'M7 7h10v10H7zM10 10h4v4h-4zM9 2v3M15 2v3M9 19v3M15 19v3M2 9h3M2 15h3M19 9h3M19 15h3',
|
|
1131
|
+
mic: 'M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3zM19 11a7 7 0 0 1-14 0M12 18v4',
|
|
1132
|
+
globe: 'M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM2 12h20M12 2c3 3 4 6.5 4 10s-1 7-4 10c-3-3-4-6.5-4-10s1-7 4-10z',
|
|
1133
|
+
server: 'M3 4h18v7H3zM3 13h18v7H3zM7 7.5h.01M7 16.5h.01',
|
|
1134
|
+
file: 'M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8zM14 2v6h6M8 13h8M8 17h5',
|
|
1135
|
+
activity: 'M22 12h-4l-3 9L9 3l-3 9H2',
|
|
1136
|
+
link: 'M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1 1M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1-1',
|
|
1137
|
+
layout: 'M3 3h18v18H3zM3 15h18M8 18h.01',
|
|
1138
|
+
stop: 'M6 6h12v12H6z',
|
|
1139
|
+
swap: 'M7 4L3 8l4 4M3 8h14M17 20l4-4-4-4M21 16H7',
|
|
1140
|
+
filter: 'M3 4h18l-7 8v6l-4 2v-8z',
|
|
1141
|
+
key: 'M15 7a4 4 0 1 1-3.9 4.9L3 20v1h3l1-1v-2h2v-2h2l1.1-1.1A4 4 0 0 1 15 7zM16 8h.01',
|
|
1142
|
+
clock: 'M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM12 6v6l4 2',
|
|
1143
|
+
tool: 'M4 20l6-6M14 4l6 6-8 8-6-6zM15 9l-6 6',
|
|
1144
|
+
folder: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z',
|
|
1145
|
+
terminal: 'M4 17l6-5-6-5M12 19h8',
|
|
1146
|
+
upload: 'M12 21V9M7 14l5-5 5 5M5 3h14',
|
|
1147
|
+
arrow: 'M5 12h14M13 6l6 6-6 6',
|
|
1148
|
+
}
|
|
1149
|
+
const ic = (name, cls = '') => {
|
|
1150
|
+
const el = document.createElement('span')
|
|
1151
|
+
el.className = `icon ${cls}`.trim()
|
|
1152
|
+
el.setAttribute('aria-hidden', 'true')
|
|
1153
|
+
el.innerHTML = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="${ICON[name] ?? ICON.check}"/></svg>`
|
|
1154
|
+
return el
|
|
1155
|
+
}
|
|
1156
|
+
const tile = (name, tone, big = false) => {
|
|
1157
|
+
const t = h('span', { className: `tile${big ? ' lg' : ''}` }, ic(name))
|
|
1158
|
+
t.dataset.tone = tone
|
|
1159
|
+
return t
|
|
1160
|
+
}
|
|
1161
|
+
// each part of the page: its icon and its color (the sidebar, the page's title)
|
|
1162
|
+
const PART = { models: ['list', 'blue'], providers: ['server', 'blue'], general: ['sliders', 'slate'], statusbar: ['layout', 'slate'], notify: ['bell', 'amber'], skills: ['sparkles', 'violet'], mcp: ['plug', 'teal'], prompts: ['message', 'pink'], logging: ['wrench', 'gray'], files: ['folder', 'gray'] }
|
|
1163
|
+
// a button's icon, by what it says: [words it starts with, icon, kind (its color)]
|
|
1164
|
+
const BUTTON_ICONS = [
|
|
1165
|
+
[/^save|^keep only/i, 'save', 'k-save'], [/^\+|^add|^new /i, 'plus', 'k-add'], [/^install/i, 'download', 'k-save'], [/^import/i, 'download', 'k-info'],
|
|
1166
|
+
[/^test|^send a test/i, 'play', 'k-test'], [/^request|^show the raw/i, 'eye', 'k-info'], [/^edit|^set up/i, 'pencil', 'k-edit'],
|
|
1167
|
+
[/^remove|^delete|^disconnect/i, 'trash', 'k-del'], [/^stop/i, 'stop', 'k-del'], [/^refresh|^retry|^get from models|^look it up|^reset/i, 'refresh', 'k-refresh'],
|
|
1168
|
+
[/^provider ranking/i, 'bars', 'k-info'], [/^clear|^select none/i, 'x', 'k-info'], [/^invert/i, 'swap', 'k-info'], [/^connect|^sign in/i, 'link', 'k-test'],
|
|
1169
|
+
[/^your models/i, 'list', 'k-info'], [/^collapse|^expand/i, 'list', 'k-info'], [/^turn off/i, 'x', 'k-del'],
|
|
1170
|
+
]
|
|
1171
|
+
// card titles: their icon and color
|
|
1172
|
+
const TITLE_ICONS = [
|
|
1173
|
+
[/^permissions/i, 'shield', 'green'], [/^terminal colors/i, 'palette', 'pink'], [/^behavior/i, 'toggle', 'blue'], [/^model$/i, 'cpu', 'violet'], [/^voice/i, 'mic', 'amber'],
|
|
1174
|
+
[/^external tools/i, 'tool', 'slate'], [/^web search/i, 'globe', 'teal'], [/^telegram/i, 'send', 'blue'], [/^when to send/i, 'bell', 'amber'], [/^servers/i, 'server', 'teal'],
|
|
1175
|
+
[/^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'],
|
|
1176
|
+
[/^items/i, 'list', 'slate'], [/^show the status bar/i, 'layout', 'slate'],
|
|
1177
|
+
]
|
|
1178
|
+
// Icons put where they belong, as things are drawn (one pass: a button or title that has one is left alone)
|
|
1179
|
+
function decorate(root = document.body) {
|
|
1180
|
+
for (const b of root.querySelectorAll('button:not([data-ic])')) {
|
|
1181
|
+
if (b.closest('.acts, .mt-h:not(.mt-hpick), .chip, .pill, .seg, .subtabs, .theme-btn, .f-tog, .sw, nav, [data-no-ic]') || b.querySelector('.icon')) continue
|
|
1182
|
+
const text = b.textContent.trim()
|
|
1183
|
+
const hit = BUTTON_ICONS.find(([re]) => re.test(text))
|
|
1184
|
+
if (!hit || text.length < 3) continue
|
|
1185
|
+
b.dataset.ic = '1'
|
|
1186
|
+
if (/^\+\s*/.test(text)) b.textContent = text.replace(/^\+\s*/, '')
|
|
1187
|
+
b.prepend(ic(hit[1], hit[2]))
|
|
1188
|
+
}
|
|
1189
|
+
for (const t of root.querySelectorAll('.card h2:first-child:not([data-ic]), .card h2:first-of-type:not([data-ic])')) {
|
|
1190
|
+
const hit = TITLE_ICONS.find(([re]) => re.test(t.textContent.trim()))
|
|
1191
|
+
if (!hit) continue
|
|
1192
|
+
t.dataset.ic = '1'
|
|
1193
|
+
t.prepend(tile(hit[1], hit[2]))
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
let decorating = false
|
|
1197
|
+
new MutationObserver(() => {
|
|
1198
|
+
if (decorating) return
|
|
1199
|
+
decorating = true
|
|
1200
|
+
queueMicrotask(() => ((decorating = false), decorate()))
|
|
1201
|
+
}).observe(document.documentElement, { childList: true, subtree: true, characterData: true })
|
|
1202
|
+
// the sidebar's parts and the pages' titles: their tiles
|
|
1203
|
+
addEventListener('DOMContentLoaded', () => {
|
|
1204
|
+
for (const a of document.querySelectorAll('nav a[data-page]')) {
|
|
1205
|
+
const [name, tone] = PART[a.dataset.page] ?? ['list', 'slate']
|
|
1206
|
+
a.querySelector('.ic')?.replaceWith(tile(name, tone))
|
|
1207
|
+
}
|
|
1208
|
+
for (const sec of document.querySelectorAll('section.page')) {
|
|
1209
|
+
const [name, tone] = PART[sec.id.replace(/^page-/, '')] ?? ['list', 'slate']
|
|
1210
|
+
sec.querySelector('.head h1')?.prepend(tile(name, tone, true))
|
|
1211
|
+
}
|
|
1212
|
+
decorate()
|
|
1213
|
+
})
|
|
984
1214
|
// an element's content, without the null/false parts (left out on purpose)
|
|
985
1215
|
const put = (el, ...kids) => el.replaceChildren(...kids.flat(Infinity).filter((x) => x != null && x !== false))
|
|
986
1216
|
let S = null
|
|
@@ -1376,7 +1606,8 @@ $('dev-all').onclick = async () => {
|
|
|
1376
1606
|
$('m-search').oninput = (e) => ((modelQuery = e.target.value), (searchOpen = true), S && drawProviders(S), applyFolds())
|
|
1377
1607
|
// A model's tooltip: its full name and what's known about it (from the provider, HeartCode's price
|
|
1378
1608
|
// list and its own test), and what a click does. Shown on hover and on keyboard focus.
|
|
1379
|
-
|
|
1609
|
+
// a token count, short: 1M, 1.05M (two decimals, not rounded up to 1.1M), 131k
|
|
1610
|
+
const kTok = (n) => (n >= 1e6 ? `${Number((n / 1e6).toFixed(2))}M` : n >= 1000 ? `${Math.round(n / 1000)}k` : String(n))
|
|
1380
1611
|
const usd = (x) => (x === 0 ? 'free' : `$${x < 0.01 ? x.toFixed(4) : x < 1 ? x.toFixed(3).replace(/0$/, '') : x.toFixed(2)}`)
|
|
1381
1612
|
// where what a model can do comes from (the Your models table)
|
|
1382
1613
|
const FROM = { 'models.dev': 'from models.dev', you: 'set by you', tested: 'tested' }
|
|
@@ -1416,12 +1647,13 @@ function triedCell(t) {
|
|
|
1416
1647
|
: r.going ? ['going', 'testing…', 'sending it a short message']
|
|
1417
1648
|
: r.ok ? ['ok', `✓ ${(r.ms / 1000).toFixed(1)}s`, `works: it answered "${r.reply}"${secs}`]
|
|
1418
1649
|
: ['bad', `✗ ${outcome(r)}`, `doesn't work: ${r.error}${secs}`] // the reason on hover
|
|
1419
|
-
return h('div', { className: 'try ' + cls },
|
|
1420
|
-
h('span', { className: 'msg', textContent: text, title: about }),
|
|
1421
|
-
h('button', { className: 'small', textContent: 'Test', disabled: Boolean(r?.going), title: 'send it a short message to see that it really answers', 'aria-label': `test ${t.model}`, onclick: () => tryModel(t) }))
|
|
1650
|
+
return h('div', { className: 'try ' + cls }, h('span', { className: 'msg', textContent: text, title: about }))
|
|
1422
1651
|
}
|
|
1423
1652
|
function showTried(t) {
|
|
1424
|
-
document.querySelector(`#mt li[data-key="${CSS.escape(keyOf(t))}"]
|
|
1653
|
+
const li = document.querySelector(`#mt li[data-key="${CSS.escape(keyOf(t))}"]`)
|
|
1654
|
+
li?.querySelector('.try')?.replaceWith(triedCell(t))
|
|
1655
|
+
const btn = li?.querySelector('.row-test')
|
|
1656
|
+
if (btn) (btn.disabled = Boolean(TRIES[keyOf(t)]?.going)), btn.replaceChildren(ic(btn.disabled ? 'clock' : 'play'))
|
|
1425
1657
|
if (!TRIES[keyOf(t)]?.going) mineSoon() // a result: the counts by result (and a sort by it) change
|
|
1426
1658
|
}
|
|
1427
1659
|
let mineFrame = 0
|
|
@@ -1833,7 +2065,7 @@ async function clearAdded(p) {
|
|
|
1833
2065
|
if (inList.length && !(await saveOrder(S.order.filter((t) => !inList.includes(t))))) return
|
|
1834
2066
|
act('/api/provider/added', { name: p.name, all: true }, `${p.name}: the models you added are forgotten`)
|
|
1835
2067
|
}
|
|
1836
|
-
const CAT_ROW =
|
|
2068
|
+
const CAT_ROW = 40 // a model's row: its name, and what it can do beside it
|
|
1837
2069
|
// The models ticked (provider → Set of ids): kept while you search, so ones ticked for one search
|
|
1838
2070
|
// and the next are added (or taken off) together. SHOWN: each provider's models shown now (the
|
|
1839
2071
|
// search's matches).
|
|
@@ -1972,6 +2204,8 @@ const COLS = {
|
|
|
1972
2204
|
images: { label: 'Images', first: 'down', get: (t) => can(t).images, words: ['without first', 'with first'] },
|
|
1973
2205
|
input: { label: 'In $/M', first: 'up', get: (t) => t.price?.input ?? null, words: ['cheapest first', 'priciest first'] },
|
|
1974
2206
|
output: { label: 'Out $/M', first: 'up', get: (t) => t.price?.output ?? null, words: ['cheapest first', 'priciest first'] },
|
|
2207
|
+
// in and out together, per million tokens
|
|
2208
|
+
price: { label: 'Price $/M', first: 'up', get: (t) => (t.price?.input == null && t.price?.output == null ? null : (t.price.input ?? 0) + (t.price.output ?? 0)), words: ['cheapest first', 'priciest first'] },
|
|
1975
2209
|
// its test's time (seconds, as shown); failed or not tested: no time, at the end (not tested before failed)
|
|
1976
2210
|
works: { label: 'Works?', first: 'up', get: (t) => { const r = TRIES[keyOf(t)]; return r?.ok && !r.going ? r.ms ?? 0 : null }, missing: (t) => { const r = TRIES[keyOf(t)]; return !r || r.going ? 0 : 1 }, words: ['fastest first', 'slowest first'] },
|
|
1977
2211
|
}
|
|
@@ -2043,54 +2277,202 @@ function sorted(order) {
|
|
|
2043
2277
|
return order.map((t, i) => ({ t, i })).sort((a, b) => SORT.reduce((r, s) => r || cmp(a.t, b.t, s), 0) || a.i - b.i).map((x) => x.t)
|
|
2044
2278
|
}
|
|
2045
2279
|
const dirText = (key, dir) => COLS[key].words[dir === 'up' ? 0 : 1] + (key === 'works' ? ' (then not tested, then not working)' : '')
|
|
2280
|
+
// Filters on the Your models page: which models are shown (and tested by "Test N shown", counted,
|
|
2281
|
+
// sorted, selected by "select all", saved first by Save list). Combined: a model shows when it passes
|
|
2282
|
+
// all of them. Kept with the page's choices.
|
|
2283
|
+
const NO_FILTER = { text: '', provider: '', works: '', context: 0, tools: false, thinking: false, images: false, free: false }
|
|
2284
|
+
let FILTER = { ...NO_FILTER }
|
|
2285
|
+
let filtersLoaded = false
|
|
2286
|
+
const filtering = () => Object.keys(NO_FILTER).some((k) => FILTER[k] !== NO_FILTER[k])
|
|
2287
|
+
function passes(t, skip) {
|
|
2288
|
+
const f = FILTER
|
|
2289
|
+
if (f.text) {
|
|
2290
|
+
const hay = `${t.model} ${t.provider}`.toLowerCase()
|
|
2291
|
+
if (!f.text.toLowerCase().split(/\s+/).filter(Boolean).every((w) => hay.includes(w))) return false
|
|
2292
|
+
}
|
|
2293
|
+
if (f.provider && t.provider !== f.provider) return false
|
|
2294
|
+
if (f.works && skip !== 'works') {
|
|
2295
|
+
const r = TRIES[keyOf(t)]
|
|
2296
|
+
const tested = r && !r.going
|
|
2297
|
+
if (f.works === 'works' ? !(tested && r.ok) : f.works === 'fails' ? !(tested && !r.ok) : f.works === 'untested' ? tested : outcome(r) !== f.works) return false
|
|
2298
|
+
}
|
|
2299
|
+
if (f.context && !((COLS.context.get(t) ?? 0) >= f.context)) return false
|
|
2300
|
+
const c = can(t)
|
|
2301
|
+
if ((f.tools && !c.tools) || (f.thinking && !c.thinking) || (f.images && !c.images)) return false
|
|
2302
|
+
if (f.free && !(t.price?.input === 0 && t.price?.output === 0)) return false
|
|
2303
|
+
return true
|
|
2304
|
+
}
|
|
2305
|
+
const setFilter = (change) => {
|
|
2306
|
+
FILTER = { ...FILTER, ...change }
|
|
2307
|
+
if ('text' in change && filterBar) filterBar.querySelector('.f-text').value = FILTER.text
|
|
2308
|
+
savePref('filters', FILTER)
|
|
2309
|
+
drawMine(S)
|
|
2310
|
+
}
|
|
2311
|
+
const RESULT_NAME = (w) => (w === 'works' ? '✓ works' : w === 'fails' ? "✗ doesn't work" : w === 'untested' ? 'not tested' : `✗ ${w}`)
|
|
2312
|
+
const CONTEXTS = [[0, 'Any context'], [32_000, '32k+'], [128_000, '128k+'], [200_000, '200k+'], [1_000_000, '1M+']]
|
|
2313
|
+
// the active filters, as chips to take off one by one
|
|
2314
|
+
const filterChips = () => [
|
|
2315
|
+
FILTER.text && [`“${FILTER.text}”`, { text: '' }],
|
|
2316
|
+
FILTER.provider && [`Provider: ${FILTER.provider}`, { provider: '' }],
|
|
2317
|
+
FILTER.works && [`Result: ${RESULT_NAME(FILTER.works)}`, { works: '' }],
|
|
2318
|
+
FILTER.context && [`Context ${CONTEXTS.find(([v]) => v === FILTER.context)?.[1] ?? FILTER.context}`, { context: 0 }],
|
|
2319
|
+
FILTER.tools && ['Tools', { tools: false }],
|
|
2320
|
+
FILTER.thinking && ['Thinking', { thinking: false }],
|
|
2321
|
+
FILTER.images && ['Images', { images: false }],
|
|
2322
|
+
FILTER.free && ['Free', { free: false }],
|
|
2323
|
+
].filter(Boolean)
|
|
2324
|
+
const clearView = () => {
|
|
2325
|
+
SORT = []
|
|
2326
|
+
savePref('sorts', SORT)
|
|
2327
|
+
setFilter({ ...NO_FILTER })
|
|
2328
|
+
}
|
|
2329
|
+
// The filter controls: made once (typing in the search isn't interrupted by the table being drawn
|
|
2330
|
+
// again), brought up to date each time
|
|
2331
|
+
let filterBar = null
|
|
2332
|
+
function filterBarOf(order, counts = {}) {
|
|
2333
|
+
if (!filterBar) {
|
|
2334
|
+
let typing = 0
|
|
2335
|
+
const toggle = (key, label, about) => h('label', { className: 'f-tog', title: about }, h('input', { type: 'checkbox', 'data-f': key, onchange: (e) => setFilter({ [key]: e.target.checked }) }), label)
|
|
2336
|
+
filterBar = h('div', { className: 'mt-filters' },
|
|
2337
|
+
h('label', { className: 'f-search' },
|
|
2338
|
+
h('span', { className: 'f-icon', 'aria-hidden': 'true', textContent: '⌕' }),
|
|
2339
|
+
h('input', { type: 'search', className: 'f-text', placeholder: 'Search models', 'aria-label': 'Search models and providers', oninput: (e) => (clearTimeout(typing), (typing = setTimeout(() => ((FILTER = { ...FILTER, text: e.target.value.trim() }), savePref('filters', FILTER), drawMine(S)), 150))) })),
|
|
2340
|
+
h('select', { className: 'f-provider', 'aria-label': 'Filter by provider', onchange: (e) => setFilter({ provider: e.target.value }) }),
|
|
2341
|
+
h('select', { className: 'f-works', 'aria-label': 'Filter by test result', onchange: (e) => setFilter({ works: e.target.value }) }),
|
|
2342
|
+
h('select', { className: 'f-context', 'aria-label': 'Filter by context window', onchange: (e) => setFilter({ context: Number(e.target.value) }) },
|
|
2343
|
+
CONTEXTS.map(([v, l]) => h('option', { value: v, textContent: v ? `Context ${l}` : l }))),
|
|
2344
|
+
h('span', { className: 'f-togs' },
|
|
2345
|
+
toggle('tools', 'Tools', 'only models that call tools'),
|
|
2346
|
+
toggle('thinking', 'Thinking', 'only models that think'),
|
|
2347
|
+
toggle('images', 'Images', 'only models that see images'),
|
|
2348
|
+
toggle('free', 'Free', 'only models that cost nothing, in and out')))
|
|
2349
|
+
}
|
|
2350
|
+
const bar = filterBar
|
|
2351
|
+
const focused = (el) => document.activeElement === el
|
|
2352
|
+
const providers = [...new Set(order.map((t) => t.provider))].sort(byName)
|
|
2353
|
+
const results = [...new Set(order.map((t) => outcome(TRIES[keyOf(t)])).filter((o) => o && o !== 'works'))].sort(byName)
|
|
2354
|
+
const fill = (sel, opts, value) => {
|
|
2355
|
+
const sig = JSON.stringify(opts)
|
|
2356
|
+
if (sel.dataset.sig !== sig && !focused(sel)) (sel.dataset.sig = sig), put(sel, opts.map(([v, l]) => h('option', { value: v, textContent: l })))
|
|
2357
|
+
if (!focused(sel)) sel.value = String(value)
|
|
2358
|
+
}
|
|
2359
|
+
fill(bar.querySelector('.f-provider'), [['', 'All providers'], ...providers.map((p) => [p, p])], FILTER.provider)
|
|
2360
|
+
const c = (k) => (counts[k] ? ` (${counts[k].toLocaleString()})` : ' (0)')
|
|
2361
|
+
fill(bar.querySelector('.f-works'), [['', 'Any result'], ['works', `✓ Works${c('works')}`], ['fails', `✗ Doesn't work${c('fails')}`], ['untested', `Not tested${c('untested')}`], ...results.map((o) => [o, ` ✗ ${o}${c(o)}`])], FILTER.works)
|
|
2362
|
+
if (!focused(bar.querySelector('.f-context'))) bar.querySelector('.f-context').value = String(FILTER.context)
|
|
2363
|
+
const text = bar.querySelector('.f-text')
|
|
2364
|
+
if (!focused(text) && text.value.trim() !== FILTER.text) text.value = FILTER.text
|
|
2365
|
+
for (const box of bar.querySelectorAll('input[data-f]')) box.checked = Boolean(FILTER[box.dataset.f])
|
|
2366
|
+
for (const sel of bar.querySelectorAll('select')) sel.classList.toggle('on', Boolean(FILTER[{ 'f-provider': 'provider', 'f-works': 'works', 'f-context': 'context' }[sel.className.split(' ')[0]]]))
|
|
2367
|
+
return bar
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2046
2370
|
// The models ticked on the Your models page ("provider/model"), to remove several at once; the last
|
|
2047
2371
|
// one ticked, so a Shift+click ticks the ones between
|
|
2048
2372
|
const PICKED = new Set()
|
|
2049
2373
|
let lastPicked = null
|
|
2374
|
+
|
|
2050
2375
|
function drawMine(s) {
|
|
2051
2376
|
const order = shownOrder() // a provider switched off: its models aren't shown (nor tested, sorted, ranked)
|
|
2052
2377
|
$('n-mine').textContent = order.length || ''
|
|
2053
|
-
const
|
|
2378
|
+
const shown = filtering() ? order.filter((t) => passes(t)) : order
|
|
2379
|
+
const view = sorted(shown)
|
|
2380
|
+
const filtered = shown.length !== order.length
|
|
2054
2381
|
for (const k of PICKED) if (placeOf(...k.split(/\/(.*)/s)) === undefined) PICKED.delete(k) // gone from the list
|
|
2055
|
-
const
|
|
2056
|
-
const rest = order.filter((t) => !PICKED.has(keyOf(t)))
|
|
2057
|
-
const n = order.length - rest.length
|
|
2058
|
-
if (!confirm(`Take ${n} model${n === 1 ? '' : 's'} off your list?${!rest.length ? ' None is left then: HeartCode has no model to use until you choose one.' : rest[0] !== order[0] ? ` HeartCode then uses ${rest[0].provider} · ${rest[0].model}.` : ''} (They stay under their providers.)`)) return
|
|
2059
|
-
PICKED.clear()
|
|
2060
|
-
saveOrder(withOff(rest), `${n} removed${rest.length ? '' : ': no model chosen now'}`)
|
|
2061
|
-
}
|
|
2062
|
-
const all = view.length > 0 && view.every((t) => PICKED.has(keyOf(t)))
|
|
2063
|
-
// the tests' results, by outcome: a click selects those models (again: unselects them)
|
|
2064
|
-
const outcomes = Map.groupBy(order.filter((t) => outcome(TRIES[keyOf(t)])), (t) => outcome(TRIES[keyOf(t)]))
|
|
2065
|
-
const byOutcome = [...outcomes].sort(([a, x], [b, y]) => (b === 'works') - (a === 'works') || y.length - x.length).map(([what, models]) => {
|
|
2066
|
-
const on = models.every((t) => PICKED.has(keyOf(t)))
|
|
2067
|
-
const n = models.length
|
|
2068
|
-
return h('span', { className: 'pill' + (what === 'works' ? ' ok' : ' bad') + (on ? ' on' : '') },
|
|
2069
|
-
h('button', { type: 'button', className: 'pick', title: `${MEANS[what] ?? `the provider answered ${what}`}\n${on ? 'Unselect' : 'Select'} the ${n} model${n === 1 ? '' : 's'}`, onclick: () => (models.forEach((t) => (on ? PICKED.delete(keyOf(t)) : PICKED.add(keyOf(t)))), drawMine(S)) },
|
|
2070
|
-
h('span', { className: 'what', textContent: what === 'works' ? '✓ works' : `✗ ${what}` }), h('span', { className: 'n', textContent: n.toLocaleString() })),
|
|
2071
|
-
what === 'works' ? null : h('button', { type: 'button', className: 'again', textContent: '↻', title: `Test these ${n} again`, 'aria-label': `test the ${what} ones again`, disabled: testingAll, onclick: () => tryAll(models) }))
|
|
2072
|
-
})
|
|
2382
|
+
const n = (x) => x.toLocaleString()
|
|
2073
2383
|
|
|
2384
|
+
// --- what you do to the list ---
|
|
2074
2385
|
// the order you see, saved as yours; the sort then goes (your own order from here on: drag on)
|
|
2075
2386
|
const keep = (list, moved) => {
|
|
2076
2387
|
SORT = []
|
|
2077
2388
|
savePref('sorts', SORT)
|
|
2078
|
-
return saveOrder(withOff(list), list[0] !== order[0] ? `${moved ? '' : '
|
|
2389
|
+
return saveOrder(withOff(list), list[0] !== order[0] ? `${moved ? '' : 'list saved: '}HeartCode now uses ${list[0].provider} · ${list[0].model}` : 'list saved')
|
|
2079
2390
|
}
|
|
2080
|
-
// a row dragged (in the order shown, sorted or not)
|
|
2391
|
+
// a row dragged (in the order shown, sorted or not). Filtered: it moves among the ones shown; the
|
|
2392
|
+
// hidden ones keep their places (the shown ones fill their own places in the new order)
|
|
2081
2393
|
const move = (i, j) => {
|
|
2082
2394
|
if (i === j) return
|
|
2083
2395
|
const list = [...view]
|
|
2084
2396
|
const [t] = list.splice(i, 1)
|
|
2085
2397
|
list.splice(j, 0, t)
|
|
2086
|
-
return keep(list, true)
|
|
2398
|
+
if (!filtered) return keep(list, true)
|
|
2399
|
+
const mine = new Set(list)
|
|
2400
|
+
const slots = order.map((x, k) => (mine.has(x) ? k : -1)).filter((k) => k >= 0)
|
|
2401
|
+
const all = [...order]
|
|
2402
|
+
slots.forEach((k, m) => (all[k] = list[m]))
|
|
2403
|
+
return keep(all, true)
|
|
2404
|
+
}
|
|
2405
|
+
// Save list: the models HeartCode uses become the ones shown, in the order shown. Filtered: only
|
|
2406
|
+
// those (asked first; the others stay under Providers, to add back any time)
|
|
2407
|
+
const saveList = () => {
|
|
2408
|
+
if (filtered && !confirm(`HeartCode will use only these ${n(view.length)}, in this order.\n\nThe other ${n(order.length - view.length)} stay under Providers: add any back whenever you like.`)) return
|
|
2409
|
+
return keep(view)
|
|
2087
2410
|
}
|
|
2088
|
-
const
|
|
2411
|
+
const removePicked = () => {
|
|
2412
|
+
const rest = order.filter((t) => !PICKED.has(keyOf(t)))
|
|
2413
|
+
const k = order.length - rest.length
|
|
2414
|
+
if (!confirm(`Take ${k} model${k === 1 ? '' : 's'} off your list?${!rest.length ? ' None is left then: HeartCode has no model to use until you choose one.' : rest[0] !== order[0] ? ` HeartCode then uses ${rest[0].provider} · ${rest[0].model}.` : ''} (They stay under their providers.)`)) return
|
|
2415
|
+
PICKED.clear()
|
|
2416
|
+
saveOrder(withOff(rest), `${k} removed${rest.length ? '' : ': no model chosen now'}`)
|
|
2417
|
+
}
|
|
2418
|
+
const pickedList = order.filter((t) => PICKED.has(keyOf(t)))
|
|
2419
|
+
|
|
2420
|
+
// --- the page's header, right: what's known about the models ---
|
|
2421
|
+
put($('mt-actions'),
|
|
2422
|
+
h('button', { className: 'small', textContent: 'Provider ranking', disabled: !order.some((t) => t.provider !== order[0]?.provider), title: 'drag your providers into order; the Provider column sorts by it', onclick: openRanking }),
|
|
2423
|
+
h('button', { className: 'small', textContent: 'Refresh from models.dev', disabled: !order.length, title: 'ask models.dev again what each model can do: context, tools, thinking, images, price', onclick: () => lookUp() }))
|
|
2424
|
+
|
|
2425
|
+
// --- the list's settings: three cells across, a label over each control ---
|
|
2426
|
+
const ro = s.rotation
|
|
2427
|
+
const cell = (label, about, ...control) => h('label', { className: 'mt-set', title: about }, h('span', { className: 'mt-setl', textContent: label }), h('span', { className: 'mt-setc' }, ...control))
|
|
2428
|
+
const settings = h('div', { className: 'mt-sets' },
|
|
2429
|
+
cell('When a model fails', ro.on === 'retries' ? 'a rate limit or outage: that model is tried again that many times first; any other error moves on at once' : "any error moves on at once, to another provider's model first",
|
|
2430
|
+
h('select', { onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
|
|
2431
|
+
[['failure', 'the next one answers'], ['retries', 'try it again first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
|
|
2432
|
+
ro.on === 'retries' ? h('input', { type: 'number', className: 'tries', 'aria-label': 'tries', title: 'tries of the same model first (rate limits, outages)', min: 1, max: 20, value: ro.retries, onchange: (e) => saveOrder(S.order, 'saved', { retries: Number(e.target.value) }) }) : null),
|
|
2433
|
+
cell('A new message starts with', 'the model a new message goes to first',
|
|
2434
|
+
h('select', { onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
|
|
2435
|
+
[['first', '#1'], ['stay', 'the last that answered']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.next === v })))),
|
|
2436
|
+
cell('A test waits for an answer', 'every model test: Test, Test all, Request',
|
|
2437
|
+
h('input', { type: 'number', min: 1, max: 600, step: 1, value: S.settings.testTimeout ?? 10, 'aria-label': 'Test timeout in seconds', onchange: (e) => {
|
|
2438
|
+
const v = Math.round(Number(e.target.value))
|
|
2439
|
+
if (!(v >= 1 && v <= 600)) return (e.target.value = S.settings.testTimeout ?? 10), toast('a whole number of seconds, 1 to 600', true)
|
|
2440
|
+
act('/api/setting', { name: 'testTimeout', value: v }, `tests wait ${v} second${v === 1 ? '' : 's'} for an answer`)
|
|
2441
|
+
} }), h('span', { className: 'unit', textContent: 'seconds' })))
|
|
2442
|
+
|
|
2443
|
+
// --- under the filters: what's shown (left) · what you do with it (right) ---
|
|
2444
|
+
const chip = (label, off, cls = '') => h('span', { className: 'chip ' + cls }, label, h('button', { type: 'button', textContent: '✕', 'aria-label': `remove ${label}`, onclick: off }))
|
|
2445
|
+
const line = h('div', { className: 'mt-line' },
|
|
2446
|
+
h('div', { className: 'mt-status' },
|
|
2447
|
+
h('span', { className: 'count' }, filtered ? [h('b', { textContent: n(shown.length) }), ` of ${n(order.length)} shown`] : [h('b', { textContent: n(order.length) }), ` model${order.length === 1 ? '' : 's'}, in your order`]),
|
|
2448
|
+
...filterChips().map(([label, off]) => chip(label, () => setFilter(off))),
|
|
2449
|
+
...SORT.map(({ key, dir }, k) => chip(`${SORT.length > 1 ? `${k + 1}. ` : 'Sorted: '}${COLS[key].label} ${COLS[key].words[dir === 'up' ? 0 : 1]}`, () => setSort(SORT.filter((x) => x.key !== key)), 'sort')),
|
|
2450
|
+
testingAll && SORT.some((x) => x.key === 'works') ? h('span', { className: 'sort-live', textContent: 'tests running: the order moves as results come in' }) : null,
|
|
2451
|
+
filtering() || SORT.length ? h('button', { className: 'small ghost', textContent: 'Clear all', title: 'every filter and the sort off: your whole list, in your order', onclick: clearView }) : null),
|
|
2452
|
+
h('div', { className: 'mt-do' },
|
|
2453
|
+
h('button', { className: 'small', textContent: filtered ? `Test ${n(shown.length)} shown` : 'Test all', disabled: testingAll || !shown.length, title: `send ${filtered ? 'the models shown' : 'each model'} a short message to see which really answer`, onclick: () => tryAll(filtered ? shown : order) }),
|
|
2454
|
+
h('button', { className: 'small primary', textContent: filtered ? `Use these ${n(view.length)}` : 'Save list', disabled: !view.length || order.length < 2, title: filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : 'save the list in the order shown (#1 first)', onclick: saveList })))
|
|
2455
|
+
|
|
2456
|
+
// --- the table ---
|
|
2457
|
+
const all = view.length > 0 && view.every((t) => PICKED.has(keyOf(t)))
|
|
2458
|
+
const head = (key, align) => {
|
|
2089
2459
|
const at = SORT.findIndex((x) => x.key === key)
|
|
2090
|
-
return h('button', { type: 'button', className: (at >= 0 ? 'on ' : '') + (
|
|
2091
|
-
COLS[key].label, at >= 0 ? ` ${SORT[at].dir === 'up' ? '↑' : '↓'}${SORT.length > 1 ? at + 1 : ''}` : '')
|
|
2460
|
+
return h('button', { type: 'button', className: (at >= 0 ? 'on ' : '') + (align || ''), title: `sort by ${COLS[key].label.toLowerCase()} (after the ones already sorted by) · click again: reversed · again: off`, onclick: (e) => clickSort(key, e.currentTarget) },
|
|
2461
|
+
COLS[key].label, at >= 0 ? h('span', { className: 'dir', textContent: ` ${SORT[at].dir === 'up' ? '↑' : '↓'}${SORT.length > 1 ? at + 1 : ''}` }) : '')
|
|
2092
2462
|
}
|
|
2093
|
-
const
|
|
2463
|
+
const selectAll = h('input', { type: 'checkbox', checked: all, indeterminate: PICKED.size > 0 && !all, title: all ? 'select none' : 'select all shown', 'aria-label': 'select all shown', onchange: () => (all ? PICKED.clear() : view.forEach((t) => PICKED.add(keyOf(t))), (lastPicked = null), drawMine(S)) })
|
|
2464
|
+
// the columns' names; with models selected, what to do with them instead (the checkbox stays)
|
|
2465
|
+
const header = PICKED.size
|
|
2466
|
+
? h('div', { className: 'mt-h mt-hpick' }, h('span'), selectAll,
|
|
2467
|
+
h('div', { className: 'mt-pickbar' },
|
|
2468
|
+
h('b', { textContent: `${n(PICKED.size)} selected` }),
|
|
2469
|
+
h('button', { className: 'small', textContent: 'Test', disabled: testingAll, onclick: () => tryAll(pickedList) }),
|
|
2470
|
+
h('button', { className: 'small danger', textContent: 'Remove', onclick: removePicked }),
|
|
2471
|
+
h('button', { className: 'small ghost', textContent: 'Invert', title: "select the ones shown that aren't selected, unselect the ones that are", onclick: () => (view.forEach((t) => (PICKED.has(keyOf(t)) ? PICKED.delete(keyOf(t)) : PICKED.add(keyOf(t)))), (lastPicked = null), drawMine(S)) }),
|
|
2472
|
+
h('button', { className: 'small ghost', textContent: 'Select none', onclick: () => (PICKED.clear(), drawMine(S)) })))
|
|
2473
|
+
: h('div', { className: 'mt mt-h' }, h('span'), selectAll,
|
|
2474
|
+
h('span', { textContent: '#', title: 'its place in your list' }), head('model'), head('provider'), head('context', 'num'), head('tools', 'mid'), head('thinking', 'mid'), head('images', 'mid'), head('price', 'num'), head('works'), h('span', { className: 'num', textContent: '' }))
|
|
2475
|
+
const table = view.length ? h('ol', { className: 'mtable' + (view.length < 2 ? '' : ' drag') }) : null
|
|
2094
2476
|
// ticked or not; with Shift, every row from the last one ticked to this one
|
|
2095
2477
|
const pick = (i, e) => {
|
|
2096
2478
|
const on = !PICKED.has(keyOf(view[i]))
|
|
@@ -2102,54 +2484,41 @@ function drawMine(s) {
|
|
|
2102
2484
|
}
|
|
2103
2485
|
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 })
|
|
2104
2486
|
if (tableV) tableV.items = view.length
|
|
2487
|
+
// typing in a filter: the box is put back in the redrawn page, still with the focus and the caret
|
|
2488
|
+
const typing = filterBar?.contains(document.activeElement) ? document.activeElement : null
|
|
2489
|
+
const caret = typing?.selectionStart ?? null
|
|
2490
|
+
const empty = (text, ...more) => h('div', { className: 'mt-empty' }, text, ...more)
|
|
2491
|
+
// the counts of each test result, for the Result filter (with the other filters as they are)
|
|
2492
|
+
const counted = order.filter((t) => passes(t, 'works'))
|
|
2493
|
+
const results = { works: 0, fails: 0, untested: 0 }
|
|
2494
|
+
for (const t of counted) {
|
|
2495
|
+
const o = outcome(TRIES[keyOf(t)])
|
|
2496
|
+
if (!o) results.untested++
|
|
2497
|
+
else if (o === 'works') results.works++
|
|
2498
|
+
else (results.fails++, (results[o] = (results[o] ?? 0) + 1))
|
|
2499
|
+
}
|
|
2105
2500
|
put($('mt'),
|
|
2106
|
-
|
|
2107
|
-
h('div', { className: 'sorts' }, SORT.length
|
|
2108
|
-
? ['Sorted by ', SORT.map(({ key, dir }, k) => h('span', { className: 'chip' }, `${k + 1}. ${COLS[key].label}: ${dirText(key, dir)}`, h('button', { type: 'button', textContent: '✕', 'aria-label': `stop sorting by ${COLS[key].label}`, onclick: () => setSort(SORT.filter((x) => x.key !== key)) })))]
|
|
2109
|
-
: order.length > 1 ? 'Your order: #1 first, the next when one fails.' : '',
|
|
2110
|
-
testingAll && SORT.some((x) => x.key === 'works') ? h('span', { className: 'sort-live' }, ' · tests still running: the order moves as their results come in') : null),
|
|
2111
|
-
PICKED.size ? h('button', { className: 'small danger', textContent: `Remove ${PICKED.size} selected`, onclick: removePicked }) : null,
|
|
2112
|
-
PICKED.size ? h('button', { className: 'small', textContent: `Test ${PICKED.size} selected`, disabled: testingAll, onclick: () => tryAll(order.filter((t) => PICKED.has(keyOf(t)))) }) : null,
|
|
2113
|
-
PICKED.size ? h('button', { className: 'small', textContent: 'Clear selection', onclick: () => (PICKED.clear(), drawMine(S)) }) : null,
|
|
2114
|
-
PICKED.size ? h('button', { className: 'small', textContent: 'Invert selection', title: 'tick the ones not ticked, untick the ones ticked', onclick: () => (view.forEach((t) => (PICKED.has(keyOf(t)) ? PICKED.delete(keyOf(t)) : PICKED.add(keyOf(t)))), (lastPicked = null), drawMine(S)) }) : null,
|
|
2115
|
-
order.some((t) => t.provider !== order[0].provider) ? h('button', { className: 'small', textContent: 'Provider ranking', title: 'drag your providers into order; the Provider column sorts by it', onclick: openRanking }) : null,
|
|
2116
|
-
SORT.length ? h('button', { className: 'small', textContent: 'Clear sort', onclick: () => setSort([]) }) : null,
|
|
2117
|
-
order.length > 1 ? h('button', { className: 'small primary', textContent: 'Save order', title: 'save the order shown as your model order (#1 first)', onclick: () => keep(view) }) : null,
|
|
2118
|
-
order.length ? h('button', { className: 'small', textContent: 'Refresh from models.dev', title: 'ask models.dev again what each model can do: context, tools, thinking, images, price', onclick: () => lookUp() }) : null,
|
|
2119
|
-
order.length ? h('button', { className: 'small', textContent: 'Test all', disabled: testingAll, title: 'send each a short message to see which really answer: every provider at once, a few from each (one at a time per 100 models)', onclick: () => tryAll(order) }) : null,
|
|
2120
|
-
// how long a test waits for an answer (every model test: Test all, a row's Test and Hello)
|
|
2121
|
-
order.length ? h('label', { className: 'test-wait', title: 'how long a model test waits for its answer before it counts as failed' }, 'Timeout',
|
|
2122
|
-
h('input', { type: 'number', min: 1, max: 600, step: 1, value: S.settings.testTimeout ?? 10, 'aria-label': 'Test timeout in seconds', onchange: (e) => {
|
|
2123
|
-
const v = Math.round(Number(e.target.value))
|
|
2124
|
-
if (!(v >= 1 && v <= 600)) return (e.target.value = S.settings.testTimeout ?? 10), toast('a whole number of seconds, 1 to 600', true)
|
|
2125
|
-
act('/api/setting', { name: 'testTimeout', value: v }, `tests wait ${v} second${v === 1 ? '' : 's'} for an answer`)
|
|
2126
|
-
} }), 's') : null),
|
|
2127
|
-
// when the one in use fails, and what a new message starts with
|
|
2128
|
-
order.length > 1 ? h('div', { className: 'mt-rules' },
|
|
2129
|
-
h('span', { className: 'rule' },
|
|
2130
|
-
h('label', { for: 'r-on', textContent: 'When a model fails, go on to the next' }),
|
|
2131
|
-
h('select', { id: 'r-on', onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
|
|
2132
|
-
[['failure', 'at its first failure'], ['retries', 'after some tries of the same model']].map(([v, t]) => h('option', { value: v, textContent: t, selected: s.rotation.on === v }))),
|
|
2133
|
-
s.rotation.on === 'retries' ? h('input', { type: 'number', 'aria-label': 'tries', title: 'tries of the same model first (rate limits, outages)', min: 1, max: 20, value: s.rotation.retries, onchange: (e) => saveOrder(S.order, 'saved', { retries: Number(e.target.value) }) }) : null),
|
|
2134
|
-
h('span', { className: 'rule' },
|
|
2135
|
-
h('label', { for: 'r-next', textContent: 'A new message starts with' }),
|
|
2136
|
-
h('select', { id: 'r-next', onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
|
|
2137
|
-
[['first', '#1 again'], ['stay', 'the model that answered last']].map(([v, t]) => h('option', { value: v, textContent: t, selected: s.rotation.next === v })))),
|
|
2138
|
-
h('span', { className: 'hint', textContent: s.rotation.on === 'retries' ? 'A rate limit or outage: that model is tried again that many times first; any other error moves on at once.' : "Any error moves on at once, to another provider's model first." })) : null,
|
|
2501
|
+
order.length > 1 ? settings : null,
|
|
2139
2502
|
order.length
|
|
2140
|
-
? h('div', { className: 'mt-
|
|
2503
|
+
? h('div', { className: 'mt-tools' },
|
|
2504
|
+
filterBarOf(order, results),
|
|
2505
|
+
line,
|
|
2141
2506
|
(tableJobs ??= jobSlot('table')), // the same one every time: its Stop button isn't replaced under the mouse
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
table))
|
|
2147
|
-
:
|
|
2507
|
+
view.length ? h('div', { className: 'mt-hwrap' }, header) : null)
|
|
2508
|
+
: null,
|
|
2509
|
+
order.length
|
|
2510
|
+
? h('div', { className: 'mt-scroll', onscroll: (e) => { const hw = e.target.closest('.card')?.querySelector('.mt-hwrap'); if (hw) hw.scrollLeft = e.target.scrollLeft } }, h('div', { className: 'mt' },
|
|
2511
|
+
table ?? empty('No model matches these filters. ', h('button', { type: 'button', className: 'small', textContent: 'Clear all', onclick: clearView }))))
|
|
2512
|
+
: empty('No models in your list yet. ', h('a', { href: '#providers', textContent: 'Choose some under Providers' }), '.'))
|
|
2513
|
+
if (typing && document.activeElement !== typing) {
|
|
2514
|
+
typing.focus({ preventScroll: true })
|
|
2515
|
+
if (caret !== null && typing.setSelectionRange) typing.setSelectionRange(caret, caret)
|
|
2516
|
+
}
|
|
2148
2517
|
tableV?.draw()
|
|
2149
2518
|
sortable(tableV, move)
|
|
2150
2519
|
}
|
|
2151
2520
|
// the table's cells: yes or no; where what it can do comes from
|
|
2152
|
-
const yes = (v) => h('span', { className: v ? 'yes' : 'no', textContent: v ? '✓' : '–' })
|
|
2521
|
+
const yes = (v) => h('span', { className: (v ? 'yes' : 'no') + ' mid', textContent: v ? '✓' : '–' })
|
|
2153
2522
|
const src = (t) => {
|
|
2154
2523
|
const x = t.tested
|
|
2155
2524
|
if (!x) return h('div', { className: 'src', textContent: 'looking it up…' })
|
|
@@ -2157,24 +2526,33 @@ const src = (t) => {
|
|
|
2157
2526
|
return h('div', { className: 'src' }, Object.keys(x.set ?? {}).length ? 'set by you' : x.source === 'models.dev' ? 'models.dev' : FROM[x.source], h('button', { className: 'small', textContent: 'Edit', onclick: () => openSetup(t) }))
|
|
2158
2527
|
}
|
|
2159
2528
|
// a row of the table: one model of your list, in the order shown (at: its place in your order)
|
|
2529
|
+
const money = (x) => (x == null ? '–' : x === 0 ? '$0' : usd(x))
|
|
2530
|
+
const priceOf = (t) => (t.price?.input == null && t.price?.output == null ? '–' : t.price.input === 0 && t.price.output === 0 ? 'free' : `${money(t.price.input)} / ${money(t.price.output)}`)
|
|
2160
2531
|
function tableRow(t, at, pick) {
|
|
2161
2532
|
const c = can(t)
|
|
2162
2533
|
const ctx = COLS.context.get(t)
|
|
2163
2534
|
const picked = PICKED.has(keyOf(t))
|
|
2535
|
+
const x = t.tested
|
|
2536
|
+
// where what it can do comes from, when that's worth a look: not known to models.dev (a guess), or set by you
|
|
2537
|
+
const tag = !x ? h('span', { className: 'tag', textContent: '…', title: 'looking it up in models.dev' })
|
|
2538
|
+
: x.source === 'assumed' ? h('button', { type: 'button', className: 'tag warn', textContent: 'unknown', title: "models.dev doesn't know it: what it can do is a guess. Click to set it up", onclick: () => openSetup(t) })
|
|
2539
|
+
: Object.keys(x.set ?? {}).length ? h('button', { type: 'button', className: 'tag', textContent: 'edited', title: 'what it can do: set by you (click to change)', onclick: () => openSetup(t) }) : null
|
|
2540
|
+
const going = Boolean(TRIES[keyOf(t)]?.going)
|
|
2164
2541
|
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` : '' },
|
|
2165
2542
|
h('span', { className: 'grip', textContent: '⋮⋮', 'aria-hidden': 'true' }),
|
|
2166
2543
|
h('input', { type: 'checkbox', checked: picked, 'aria-label': `select ${t.model}`, title: 'select (Shift: and every row up to the last one selected)', onclick: (e) => (e.preventDefault(), pick(e)) }),
|
|
2167
|
-
h('span', { className: 'n', textContent: `#${at + 1}`, title: SORT.length ? 'its place in your
|
|
2168
|
-
h('span', { className: 'm', textContent: t.model, title: t.model }),
|
|
2544
|
+
h('span', { className: 'n', textContent: `#${at + 1}`, title: SORT.length || filtering() ? 'its place in your list' : '' }),
|
|
2545
|
+
h('span', { className: 'm' }, h('span', { className: 'name', textContent: t.model, title: t.model }), tag),
|
|
2169
2546
|
h('span', { className: 'p', textContent: isOff(t.provider) ? `${t.provider} · off` : t.provider, title: t.provider }),
|
|
2170
|
-
h('span', { className: 'num', textContent: ctx ? `${t.tested?.sure === false ? '~' : ''}${kTok(ctx)}` : '–' }),
|
|
2171
|
-
h('span', { className: 'num', textContent: `${Object.values(c).filter(Boolean).length} of 3` }),
|
|
2547
|
+
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)' : ''}` : '' }),
|
|
2172
2548
|
yes(c.tools), yes(c.thinking), yes(c.images),
|
|
2173
|
-
h('span', { className: 'num', textContent: t.price
|
|
2174
|
-
h('span', { className: 'num', textContent: t.price?.output != null ? usd(t.price.output) : '–' }),
|
|
2175
|
-
src(t),
|
|
2549
|
+
h('span', { className: 'num price', textContent: priceOf(t), title: t.price ? `in ${money(t.price.input)} · out ${money(t.price.output)} per million tokens` : 'price not known' }),
|
|
2176
2550
|
triedCell(t),
|
|
2177
|
-
h('
|
|
2551
|
+
h('span', { className: 'acts' },
|
|
2552
|
+
h('button', { type: 'button', className: 'small ghost ib k-test row-test', disabled: going, title: going ? 'testing…' : 'Test: send it a short message to see that it really answers', 'aria-label': `test ${t.model}`, onclick: () => tryModel(t) }, ic(going ? 'clock' : 'play')),
|
|
2553
|
+
h('button', { type: 'button', className: 'small ghost ib k-info', title: 'Request: send it "Hello" and see exactly what was sent and what came back', 'aria-label': `raw request to ${t.model}`, onclick: () => hello(t.provider, t.model) }, ic('eye')),
|
|
2554
|
+
h('button', { type: 'button', className: 'small ghost ib k-edit', title: 'Edit what it can do: context, tool calls, thinking, images (or look it up in models.dev again)', 'aria-label': `edit ${t.model}`, onclick: () => openSetup(t) }, ic('pencil')),
|
|
2555
|
+
h('button', { type: 'button', className: 'small ghost ib k-del', title: 'Remove it from your list (it stays under its provider)', 'aria-label': `remove ${t.model}`, onclick: () => removeMine(t.provider, t.model) }, ic('trash'))))
|
|
2178
2556
|
}
|
|
2179
2557
|
|
|
2180
2558
|
// your list changed: the rows and counts it touches, in place
|
|
@@ -2354,6 +2732,7 @@ function drawNotify(s) {
|
|
|
2354
2732
|
h('button', { className: 'ghost', type: 'button', textContent: 'Disconnect', onclick: () => confirm('Stop sending notifications to Telegram and forget the bot token?') && act('/api/telegram/remove', {}, 'Telegram disconnected') })))
|
|
2355
2733
|
}
|
|
2356
2734
|
put($('tg-events'), Object.entries(t.names ?? {}).map(([k, label]) => h('label', { className: 'opt' + (t.connected ? '' : ' tg-off') },
|
|
2735
|
+
tile(...({ done: ['check', 'green'], failed: ['x', 'red'], waiting: ['clock', 'amber'] }[k] ?? ['bell', 'amber'])),
|
|
2357
2736
|
h('div', { className: 't' }, h('b', { textContent: label }), h('span', { textContent: TG_EVENT_INFO[k] ?? '' })),
|
|
2358
2737
|
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'}`) }))))
|
|
2359
2738
|
}
|
|
@@ -2536,7 +2915,8 @@ $('c-cancel').onclick = () => $('c-form').close()
|
|
|
2536
2915
|
function drawMcp(s) {
|
|
2537
2916
|
const authTag = (a) => (a === 'in' ? h('span', { className: 'tag ok', textContent: 'signed in' }) : h('span', { className: 'tag need', textContent: 'sign-in needed' }))
|
|
2538
2917
|
put($('c-list'), h('h2', { textContent: 'Servers' }), h('p', { className: 'sub', textContent: 'Built in, and yours. Remote ones (a URL) may need signing in; local ones don\'t. Switch one off to keep it without using it.' }),
|
|
2539
|
-
s.mcp.length ? s.mcp.map((m) => h('div', { className: 'opt' },
|
|
2918
|
+
s.mcp.length ? s.mcp.map((m) => h('div', { className: 'opt mcp-row' },
|
|
2919
|
+
tile(m.remote ? 'globe' : m.name.includes('chrome') || m.name.includes('browser') ? 'globe' : m.name.includes('computer') ? 'cpu' : 'plug', m.on ? 'teal' : 'gray'),
|
|
2540
2920
|
h('div', { className: 't' }, h('b', {}, m.name, ' ', h('span', { className: 'tag', textContent: m.from }), m.remote ? authTag(m.auth) : null), m.description ? h('span', { textContent: m.description }) : null, h('div', { className: 'mono muted', style: 'word-break:break-all;margin-top:3px', textContent: m.what })),
|
|
2541
2921
|
m.remote ? h('button', { className: 'small', textContent: m.auth === 'in' ? 'Sign in again' : 'Sign in', onclick: () => act('/api/mcp/login', { name: m.name }, `signed in to ${m.name}`) }) : null,
|
|
2542
2922
|
m.from === 'yours' ? h('button', { className: 'small danger', textContent: 'Remove', onclick: () => confirm(`Remove the MCP server ${m.name}?`) && act('/api/mcp/remove', { name: m.name }, `removed ${m.name}`) }) : null,
|
|
@@ -2810,8 +3190,11 @@ function render(s) {
|
|
|
2810
3190
|
FOLDED.clear()
|
|
2811
3191
|
for (const n of Array.isArray(p.folded) ? p.folded : []) FOLDED.add(n)
|
|
2812
3192
|
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
|
|
2813
|
-
|
|
3193
|
+
// the sort and filters: taken in once; after that the page's own are the latest (a state from the
|
|
3194
|
+
// server can be older than a change made here a moment ago)
|
|
3195
|
+
if (!filtersLoaded) SORT = Array.isArray(p.sorts) ? p.sorts.filter((x) => COLS[x?.key]) : Array.isArray(p.sort) ? p.sort.filter((x) => COLS[x?.key]).map(flip) : []
|
|
2814
3196
|
RANK = Array.isArray(p.rank) ? p.rank.filter((x) => typeof x === 'string') : []
|
|
3197
|
+
if (!filtersLoaded) (filtersLoaded = true), (FILTER = { ...NO_FILTER, ...(p.filters && typeof p.filters === 'object' ? p.filters : {}) }) // after that the page's own are the latest
|
|
2815
3198
|
}
|
|
2816
3199
|
S = s
|
|
2817
3200
|
for (const [key, r] of Object.entries(TRIES)) if (!r.going && placeOf(...key.split(/\/(.*)/s)) === undefined) delete TRIES[key] // off your list: its result too
|
package/src/settings.js
CHANGED
|
@@ -127,7 +127,7 @@ const LIST_V = 2 // how a saved list was read (2: airforce's cents, Cloudflare's
|
|
|
127
127
|
// The page's own choices (sorts, folded providers, the provider ranking): kept here, not in the
|
|
128
128
|
// browser, whose storage is per address (a new port each time)
|
|
129
129
|
const PREFS = path.join(HOME, 'settings-page.json')
|
|
130
|
-
const PREF_KEYS = ['catSort', 'freeOnly', 'folded', 'sort', 'sorts', 'rank']
|
|
130
|
+
const PREF_KEYS = ['catSort', 'freeOnly', 'folded', 'sort', 'sorts', 'rank', 'filters']
|
|
131
131
|
function forgetList(...names) {
|
|
132
132
|
const all = readJson(LISTS, {})
|
|
133
133
|
if (!names.some((n) => n in all)) return
|
|
@@ -145,7 +145,9 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
145
145
|
log('web', `applying ${what}: ${e.stack}`)
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
// a file this page's server writes itself: its watcher (below) needn't look at it again
|
|
149
|
+
let ownWrite = 0
|
|
150
|
+
const save = (what) => ((ownWrite = Date.now()), saveConfig(cfg), changed(what))
|
|
149
151
|
|
|
150
152
|
// the page listens (GET /api/events): a model's profile as it changes, a request as it's logged
|
|
151
153
|
const listeners = new Set()
|
|
@@ -385,8 +387,8 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
385
387
|
'GET /api/log-size': () => logSize(),
|
|
386
388
|
'POST /api/prefs': ({ key, value }) => {
|
|
387
389
|
if (!PREF_KEYS.includes(key)) throw new Error(`no such choice: ${key}`)
|
|
390
|
+
ownWrite = Date.now() // the page's own choice: not sent back to it as a change (a second redraw)
|
|
388
391
|
writeJson(PREFS, { ...readJson(PREFS, {}), [key]: value })
|
|
389
|
-
shown = JSON.stringify(state()) // the page's own choice: not sent back to it as a change (a second redraw)
|
|
390
392
|
return {}
|
|
391
393
|
},
|
|
392
394
|
'POST /api/clear-logs': () => ({ gone: clearLogs(), size: logSize() }),
|
|
@@ -533,6 +535,7 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
533
535
|
const changed1 = cfg.provider !== clean[0]?.provider || cfg.model !== clean[0]?.model
|
|
534
536
|
Object.assign(cfg, { provider: clean[0]?.provider, model: clean[0]?.model })
|
|
535
537
|
cfg.rotation = { on: opts.on, retries: opts.retries, next: opts.next, then: clean.slice(1) }
|
|
538
|
+
ownWrite = Date.now()
|
|
536
539
|
saveConfig(cfg)
|
|
537
540
|
changed(changed1 ? 'model' : 'setting:rotation')
|
|
538
541
|
test(clean)
|
|
@@ -887,6 +890,7 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
|
|
|
887
890
|
try {
|
|
888
891
|
const w = fs.watch(HOME, { recursive: true }, (_, f) => {
|
|
889
892
|
if (!SETTINGS_FILES.includes(String(f ?? '').split(path.sep)[0])) return
|
|
893
|
+
if (Date.now() - ownWrite < 1000 && ['config.json', 'settings-page.json'].includes(String(f))) return // written here a moment ago: the page has it
|
|
890
894
|
clearTimeout(pending)
|
|
891
895
|
pending = setTimeout(pushState, 150) // a file written in parts, several at once: one look
|
|
892
896
|
})
|
package/src/ui.js
CHANGED
|
@@ -1132,7 +1132,7 @@ export class UI {
|
|
|
1132
1132
|
for (const [i, l] of this.ahead.slice(0, 5).entries()) bottom.push(fit(` ${c.accent(`${i + 1}.`)} ${c.muted(l.replace(/\s+/g, ' '))}`, cols))
|
|
1133
1133
|
if (this.ahead.length > 5) bottom.push(c.faint(` … ${this.ahead.length - 5} more`))
|
|
1134
1134
|
}
|
|
1135
|
-
if (this.noticeText) bottom.push(fit(`${c.warn(
|
|
1135
|
+
if (this.noticeText) bottom.push(fit(this.noticeMark ? `${c.warn(this.noticeMark)} ${c.muted(this.noticeText)}` : ` ${c.muted(this.noticeText)}`, cols))
|
|
1136
1136
|
if (menu.on && !asked) bottom.push(...this.#menuLines(cols))
|
|
1137
1137
|
bottom.push(first ? note(first, '↑') : rule)
|
|
1138
1138
|
const head = [...(this.tabBar?.(cols) ?? []), ...(this.header?.(cols) ?? [])].map((l) => fit(l, cols))
|
|
@@ -1464,14 +1464,27 @@ export class UI {
|
|
|
1464
1464
|
write('\r', { name: 'return' })
|
|
1465
1465
|
}
|
|
1466
1466
|
|
|
1467
|
-
//
|
|
1468
|
-
|
|
1467
|
+
// Voice: listening at once; the words go where the cursor is, in the box (also while it works), and
|
|
1468
|
+
// on Enter they're sent: at the prompt as if Enter was pressed, while it works as a message typed
|
|
1469
|
+
// then (a command that can run beside the task runs; the rest waits in the queue).
|
|
1470
|
+
async dictateIn(send = true) {
|
|
1469
1471
|
const text = await this.dictate()
|
|
1470
1472
|
if (!text) return
|
|
1471
1473
|
const rl = this.rl
|
|
1472
1474
|
const pad = rl.line && !/\s$/.test(rl.line.slice(0, rl.cursor)) ? ' ' : ''
|
|
1473
1475
|
rl.line = rl.line.slice(0, rl.cursor) + pad + text + rl.line.slice(rl.cursor)
|
|
1474
1476
|
rl.cursor += pad.length + text.length
|
|
1477
|
+
if (!send) return this.render()
|
|
1478
|
+
if (this.asking && this.histOn) {
|
|
1479
|
+
this.sent = rl.line
|
|
1480
|
+
this.menu.items = []
|
|
1481
|
+
return this.ttyWrite('\r', { name: 'return' })
|
|
1482
|
+
}
|
|
1483
|
+
if (this.asking) return this.render() // a question's answer: in its box, to check and send
|
|
1484
|
+
const line = rl.line.trim()
|
|
1485
|
+
rl.line = ''
|
|
1486
|
+
rl.cursor = 0
|
|
1487
|
+
if (line && !this.onNow?.(line)) this.ahead.push(line)
|
|
1475
1488
|
this.render()
|
|
1476
1489
|
}
|
|
1477
1490
|
|
|
@@ -1514,9 +1527,9 @@ export class UI {
|
|
|
1514
1527
|
}
|
|
1515
1528
|
const draw = () => {
|
|
1516
1529
|
showBox()
|
|
1517
|
-
const keys = 'Enter to
|
|
1518
|
-
if (finishing) return this.notice('transcribing…', 60 * 60_000)
|
|
1519
|
-
this.notice(mic ?
|
|
1530
|
+
const keys = 'Enter to send · Esc to cancel'
|
|
1531
|
+
if (finishing) return this.notice('transcribing the last part… (Esc cancels)', 60 * 60_000, '')
|
|
1532
|
+
this.notice(mic ? `${c.red('●')} listening ${Math.floor(mic.seconds())}s · Space to pause · ${keys}` : `paused · Space to go on · ${keys}`, 60 * 60_000, '')
|
|
1520
1533
|
}
|
|
1521
1534
|
const heard = (pcm, fast) =>
|
|
1522
1535
|
transcribePcm(pcm, voice, providers, { fast }).catch((e) => {
|
|
@@ -1552,9 +1565,9 @@ export class UI {
|
|
|
1552
1565
|
draw()
|
|
1553
1566
|
})
|
|
1554
1567
|
}
|
|
1555
|
-
|
|
1568
|
+
start() // listening at once: the key that got here was the go-ahead
|
|
1556
1569
|
const tick = setInterval(() => mic && draw(), 1000)
|
|
1557
|
-
|
|
1570
|
+
let go = await new Promise((resolve) => {
|
|
1558
1571
|
this.recording = {
|
|
1559
1572
|
key: (key, bound) => {
|
|
1560
1573
|
if (key.name === 'escape') resolve(false)
|
|
@@ -1564,10 +1577,12 @@ export class UI {
|
|
|
1564
1577
|
}
|
|
1565
1578
|
})
|
|
1566
1579
|
clearInterval(tick)
|
|
1567
|
-
|
|
1580
|
+
// the last part being transcribed: keys still wait (an Enter now would send half of it); Esc cancels
|
|
1581
|
+
this.recording = { key: (key) => key.name === 'escape' && (go = false) }
|
|
1568
1582
|
if (!go) mic?.cancel(), (mic = null)
|
|
1569
1583
|
else if (mic) (finishing = true), pause()
|
|
1570
1584
|
await busy
|
|
1585
|
+
this.recording = null
|
|
1571
1586
|
if (rl) [rl.line, rl.cursor] = [base.line, base.cursor] // the caller puts the words in
|
|
1572
1587
|
const text = go ? words().trim() : ''
|
|
1573
1588
|
log('voice', go ? text : '(cancelled)')
|
|
@@ -1644,8 +1659,10 @@ export class UI {
|
|
|
1644
1659
|
|
|
1645
1660
|
// initial: text already typed in, ready to edit. suggest: show the suggestion menu while typing.
|
|
1646
1661
|
// A one-line message just above the input until `ms` pass or a key is pressed ('' hides it).
|
|
1647
|
-
|
|
1662
|
+
// mark: what goes before it ('!' a warning; '' none, for a state like voice listening)
|
|
1663
|
+
notice(text, ms = 2000, mark = '!') {
|
|
1648
1664
|
this.noticeText = text
|
|
1665
|
+
this.noticeMark = mark
|
|
1649
1666
|
clearTimeout(this.noticeTimer)
|
|
1650
1667
|
if (text) this.noticeTimer = setTimeout(() => this.notice(''), ms)
|
|
1651
1668
|
this.render()
|