tabherd 0.0.0-stage → 0.6.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/LICENSE +674 -0
  3. package/README.md +540 -2
  4. package/launcher/npm.js +9 -0
  5. package/lib/agents.js +324 -0
  6. package/lib/codex-client.js +306 -0
  7. package/lib/codex-rollout.js +251 -0
  8. package/lib/codex.js +424 -0
  9. package/lib/comfy.js +479 -0
  10. package/lib/completed.js +55 -0
  11. package/lib/copilot.js +359 -0
  12. package/lib/cursor.js +516 -0
  13. package/lib/dismissed.js +30 -0
  14. package/lib/filters.js +120 -0
  15. package/lib/groups.js +144 -0
  16. package/lib/history.js +253 -0
  17. package/lib/llamacpp.js +159 -0
  18. package/lib/lmstudio.js +134 -0
  19. package/lib/localai.js +291 -0
  20. package/lib/memory.js +55 -0
  21. package/lib/ollama.js +124 -0
  22. package/lib/open-dashboard.js +39 -0
  23. package/lib/opencode.js +371 -0
  24. package/lib/repos.js +81 -0
  25. package/lib/saved.js +33 -0
  26. package/lib/secrets.js +196 -0
  27. package/lib/session-id.js +9 -0
  28. package/lib/settings.js +231 -0
  29. package/lib/store.js +44 -0
  30. package/lib/terminals/index.js +62 -0
  31. package/lib/terminals/kitty.js +126 -0
  32. package/lib/terminals/linux.js +310 -0
  33. package/lib/terminals/macos.js +468 -0
  34. package/lib/terminals/tmux.js +89 -0
  35. package/lib/terminals/unix-driver.js +172 -0
  36. package/lib/terminals/unix.js +204 -0
  37. package/lib/terminals/unsupported.js +22 -0
  38. package/lib/terminals/wezterm.js +103 -0
  39. package/lib/terminals/windows-close.ps1 +125 -0
  40. package/lib/terminals/windows-focus.ps1 +235 -0
  41. package/lib/terminals/windows-pick-folder.ps1 +57 -0
  42. package/lib/terminals/windows-titles.js +124 -0
  43. package/lib/terminals/windows-titles.ps1 +95 -0
  44. package/lib/terminals/windows.js +166 -0
  45. package/lib/ticket-refs.js +184 -0
  46. package/lib/tickets.js +437 -0
  47. package/lib/todos.js +166 -0
  48. package/lib/trackers.js +541 -0
  49. package/lib/transcript.js +314 -0
  50. package/lib/updates.js +186 -0
  51. package/package.json +44 -4
  52. package/public/app.js +4077 -0
  53. package/public/favicon.svg +1 -0
  54. package/public/icons/tabherd-128.png +0 -0
  55. package/public/icons/tabherd-16.png +0 -0
  56. package/public/icons/tabherd-20.png +0 -0
  57. package/public/icons/tabherd-24.png +0 -0
  58. package/public/icons/tabherd-256.png +0 -0
  59. package/public/icons/tabherd-32.png +0 -0
  60. package/public/icons/tabherd-40.png +0 -0
  61. package/public/icons/tabherd-48.png +0 -0
  62. package/public/icons/tabherd-512.png +0 -0
  63. package/public/icons/tabherd-64.png +0 -0
  64. package/public/index.html +655 -0
  65. package/public/lang/es.js +742 -0
  66. package/public/style.css +1443 -0
  67. package/server.js +814 -0
