athanor 1.1.0 → 1.3.0
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/README.md +24 -7
- package/dist/app/models.d.ts +11 -3
- package/dist/app/models.d.ts.map +1 -1
- package/dist/app/models.js +83 -4
- package/dist/app/models.js.map +1 -1
- package/dist/app/preflight.d.ts +12 -0
- package/dist/app/preflight.d.ts.map +1 -0
- package/dist/app/preflight.js +18 -0
- package/dist/app/preflight.js.map +1 -0
- package/dist/cli/model-commands.d.ts.map +1 -1
- package/dist/cli/model-commands.js +80 -7
- package/dist/cli/model-commands.js.map +1 -1
- package/dist/control/server.js +1 -1
- package/dist/control/server.js.map +1 -1
- package/dist/discovery/scanner.d.ts +3 -0
- package/dist/discovery/scanner.d.ts.map +1 -1
- package/dist/discovery/scanner.js +66 -3
- package/dist/discovery/scanner.js.map +1 -1
- package/dist/index.js +36 -6
- package/dist/index.js.map +1 -1
- package/dist/machine/profile.d.ts +7 -0
- package/dist/machine/profile.d.ts.map +1 -0
- package/dist/machine/profile.js +25 -0
- package/dist/machine/profile.js.map +1 -0
- package/dist/pull/api.d.ts +18 -0
- package/dist/pull/api.d.ts.map +1 -1
- package/dist/pull/api.js +55 -1
- package/dist/pull/api.js.map +1 -1
- package/dist/pull/suggestions.d.ts +4 -0
- package/dist/pull/suggestions.d.ts.map +1 -1
- package/dist/pull/suggestions.js +15 -3
- package/dist/pull/suggestions.js.map +1 -1
- package/dist/registry/materialize.d.ts +7 -0
- package/dist/registry/materialize.d.ts.map +1 -1
- package/dist/registry/materialize.js +57 -2
- package/dist/registry/materialize.js.map +1 -1
- package/dist/registry/recommend.d.ts +16 -0
- package/dist/registry/recommend.d.ts.map +1 -0
- package/dist/registry/recommend.js +104 -0
- package/dist/registry/recommend.js.map +1 -0
- package/dist/registry/sort.d.ts +2 -0
- package/dist/registry/sort.d.ts.map +1 -1
- package/dist/registry/sort.js +12 -2
- package/dist/registry/sort.js.map +1 -1
- package/dist/router/lifecycle.d.ts +5 -0
- package/dist/router/lifecycle.d.ts.map +1 -0
- package/dist/router/lifecycle.js +79 -0
- package/dist/router/lifecycle.js.map +1 -0
- package/dist/search/cache.d.ts +4 -0
- package/dist/search/cache.d.ts.map +1 -0
- package/dist/search/cache.js +50 -0
- package/dist/search/cache.js.map +1 -0
- package/dist/search/hf.d.ts +18 -0
- package/dist/search/hf.d.ts.map +1 -1
- package/dist/search/hf.js +153 -13
- package/dist/search/hf.js.map +1 -1
- package/dist/supervisor/state.d.ts +9 -0
- package/dist/supervisor/state.d.ts.map +1 -1
- package/dist/supervisor/state.js +28 -8
- package/dist/supervisor/state.js.map +1 -1
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/ui/App.d.ts.map +1 -1
- package/dist/ui/App.js +82 -32
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/Banner.d.ts +3 -0
- package/dist/ui/Banner.d.ts.map +1 -1
- package/dist/ui/Banner.js +19 -2
- package/dist/ui/Banner.js.map +1 -1
- package/dist/ui/ConfirmModal.d.ts +12 -0
- package/dist/ui/ConfirmModal.d.ts.map +1 -0
- package/dist/ui/ConfirmModal.js +130 -0
- package/dist/ui/ConfirmModal.js.map +1 -0
- package/dist/ui/DownloadsModal.d.ts +18 -0
- package/dist/ui/DownloadsModal.d.ts.map +1 -0
- package/dist/ui/DownloadsModal.js +103 -0
- package/dist/ui/DownloadsModal.js.map +1 -0
- package/dist/ui/LogFocus.d.ts.map +1 -1
- package/dist/ui/LogFocus.js +4 -1
- package/dist/ui/LogFocus.js.map +1 -1
- package/dist/ui/LogTail.d.ts +1 -0
- package/dist/ui/LogTail.d.ts.map +1 -1
- package/dist/ui/LogTail.js +2 -2
- package/dist/ui/LogTail.js.map +1 -1
- package/dist/ui/ModelList.d.ts +2 -0
- package/dist/ui/ModelList.d.ts.map +1 -1
- package/dist/ui/ModelList.js +39 -23
- package/dist/ui/ModelList.js.map +1 -1
- package/dist/ui/PresetEditor.d.ts +1 -0
- package/dist/ui/PresetEditor.d.ts.map +1 -1
- package/dist/ui/PresetEditor.js +17 -14
- package/dist/ui/PresetEditor.js.map +1 -1
- package/dist/ui/SearchBrowser.d.ts +5 -0
- package/dist/ui/SearchBrowser.d.ts.map +1 -1
- package/dist/ui/SearchBrowser.js +304 -49
- package/dist/ui/SearchBrowser.js.map +1 -1
- package/dist/ui/Suggestions.d.ts.map +1 -1
- package/dist/ui/Suggestions.js +2 -1
- package/dist/ui/Suggestions.js.map +1 -1
- package/dist/ui/useAppData.d.ts.map +1 -1
- package/dist/ui/useAppData.js +10 -7
- package/dist/ui/useAppData.js.map +1 -1
- package/dist/ui/useAppInput.d.ts +1 -1
- package/dist/ui/useAppInput.d.ts.map +1 -1
- package/dist/ui/useAppInput.js +7 -3
- package/dist/ui/useAppInput.js.map +1 -1
- package/dist/ui/useDownloads.d.ts +38 -0
- package/dist/ui/useDownloads.d.ts.map +1 -0
- package/dist/ui/useDownloads.js +131 -0
- package/dist/ui/useDownloads.js.map +1 -0
- package/dist/ui/useModelActions.d.ts.map +1 -1
- package/dist/ui/useModelActions.js +25 -12
- package/dist/ui/useModelActions.js.map +1 -1
- package/package.json +2 -1
package/dist/ui/SearchBrowser.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Box, Text, useApp, useInput, useStdin, useStdout } from "ink";
|
|
4
|
-
import { searchModelsPage, sortByKey } from "../search/hf.js";
|
|
4
|
+
import { enrichSelectionHint, searchModelsPage, sortByKey } from "../search/hf.js";
|
|
5
5
|
import { formatBytes, formatCount, formatRelTime } from "../search/format.js";
|
|
6
|
+
import { loadRepoHintCache, saveRepoHint } from "../search/cache.js";
|
|
7
|
+
import { fetchRepoTree } from "../pull/api.js";
|
|
8
|
+
import { DownloadsModal } from "./DownloadsModal.js";
|
|
6
9
|
import { PullModal } from "./PullModal.js";
|
|
10
|
+
import { useDownloads } from "./useDownloads.js";
|
|
7
11
|
const COLUMNS = [
|
|
12
|
+
{ key: "rt", width: 8, minCols: 52, sortKey: null, label: "rt" },
|
|
8
13
|
{ key: "size", width: 10, minCols: 38, sortKey: "size", label: "size" },
|
|
9
14
|
{ key: "dl", width: 9, minCols: 70, sortKey: "downloads", label: "dl ↓" },
|
|
10
15
|
{ key: "likes", width: 8, minCols: 88, sortKey: "likes", label: " ♥" },
|
|
@@ -12,10 +17,10 @@ const COLUMNS = [
|
|
|
12
17
|
{ key: "age", width: 12, minCols: 120, sortKey: "modified", label: "updated" }
|
|
13
18
|
];
|
|
14
19
|
function columnLayout(cols) {
|
|
15
|
-
// Cursor (2) +
|
|
20
|
+
// Cursor (2) + id + rights…
|
|
16
21
|
const active = COLUMNS.filter(c => cols >= c.minCols);
|
|
17
22
|
const rightWidth = active.reduce((a, c) => a + c.width, 0);
|
|
18
|
-
const idStart =
|
|
23
|
+
const idStart = 2;
|
|
19
24
|
const idWidth = Math.max(8, cols - idStart - rightWidth);
|
|
20
25
|
const idEnd = idStart + idWidth;
|
|
21
26
|
const right = [];
|
|
@@ -26,6 +31,66 @@ function columnLayout(cols) {
|
|
|
26
31
|
}
|
|
27
32
|
return { idStart, idEnd, idWidth, right };
|
|
28
33
|
}
|
|
34
|
+
function SearchDetailsModal({ result, hint, width, selectedFileIdx, machineMemBytes }) {
|
|
35
|
+
const runtime = runtimeBadge(result);
|
|
36
|
+
const isGguf = result.runtime === "llama.cpp";
|
|
37
|
+
const bodyLines = [
|
|
38
|
+
{ label: "runtime", value: runtime.label, color: runtime.color },
|
|
39
|
+
{ label: "size", value: result.sizeBytes !== undefined ? formatBytes(result.sizeBytes) : "—" },
|
|
40
|
+
{ label: "downloads", value: formatCount(result.downloads) },
|
|
41
|
+
{ label: "likes", value: formatCount(result.likes) },
|
|
42
|
+
{ label: "updated", value: formatRelTime(result.lastModified) },
|
|
43
|
+
{ label: "license", value: result.license ?? "—" }
|
|
44
|
+
];
|
|
45
|
+
const innerWidth = Math.max(24, width - 4);
|
|
46
|
+
const valueWidth = Math.max(16, innerWidth - 14);
|
|
47
|
+
const selectable = hint?.ggufSelectableCount;
|
|
48
|
+
const ggufSummary = !isGguf
|
|
49
|
+
? null
|
|
50
|
+
: !hint
|
|
51
|
+
? "Resolving GGUF files…"
|
|
52
|
+
: hint.defaultFile
|
|
53
|
+
? selectable && selectable > 1
|
|
54
|
+
? `Default: ${hint.defaultFile}${hint.defaultFileSizeBytes !== undefined ? ` · ${formatBytes(hint.defaultFileSizeBytes)}` : ""} · ${selectable} selectable files`
|
|
55
|
+
: `Selected: ${hint.defaultFile}${hint.defaultFileSizeBytes !== undefined ? ` · ${formatBytes(hint.defaultFileSizeBytes)}` : ""}`
|
|
56
|
+
: selectable && selectable > 0
|
|
57
|
+
? `${selectable} selectable GGUF files`
|
|
58
|
+
: "No GGUF file selected yet";
|
|
59
|
+
const candidates = hint?.ggufCandidates ?? [];
|
|
60
|
+
const clampedSelectedFileIdx = Math.max(0, Math.min(candidates.length - 1, selectedFileIdx));
|
|
61
|
+
const selectedFile = candidates[clampedSelectedFileIdx];
|
|
62
|
+
const selectedIsDefault = selectedFile?.name === hint?.defaultFile;
|
|
63
|
+
const selectedSizeBytes = selectedFile?.sizeBytes;
|
|
64
|
+
const effectiveFitSizeBytes = selectedSizeBytes ?? hint?.ggufTotalSizeBytes;
|
|
65
|
+
const comfortableBytes = machineMemBytes !== undefined ? Math.max(0, machineMemBytes - 8 * 1024 ** 3) : undefined;
|
|
66
|
+
const tightBytes = machineMemBytes !== undefined ? Math.max(0, machineMemBytes - 4 * 1024 ** 3) : undefined;
|
|
67
|
+
const fitHint = machineMemBytes === undefined || effectiveFitSizeBytes === undefined
|
|
68
|
+
? null
|
|
69
|
+
: effectiveFitSizeBytes <= comfortableBytes
|
|
70
|
+
? `comfortable on this Mac (${formatBytes(machineMemBytes)} unified memory)`
|
|
71
|
+
: effectiveFitSizeBytes <= tightBytes
|
|
72
|
+
? "might work, but could be tight on this Mac"
|
|
73
|
+
: "not recommended for this Mac";
|
|
74
|
+
return (_jsxs(Box, { flexDirection: "column", width: width, borderStyle: "round", borderColor: "cyan", padding: 1, backgroundColor: "black", children: [_jsx(Text, { bold: true, color: "cyan", backgroundColor: "black", children: "Model details" }), _jsx(Text, { color: "white", bold: true, wrap: "truncate-end", backgroundColor: "black", children: truncEnd(result.id, innerWidth) }), _jsx(Text, { backgroundColor: "black", children: " " }), bodyLines.map(line => (_jsxs(Box, { backgroundColor: "black", children: [_jsx(Text, { color: "cyan", backgroundColor: "black", children: `${line.label}:`.padEnd(13) }), _jsx(Text, { color: line.color, wrap: "truncate-end", backgroundColor: "black", children: truncEnd(line.value, valueWidth) })] }, line.label))), isGguf
|
|
75
|
+
? _jsxs(_Fragment, { children: [_jsx(Text, { backgroundColor: "black", children: " " }), _jsx(Text, { color: "yellow", bold: true, backgroundColor: "black", children: "GGUF selection" }), _jsx(Text, { wrap: "truncate-end", backgroundColor: "black", children: truncEnd(ggufSummary ?? "", innerWidth) }), (candidates.length > 1 || selectedFile)
|
|
76
|
+
? _jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, backgroundColor: "black", children: [_jsxs(Box, { justifyContent: "space-between", backgroundColor: "black", children: [_jsxs(Text, { color: "yellow", bold: true, backgroundColor: "black", children: ["Option ", Math.min(candidates.length, clampedSelectedFileIdx + 1), "/", Math.max(1, candidates.length)] }), _jsx(Text, { dimColor: true, backgroundColor: "black", children: selectedIsDefault ? "recommended" : "browse" })] }), _jsx(Text, { color: "cyan", bold: true, wrap: "truncate-end", backgroundColor: "black", children: truncEnd(selectedFile?.name ?? hint?.defaultFile ?? "—", innerWidth - 2) }), _jsxs(Box, { backgroundColor: "black", children: [_jsx(Text, { color: "yellow", backgroundColor: "black", children: "size: " }), _jsx(Text, { color: "white", bold: true, backgroundColor: "black", children: selectedFile?.sizeBytes !== undefined ? formatBytes(selectedFile.sizeBytes) : "unknown" }), selectedIsDefault ? _jsx(Text, { color: "green", backgroundColor: "black", children: " \u00B7 default" }) : null] }), (hint?.ggufArchitecture || hint?.ggufContextLength)
|
|
77
|
+
? _jsxs(Box, { backgroundColor: "black", children: [hint.ggufArchitecture ? _jsxs(_Fragment, { children: [_jsx(Text, { color: "yellow", backgroundColor: "black", children: "arch: " }), _jsx(Text, { backgroundColor: "black", children: hint.ggufArchitecture })] }) : null, hint.ggufContextLength ? _jsxs(_Fragment, { children: [_jsx(Text, { color: "yellow", backgroundColor: "black", children: " ctx: " }), _jsx(Text, { backgroundColor: "black", children: formatCount(hint.ggufContextLength) })] }) : null] })
|
|
78
|
+
: null, hint?.baseModel
|
|
79
|
+
? _jsxs(Box, { backgroundColor: "black", children: [_jsx(Text, { color: "yellow", backgroundColor: "black", children: "base: " }), _jsx(Text, { wrap: "truncate-end", backgroundColor: "black", children: truncEnd(hint.baseModel, innerWidth - 8) })] })
|
|
80
|
+
: null, fitHint
|
|
81
|
+
? _jsx(Text, { color: fitHint.startsWith("comfortable") ? "green" : fitHint.startsWith("might work") ? "yellow" : "red", wrap: "truncate-end", backgroundColor: "black", children: truncEnd(fitHint, innerWidth - 2) })
|
|
82
|
+
: null, candidates.length > 1
|
|
83
|
+
? _jsxs(Text, { dimColor: true, wrap: "truncate-end", backgroundColor: "black", children: [clampedSelectedFileIdx > 0 ? "↑ previous" : "↑ start", " \u00B7 ", clampedSelectedFileIdx < candidates.length - 1 ? "↓ next" : "↓ end"] })
|
|
84
|
+
: null] })
|
|
85
|
+
: null, hint?.ggufTotalSizeBytes !== undefined
|
|
86
|
+
? _jsxs(Box, { backgroundColor: "black", children: [_jsx(Text, { color: "yellow", backgroundColor: "black", children: "repo total: " }), _jsx(Text, { backgroundColor: "black", children: formatBytes(hint.ggufTotalSizeBytes) })] })
|
|
87
|
+
: null, candidates.length > 1
|
|
88
|
+
? _jsx(Text, { dimColor: true, wrap: "truncate-end", backgroundColor: "black", children: "\u2191\u2193/j/k choose option \u00B7 PgUp/PgDn jump \u00B7 Enter pull selected \u00B7 Esc close" })
|
|
89
|
+
: _jsxs(Text, { dimColor: true, wrap: "truncate-end", backgroundColor: "black", children: ["Press ", _jsx(Text, { color: "cyan", bold: true, backgroundColor: "black", children: "Enter" }), " to pull this repo", hint?.defaultFile ? " with the selected default file" : "", "."] })] })
|
|
90
|
+
: _jsxs(_Fragment, { children: [_jsx(Text, { backgroundColor: "black", children: " " }), _jsxs(Text, { dimColor: true, wrap: "truncate-end", backgroundColor: "black", children: ["Press ", _jsx(Text, { color: "cyan", bold: true, backgroundColor: "black", children: "Enter" }), " to pull this model now."] })] }), _jsx(Text, { backgroundColor: "black", children: " " }), _jsx(Text, { dimColor: true, wrap: "truncate", backgroundColor: "black", children: isGguf && candidates.length > 1
|
|
91
|
+
? "Enter pull · ↑↓/j/k choose option · PgUp/PgDn jump · Esc close · q quit search"
|
|
92
|
+
: "Enter pull · Esc close · q quit search" })] }));
|
|
93
|
+
}
|
|
29
94
|
const SORT_CYCLE = ["downloads", "likes", "trending", "modified", "size"];
|
|
30
95
|
const FILTER_CYCLE = ["any", "mlx", "gguf"];
|
|
31
96
|
function runtimeBadge(r) {
|
|
@@ -33,7 +98,7 @@ function runtimeBadge(r) {
|
|
|
33
98
|
return { label: "mlx", color: "magenta" };
|
|
34
99
|
if (r.runtime === "llama.cpp")
|
|
35
100
|
return { label: "gguf", color: "cyan" };
|
|
36
|
-
return { label: "
|
|
101
|
+
return { label: "other", color: "gray" };
|
|
37
102
|
}
|
|
38
103
|
function truncMid(s, max) {
|
|
39
104
|
if (s.length <= max)
|
|
@@ -44,10 +109,20 @@ function truncMid(s, max) {
|
|
|
44
109
|
const tail = Math.floor((max - 1) / 2);
|
|
45
110
|
return s.slice(0, head) + "…" + s.slice(s.length - tail);
|
|
46
111
|
}
|
|
112
|
+
function truncEnd(s, max) {
|
|
113
|
+
if (max <= 0)
|
|
114
|
+
return "";
|
|
115
|
+
if (s.length <= max)
|
|
116
|
+
return s;
|
|
117
|
+
if (max <= 1)
|
|
118
|
+
return s.slice(0, max);
|
|
119
|
+
return s.slice(0, max - 1) + "…";
|
|
120
|
+
}
|
|
47
121
|
function renderCell(r, key, width) {
|
|
48
122
|
// inner width = span width minus the 2-char gap before the value
|
|
49
123
|
const inner = width - 2;
|
|
50
124
|
switch (key) {
|
|
125
|
+
case "rt": return " " + runtimeBadge(r).label.padEnd(inner).slice(0, inner);
|
|
51
126
|
case "size": return " " + (r.sizeBytes !== undefined ? formatBytes(r.sizeBytes) : "—").padStart(inner);
|
|
52
127
|
case "dl": return " " + (formatCount(r.downloads) + "↓").padStart(inner);
|
|
53
128
|
case "likes": return " " + (formatCount(r.likes) + "♥").padStart(inner);
|
|
@@ -58,26 +133,28 @@ function renderCell(r, key, width) {
|
|
|
58
133
|
function renderHeaderCell(key, width, label) {
|
|
59
134
|
const inner = width - 2;
|
|
60
135
|
// Right-align for numeric columns, left-align for textual.
|
|
61
|
-
if (key === "lic" || key === "age")
|
|
136
|
+
if (key === "rt" || key === "lic" || key === "age")
|
|
62
137
|
return " " + label.padEnd(inner).slice(0, inner);
|
|
63
138
|
return " " + label.padStart(inner).slice(-inner);
|
|
64
139
|
}
|
|
65
140
|
// Renders a single result line. Column layout adapts to available
|
|
66
141
|
// width: narrow terminals drop optional columns rather than
|
|
67
142
|
// line-wrapping, so the list always fits in one row per entry.
|
|
68
|
-
function Row({ r, cols, layout, selected }) {
|
|
143
|
+
function Row({ r, cols, layout, selected, hint }) {
|
|
69
144
|
const badge = runtimeBadge(r);
|
|
145
|
+
const displayResult = hint?.defaultFileSizeBytes !== undefined || hint?.ggufTotalSizeBytes !== undefined
|
|
146
|
+
? { ...r, sizeBytes: hint.defaultFileSizeBytes ?? hint.ggufTotalSizeBytes }
|
|
147
|
+
: r;
|
|
70
148
|
const id = truncMid(r.id, layout.idWidth).padEnd(layout.idWidth);
|
|
71
|
-
const right = layout.right.map(s => renderCell(
|
|
72
|
-
const composed = `${selected ? "› " : " "}
|
|
149
|
+
const right = layout.right.map(s => renderCell(displayResult, s.key, s.end - s.start)).join("");
|
|
150
|
+
const composed = `${selected ? "› " : " "}${id}${right}`;
|
|
73
151
|
const padded = composed.length < cols ? composed + " ".repeat(cols - composed.length) : composed;
|
|
74
152
|
if (selected) {
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
return _jsx(Text, { inverse: true, children: padded });
|
|
153
|
+
// Keep the selected row's colors stable instead of inverting the
|
|
154
|
+
// full line, which can make dim metadata disappear on some themes.
|
|
155
|
+
return _jsx(Text, { backgroundColor: "gray", children: padded });
|
|
79
156
|
}
|
|
80
|
-
return (_jsxs(Box, { children: [_jsx(Text, { children: " " }),
|
|
157
|
+
return (_jsxs(Box, { children: [_jsx(Text, { children: selected ? "› " : " " }), _jsx(Text, { color: badge.color, children: id }), _jsx(Text, { dimColor: true, children: right })] }));
|
|
81
158
|
}
|
|
82
159
|
// Column header row with clickable sort targets. The current sort
|
|
83
160
|
// column is underlined; hovering/clicking is handled by the parent
|
|
@@ -90,7 +167,7 @@ function Header({ cols, layout, sort }) {
|
|
|
90
167
|
return _jsx(Text, { dimColor: !active, bold: active, underline: active, children: text }, s.key);
|
|
91
168
|
}), _jsx(Text, { dimColor: true, children: " ".repeat(Math.max(0, cols - (layout.right.at(-1)?.end ?? layout.idEnd))) })] }));
|
|
92
169
|
}
|
|
93
|
-
export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit, embedded }) => {
|
|
170
|
+
export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit, onQueueDownload, embedded, machineMemBytes }) => {
|
|
94
171
|
const { exit } = useApp();
|
|
95
172
|
const { stdout } = useStdout();
|
|
96
173
|
const { stdin, setRawMode, isRawModeSupported } = useStdin();
|
|
@@ -114,11 +191,15 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
114
191
|
const [error, setError] = useState(null);
|
|
115
192
|
const [selectedIdx, setSelectedIdx] = useState(0);
|
|
116
193
|
const [scrollOff, setScrollOff] = useState(0);
|
|
117
|
-
const [mode, setMode] = useState(
|
|
118
|
-
const [pickedRepo, setPickedRepo] = useState();
|
|
194
|
+
const [mode, setMode] = useState("browse");
|
|
119
195
|
// Transient status shown in the footer — currently used to confirm
|
|
120
196
|
// a completed or cancelled pull after returning to browse mode.
|
|
121
197
|
const [message, setMessage] = useState("");
|
|
198
|
+
const [manualPull, setManualPull] = useState(null);
|
|
199
|
+
const downloads = useDownloads(msg => setMessage(msg));
|
|
200
|
+
const [selectionHint, setSelectionHint] = useState(null);
|
|
201
|
+
const [selectionHintsById, setSelectionHintsById] = useState({});
|
|
202
|
+
const [selectedFileIdx, setSelectedFileIdx] = useState(0);
|
|
122
203
|
// Opaque next-page cursor. Undefined when results are exhausted or
|
|
123
204
|
// we haven't fetched yet (loading covers the latter).
|
|
124
205
|
const [cursor, setCursor] = useState();
|
|
@@ -139,6 +220,8 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
139
220
|
setError(null);
|
|
140
221
|
setResults([]);
|
|
141
222
|
setCursor(undefined);
|
|
223
|
+
setSelectionHint(null);
|
|
224
|
+
setSelectionHintsById(loadRepoHintCache());
|
|
142
225
|
cursorRef.current = undefined;
|
|
143
226
|
seenIdsRef.current = new Set();
|
|
144
227
|
searchModelsPage({ query, filter, sort })
|
|
@@ -201,11 +284,25 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
201
284
|
.catch(err => setError(err instanceof Error ? err.message : String(err)))
|
|
202
285
|
.finally(() => { loadingMoreRef.current = false; setLoadingMore(false); });
|
|
203
286
|
};
|
|
204
|
-
// Chrome row count: banner + query + divider + column-header +
|
|
205
|
-
// divider + footer = 6. visibleRows absorbs the rest.
|
|
206
|
-
const chromeRows = 6;
|
|
207
|
-
const visibleRows = Math.max(3, dims.rows - chromeRows);
|
|
208
287
|
const layout = useMemo(() => columnLayout(dims.cols), [dims.cols]);
|
|
288
|
+
const selected = results[selectedIdx];
|
|
289
|
+
const tail = loadingMore ? " · loading more…" :
|
|
290
|
+
cursor ? " · +more" :
|
|
291
|
+
results.length > 0 ? " · end" : "";
|
|
292
|
+
const countLine = loading ? "searching…" :
|
|
293
|
+
error ? `error: ${error}` :
|
|
294
|
+
results.length === 0 ? "no results" :
|
|
295
|
+
`${results.length} results · ${selectedIdx + 1}/${results.length}${tail}`;
|
|
296
|
+
const hintLine = selected?.runtime === "llama.cpp"
|
|
297
|
+
? selectionHint?.defaultFile
|
|
298
|
+
? `gguf default: ${selectionHint.defaultFile}${selectionHint.defaultFileSizeBytes !== undefined ? ` · ${formatBytes(selectionHint.defaultFileSizeBytes)}` : ""}${selectionHint.ggufSelectableCount !== undefined ? ` · ${selectionHint.ggufSelectableCount} selectable` : ""}`
|
|
299
|
+
: "gguf: resolving default file…"
|
|
300
|
+
: null;
|
|
301
|
+
const hintLineText = mode !== "inspect" && hintLine ? truncEnd(hintLine, dims.cols) : null;
|
|
302
|
+
// Fixed rows: title, query, top divider, header, bottom divider,
|
|
303
|
+
// key help footer. Optional hint/message lines live below that.
|
|
304
|
+
const chromeRows = 6 + (hintLineText ? 1 : 0) + (message ? 1 : 0);
|
|
305
|
+
const visibleRows = Math.max(3, dims.rows - chromeRows);
|
|
209
306
|
// y-coordinates (1-based, matching SGR mouse) for the two clickable
|
|
210
307
|
// regions. Used by the mouse handler to map a click to a sort column
|
|
211
308
|
// or a selection change.
|
|
@@ -232,6 +329,33 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
232
329
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
233
330
|
}, [selectedIdx, results.length, visibleRows, cursor, loadingMore, loading]);
|
|
234
331
|
const visible = useMemo(() => results.slice(scrollOff, scrollOff + visibleRows), [results, scrollOff, visibleRows]);
|
|
332
|
+
useEffect(() => {
|
|
333
|
+
let cancelled = false;
|
|
334
|
+
setSelectionHint(null);
|
|
335
|
+
setSelectedFileIdx(0);
|
|
336
|
+
if (!selected || selected.runtime !== "llama.cpp")
|
|
337
|
+
return;
|
|
338
|
+
const cached = selectionHintsById[selected.id];
|
|
339
|
+
if (cached) {
|
|
340
|
+
setSelectionHint(cached);
|
|
341
|
+
const defaultIdx = cached.ggufCandidates?.findIndex(c => c.name === cached.defaultFile) ?? -1;
|
|
342
|
+
setSelectedFileIdx(defaultIdx >= 0 ? defaultIdx : 0);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
void enrichSelectionHint(selected)
|
|
346
|
+
.then(hint => {
|
|
347
|
+
if (cancelled)
|
|
348
|
+
return;
|
|
349
|
+
setSelectionHint(hint);
|
|
350
|
+
saveRepoHint(selected.id, hint);
|
|
351
|
+
setSelectionHintsById(prev => prev[selected.id] ? prev : { ...prev, [selected.id]: hint });
|
|
352
|
+
const defaultIdx = hint.ggufCandidates?.findIndex(c => c.name === hint.defaultFile) ?? -1;
|
|
353
|
+
setSelectedFileIdx(defaultIdx >= 0 ? defaultIdx : 0);
|
|
354
|
+
})
|
|
355
|
+
.catch(() => { if (!cancelled)
|
|
356
|
+
setSelectionHint({ runtime: selected.runtime }); });
|
|
357
|
+
return () => { cancelled = true; };
|
|
358
|
+
}, [selected, selectionHintsById]);
|
|
235
359
|
// Refs let the mouse-data listener read current state without
|
|
236
360
|
// re-subscribing every render. Each ref mirrors a piece of state
|
|
237
361
|
// the SGR handler needs to translate x/y coordinates into actions.
|
|
@@ -241,6 +365,54 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
241
365
|
useEffect(() => { resultsRef.current = results; }, [results]);
|
|
242
366
|
const layoutRef = useRef(layout);
|
|
243
367
|
useEffect(() => { layoutRef.current = layout; }, [layout]);
|
|
368
|
+
useEffect(() => {
|
|
369
|
+
const targets = results.filter(r => {
|
|
370
|
+
if (selectionHintsById[r.id])
|
|
371
|
+
return false;
|
|
372
|
+
if (r.runtime === "llama.cpp")
|
|
373
|
+
return true;
|
|
374
|
+
if (r.runtime === "mlx" && r.sizeBytes === undefined)
|
|
375
|
+
return true;
|
|
376
|
+
return false;
|
|
377
|
+
});
|
|
378
|
+
if (targets.length === 0)
|
|
379
|
+
return;
|
|
380
|
+
let cancelled = false;
|
|
381
|
+
const limit = 4;
|
|
382
|
+
const batches = [];
|
|
383
|
+
for (let i = 0; i < targets.length; i += limit)
|
|
384
|
+
batches.push(targets.slice(i, i + limit));
|
|
385
|
+
void (async () => {
|
|
386
|
+
for (const batch of batches) {
|
|
387
|
+
const settled = await Promise.allSettled(batch.map(async (r) => {
|
|
388
|
+
if (r.runtime === "llama.cpp")
|
|
389
|
+
return { id: r.id, hint: await enrichSelectionHint(r) };
|
|
390
|
+
const tree = await fetchRepoTree(r.id);
|
|
391
|
+
const mlxSizeBytes = tree
|
|
392
|
+
.filter(entry => entry.type === "file" && entry.path.toLowerCase().endsWith(".safetensors"))
|
|
393
|
+
.reduce((sum, entry) => sum + (entry.lfs?.size ?? entry.size ?? 0), 0);
|
|
394
|
+
return { id: r.id, hint: { runtime: "mlx", ggufTotalSizeBytes: mlxSizeBytes > 0 ? mlxSizeBytes : undefined } };
|
|
395
|
+
}));
|
|
396
|
+
if (cancelled)
|
|
397
|
+
return;
|
|
398
|
+
setSelectionHintsById(prev => {
|
|
399
|
+
const next = { ...prev };
|
|
400
|
+
let changed = false;
|
|
401
|
+
for (const item of settled) {
|
|
402
|
+
if (item.status !== "fulfilled")
|
|
403
|
+
continue;
|
|
404
|
+
if (next[item.value.id])
|
|
405
|
+
continue;
|
|
406
|
+
saveRepoHint(item.value.id, item.value.hint);
|
|
407
|
+
next[item.value.id] = item.value.hint;
|
|
408
|
+
changed = true;
|
|
409
|
+
}
|
|
410
|
+
return changed ? next : prev;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
})();
|
|
414
|
+
return () => { cancelled = true; };
|
|
415
|
+
}, [results, selectionHintsById]);
|
|
244
416
|
const scrollRef = useRef(scrollOff);
|
|
245
417
|
useEffect(() => { scrollRef.current = scrollOff; }, [scrollOff]);
|
|
246
418
|
const visibleRowsRef = useRef(visibleRows);
|
|
@@ -329,8 +501,6 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
329
501
|
};
|
|
330
502
|
}, [stdin, stdout, setRawMode, isRawModeSupported, embedded]);
|
|
331
503
|
useInput((input, key) => {
|
|
332
|
-
if (mode === "pull")
|
|
333
|
-
return;
|
|
334
504
|
// Mouse sequences arrive as stdin data; Ink may synthesize a lone
|
|
335
505
|
// `escape` from the leading ESC byte. Suppress any useInput fired
|
|
336
506
|
// within a short window of a mouse event, and any chunk that
|
|
@@ -340,10 +510,17 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
340
510
|
if (input.indexOf("[<") >= 0 || input.indexOf("\x1b[<") >= 0)
|
|
341
511
|
return;
|
|
342
512
|
if (key.escape) {
|
|
343
|
-
if (mode === "
|
|
513
|
+
if (mode === "inspect") {
|
|
344
514
|
setMode("browse");
|
|
345
515
|
return;
|
|
346
516
|
}
|
|
517
|
+
if (mode === "edit") {
|
|
518
|
+
setMode("browse");
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
if (input === "q") {
|
|
347
524
|
onExit();
|
|
348
525
|
if (!embedded)
|
|
349
526
|
exit();
|
|
@@ -354,6 +531,10 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
354
531
|
setMode("browse");
|
|
355
532
|
return;
|
|
356
533
|
}
|
|
534
|
+
if (key.downArrow) {
|
|
535
|
+
setMode("browse");
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
357
538
|
if (key.backspace || key.delete) {
|
|
358
539
|
setQuery(q => q.slice(0, -1));
|
|
359
540
|
return;
|
|
@@ -362,6 +543,49 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
362
543
|
setQuery(q => q + input);
|
|
363
544
|
return;
|
|
364
545
|
}
|
|
546
|
+
if (mode === "inspect") {
|
|
547
|
+
const r = results[selectedIdx];
|
|
548
|
+
if (!r)
|
|
549
|
+
return;
|
|
550
|
+
const candidateCount = selectionHint?.ggufCandidates?.length ?? 0;
|
|
551
|
+
const chosenFile = r.runtime === "llama.cpp"
|
|
552
|
+
? (selectionHint?.ggufCandidates?.[selectedFileIdx]?.name ?? selectionHint?.defaultFile)
|
|
553
|
+
: undefined;
|
|
554
|
+
const canChooseFile = r.runtime === "llama.cpp" && candidateCount > 1;
|
|
555
|
+
if ((key.upArrow || input === "k") && canChooseFile) {
|
|
556
|
+
setSelectedFileIdx(i => Math.max(0, i - 1));
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if ((key.downArrow || input === "j") && canChooseFile) {
|
|
560
|
+
setSelectedFileIdx(i => Math.min(candidateCount - 1, i + 1));
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (key.pageUp && canChooseFile) {
|
|
564
|
+
setSelectedFileIdx(i => Math.max(0, i - 5));
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (key.pageDown && canChooseFile) {
|
|
568
|
+
setSelectedFileIdx(i => Math.min(candidateCount - 1, i + 5));
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (input === "f" && r.runtime === "llama.cpp") {
|
|
572
|
+
setManualPull({ repo: r.id, file: chosenFile ?? "" });
|
|
573
|
+
setMode("manual-pull");
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if (input === "p" || key.return) {
|
|
577
|
+
if (onQueueDownload) {
|
|
578
|
+
onQueueDownload({ repo: r.id, file: chosenFile });
|
|
579
|
+
setMessage(`queued ${r.id}${chosenFile ? ` · ${chosenFile}` : ""}`);
|
|
580
|
+
setMode("browse");
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
downloads.queueDownload({ repo: r.id, file: chosenFile });
|
|
584
|
+
setMode("downloads");
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
365
589
|
// browse mode
|
|
366
590
|
if (input === "/" || input === "i") {
|
|
367
591
|
setMode("edit");
|
|
@@ -375,6 +599,20 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
375
599
|
setSort(s => SORT_CYCLE[(SORT_CYCLE.indexOf(s) + 1) % SORT_CYCLE.length]);
|
|
376
600
|
return;
|
|
377
601
|
}
|
|
602
|
+
if (input === "p") {
|
|
603
|
+
const r = results[selectedIdx];
|
|
604
|
+
if (!r)
|
|
605
|
+
return;
|
|
606
|
+
if (onQueueDownload) {
|
|
607
|
+
onQueueDownload({ repo: r.id, file: r.runtime === "llama.cpp" ? selectionHint?.defaultFile : undefined });
|
|
608
|
+
setMessage(`queued ${r.id}`);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
downloads.queueDownload({ repo: r.id, file: r.runtime === "llama.cpp" ? selectionHint?.defaultFile : undefined });
|
|
612
|
+
setMode("downloads");
|
|
613
|
+
}
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
378
616
|
if (key.upArrow) {
|
|
379
617
|
setSelectedIdx(i => Math.max(0, i - 1));
|
|
380
618
|
return;
|
|
@@ -400,34 +638,51 @@ export const SearchBrowser = ({ initialQuery, initialFilter, initialSort, onExit
|
|
|
400
638
|
return;
|
|
401
639
|
}
|
|
402
640
|
if (key.return) {
|
|
403
|
-
|
|
404
|
-
if (!r)
|
|
641
|
+
if (!results[selectedIdx])
|
|
405
642
|
return;
|
|
406
|
-
|
|
407
|
-
setMode("pull");
|
|
643
|
+
setMode("inspect");
|
|
408
644
|
}
|
|
409
645
|
});
|
|
410
|
-
if (mode === "pull"
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
646
|
+
if (mode === "manual-pull") {
|
|
647
|
+
return _jsx(PullModal, { initialRepo: manualPull?.repo, initialFile: manualPull?.file, onDone: msg => {
|
|
648
|
+
const needsFile = msg.startsWith("pull failed: Multiple GGUF files in ");
|
|
649
|
+
setMessage(msg);
|
|
650
|
+
if (needsFile) {
|
|
651
|
+
setManualPull(prev => ({ repo: prev?.repo, file: "" }));
|
|
652
|
+
setMode("manual-pull");
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
setManualPull(null);
|
|
656
|
+
setMode("browse");
|
|
657
|
+
}, onCancel: () => {
|
|
658
|
+
setManualPull(null);
|
|
659
|
+
setMode("browse");
|
|
660
|
+
} });
|
|
416
661
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
662
|
+
const downloadsModalWidth = Math.max(72, Math.min(104, dims.cols - 8));
|
|
663
|
+
const downloadsModalHeight = 24;
|
|
664
|
+
const downloadsLeft = Math.max(0, Math.floor((dims.cols - downloadsModalWidth) / 2));
|
|
665
|
+
const downloadsTop = Math.max(0, Math.floor((dims.rows - downloadsModalHeight) / 2));
|
|
666
|
+
const helpLine = truncEnd(mode === "edit"
|
|
667
|
+
? "type query · ⏎ search · esc back · q quit"
|
|
668
|
+
: mode === "inspect"
|
|
669
|
+
? (selected?.runtime === "llama.cpp" && (selectionHint?.ggufCandidates?.length ?? 0) > 1
|
|
670
|
+
? "⏎ pull · ↑↓/j/k choose option · PgUp/PgDn jump · esc close · q quit"
|
|
671
|
+
: "⏎ pull · esc close · q quit")
|
|
672
|
+
: "↑↓ · ⏎ details · p pull · click header to sort · / edit · f filter · s sort · esc back · q quit", Math.max(0, dims.cols - 3 - countLine.length));
|
|
673
|
+
const footerLine = truncEnd(`${helpLine} · ${countLine}`, dims.cols);
|
|
674
|
+
const modalWidth = Math.max(64, Math.min(88, dims.cols - 10));
|
|
675
|
+
const modalHeight = selected?.runtime === "llama.cpp"
|
|
676
|
+
? ((selectionHint?.ggufCandidates?.length ?? 0) > 1 ? 22 : 19)
|
|
677
|
+
: 13;
|
|
678
|
+
const modalLeft = Math.max(0, Math.floor((dims.cols - modalWidth) / 2));
|
|
679
|
+
const modalTop = Math.max(0, Math.floor((dims.rows - modalHeight) / 2) - 2);
|
|
680
|
+
return (_jsxs(Box, { width: dims.cols, height: dims.rows, children: [_jsxs(Box, { flexDirection: "column", width: dims.cols, height: dims.rows, children: [_jsxs(Box, { children: [_jsx(Text, { bold: true, children: "HuggingFace search" }), _jsx(Text, { dimColor: true, children: " \u00B7 filter: " }), _jsx(Text, { color: "yellow", children: filter }), _jsx(Text, { dimColor: true, children: " sort: " }), _jsx(Text, { color: "yellow", children: sort })] }), _jsxs(Box, { children: [_jsx(Text, { children: mode === "edit" ? "q› " : "q " }), _jsx(Text, { color: mode === "edit" ? "cyan" : undefined, children: query || (mode === "edit" ? "" : "(any)") }), mode === "edit" ? _jsx(Text, { color: "cyan", children: "\u258F" }) : null] }), _jsx(Text, { dimColor: true, children: "─".repeat(Math.max(8, dims.cols - 2)) }), _jsx(Header, { cols: dims.cols, layout: layout, sort: sort }), _jsx(Box, { flexDirection: "column", height: visibleRows, overflow: "hidden", children: visible.length === 0
|
|
681
|
+
? _jsx(Text, { dimColor: true, children: countLine })
|
|
682
|
+
: visible.map((r, i) => (_jsx(Row, { r: r, cols: dims.cols, layout: layout, selected: scrollOff + i === selectedIdx, hint: selectionHintsById[r.id] }, r.id))) }), _jsx(Text, { dimColor: true, children: "─".repeat(Math.max(8, dims.cols - 2)) }), _jsx(Text, { dimColor: true, children: footerLine }), hintLineText ? _jsx(Text, { dimColor: true, children: hintLineText }) : null, message ? _jsx(Text, { color: "yellow", children: message }) : null] }), mode === "inspect" && selected
|
|
683
|
+
? _jsx(Box, { position: "absolute", marginLeft: modalLeft, marginTop: modalTop, children: _jsx(SearchDetailsModal, { result: selected, hint: selectionHint, width: modalWidth, selectedFileIdx: selectedFileIdx, machineMemBytes: machineMemBytes }) })
|
|
684
|
+
: null, mode === "downloads"
|
|
685
|
+
? _jsx(Box, { position: "absolute", marginLeft: downloadsLeft, marginTop: downloadsTop, children: _jsx(DownloadsModal, { tasks: downloads.tasks, width: downloadsModalWidth, onCancelTask: downloads.cancelDownload, onClearFinished: downloads.clearFinished, onClose: () => setMode("browse") }) })
|
|
686
|
+
: null] }));
|
|
432
687
|
};
|
|
433
688
|
//# sourceMappingURL=SearchBrowser.js.map
|