package/lib/localai.js ADDED
@@ -0,0 +1,291 @@
1
+ 'use strict';
2
+
3
+ // LocalAI as cards: each model loaded in memory, each download or install in
4
+ // progress, each agent chat that's running, waiting on you, or finished in
5
+ // the last few minutes, each agent job running or queued, and each model
6
+ // that's working on a request.
7
+ //
8
+ // It's found at Settings' LocalAI address, http://127.0.0.1:8080 unless set,
9
+ // and asked with Settings' API key if LocalAI has one set.
10
+
11
+ const REFRESH_MS = 2000;
12
+ const REQUEST_MS = 2500;
13
+ const INFO_REFRESH_MS = 60 * 1000;
14
+ // A chat or job that finishes leaves the dashboard at once. One that failed
15
+ // keeps its card until it's cleared, from up to a day ago.
16
+ const FAILED_SHOWN_MS = 24 * 60 * 60 * 1000;
17
+ const DEFAULT_URL = 'http://127.0.0.1:8080';
18
+ // LocalAI doesn't list the requests it's answering, so a model counts as
19
+ // working while its backend's process uses a processor: one generating keeps
20
+ // at least a core busy, and an idle one sits near zero. It starts at the
21
+ // first reading of BUSY_CPU% or more and stops after QUIET_READS readings
22
+ // below that in a row, so one low or missing reading doesn't end it.
23
+ const BUSY_CPU = 20;
24
+ const QUIET_READS = 2;
25
+ // A model that worked this long dings when it stops. Shorter runs, such as an
26
+ // agent's quick requests one after another, come and go quietly.
27
+ const DING_AFTER_MS = 30 * 1000;
28
+
29
+ let config = { url: DEFAULT_URL, key: '' };
30
+ let state = null;
31
+ let info = null;
32
+ let infoAt = 0;
33
+ let refreshing = null;
34
+ let refreshedAt = 0;
35
+ // When each download, and a refused key, was first seen, for how long it's
36
+ // been going.
37
+ const firstSeen = new Map();
38
+ // Each working model's ID, with when it started and its low readings since.
39
+ let working = new Map();
40
+
41
+ function seenSince(id, now = Date.now()) {
42
+ if (!firstSeen.has(id)) firstSeen.set(id, now);
43
+ return firstSeen.get(id);
44
+ }
45
+
46
+ // Which models are working after one more reading of each, from those that were.
47
+ function trackWork(was, models, now = Date.now()) {
48
+ const next = new Map();
49
+ for (const m of models) {
50
+ if (!m?.id) continue;
51
+ const cpu = m.process?.cpu_percent;
52
+ const before = was.get(m.id);
53
+ if (Number.isFinite(cpu) && cpu >= BUSY_CPU) next.set(m.id, { since: before?.since ?? now, quiet: 0 });
54
+ else if (before) {
55
+ // LocalAI gives no reading the first time it samples a process.
56
+ const quiet = before.quiet + (Number.isFinite(cpu) ? 1 : 0);
57
+ if (quiet < QUIET_READS) next.set(m.id, { since: before.since, quiet });
58
+ }
59
+ }
60
+ return next;
61
+ }
62
+
63
+ const headers = () => (config.key ? { Authorization: `Bearer ${config.key}` } : {});
64
+
65
+ async function request(route, { method = 'GET', body } = {}) {
66
+ const res = await fetch(config.url.replace(/\/+$/, '') + route, {
67
+ method,
68
+ headers: { ...headers(), ...(body ? { 'Content-Type': 'application/json' } : {}) },
69
+ body: body ? JSON.stringify(body) : undefined,
70
+ signal: AbortSignal.timeout(REQUEST_MS),
71
+ });
72
+ if (!res.ok) {
73
+ const err = new Error(res.status === 401 || res.status === 403 ? 'LocalAI wants an API key: set it in Settings.' : `LocalAI answered ${res.status}`);
74
+ err.status = res.status;
75
+ throw err;
76
+ }
77
+ return res.json().catch(() => ({}));
78
+ }
79
+
80
+ // What may be missing, such as chats when LocalAI has them turned off, is
81
+ // left out rather than failing the rest.
82
+ const optional = (p) => p.catch((err) => (err.status === 401 || err.status === 403 ? Promise.reject(err) : null));
83
+
84
+ async function refresh() {
85
+ if (!info || Date.now() - infoAt > INFO_REFRESH_MS) {
86
+ info = await request('/.well-known/localai.json');
87
+ infoAt = Date.now();
88
+ }
89
+ const caps = info?.capabilities || {};
90
+ const [system, operations, chats, jobs] = await Promise.all([
91
+ request('/system'),
92
+ optional(request('/api/operations')),
93
+ caps.chats === false ? null : optional(request('/api/chats?limit=50')),
94
+ // Version 4 calls the feature agents, version 5 agent_jobs.
95
+ caps.agent_jobs || caps.agents ? optional(request('/api/agent/jobs?limit=20')) : null,
96
+ ]);
97
+ working = trackWork(working, system?.loaded_models || []);
98
+ const ids = new Set((operations?.operations || []).map((o) => `op:${o.jobID || o.id}`));
99
+ for (const id of firstSeen.keys()) if (!ids.has(id)) firstSeen.delete(id);
100
+ state = {
101
+ // Version 4 adds the commit after a space.
102
+ version: typeof info?.version === 'string' ? info.version.split(' ')[0] : null,
103
+ models: system?.loaded_models || [],
104
+ working,
105
+ operations: operations?.operations || [],
106
+ chats: chats?.conversations || [],
107
+ jobs: Array.isArray(jobs) ? jobs : jobs?.jobs || [],
108
+ error: null,
109
+ };
110
+ }
111
+
112
+ function poll() {
113
+ if (refreshing || Date.now() - refreshedAt < REFRESH_MS) return;
114
+ refreshing = refresh()
115
+ .catch((err) => {
116
+ // Not running is the usual case, and shows nothing. A refused key shows
117
+ // once on a card, so it can be fixed.
118
+ state = err.status === 401 || err.status === 403 ? { error: err.message, models: [], operations: [], chats: [], jobs: [] } : null;
119
+ if (!state) info = null;
120
+ working = new Map();
121
+ })
122
+ .finally(() => {
123
+ refreshing = null;
124
+ refreshedAt = Date.now();
125
+ });
126
+ }
127
+
128
+ const ms = (t) => (typeof t === 'number' ? (t < 1e12 ? t * 1000 : t) : t ? Date.parse(t) : null);
129
+ const bytes = (n) => (n >= 1e9 ? `${(n / 1e9).toFixed(1)} GB` : n >= 1e6 ? `${Math.round(n / 1e6)} MB` : n ? `${n} B` : null);
130
+
131
+ // LocalAI's state as cards.
132
+ function itemsFrom(s, { url = DEFAULT_URL, now = Date.now() } = {}) {
133
+ if (!s) return [];
134
+ const base = url.replace(/\/+$/, '');
135
+ const items = [];
136
+ const card = (fields) => ({ app: 'localai', host: s.version ? `LocalAI ${s.version}` : 'LocalAI', url: `${base}/`, ...fields });
137
+ if (s.error) {
138
+ items.push(card({ kind: 'service', id: 'localai:service', name: 'LocalAI', status: 'waiting', waitingFor: s.error, statusSince: seenSince('service', now), actions: ['open'] }));
139
+ }
140
+ for (const m of s.models) {
141
+ if (!m?.id) continue;
142
+ items.push(
143
+ card({
144
+ kind: 'model',
145
+ id: `localai:model:${m.id}`,
146
+ model: m.id,
147
+ name: m.id,
148
+ where: m.backend || null,
149
+ status: 'loaded',
150
+ statusSince: ms(m.process?.started_at),
151
+ startedAt: ms(m.process?.started_at),
152
+ facts: [
153
+ ['Graphics memory', bytes(m.size_vram)],
154
+ ['Memory', bytes(m.process?.rss_bytes)],
155
+ ['CPU', Number.isFinite(m.process?.cpu_percent) ? `${Math.round(m.process.cpu_percent)}%` : null],
156
+ ].filter(([, v]) => v),
157
+ // Its graphics memory, else its memory where that's all LocalAI says.
158
+ memory: m.size_vram > 0 ? { used: m.size_vram, graphics: m.size_vram } : m.process?.rss_bytes > 0 ? { used: m.process.rss_bytes } : null,
159
+ actions: ['open', 'unload'],
160
+ }),
161
+ );
162
+ const work = s.working?.get(m.id);
163
+ if (work) {
164
+ items.push(
165
+ card({
166
+ kind: 'work',
167
+ id: `localai:work:${m.id}`,
168
+ model: m.id,
169
+ name: m.id,
170
+ where: m.backend || null,
171
+ status: 'busy',
172
+ statusSince: work.since,
173
+ startedAt: work.since,
174
+ facts: [['CPU', Number.isFinite(m.process?.cpu_percent) ? `${Math.round(m.process.cpu_percent)}%` : null]].filter(([, v]) => v),
175
+ // It leaves when the model stops working, which counts as finishing,
176
+ // and dings, after a long run.
177
+ leavesWhenDone: now - work.since >= DING_AFTER_MS,
178
+ actions: ['open'],
179
+ }),
180
+ );
181
+ }
182
+ }
183
+ for (const o of s.operations) {
184
+ if (!o?.jobID && !o?.id) continue;
185
+ const what = o.isDeletion ? 'Removing' : o.isBackend ? 'Installing backend' : 'Downloading';
186
+ items.push(
187
+ card({
188
+ kind: 'download',
189
+ id: `localai:op:${o.jobID || o.id}`,
190
+ jobId: o.jobID || o.id,
191
+ name: o.name || o.fullName || 'Download',
192
+ where: what,
193
+ status: o.error ? 'waiting' : o.isQueued ? 'queued' : 'busy',
194
+ statusLabel: o.error ? 'Failed' : o.isQueued ? 'Queued' : what,
195
+ waitingFor: o.error ? `Failed: ${String(o.error).slice(0, 200)}` : o.needsApproval ? 'Waiting for approval in LocalAI' : null,
196
+ statusSince: seenSince(`op:${o.jobID || o.id}`, now),
197
+ progress: Number.isFinite(o.progress) ? { value: o.progress, max: 100 } : null,
198
+ facts: [
199
+ ['Size', o.totalBytes ? `${bytes(o.currentBytes || 0)} of ${bytes(o.totalBytes)}` : null],
200
+ ['Now', o.message || o.phase || null],
201
+ ].filter(([, v]) => v),
202
+ // It leaves the list when it's done, which counts as finishing.
203
+ leavesWhenDone: true,
204
+ actions: [...(o.cancellable ? ['open', 'cancel'] : ['open']), ...(o.error ? ['dismiss'] : [])],
205
+ }),
206
+ );
207
+ }
208
+ for (const c of s.chats) {
209
+ if (!c?.id || c.kind === 'subagent') continue;
210
+ const updated = ms(c.updated) || ms(c.created);
211
+ const paused = !c.running && c.last_turn === 'paused';
212
+ const failed = !c.running && c.last_turn === 'failed';
213
+ if (!c.running && !paused && !(failed && updated && now - updated < FAILED_SHOWN_MS)) continue;
214
+ items.push(
215
+ card({
216
+ kind: 'chat',
217
+ id: `localai:chat:${c.id}`,
218
+ chatId: c.id,
219
+ name: c.title || 'Chat',
220
+ where: c.model || null,
221
+ status: c.running ? 'busy' : 'waiting',
222
+ statusLabel: failed ? 'Failed' : null,
223
+ waitingFor: paused ? 'Paused: reply to continue' : failed ? 'Its last turn failed' : null,
224
+ statusSince: updated,
225
+ startedAt: ms(c.created),
226
+ // A running chat that finishes leaves, which counts as finishing.
227
+ leavesWhenDone: Boolean(c.running),
228
+ actions: c.running ? ['open', 'stop'] : failed ? ['open', 'dismiss'] : ['open'],
229
+ }),
230
+ );
231
+ }
232
+ for (const j of s.jobs) {
233
+ if (!j?.id) continue;
234
+ const ended = ms(j.completed_at);
235
+ const active = j.status === 'running' || j.status === 'pending';
236
+ const failed = j.status === 'failed';
237
+ if (!active && !(failed && ended && now - ended < FAILED_SHOWN_MS)) continue;
238
+ items.push(
239
+ card({
240
+ kind: 'agent-job',
241
+ id: `localai:job:${j.id}`,
242
+ jobId: j.id,
243
+ name: j.task_name || j.task_id || 'Agent job',
244
+ where: j.triggered_by ? `Started by ${j.triggered_by}` : null,
245
+ status: j.status === 'running' ? 'busy' : j.status === 'pending' ? 'queued' : 'waiting',
246
+ statusLabel: failed ? 'Failed' : null,
247
+ waitingFor: failed ? `Failed${j.error ? `: ${String(j.error).slice(0, 200)}` : ''}` : null,
248
+ statusSince: ended || ms(j.started_at) || ms(j.created_at),
249
+ startedAt: ms(j.started_at) || ms(j.created_at),
250
+ leavesWhenDone: active,
251
+ actions: active ? ['open', 'cancel'] : ['open', 'dismiss'],
252
+ }),
253
+ );
254
+ }
255
+ return items;
256
+ }
257
+
258
+ // Where LocalAI is, and its key, from Settings. A change starts afresh.
259
+ function configure({ url, key } = {}) {
260
+ const next = { url: url || DEFAULT_URL, key: key || '' };
261
+ if (next.url === config.url && next.key === config.key) return;
262
+ config = next;
263
+ state = null;
264
+ info = null;
265
+ working = new Map();
266
+ refreshedAt = 0;
267
+ }
268
+
269
+ // LocalAI's cards from the last check, which checks again in the background.
270
+ function snapshot() {
271
+ poll();
272
+ if (!state?.error) firstSeen.delete('service');
273
+ return itemsFrom(state, { url: config.url });
274
+ }
275
+
276
+ // Unload a model, stop a chat's turn, or cancel a download or agent job.
277
+ async function act(item, action) {
278
+ try {
279
+ if (action === 'unload' && item.kind === 'model') await request('/backend/shutdown', { method: 'POST', body: { model: item.model } });
280
+ else if (action === 'stop' && item.kind === 'chat') await request(`/api/chats/${encodeURIComponent(item.chatId)}/stop`, { method: 'POST' });
281
+ else if (action === 'cancel' && item.kind === 'download') await request(`/api/operations/${encodeURIComponent(item.jobId)}/cancel`, { method: 'POST' });
282
+ else if (action === 'cancel' && item.kind === 'agent-job') await request(`/api/agent/jobs/${encodeURIComponent(item.jobId)}/cancel`, { method: 'POST' });
283
+ else return { ok: false, error: "That can't be done here." };
284
+ refreshedAt = 0;
285
+ return { ok: true };
286
+ } catch (err) {
287
+ return { ok: false, error: err.message };
288
+ }
289
+ }
290
+
291
+ module.exports = { snapshot, configure, act, itemsFrom, trackWork, DEFAULT_URL };
package/lib/memory.js ADDED
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ // Memory in use and free, for the card at the top of the dashboard: the
4
+ // computer's RAM, and each NVIDIA graphics card's memory and load, from
5
+ // nvidia-smi, which comes with NVIDIA's driver. Read every few seconds in
6
+ // the background; a computer without nvidia-smi shows RAM alone.
7
+
8
+ const os = require('os');
9
+ const { execFile } = require('child_process');
10
+
11
+ const GPU_REFRESH_MS = 5000;
12
+
13
+ let gpus = [];
14
+ let gpuAt = 0;
15
+ let gpuPending = false;
16
+ let noSmi = false;
17
+
18
+ // One line per card: index, name, MiB used, MiB total, % busy.
19
+ function parseSmi(out) {
20
+ const found = [];
21
+ for (const line of String(out).split(/\r?\n/)) {
22
+ const [index, name, used, total, util] = line.split(',').map((s) => s.trim());
23
+ if (!name || !Number.isFinite(Number(total))) continue;
24
+ found.push({
25
+ index: Number(index),
26
+ name: name.replace(/^NVIDIA\s+/, ''),
27
+ used: Number(used) * 1048576,
28
+ total: Number(total) * 1048576,
29
+ busy: Number.isFinite(Number(util)) ? Number(util) : null,
30
+ });
31
+ }
32
+ return found;
33
+ }
34
+
35
+ function refreshGpus() {
36
+ if (noSmi || gpuPending || Date.now() - gpuAt < GPU_REFRESH_MS) return;
37
+ gpuPending = true;
38
+ const args = ['--query-gpu=index,name,memory.used,memory.total,utilization.gpu', '--format=csv,noheader,nounits'];
39
+ execFile('nvidia-smi', args, { windowsHide: true, timeout: 10000 }, (err, stdout) => {
40
+ gpuPending = false;
41
+ gpuAt = Date.now();
42
+ // Not there: no NVIDIA card, or no driver. Not asked again this run.
43
+ if (err && err.code === 'ENOENT') noSmi = true;
44
+ if (!err) gpus = parseSmi(stdout);
45
+ });
46
+ }
47
+
48
+ // RAM and graphics memory, as { ram: { used, total }, gpus: [...] }, in bytes.
49
+ function snapshot() {
50
+ refreshGpus();
51
+ const total = os.totalmem();
52
+ return { ram: { used: total - os.freemem(), total }, gpus };
53
+ }
54
+
55
+ module.exports = { snapshot, parseSmi };
package/lib/ollama.js ADDED
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ // Ollama's loaded models as cards, from /api/ps: each with the graphics
4
+ // memory it holds, its size and context, when Ollama will unload it, and
5
+ // Unload. Ollama shows downloads and requests in progress only to whoever
6
+ // started them, so those don't get cards.
7
+ //
8
+ // It's found at Settings' Ollama address, else OLLAMA_HOST, else
9
+ // http://127.0.0.1:11434.
10
+
11
+ const REFRESH_MS = 2000;
12
+ const REQUEST_MS = 2500;
13
+ const DEFAULT_URL = 'http://127.0.0.1:11434';
14
+
15
+ // OLLAMA_HOST can be host, host:port or a URL, and 0.0.0.0 means every
16
+ // address, this computer's included. As Ollama reads it, a host without a
17
+ // scheme is on port 11434 unless it says otherwise; a URL is on its scheme's
18
+ // usual port.
19
+ function fromEnv(host = process.env.OLLAMA_HOST) {
20
+ if (!host) return null;
21
+ const given = host.trim();
22
+ const schemeless = !/^https?:\/\//.test(given);
23
+ try {
24
+ const u = new URL(schemeless ? `http://${given}` : given);
25
+ if (u.hostname === '0.0.0.0' || u.hostname === '[::]') u.hostname = '127.0.0.1';
26
+ if (schemeless && !u.port) u.port = '11434';
27
+ return u.origin;
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ let url = fromEnv() || DEFAULT_URL;
34
+ let state = null;
35
+ let refreshing = null;
36
+ let refreshedAt = 0;
37
+
38
+ function configure({ url: next } = {}) {
39
+ const u = (next || fromEnv() || DEFAULT_URL).replace(/\/+$/, '');
40
+ if (u === url) return;
41
+ url = u;
42
+ state = null;
43
+ refreshedAt = 0;
44
+ }
45
+
46
+ async function request(route, body) {
47
+ const res = await fetch(url + route, {
48
+ method: body ? 'POST' : 'GET',
49
+ headers: body ? { 'Content-Type': 'application/json' } : {},
50
+ body: body ? JSON.stringify(body) : undefined,
51
+ signal: AbortSignal.timeout(REQUEST_MS),
52
+ });
53
+ if (!res.ok) throw new Error(`Ollama answered ${res.status}`);
54
+ return res.json();
55
+ }
56
+
57
+ async function refresh() {
58
+ const [version, ps] = await Promise.all([request('/api/version'), request('/api/ps')]);
59
+ state = { version: version?.version || null, models: ps?.models || [] };
60
+ }
61
+
62
+ function poll() {
63
+ if (refreshing || Date.now() - refreshedAt < REFRESH_MS) return;
64
+ refreshing = refresh()
65
+ // Not running is the usual case, and shows nothing.
66
+ .catch(() => (state = null))
67
+ .finally(() => {
68
+ refreshing = null;
69
+ refreshedAt = Date.now();
70
+ });
71
+ }
72
+
73
+ const bytes = (n) => (n >= 1e9 ? `${(n / 1e9).toFixed(1)} GB` : n >= 1e6 ? `${Math.round(n / 1e6)} MB` : null);
74
+
75
+ // When it unloads: a time today, or none for a model kept loaded.
76
+ function unloads(expiresAt, now) {
77
+ const t = Date.parse(expiresAt || '');
78
+ if (!Number.isFinite(t) || t - now > 30 * 24 * 3600 * 1000) return 'Stays loaded';
79
+ const mins = Math.max(0, Math.round((t - now) / 60000));
80
+ return mins < 1 ? 'Within a minute' : `In ${mins} min`;
81
+ }
82
+
83
+ function itemsFrom(s, { now = Date.now() } = {}) {
84
+ if (!s) return [];
85
+ return s.models.map((m) => ({
86
+ app: 'ollama',
87
+ kind: 'model',
88
+ id: `ollama:model:${m.name || m.model}`,
89
+ model: m.name || m.model,
90
+ name: m.name || m.model,
91
+ host: s.version ? `Ollama ${s.version}` : 'Ollama',
92
+ where: [m.details?.parameter_size, m.details?.quantization_level].filter(Boolean).join(' · ') || null,
93
+ status: 'loaded',
94
+ facts: [
95
+ ['Graphics memory', bytes(m.size_vram) || (m.size_vram === 0 ? 'None, on the CPU' : null)],
96
+ ['Size', bytes(m.size)],
97
+ ['Context', Number.isFinite(m.context_length) ? `${m.context_length.toLocaleString('en')} tokens` : null],
98
+ ['Unloads', unloads(m.expires_at, now)],
99
+ ].filter(([, v]) => v),
100
+ // What it takes, and how much of that is graphics memory.
101
+ memory: m.size > 0 ? { used: m.size, graphics: Number.isFinite(m.size_vram) ? m.size_vram : null } : null,
102
+ actions: ['unload'],
103
+ }));
104
+ }
105
+
106
+ // Ollama's cards from the last check, which checks again in the background.
107
+ function snapshot() {
108
+ poll();
109
+ return itemsFrom(state);
110
+ }
111
+
112
+ // Unloads a model: a request that keeps it loaded for no time.
113
+ async function act(item, action) {
114
+ if (action !== 'unload') return { ok: false, error: "That can't be done here." };
115
+ try {
116
+ await request('/api/generate', { model: item.model, keep_alive: 0 });
117
+ refreshedAt = 0;
118
+ return { ok: true };
119
+ } catch (err) {
120
+ return { ok: false, error: `Couldn't unload it: ${err.message}` };
121
+ }
122
+ }
123
+
124
+ module.exports = { snapshot, configure, act, itemsFrom, fromEnv, DEFAULT_URL };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ // Opens the dashboard. On macOS and Linux, a Chromium-based browser can show it
4
+ // as an app window, with no tabs or address bar, as the Windows launcher does
5
+ // with Edge; otherwise it opens in the default browser.
6
+
7
+ const fs = require('fs');
8
+ const { spawn } = require('child_process');
9
+
10
+ const MAC_BROWSERS = ['Google Chrome', 'Microsoft Edge', 'Brave Browser', 'Chromium', 'Vivaldi'];
11
+ const LINUX_BROWSERS = ['google-chrome', 'google-chrome-stable', 'microsoft-edge', 'microsoft-edge-stable', 'brave-browser', 'chromium', 'chromium-browser', 'vivaldi'];
12
+
13
+ function detached(cmd, args) {
14
+ const child = spawn(cmd, args, { detached: true, stdio: 'ignore' });
15
+ child.on('error', () => {});
16
+ child.unref();
17
+ }
18
+
19
+ const onPath = (cmd) =>
20
+ (process.env.PATH || '').split(':').some((dir) => {
21
+ try {
22
+ fs.accessSync(`${dir}/${cmd}`, fs.constants.X_OK);
23
+ return true;
24
+ } catch {
25
+ return false;
26
+ }
27
+ });
28
+
29
+ function openDashboard(url) {
30
+ if (process.platform === 'win32') return detached('cmd.exe', ['/c', 'start', '', url]);
31
+ if (process.platform === 'darwin') {
32
+ const app = MAC_BROWSERS.find((name) => fs.existsSync(`/Applications/${name}.app`));
33
+ return app ? detached('open', ['-na', app, '--args', `--app=${url}`]) : detached('open', [url]);
34
+ }
35
+ const browser = LINUX_BROWSERS.find(onPath);
36
+ return browser ? detached(browser, [`--app=${url}`]) : detached('xdg-open', [url]);
37
+ }
38
+
39
+ module.exports = { openDashboard };