@goodandready/dsh-ollama-cloud-provider 0.1.19 → 0.1.21
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 +24 -0
- package/README.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +389 -0
- package/lib/index.d.ts +8 -1
- package/lib/index.js +541 -26
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.21 — 2026-11-05
|
|
4
|
+
|
|
5
|
+
- Added local Ollama model management: `/api/tags` disk inventory, `/api/ps`
|
|
6
|
+
running models and VRAM, `/api/show` details, `/api/pull` progress streaming,
|
|
7
|
+
and confirmed `/api/delete`. Cloud endpoints are rejected.
|
|
8
|
+
- Added `/ollama local [models|ps|show|pull|remove]` CLI commands; removal
|
|
9
|
+
requires `--yes` and never forces a delete.
|
|
10
|
+
- Added the local models settings card with pull progress, disk/running totals,
|
|
11
|
+
details and a two-step remove confirmation.
|
|
12
|
+
- Extended the mock Ollama contract with tags sizes, ps, pull and delete;
|
|
13
|
+
119/119 tests.
|
|
14
|
+
|
|
15
|
+
## 0.1.20 — 2026-11-05
|
|
16
|
+
|
|
17
|
+
- Persisted the catalog snapshot under `$DSH_HOME/cache/dsh-ollama-cloud/`
|
|
18
|
+
with atomic temp+rename writes, schema/endpoint validation, and corrupt-file
|
|
19
|
+
recovery. Offline starts serve the last snapshot immediately.
|
|
20
|
+
- Added `autoRefresh` and `refreshMinutes` controls: mount refresh, periodic
|
|
21
|
+
forced refresh, and a settings UI; turning auto-refresh off leaves the cache
|
|
22
|
+
untouched.
|
|
23
|
+
- Retired models explicitly missing from `/api/show` (404/410), while
|
|
24
|
+
transient show failures keep the previous model.
|
|
25
|
+
- Added cache, offline, retirement and settings tests; 115/115 tests.
|
|
26
|
+
|
|
3
27
|
## 0.1.19 — 2026-11-05
|
|
4
28
|
|
|
5
29
|
- Added configurable native generation defaults: temperature, top_k, top_p,
|
package/README.md
CHANGED
|
@@ -137,17 +137,17 @@ npm pack
|
|
|
137
137
|
Install the published package:
|
|
138
138
|
|
|
139
139
|
```bash
|
|
140
|
-
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
140
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.21
|
|
141
141
|
# DSH Desktop:
|
|
142
|
-
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
142
|
+
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.21
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
Or install the packed tarball into a profile:
|
|
146
146
|
|
|
147
147
|
```bash
|
|
148
|
-
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
148
|
+
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
|
|
149
149
|
# DSH Desktop:
|
|
150
|
-
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
150
|
+
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
Restart dsh (or DSH Desktop), then pick **Ollama Cloud** in the model picker.
|
package/README.ru.md
CHANGED
|
@@ -103,17 +103,17 @@ npm pack
|
|
|
103
103
|
Установка опубликованного пакета из npm:
|
|
104
104
|
|
|
105
105
|
```bash
|
|
106
|
-
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
106
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.21
|
|
107
107
|
# DSH Desktop:
|
|
108
|
-
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
108
|
+
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.21
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
Либо установка из упакованного tarball:
|
|
112
112
|
|
|
113
113
|
```bash
|
|
114
|
-
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
114
|
+
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
|
|
115
115
|
# DSH Desktop:
|
|
116
|
-
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
116
|
+
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
|
|
117
117
|
```
|
|
118
118
|
|
|
119
119
|
После установки перезапустите dsh (или DSH Desktop) и выберите **Ollama Cloud** в списке моделей.
|
package/README.zh.md
CHANGED
|
@@ -102,17 +102,17 @@ npm pack
|
|
|
102
102
|
从 npm 安装已发布版本:
|
|
103
103
|
|
|
104
104
|
```bash
|
|
105
|
-
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
105
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.21
|
|
106
106
|
# DSH 桌面端:
|
|
107
|
-
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
107
|
+
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.21
|
|
108
108
|
```
|
|
109
109
|
|
|
110
110
|
或通过打包文件安装:
|
|
111
111
|
|
|
112
112
|
```bash
|
|
113
|
-
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
113
|
+
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
|
|
114
114
|
# DSH 桌面端:
|
|
115
|
-
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
115
|
+
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
|
package/lib/client.js
CHANGED
|
@@ -136,6 +136,29 @@ window.__ModuleLoader__.load({
|
|
|
136
136
|
keepAliveHint: "Ollama keep_alive, for example 5m or -1.",
|
|
137
137
|
stop: "Stop sequences",
|
|
138
138
|
stopHint: "Comma-separated; sent as the native stop list.",
|
|
139
|
+
autoRefresh: "Refresh model catalog automatically",
|
|
140
|
+
refreshMinutes: "Refresh interval (minutes)",
|
|
141
|
+
autoRefreshHint: "Mount refresh plus this interval; 0 keeps the mount refresh only.",
|
|
142
|
+
localModels: "Local Ollama models",
|
|
143
|
+
localModelsHint: "List, inspect, pull and remove models on the configured local endpoint. Remove always asks for confirmation.",
|
|
144
|
+
localDisk: "Disk",
|
|
145
|
+
localRunning: "Running",
|
|
146
|
+
localPullPlaceholder: "model name, for example llama3.2",
|
|
147
|
+
localPull: "Pull",
|
|
148
|
+
localPulling: "Pulling…",
|
|
149
|
+
localRefresh: "Reload",
|
|
150
|
+
localNoModels: "No local models.",
|
|
151
|
+
localRunningBadge: "running",
|
|
152
|
+
localShow: "Details",
|
|
153
|
+
localRemove: "Remove",
|
|
154
|
+
localConfirmRemove: "Confirm remove",
|
|
155
|
+
localCancel: "Cancel",
|
|
156
|
+
localModified: "Modified",
|
|
157
|
+
localCapabilities: "Capabilities",
|
|
158
|
+
localPullFailed: "Pull failed",
|
|
159
|
+
localRemoveDone: "removed",
|
|
160
|
+
localRemoveFailed: "Remove failed",
|
|
161
|
+
localShowFailed: "Details unavailable",
|
|
139
162
|
sidebar: "Sidebar",
|
|
140
163
|
serviceStatus: "Service status",
|
|
141
164
|
serviceStatusHint: "Checks the public Ollama Cloud tag endpoint without using your key or quota.",
|
|
@@ -323,6 +346,29 @@ window.__ModuleLoader__.load({
|
|
|
323
346
|
keepAliveHint: "Ollama keep_alive,例如 5m 或 -1。",
|
|
324
347
|
stop: "Stop sequences",
|
|
325
348
|
stopHint: "逗号分隔,作为原生 stop 列表发送。",
|
|
349
|
+
autoRefresh: "自动刷新模型目录",
|
|
350
|
+
refreshMinutes: "刷新间隔(分钟)",
|
|
351
|
+
autoRefreshHint: "启动时刷新,并按此间隔刷新;0 仅启动时刷新。",
|
|
352
|
+
localModels: "本地 Ollama 模型",
|
|
353
|
+
localModelsHint: "列出、查看、拉取和删除已配置本地端点上的模型。删除始终需要确认。",
|
|
354
|
+
localDisk: "磁盘",
|
|
355
|
+
localRunning: "运行中",
|
|
356
|
+
localPullPlaceholder: "模型名称,例如 llama3.2",
|
|
357
|
+
localPull: "拉取",
|
|
358
|
+
localPulling: "拉取中…",
|
|
359
|
+
localRefresh: "重新加载",
|
|
360
|
+
localNoModels: "没有本地模型。",
|
|
361
|
+
localRunningBadge: "运行中",
|
|
362
|
+
localShow: "详情",
|
|
363
|
+
localRemove: "删除",
|
|
364
|
+
localConfirmRemove: "确认删除",
|
|
365
|
+
localCancel: "取消",
|
|
366
|
+
localModified: "修改时间",
|
|
367
|
+
localCapabilities: "能力",
|
|
368
|
+
localPullFailed: "拉取失败",
|
|
369
|
+
localRemoveDone: "已删除",
|
|
370
|
+
localRemoveFailed: "删除失败",
|
|
371
|
+
localShowFailed: "详情不可用",
|
|
326
372
|
sidebar: "侧边栏",
|
|
327
373
|
serviceStatus: "服务状态",
|
|
328
374
|
serviceStatusHint: "检查 Ollama Cloud 公共 tag 端点,不使用密钥或额度。",
|
|
@@ -483,6 +529,80 @@ window.__ModuleLoader__.load({
|
|
|
483
529
|
body: "{}"
|
|
484
530
|
});
|
|
485
531
|
}
|
|
532
|
+
function fetchLocalModels() {
|
|
533
|
+
return call("/dsh-ollama/local/models");
|
|
534
|
+
}
|
|
535
|
+
function fetchLocalShow(model) {
|
|
536
|
+
return call(`/dsh-ollama/local/show?model=${encodeURIComponent(model)}`);
|
|
537
|
+
}
|
|
538
|
+
async function pullLocalModel(model, onProgress) {
|
|
539
|
+
const response = await fetch("/dsh-ollama/local/pull", {
|
|
540
|
+
method: "POST",
|
|
541
|
+
credentials: "same-origin",
|
|
542
|
+
headers: {
|
|
543
|
+
accept: "application/x-ndjson",
|
|
544
|
+
"content-type": "application/json"
|
|
545
|
+
},
|
|
546
|
+
body: JSON.stringify({ model })
|
|
547
|
+
});
|
|
548
|
+
if (!response.ok) {
|
|
549
|
+
const body = await response.json().catch(() => ({}));
|
|
550
|
+
throw new Error(body.error ?? `HTTP ${response.status}`);
|
|
551
|
+
}
|
|
552
|
+
if (response.body === null) throw new Error("empty pull stream");
|
|
553
|
+
const reader = response.body.getReader();
|
|
554
|
+
const decoder = new TextDecoder();
|
|
555
|
+
let buffer = "";
|
|
556
|
+
let last = { status: "starting" };
|
|
557
|
+
const consume = (line) => {
|
|
558
|
+
if (line.trim() === "") return;
|
|
559
|
+
let event;
|
|
560
|
+
try {
|
|
561
|
+
event = JSON.parse(line);
|
|
562
|
+
} catch {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (typeof event.error === "string" && event.error !== "") throw new Error(event.error);
|
|
566
|
+
if (typeof event.status === "string") last = event;
|
|
567
|
+
onProgress(event);
|
|
568
|
+
};
|
|
569
|
+
for (;;) {
|
|
570
|
+
const { done, value } = await reader.read();
|
|
571
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
572
|
+
const lines = buffer.split("\n");
|
|
573
|
+
buffer = lines.pop() ?? "";
|
|
574
|
+
for (const line of lines) consume(line);
|
|
575
|
+
if (done) break;
|
|
576
|
+
}
|
|
577
|
+
if (buffer.trim() !== "") consume(buffer);
|
|
578
|
+
return last;
|
|
579
|
+
}
|
|
580
|
+
function removeLocalModel(model) {
|
|
581
|
+
return call("/dsh-ollama/local/remove", {
|
|
582
|
+
method: "POST",
|
|
583
|
+
body: JSON.stringify({
|
|
584
|
+
model,
|
|
585
|
+
confirm: true
|
|
586
|
+
})
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
function formatBytes(bytes) {
|
|
590
|
+
if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
|
|
591
|
+
const units = [
|
|
592
|
+
"B",
|
|
593
|
+
"KB",
|
|
594
|
+
"MB",
|
|
595
|
+
"GB",
|
|
596
|
+
"TB"
|
|
597
|
+
];
|
|
598
|
+
let value = bytes;
|
|
599
|
+
let index = 0;
|
|
600
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
601
|
+
value /= 1024;
|
|
602
|
+
index += 1;
|
|
603
|
+
}
|
|
604
|
+
return `${value >= 10 || index === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[index]}`;
|
|
605
|
+
}
|
|
486
606
|
function saveConfig(patch) {
|
|
487
607
|
return call("/dsh-ollama/config", {
|
|
488
608
|
method: "POST",
|
|
@@ -1540,6 +1660,8 @@ window.__ModuleLoader__.load({
|
|
|
1540
1660
|
numCtx: textOf(state.config.numCtx),
|
|
1541
1661
|
keepAlive: state.config.keepAlive ?? "",
|
|
1542
1662
|
stop: (state.config.stop ?? []).join(", "),
|
|
1663
|
+
autoRefresh: state.config.autoRefresh !== false,
|
|
1664
|
+
refreshMinutes: String(state.config.refreshMinutes ?? 1440),
|
|
1543
1665
|
showSidebarQuota: state.config.showSidebarQuota,
|
|
1544
1666
|
planLabel: state.config.planLabel,
|
|
1545
1667
|
activeAccount: state.config.activeAccount,
|
|
@@ -1591,6 +1713,8 @@ window.__ModuleLoader__.load({
|
|
|
1591
1713
|
numCtx: boundedNumber(draft.numCtx, 1, 1e7, true),
|
|
1592
1714
|
keepAlive: draft.keepAlive.trim(),
|
|
1593
1715
|
stop: stopList(draft.stop),
|
|
1716
|
+
autoRefresh: draft.autoRefresh,
|
|
1717
|
+
refreshMinutes: boundedNumber(draft.refreshMinutes, 0, 10080, true) ?? 1440,
|
|
1594
1718
|
showSidebarQuota: draft.showSidebarQuota,
|
|
1595
1719
|
planLabel: draft.planLabel.trim(),
|
|
1596
1720
|
activeAccount: draft.activeAccount.trim(),
|
|
@@ -1623,6 +1747,246 @@ window.__ModuleLoader__.load({
|
|
|
1623
1747
|
function mergeLoadedDraft(current, next, preserve) {
|
|
1624
1748
|
return preserve && current !== null ? current : next;
|
|
1625
1749
|
}
|
|
1750
|
+
// src/client/local-models-card.tsx
|
|
1751
|
+
function isLocalConfig(config) {
|
|
1752
|
+
if (config.apiKeyEnv === "") return true;
|
|
1753
|
+
try {
|
|
1754
|
+
const host = new URL(config.apiBase).hostname;
|
|
1755
|
+
return host === "127.0.0.1" || host === "localhost" || host === "::1" || host === "[::1]";
|
|
1756
|
+
} catch {
|
|
1757
|
+
return false;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
function LocalModelsCard(props) {
|
|
1761
|
+
const { t, config, onChanged } = props;
|
|
1762
|
+
const [inventory, setInventory] = (0, react.useState)(null);
|
|
1763
|
+
const [details, setDetails] = (0, react.useState)(null);
|
|
1764
|
+
const [error, setError] = (0, react.useState)(null);
|
|
1765
|
+
const [notice, setNotice] = (0, react.useState)(null);
|
|
1766
|
+
const [pullName, setPullName] = (0, react.useState)("");
|
|
1767
|
+
const [pulling, setPulling] = (0, react.useState)(false);
|
|
1768
|
+
const [progress, setProgress] = (0, react.useState)(null);
|
|
1769
|
+
const [confirmRemove, setConfirmRemove] = (0, react.useState)(null);
|
|
1770
|
+
const local = isLocalConfig(config);
|
|
1771
|
+
const load = (0, react.useCallback)(async () => {
|
|
1772
|
+
if (!local) return;
|
|
1773
|
+
try {
|
|
1774
|
+
setInventory(await fetchLocalModels());
|
|
1775
|
+
setError(null);
|
|
1776
|
+
} catch (cause) {
|
|
1777
|
+
setError(cause instanceof Error ? cause.message : "local models failed");
|
|
1778
|
+
}
|
|
1779
|
+
}, [local]);
|
|
1780
|
+
(0, react.useEffect)(() => {
|
|
1781
|
+
load();
|
|
1782
|
+
}, [
|
|
1783
|
+
load,
|
|
1784
|
+
config.apiKeyEnv,
|
|
1785
|
+
config.apiBase
|
|
1786
|
+
]);
|
|
1787
|
+
if (!local) return null;
|
|
1788
|
+
const pull = async () => {
|
|
1789
|
+
const model = pullName.trim();
|
|
1790
|
+
if (model === "" || pulling) return;
|
|
1791
|
+
setPulling(true);
|
|
1792
|
+
setError(null);
|
|
1793
|
+
setNotice(null);
|
|
1794
|
+
setProgress({ status: "starting" });
|
|
1795
|
+
try {
|
|
1796
|
+
const last = await pullLocalModel(model, setProgress);
|
|
1797
|
+
setNotice(`${model}: ${last.status}`);
|
|
1798
|
+
setPullName("");
|
|
1799
|
+
await load();
|
|
1800
|
+
onChanged?.();
|
|
1801
|
+
} catch (cause) {
|
|
1802
|
+
setError(cause instanceof Error ? cause.message : t("localPullFailed"));
|
|
1803
|
+
} finally {
|
|
1804
|
+
setPulling(false);
|
|
1805
|
+
setProgress(null);
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
const remove = async (model) => {
|
|
1809
|
+
setError(null);
|
|
1810
|
+
setNotice(null);
|
|
1811
|
+
try {
|
|
1812
|
+
await removeLocalModel(model);
|
|
1813
|
+
setConfirmRemove(null);
|
|
1814
|
+
setDetails((current) => current?.name === model ? null : current);
|
|
1815
|
+
setNotice(`${model}: ${t("localRemoveDone")}`);
|
|
1816
|
+
await load();
|
|
1817
|
+
onChanged?.();
|
|
1818
|
+
} catch (cause) {
|
|
1819
|
+
setError(cause instanceof Error ? cause.message : t("localRemoveFailed"));
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
const show = async (model) => {
|
|
1823
|
+
setError(null);
|
|
1824
|
+
try {
|
|
1825
|
+
setDetails(await fetchLocalShow(model));
|
|
1826
|
+
} catch (cause) {
|
|
1827
|
+
setError(cause instanceof Error ? cause.message : t("localShowFailed"));
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
const running = new Set(inventory?.running.map((entry) => entry.name) ?? []);
|
|
1831
|
+
const percent = progress?.total !== void 0 && progress.total > 0 ? Math.min(100, Math.round((progress.completed ?? 0) / progress.total * 100)) : null;
|
|
1832
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1833
|
+
className: "ocl-card",
|
|
1834
|
+
children: [
|
|
1835
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
1836
|
+
className: "ocl-card-title",
|
|
1837
|
+
children: t("localModels")
|
|
1838
|
+
}),
|
|
1839
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1840
|
+
className: "ocl-hint",
|
|
1841
|
+
children: t("localModelsHint")
|
|
1842
|
+
}),
|
|
1843
|
+
inventory !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1844
|
+
className: "ocl-hint",
|
|
1845
|
+
children: [
|
|
1846
|
+
t("localDisk"),
|
|
1847
|
+
": ",
|
|
1848
|
+
formatBytes(inventory.diskBytes),
|
|
1849
|
+
" · ",
|
|
1850
|
+
t("localRunning"),
|
|
1851
|
+
": ",
|
|
1852
|
+
formatBytes(inventory.runningBytes)
|
|
1853
|
+
]
|
|
1854
|
+
}),
|
|
1855
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1856
|
+
className: "ocl-row",
|
|
1857
|
+
children: [
|
|
1858
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1859
|
+
className: "ocl-input",
|
|
1860
|
+
value: pullName,
|
|
1861
|
+
placeholder: t("localPullPlaceholder"),
|
|
1862
|
+
onChange: (event) => setPullName(event.target.value),
|
|
1863
|
+
onKeyDown: (event) => {
|
|
1864
|
+
if (event.key === "Enter") {
|
|
1865
|
+
event.preventDefault();
|
|
1866
|
+
pull();
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}),
|
|
1870
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1871
|
+
type: "button",
|
|
1872
|
+
className: "ocl-button",
|
|
1873
|
+
disabled: pulling || pullName.trim() === "",
|
|
1874
|
+
onClick: () => {
|
|
1875
|
+
pull();
|
|
1876
|
+
},
|
|
1877
|
+
children: pulling ? t("localPulling") : t("localPull")
|
|
1878
|
+
}),
|
|
1879
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1880
|
+
type: "button",
|
|
1881
|
+
className: "ocl-button",
|
|
1882
|
+
onClick: () => {
|
|
1883
|
+
load();
|
|
1884
|
+
},
|
|
1885
|
+
children: t("localRefresh")
|
|
1886
|
+
})
|
|
1887
|
+
]
|
|
1888
|
+
}),
|
|
1889
|
+
progress !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1890
|
+
className: "ocl-row",
|
|
1891
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1892
|
+
className: "ocl-hint",
|
|
1893
|
+
children: percent === null ? progress.status : `${progress.status} · ${percent}%`
|
|
1894
|
+
})
|
|
1895
|
+
}),
|
|
1896
|
+
notice !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1897
|
+
className: "ocl-notice",
|
|
1898
|
+
children: notice
|
|
1899
|
+
}),
|
|
1900
|
+
error !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1901
|
+
className: "ocl-error",
|
|
1902
|
+
children: error
|
|
1903
|
+
}),
|
|
1904
|
+
inventory !== null && inventory.models.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1905
|
+
className: "ocl-hint",
|
|
1906
|
+
children: t("localNoModels")
|
|
1907
|
+
}),
|
|
1908
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1909
|
+
className: "ocl-models",
|
|
1910
|
+
children: (inventory?.models ?? []).map((model) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1911
|
+
className: "ocl-model",
|
|
1912
|
+
children: [
|
|
1913
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1914
|
+
className: "ocl-model-name",
|
|
1915
|
+
children: model.name
|
|
1916
|
+
}),
|
|
1917
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1918
|
+
className: "ocl-badge",
|
|
1919
|
+
children: formatBytes(model.size)
|
|
1920
|
+
}),
|
|
1921
|
+
running.has(model.name) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1922
|
+
className: "ocl-badge ocl-badge-ok",
|
|
1923
|
+
children: t("localRunningBadge")
|
|
1924
|
+
}),
|
|
1925
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1926
|
+
type: "button",
|
|
1927
|
+
className: "ocl-button",
|
|
1928
|
+
onClick: () => {
|
|
1929
|
+
show(model.name);
|
|
1930
|
+
},
|
|
1931
|
+
children: t("localShow")
|
|
1932
|
+
}),
|
|
1933
|
+
confirmRemove === model.name ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1934
|
+
type: "button",
|
|
1935
|
+
className: "ocl-button ocl-button-danger",
|
|
1936
|
+
onClick: () => {
|
|
1937
|
+
remove(model.name);
|
|
1938
|
+
},
|
|
1939
|
+
children: t("localConfirmRemove")
|
|
1940
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1941
|
+
type: "button",
|
|
1942
|
+
className: "ocl-button",
|
|
1943
|
+
onClick: () => setConfirmRemove(null),
|
|
1944
|
+
children: t("localCancel")
|
|
1945
|
+
})] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1946
|
+
type: "button",
|
|
1947
|
+
className: "ocl-button ocl-button-danger",
|
|
1948
|
+
onClick: () => setConfirmRemove(model.name),
|
|
1949
|
+
children: t("localRemove")
|
|
1950
|
+
})
|
|
1951
|
+
]
|
|
1952
|
+
}, model.name))
|
|
1953
|
+
}),
|
|
1954
|
+
details !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1955
|
+
className: "ocl-model-section",
|
|
1956
|
+
children: [
|
|
1957
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1958
|
+
className: "ocl-model-section-head",
|
|
1959
|
+
children: details.name
|
|
1960
|
+
}),
|
|
1961
|
+
details.modifiedAt !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1962
|
+
className: "ocl-hint",
|
|
1963
|
+
children: [
|
|
1964
|
+
t("localModified"),
|
|
1965
|
+
": ",
|
|
1966
|
+
details.modifiedAt
|
|
1967
|
+
]
|
|
1968
|
+
}),
|
|
1969
|
+
details.details !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1970
|
+
className: "ocl-hint",
|
|
1971
|
+
children: [
|
|
1972
|
+
details.details.family,
|
|
1973
|
+
details.details.parameterSize,
|
|
1974
|
+
details.details.quantization
|
|
1975
|
+
].filter((entry) => entry !== void 0).join(" · ")
|
|
1976
|
+
}),
|
|
1977
|
+
details.capabilities.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1978
|
+
className: "ocl-hint",
|
|
1979
|
+
children: [
|
|
1980
|
+
t("localCapabilities"),
|
|
1981
|
+
": ",
|
|
1982
|
+
details.capabilities.join(", ")
|
|
1983
|
+
]
|
|
1984
|
+
})
|
|
1985
|
+
]
|
|
1986
|
+
})
|
|
1987
|
+
]
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1626
1990
|
// src/client/update-state.ts
|
|
1627
1991
|
function updateBadge(status) {
|
|
1628
1992
|
if (status.latestCheckFailed) return "failed";
|
|
@@ -2569,6 +2933,13 @@ window.__ModuleLoader__.load({
|
|
|
2569
2933
|
})
|
|
2570
2934
|
]
|
|
2571
2935
|
}),
|
|
2936
|
+
state !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LocalModelsCard, {
|
|
2937
|
+
t,
|
|
2938
|
+
config: state.config,
|
|
2939
|
+
onChanged: () => {
|
|
2940
|
+
reloadModels();
|
|
2941
|
+
}
|
|
2942
|
+
}),
|
|
2572
2943
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2573
2944
|
className: "ocl-card",
|
|
2574
2945
|
children: [
|
|
@@ -2644,6 +3015,24 @@ window.__ModuleLoader__.load({
|
|
|
2644
3015
|
onChange: (value) => update({ stop: value })
|
|
2645
3016
|
})
|
|
2646
3017
|
]
|
|
3018
|
+
}),
|
|
3019
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
3020
|
+
className: "ocl-row",
|
|
3021
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
3022
|
+
type: "checkbox",
|
|
3023
|
+
checked: draft.autoRefresh,
|
|
3024
|
+
onChange: (event) => update({ autoRefresh: event.target.checked })
|
|
3025
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("autoRefresh") })]
|
|
3026
|
+
}),
|
|
3027
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
3028
|
+
label: t("refreshMinutes"),
|
|
3029
|
+
type: "number",
|
|
3030
|
+
value: draft.refreshMinutes,
|
|
3031
|
+
onChange: (value) => update({ refreshMinutes: value })
|
|
3032
|
+
}),
|
|
3033
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
3034
|
+
className: "ocl-hint",
|
|
3035
|
+
children: t("autoRefreshHint")
|
|
2647
3036
|
})
|
|
2648
3037
|
]
|
|
2649
3038
|
}),
|
package/lib/index.d.ts
CHANGED
|
@@ -69,6 +69,10 @@ interface Config {
|
|
|
69
69
|
numCtx?: number;
|
|
70
70
|
keepAlive?: string;
|
|
71
71
|
stop?: string[];
|
|
72
|
+
/** Refresh the model catalog at mount and on an interval. */
|
|
73
|
+
autoRefresh?: boolean;
|
|
74
|
+
/** Catalog refresh interval in minutes; 0 = mount only. */
|
|
75
|
+
refreshMinutes?: number;
|
|
72
76
|
/** Extra accounts for rotation. */
|
|
73
77
|
accounts?: AccountConfig[];
|
|
74
78
|
/** Preferred account per model glob; others remain fallbacks. */
|
|
@@ -115,6 +119,8 @@ interface ResolvedConfig {
|
|
|
115
119
|
numCtx?: number;
|
|
116
120
|
keepAlive?: string;
|
|
117
121
|
stop?: readonly string[];
|
|
122
|
+
autoRefresh: boolean;
|
|
123
|
+
refreshMinutes: number;
|
|
118
124
|
accounts: readonly AccountConfig[];
|
|
119
125
|
modelAccountRules: readonly ModelAccountRule[];
|
|
120
126
|
stickySession: boolean;
|
|
@@ -421,6 +427,8 @@ interface RouteDeps {
|
|
|
421
427
|
readonly verifyDesktop?: (req: IncomingMessage) => Promise<boolean>;
|
|
422
428
|
/** Same verifier for private reads; falls back to `verifyDesktop`. */
|
|
423
429
|
readonly verifyHost?: (req: IncomingMessage) => Promise<boolean>;
|
|
430
|
+
/** Test seam for local Ollama inventory and mutation routes. */
|
|
431
|
+
readonly localFetch?: typeof fetch;
|
|
424
432
|
}
|
|
425
433
|
/** Register the Host HTTP surface consumed by the browser settings page. */
|
|
426
434
|
declare function applyRoutes(ctx: Context, web: WebServer, deps: RouteDeps): void;
|
|
@@ -468,7 +476,6 @@ interface ModelProbe {
|
|
|
468
476
|
readonly tools: boolean;
|
|
469
477
|
readonly available: boolean;
|
|
470
478
|
}
|
|
471
|
-
/** Probe one local model via `/api/show`, caching successful answers for five minutes. */
|
|
472
479
|
declare function probeModel(config: ResolvedConfig, model: string, fetchImpl?: typeof fetch): Promise<ModelProbe | undefined>;
|
|
473
480
|
/** Clear all probe entries, or only entries for one endpoint. */
|
|
474
481
|
declare function clearModelProbeCache(baseURL?: string): void;
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
-
import { appendFile, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { existsSync, readFileSync, statSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { appendFile, mkdir, readFile, readdir, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
6
|
import { CONTEXT_WINDOW_EXCEEDED_CODE, LlmAdapter, LlmError, ReasoningEffortId, ToolCallId, attributionHeaders, isContextWindowExceededError, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
@@ -50,7 +50,7 @@ const DEFAULT_API_BASE = "https://ollama.com";
|
|
|
50
50
|
const DEFAULT_OPENAI_BASE = "https://ollama.com/v1";
|
|
51
51
|
const DEFAULT_USAGE_URL = "https://ollama.com/api/usage";
|
|
52
52
|
const DEFAULT_BALANCE_URL = "https://ollama.com/api/balance";
|
|
53
|
-
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.
|
|
53
|
+
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.21";
|
|
54
54
|
const DEFAULT_CONTEXT_WINDOW = 131072;
|
|
55
55
|
const DEFAULT_MAX_TOKENS = 32768;
|
|
56
56
|
const DEFAULT_GENERATE_MAX_TOKENS = 131072;
|
|
@@ -86,6 +86,8 @@ const Config = z.object({
|
|
|
86
86
|
numCtx: markVolatile(z.number().min(1).max(1e7).step(1)),
|
|
87
87
|
keepAlive: markVolatile(z.string()),
|
|
88
88
|
stop: markVolatile(z.array(z.string())),
|
|
89
|
+
autoRefresh: markVolatile(z.boolean().default(true)),
|
|
90
|
+
refreshMinutes: markVolatile(z.number().min(0).max(10080).step(1).default(1440)),
|
|
89
91
|
accounts: markVolatile(z.array(z.object({
|
|
90
92
|
label: z.string(),
|
|
91
93
|
apiKeyEnv: z.string().role("credential-ref"),
|
|
@@ -131,23 +133,23 @@ function nonEmptyStrings(value) {
|
|
|
131
133
|
const out = value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
|
|
132
134
|
return out.length === 0 ? void 0 : out;
|
|
133
135
|
}
|
|
134
|
-
function recordOf(value) {
|
|
136
|
+
function recordOf$1(value) {
|
|
135
137
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
136
138
|
}
|
|
137
139
|
function numberRecord(value) {
|
|
138
140
|
const out = {};
|
|
139
|
-
for (const [key, entry] of Object.entries(recordOf(value))) if (typeof entry === "number" && Number.isInteger(entry) && entry > 0) out[key] = entry;
|
|
141
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) if (typeof entry === "number" && Number.isInteger(entry) && entry > 0) out[key] = entry;
|
|
140
142
|
return out;
|
|
141
143
|
}
|
|
142
144
|
function booleanRecord(value) {
|
|
143
145
|
const out = {};
|
|
144
|
-
for (const [key, entry] of Object.entries(recordOf(value))) if (typeof entry === "boolean") out[key] = entry;
|
|
146
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) if (typeof entry === "boolean") out[key] = entry;
|
|
145
147
|
return out;
|
|
146
148
|
}
|
|
147
149
|
function priceRecord(value) {
|
|
148
150
|
const out = {};
|
|
149
|
-
for (const [key, entry] of Object.entries(recordOf(value))) {
|
|
150
|
-
const raw = recordOf(entry);
|
|
151
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) {
|
|
152
|
+
const raw = recordOf$1(entry);
|
|
151
153
|
const price = {};
|
|
152
154
|
if (typeof raw.input === "number" && raw.input >= 0) price.input = raw.input;
|
|
153
155
|
if (typeof raw.output === "number" && raw.output >= 0) price.output = raw.output;
|
|
@@ -159,14 +161,14 @@ function priceRecord(value) {
|
|
|
159
161
|
const TRANSPORTS$1 = /* @__PURE__ */ new Set(["native", "openai-chat"]);
|
|
160
162
|
function transportRecord(value) {
|
|
161
163
|
const out = {};
|
|
162
|
-
for (const [key, entry] of Object.entries(recordOf(value))) if (typeof entry === "string" && TRANSPORTS$1.has(entry)) out[key] = entry;
|
|
164
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) if (typeof entry === "string" && TRANSPORTS$1.has(entry)) out[key] = entry;
|
|
163
165
|
return out;
|
|
164
166
|
}
|
|
165
167
|
function ruleList(value) {
|
|
166
168
|
if (!Array.isArray(value)) return [];
|
|
167
169
|
const out = [];
|
|
168
170
|
for (const entry of value) {
|
|
169
|
-
const raw = recordOf(entry);
|
|
171
|
+
const raw = recordOf$1(entry);
|
|
170
172
|
const pattern = typeof raw.pattern === "string" ? raw.pattern.trim() : "";
|
|
171
173
|
const account = typeof raw.account === "string" ? raw.account.trim() : "";
|
|
172
174
|
if (pattern !== "" && account !== "") out.push({
|
|
@@ -217,6 +219,8 @@ function resolveConfig(config) {
|
|
|
217
219
|
...numCtx === void 0 ? {} : { numCtx },
|
|
218
220
|
...typeof config.keepAlive === "string" && config.keepAlive.trim() !== "" ? { keepAlive: config.keepAlive.trim() } : {},
|
|
219
221
|
...stop === void 0 ? {} : { stop },
|
|
222
|
+
autoRefresh: config.autoRefresh !== false,
|
|
223
|
+
refreshMinutes: typeof config.refreshMinutes === "number" && Number.isInteger(config.refreshMinutes) && config.refreshMinutes >= 0 && config.refreshMinutes <= 10080 ? config.refreshMinutes : 1440,
|
|
220
224
|
accounts: Array.isArray(config.accounts) ? config.accounts : [],
|
|
221
225
|
modelAccountRules: ruleList(config.modelAccountRules),
|
|
222
226
|
stickySession: config.stickySession !== false,
|
|
@@ -227,6 +231,74 @@ function resolveConfig(config) {
|
|
|
227
231
|
userAgent: typeof config.userAgent === "string" && config.userAgent !== "" ? config.userAgent : DEFAULT_USER_AGENT
|
|
228
232
|
};
|
|
229
233
|
}
|
|
234
|
+
// src/catalog-cache.ts
|
|
235
|
+
const VERSION = 1;
|
|
236
|
+
function catalogCachePath() {
|
|
237
|
+
const home = process.env.DSH_HOME?.trim() || join(homedir(), ".dsh");
|
|
238
|
+
return join(home, "cache", "dsh-ollama-cloud", "catalog.json");
|
|
239
|
+
}
|
|
240
|
+
function isMeta(value) {
|
|
241
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
242
|
+
const record = value;
|
|
243
|
+
return typeof record.id === "string" && typeof record.transport === "string" && typeof record.contextWindow === "number" && Array.isArray(record.input) && Array.isArray(record.reasoning);
|
|
244
|
+
}
|
|
245
|
+
function parse(value) {
|
|
246
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
247
|
+
const record = value;
|
|
248
|
+
if (record.version !== VERSION || typeof record.baseURL !== "string") return void 0;
|
|
249
|
+
if (typeof record.at !== "number" || !Number.isFinite(record.at)) return void 0;
|
|
250
|
+
if (!Array.isArray(record.ids) || !record.ids.every((id) => typeof id === "string" && id !== "")) return void 0;
|
|
251
|
+
if (typeof record.meta !== "object" || record.meta === null || Array.isArray(record.meta)) return void 0;
|
|
252
|
+
const meta = {};
|
|
253
|
+
for (const [id, entry] of Object.entries(record.meta)) if (isMeta(entry) && entry.id === id) meta[id] = entry;
|
|
254
|
+
return {
|
|
255
|
+
version: VERSION,
|
|
256
|
+
baseURL: record.baseURL,
|
|
257
|
+
at: record.at,
|
|
258
|
+
ids: record.ids,
|
|
259
|
+
meta
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async function loadCatalogSnapshot(baseURL) {
|
|
263
|
+
try {
|
|
264
|
+
const parsed = parse(JSON.parse(await readFile(catalogCachePath(), "utf8")));
|
|
265
|
+
if (parsed === void 0 || parsed.baseURL !== baseURL) return void 0;
|
|
266
|
+
return {
|
|
267
|
+
at: parsed.at,
|
|
268
|
+
ids: parsed.ids,
|
|
269
|
+
meta: parsed.meta
|
|
270
|
+
};
|
|
271
|
+
} catch {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function saveCatalogSnapshot(baseURL, ids, meta) {
|
|
276
|
+
const path = catalogCachePath();
|
|
277
|
+
const temp = `${path}.${process.pid}.${createHash("sha1").update(`${Date.now()}`).digest("hex").slice(0, 8)}.tmp`;
|
|
278
|
+
const payload = {
|
|
279
|
+
version: VERSION,
|
|
280
|
+
baseURL,
|
|
281
|
+
at: Date.now(),
|
|
282
|
+
ids,
|
|
283
|
+
meta
|
|
284
|
+
};
|
|
285
|
+
try {
|
|
286
|
+
await mkdir(dirname(path), { recursive: true });
|
|
287
|
+
await writeFile(temp, `${JSON.stringify(payload)}\n`, "utf8");
|
|
288
|
+
await rename(temp, path);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
bestEffortFailed("catalog cache write failed", error);
|
|
291
|
+
try {
|
|
292
|
+
await unlink(temp);
|
|
293
|
+
} catch {}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** Remove the persistent snapshot together with the in-memory cache. */
|
|
297
|
+
function clearCatalogSnapshot() {
|
|
298
|
+
try {
|
|
299
|
+
unlinkSync(catalogCachePath());
|
|
300
|
+
} catch {}
|
|
301
|
+
}
|
|
230
302
|
// src/models.generated.ts
|
|
231
303
|
const GENERATED_MODELS = {
|
|
232
304
|
"beam": {
|
|
@@ -783,11 +855,14 @@ function probeOf(body) {
|
|
|
783
855
|
};
|
|
784
856
|
}
|
|
785
857
|
/** Probe one local model via `/api/show`, caching successful answers for five minutes. */
|
|
786
|
-
async function
|
|
787
|
-
if (!isLocalEndpoint(config)) return
|
|
858
|
+
async function probeModelOutcome(config, model, fetchImpl = fetch) {
|
|
859
|
+
if (!isLocalEndpoint(config)) return { missing: false };
|
|
788
860
|
const key = keyOf(config, model);
|
|
789
861
|
const hit = cache$2.get(key);
|
|
790
|
-
if (hit !== void 0 && Date.now() - hit.at < PROBE_TTL_MS) return
|
|
862
|
+
if (hit !== void 0 && Date.now() - hit.at < PROBE_TTL_MS) return {
|
|
863
|
+
probe: hit.value,
|
|
864
|
+
missing: false
|
|
865
|
+
};
|
|
791
866
|
try {
|
|
792
867
|
const response = await fetchImpl(`${rootFor(config)}/api/show`, {
|
|
793
868
|
method: "POST",
|
|
@@ -799,18 +874,25 @@ async function probeModel(config, model, fetchImpl = fetch) {
|
|
|
799
874
|
body: JSON.stringify({ model }),
|
|
800
875
|
signal: AbortSignal.timeout(1e4)
|
|
801
876
|
});
|
|
802
|
-
if (
|
|
877
|
+
if (response.status === 404 || response.status === 410) return { missing: true };
|
|
878
|
+
if (!response.ok) return { missing: false };
|
|
803
879
|
const value = probeOf(await response.json());
|
|
804
|
-
if (value === void 0) return
|
|
880
|
+
if (value === void 0) return { missing: false };
|
|
805
881
|
cache$2.set(key, {
|
|
806
882
|
at: Date.now(),
|
|
807
883
|
value
|
|
808
884
|
});
|
|
809
|
-
return
|
|
885
|
+
return {
|
|
886
|
+
probe: value,
|
|
887
|
+
missing: false
|
|
888
|
+
};
|
|
810
889
|
} catch {
|
|
811
|
-
return;
|
|
890
|
+
return { missing: false };
|
|
812
891
|
}
|
|
813
892
|
}
|
|
893
|
+
async function probeModel(config, model, fetchImpl = fetch) {
|
|
894
|
+
return (await probeModelOutcome(config, model, fetchImpl)).probe;
|
|
895
|
+
}
|
|
814
896
|
/** Clear all probe entries, or only entries for one endpoint. */
|
|
815
897
|
function clearModelProbeCache(baseURL) {
|
|
816
898
|
if (baseURL === void 0) {
|
|
@@ -978,6 +1060,7 @@ const CATALOG_TIMEOUT_MS = 15e3;
|
|
|
978
1060
|
const liveMeta = /* @__PURE__ */ new Map();
|
|
979
1061
|
const cache$1 = /* @__PURE__ */ new Map();
|
|
980
1062
|
const inflight = /* @__PURE__ */ new Map();
|
|
1063
|
+
const diskLoaded = /* @__PURE__ */ new Set();
|
|
981
1064
|
let generation = 0;
|
|
982
1065
|
function liveKey(base, id) {
|
|
983
1066
|
return `${base}|${id}`;
|
|
@@ -1081,11 +1164,27 @@ function metaFromProbe(id, probe) {
|
|
|
1081
1164
|
};
|
|
1082
1165
|
}
|
|
1083
1166
|
async function adoptProbes(config, ids, base, fetchImpl) {
|
|
1084
|
-
const
|
|
1167
|
+
const outcomes = await Promise.all(ids.slice(0, 64).map(async (id) => ({
|
|
1085
1168
|
id,
|
|
1086
|
-
|
|
1169
|
+
outcome: await probeModelOutcome(config, id, fetchImpl)
|
|
1087
1170
|
})));
|
|
1088
|
-
|
|
1171
|
+
const kept = [];
|
|
1172
|
+
for (const { id, outcome } of outcomes) {
|
|
1173
|
+
if (outcome.missing) continue;
|
|
1174
|
+
kept.push(id);
|
|
1175
|
+
const meta = metaFromProbe(id, outcome.probe);
|
|
1176
|
+
if (meta !== void 0) liveMeta.set(liveKey(base, id), meta);
|
|
1177
|
+
}
|
|
1178
|
+
return kept;
|
|
1179
|
+
}
|
|
1180
|
+
function metaForBase(base) {
|
|
1181
|
+
const out = {};
|
|
1182
|
+
const prefix = `${base}|`;
|
|
1183
|
+
for (const [key, meta] of liveMeta) if (key.startsWith(prefix)) out[key.slice(prefix.length)] = meta;
|
|
1184
|
+
return out;
|
|
1185
|
+
}
|
|
1186
|
+
async function persist(base, ids) {
|
|
1187
|
+
await saveCatalogSnapshot(base, ids, metaForBase(base));
|
|
1089
1188
|
}
|
|
1090
1189
|
/** Replace the in-memory live metadata for one API base with one successful response. */
|
|
1091
1190
|
function adoptLive(models, tags, base) {
|
|
@@ -1128,9 +1227,20 @@ async function fetchJson(url, config, fetchImpl, signal) {
|
|
|
1128
1227
|
*/
|
|
1129
1228
|
async function refreshCatalog(config, fetchImpl = fetch, force = false) {
|
|
1130
1229
|
const key = config.apiBase;
|
|
1230
|
+
if (!diskLoaded.has(key)) {
|
|
1231
|
+
diskLoaded.add(key);
|
|
1232
|
+
const snapshot = await loadCatalogSnapshot(key);
|
|
1233
|
+
if (snapshot !== void 0 && !cache$1.has(key)) {
|
|
1234
|
+
cache$1.set(key, {
|
|
1235
|
+
at: snapshot.at,
|
|
1236
|
+
ids: snapshot.ids
|
|
1237
|
+
});
|
|
1238
|
+
for (const [id, meta] of Object.entries(snapshot.meta)) liveMeta.set(liveKey(key, id), meta);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1131
1241
|
const cached = cache$1.get(key);
|
|
1132
1242
|
if (!force && cached !== void 0) {
|
|
1133
|
-
if (Date.now() - cached.at >= CATALOG_TTL_MS) refreshInBackground(config, fetchImpl, key);
|
|
1243
|
+
if (config.autoRefresh && Date.now() - cached.at >= CATALOG_TTL_MS) refreshInBackground(config, fetchImpl, key);
|
|
1134
1244
|
return cached.ids;
|
|
1135
1245
|
}
|
|
1136
1246
|
return refreshNow(config, fetchImpl, key, cached !== void 0, generation);
|
|
@@ -1150,19 +1260,21 @@ async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
|
|
|
1150
1260
|
at: Date.now(),
|
|
1151
1261
|
ids
|
|
1152
1262
|
});
|
|
1263
|
+
await persist(key, ids);
|
|
1153
1264
|
return ids;
|
|
1154
1265
|
}
|
|
1155
1266
|
}
|
|
1156
1267
|
const fromData = Array.isArray(payload.data) ? payload.data.map((entry) => str$1(entry.id)).filter((id) => id !== void 0) : [];
|
|
1157
1268
|
const fromTags = ((tagsResult.status === "fulfilled" ? tagsResult.value : void 0)?.models ?? []).map((entry) => str$1(entry.name) ?? str$1(entry.model)).filter((id) => id !== void 0);
|
|
1158
|
-
const
|
|
1159
|
-
if (
|
|
1269
|
+
const discovered = fromData.length > 0 ? fromData : fromTags;
|
|
1270
|
+
if (discovered.length > 0) {
|
|
1160
1271
|
for (const liveKey of liveMeta.keys()) if (liveKey.startsWith(`${key}|`)) liveMeta.delete(liveKey);
|
|
1161
|
-
|
|
1272
|
+
const ids = isLocalEndpoint(config) ? await adoptProbes(config, discovered, key, fetchImpl) : discovered;
|
|
1162
1273
|
cache$1.set(key, {
|
|
1163
1274
|
at: Date.now(),
|
|
1164
1275
|
ids
|
|
1165
1276
|
});
|
|
1277
|
+
await persist(key, ids);
|
|
1166
1278
|
return ids;
|
|
1167
1279
|
}
|
|
1168
1280
|
}
|
|
@@ -1189,7 +1301,9 @@ function clearCatalogCache() {
|
|
|
1189
1301
|
cache$1.clear();
|
|
1190
1302
|
inflight.clear();
|
|
1191
1303
|
liveMeta.clear();
|
|
1304
|
+
diskLoaded.clear();
|
|
1192
1305
|
clearModelProbeCache();
|
|
1306
|
+
clearCatalogSnapshot();
|
|
1193
1307
|
}
|
|
1194
1308
|
function baseMeta(id, base) {
|
|
1195
1309
|
const meta = liveMeta.get(liveKey(base, id)) ?? GENERATED_MODELS[id];
|
|
@@ -3056,6 +3170,205 @@ function windowRows(report) {
|
|
|
3056
3170
|
}
|
|
3057
3171
|
].filter((entry) => entry !== void 0);
|
|
3058
3172
|
}
|
|
3173
|
+
// src/local-models.ts
|
|
3174
|
+
const LOCAL_TIMEOUT_MS = 15e3;
|
|
3175
|
+
const MODEL_NAME = /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/;
|
|
3176
|
+
function formatBytes(bytes) {
|
|
3177
|
+
if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
|
|
3178
|
+
const units = [
|
|
3179
|
+
"B",
|
|
3180
|
+
"KB",
|
|
3181
|
+
"MB",
|
|
3182
|
+
"GB",
|
|
3183
|
+
"TB"
|
|
3184
|
+
];
|
|
3185
|
+
let value = bytes;
|
|
3186
|
+
let index = 0;
|
|
3187
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
3188
|
+
value /= 1024;
|
|
3189
|
+
index += 1;
|
|
3190
|
+
}
|
|
3191
|
+
return `${value >= 10 || index === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[index]}`;
|
|
3192
|
+
}
|
|
3193
|
+
function assertLocal(config) {
|
|
3194
|
+
if (!isLocalEndpoint(config)) throw new Error("local endpoint required");
|
|
3195
|
+
}
|
|
3196
|
+
function assertModelName(model) {
|
|
3197
|
+
const name = model.trim();
|
|
3198
|
+
if (name === "" || name.includes("..") || !MODEL_NAME.test(name)) throw new Error("invalid model name");
|
|
3199
|
+
return name;
|
|
3200
|
+
}
|
|
3201
|
+
function recordOf(value) {
|
|
3202
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
3203
|
+
}
|
|
3204
|
+
function stringOf(value) {
|
|
3205
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
3206
|
+
}
|
|
3207
|
+
function numberOf(value) {
|
|
3208
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
3209
|
+
}
|
|
3210
|
+
function detailsOf(value) {
|
|
3211
|
+
const record = recordOf(value);
|
|
3212
|
+
if (record === void 0) return void 0;
|
|
3213
|
+
const family = stringOf(record.family);
|
|
3214
|
+
const parameterSize = stringOf(record.parameter_size);
|
|
3215
|
+
const quantization = stringOf(record.quantization_level);
|
|
3216
|
+
const out = {
|
|
3217
|
+
...family === void 0 ? {} : { family },
|
|
3218
|
+
...parameterSize === void 0 ? {} : { parameterSize },
|
|
3219
|
+
...quantization === void 0 ? {} : { quantization }
|
|
3220
|
+
};
|
|
3221
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
3222
|
+
}
|
|
3223
|
+
async function localJson(config, path, init, fetchImpl) {
|
|
3224
|
+
const response = await fetchImpl(`${rootFor(config)}${path}`, {
|
|
3225
|
+
...init,
|
|
3226
|
+
headers: {
|
|
3227
|
+
accept: "application/json",
|
|
3228
|
+
"content-type": "application/json",
|
|
3229
|
+
"user-agent": config.userAgent,
|
|
3230
|
+
...init.headers
|
|
3231
|
+
},
|
|
3232
|
+
signal: AbortSignal.timeout(LOCAL_TIMEOUT_MS)
|
|
3233
|
+
});
|
|
3234
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
3235
|
+
return response.json();
|
|
3236
|
+
}
|
|
3237
|
+
async function readLocalInventory(config, fetchImpl = fetch) {
|
|
3238
|
+
assertLocal(config);
|
|
3239
|
+
const [tagsPayload, psPayload] = await Promise.all([localJson(config, "/api/tags", { method: "GET" }, fetchImpl), localJson(config, "/api/ps", { method: "GET" }, fetchImpl).catch(() => void 0)]);
|
|
3240
|
+
const tags = recordOf(tagsPayload);
|
|
3241
|
+
const models = [];
|
|
3242
|
+
for (const entry of Array.isArray(tags?.models) ? tags.models : []) {
|
|
3243
|
+
const record = recordOf(entry);
|
|
3244
|
+
if (record === void 0) continue;
|
|
3245
|
+
const name = stringOf(record.name) ?? stringOf(record.model);
|
|
3246
|
+
if (name === void 0) continue;
|
|
3247
|
+
const size = numberOf(record.size) ?? 0;
|
|
3248
|
+
const digest = stringOf(record.digest);
|
|
3249
|
+
const modifiedAt = stringOf(record.modified_at);
|
|
3250
|
+
const details = detailsOf(record.details);
|
|
3251
|
+
models.push({
|
|
3252
|
+
name,
|
|
3253
|
+
size,
|
|
3254
|
+
...digest === void 0 ? {} : { digest },
|
|
3255
|
+
...modifiedAt === void 0 ? {} : { modifiedAt },
|
|
3256
|
+
...details === void 0 ? {} : { details }
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
models.sort((a, b) => a.name.localeCompare(b.name));
|
|
3260
|
+
const running = [];
|
|
3261
|
+
const ps = recordOf(psPayload);
|
|
3262
|
+
for (const entry of Array.isArray(ps?.models) ? ps.models : []) {
|
|
3263
|
+
const record = recordOf(entry);
|
|
3264
|
+
if (record === void 0) continue;
|
|
3265
|
+
const name = stringOf(record.name) ?? stringOf(record.model);
|
|
3266
|
+
if (name === void 0) continue;
|
|
3267
|
+
const digest = stringOf(record.digest);
|
|
3268
|
+
const expiresAt = stringOf(record.expires_at);
|
|
3269
|
+
running.push({
|
|
3270
|
+
name,
|
|
3271
|
+
size: numberOf(record.size) ?? 0,
|
|
3272
|
+
sizeVram: numberOf(record.size_vram) ?? 0,
|
|
3273
|
+
...digest === void 0 ? {} : { digest },
|
|
3274
|
+
...expiresAt === void 0 ? {} : { expiresAt }
|
|
3275
|
+
});
|
|
3276
|
+
}
|
|
3277
|
+
running.sort((a, b) => a.name.localeCompare(b.name));
|
|
3278
|
+
return {
|
|
3279
|
+
models,
|
|
3280
|
+
running,
|
|
3281
|
+
diskBytes: models.reduce((sum, model) => sum + model.size, 0),
|
|
3282
|
+
runningBytes: running.reduce((sum, model) => sum + model.sizeVram, 0)
|
|
3283
|
+
};
|
|
3284
|
+
}
|
|
3285
|
+
async function showLocalModel(config, model, fetchImpl = fetch) {
|
|
3286
|
+
assertLocal(config);
|
|
3287
|
+
const name = assertModelName(model);
|
|
3288
|
+
const payload = recordOf(await localJson(config, "/api/show", {
|
|
3289
|
+
method: "POST",
|
|
3290
|
+
body: JSON.stringify({ model: name })
|
|
3291
|
+
}, fetchImpl));
|
|
3292
|
+
if (payload === void 0) throw new Error("invalid show response");
|
|
3293
|
+
const capabilities = Array.isArray(payload.capabilities) ? payload.capabilities.filter((entry) => typeof entry === "string") : [];
|
|
3294
|
+
const modifiedAt = stringOf(payload.modified_at);
|
|
3295
|
+
const details = detailsOf(payload.details);
|
|
3296
|
+
const parameters = stringOf(payload.parameters);
|
|
3297
|
+
return {
|
|
3298
|
+
name,
|
|
3299
|
+
...modifiedAt === void 0 ? {} : { modifiedAt },
|
|
3300
|
+
...details === void 0 ? {} : { details },
|
|
3301
|
+
capabilities,
|
|
3302
|
+
...parameters === void 0 ? {} : { parameters }
|
|
3303
|
+
};
|
|
3304
|
+
}
|
|
3305
|
+
async function pullLocalModel(config, model, onProgress = () => {}, fetchImpl = fetch, signal) {
|
|
3306
|
+
assertLocal(config);
|
|
3307
|
+
const name = assertModelName(model);
|
|
3308
|
+
const response = await fetchImpl(`${rootFor(config)}/api/pull`, {
|
|
3309
|
+
method: "POST",
|
|
3310
|
+
headers: {
|
|
3311
|
+
accept: "application/x-ndjson",
|
|
3312
|
+
"content-type": "application/json",
|
|
3313
|
+
"user-agent": config.userAgent
|
|
3314
|
+
},
|
|
3315
|
+
body: JSON.stringify({
|
|
3316
|
+
model: name,
|
|
3317
|
+
stream: true
|
|
3318
|
+
}),
|
|
3319
|
+
...signal === void 0 ? {} : { signal }
|
|
3320
|
+
});
|
|
3321
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
3322
|
+
if (response.body === null) throw new Error("empty pull stream");
|
|
3323
|
+
const reader = response.body.getReader();
|
|
3324
|
+
const decoder = new TextDecoder();
|
|
3325
|
+
let buffer = "";
|
|
3326
|
+
let last = { status: "starting" };
|
|
3327
|
+
const consume = (line) => {
|
|
3328
|
+
if (line.trim() === "") return;
|
|
3329
|
+
const entry = recordOf(JSON.parse(line));
|
|
3330
|
+
if (entry === void 0) return;
|
|
3331
|
+
if (typeof entry.error === "string" && entry.error !== "") throw new Error(entry.error);
|
|
3332
|
+
if (typeof entry.status === "string") {
|
|
3333
|
+
const digest = stringOf(entry.digest);
|
|
3334
|
+
const completed = numberOf(entry.completed);
|
|
3335
|
+
const total = numberOf(entry.total);
|
|
3336
|
+
last = {
|
|
3337
|
+
status: entry.status,
|
|
3338
|
+
...digest === void 0 ? {} : { digest },
|
|
3339
|
+
...completed === void 0 ? {} : { completed },
|
|
3340
|
+
...total === void 0 ? {} : { total }
|
|
3341
|
+
};
|
|
3342
|
+
onProgress(last);
|
|
3343
|
+
}
|
|
3344
|
+
};
|
|
3345
|
+
for (;;) {
|
|
3346
|
+
const { done, value } = await reader.read();
|
|
3347
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
3348
|
+
const lines = buffer.split("\n");
|
|
3349
|
+
buffer = lines.pop() ?? "";
|
|
3350
|
+
for (const line of lines) consume(line);
|
|
3351
|
+
if (done) break;
|
|
3352
|
+
}
|
|
3353
|
+
if (buffer.trim() !== "") consume(buffer);
|
|
3354
|
+
return last;
|
|
3355
|
+
}
|
|
3356
|
+
/** Delete one local model. Callers must obtain explicit confirmation first. */
|
|
3357
|
+
async function removeLocalModel(config, model, fetchImpl = fetch) {
|
|
3358
|
+
assertLocal(config);
|
|
3359
|
+
const name = assertModelName(model);
|
|
3360
|
+
const response = await fetchImpl(`${rootFor(config)}/api/delete`, {
|
|
3361
|
+
method: "DELETE",
|
|
3362
|
+
headers: {
|
|
3363
|
+
accept: "application/json",
|
|
3364
|
+
"content-type": "application/json",
|
|
3365
|
+
"user-agent": config.userAgent
|
|
3366
|
+
},
|
|
3367
|
+
body: JSON.stringify({ model: name }),
|
|
3368
|
+
signal: AbortSignal.timeout(LOCAL_TIMEOUT_MS)
|
|
3369
|
+
});
|
|
3370
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
3371
|
+
}
|
|
3059
3372
|
// src/commands.ts
|
|
3060
3373
|
function bar(percent, width = 10) {
|
|
3061
3374
|
const clamped = Math.max(0, Math.min(100, percent));
|
|
@@ -3170,6 +3483,57 @@ async function testText(deps, model) {
|
|
|
3170
3483
|
};
|
|
3171
3484
|
}
|
|
3172
3485
|
}
|
|
3486
|
+
async function localText(deps) {
|
|
3487
|
+
const config = deps.config();
|
|
3488
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3489
|
+
const inventory = await readLocalInventory(config);
|
|
3490
|
+
const running = new Map(inventory.running.map((entry) => [entry.name, entry]));
|
|
3491
|
+
const lines = [`Local Ollama · disk ${formatBytes(inventory.diskBytes)} · running ${formatBytes(inventory.runningBytes)}`];
|
|
3492
|
+
if (inventory.models.length === 0) return [...lines, "No local models."].join("\n");
|
|
3493
|
+
for (const model of inventory.models) {
|
|
3494
|
+
const active = running.get(model.name);
|
|
3495
|
+
const details = model.details === void 0 ? "" : [
|
|
3496
|
+
model.details.family,
|
|
3497
|
+
model.details.parameterSize,
|
|
3498
|
+
model.details.quantization
|
|
3499
|
+
].filter((entry) => entry !== void 0).join(" ");
|
|
3500
|
+
lines.push(`- ${model.name} · ${formatBytes(model.size)}${active === void 0 ? "" : " · RUNNING"}${details === "" ? "" : ` · ${details}`}`);
|
|
3501
|
+
}
|
|
3502
|
+
return lines.join("\n");
|
|
3503
|
+
}
|
|
3504
|
+
async function localPsText(deps) {
|
|
3505
|
+
const config = deps.config();
|
|
3506
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3507
|
+
const inventory = await readLocalInventory(config);
|
|
3508
|
+
if (inventory.running.length === 0) return "No running models.";
|
|
3509
|
+
return inventory.running.map((entry) => `- ${entry.name} · VRAM ${formatBytes(entry.sizeVram)}${entry.expiresAt === void 0 ? "" : ` · expires ${entry.expiresAt}`}`).join("\n");
|
|
3510
|
+
}
|
|
3511
|
+
async function localShowText(deps, model) {
|
|
3512
|
+
const config = deps.config();
|
|
3513
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3514
|
+
const show = await showLocalModel(config, model);
|
|
3515
|
+
const lines = [`Local model: ${show.name}`];
|
|
3516
|
+
if (show.modifiedAt !== void 0) lines.push(`Modified: ${show.modifiedAt}`);
|
|
3517
|
+
if (show.details !== void 0) lines.push(`Details: ${show.details.family ?? "?"} ${show.details.parameterSize ?? ""} ${show.details.quantization ?? ""}`.trim());
|
|
3518
|
+
if (show.capabilities.length > 0) lines.push(`Capabilities: ${show.capabilities.join(", ")}`);
|
|
3519
|
+
if (show.parameters !== void 0) lines.push(`Parameters:\n${show.parameters.slice(0, 2e3)}`);
|
|
3520
|
+
return lines.join("\n");
|
|
3521
|
+
}
|
|
3522
|
+
async function localPullText(deps, model) {
|
|
3523
|
+
const config = deps.config();
|
|
3524
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3525
|
+
let fraction = 0;
|
|
3526
|
+
return `${model}: ${(await pullLocalModel(config, model, (progress) => {
|
|
3527
|
+
if (progress.total !== void 0 && progress.total > 0) fraction = (progress.completed ?? 0) / progress.total;
|
|
3528
|
+
})).status}${fraction > 0 ? ` · ${Math.round(fraction * 100)}%` : ""}`;
|
|
3529
|
+
}
|
|
3530
|
+
async function localRemoveText(deps, model, confirmed) {
|
|
3531
|
+
if (!confirmed) return `Refusing to remove ${model}: add --yes to confirm.`;
|
|
3532
|
+
const config = deps.config();
|
|
3533
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3534
|
+
await removeLocalModel(config, model);
|
|
3535
|
+
return `${model}: removed.`;
|
|
3536
|
+
}
|
|
3173
3537
|
async function statusText(deps) {
|
|
3174
3538
|
const config = deps.config();
|
|
3175
3539
|
const rules = config.modelAccountRules.length === 0 ? "none" : config.modelAccountRules.map((rule) => `${rule.pattern} → ${rule.account}`).join(", ");
|
|
@@ -3188,7 +3552,7 @@ function applyCommands(ctx, deps) {
|
|
|
3188
3552
|
ctx.commands.register({
|
|
3189
3553
|
name: "ollama",
|
|
3190
3554
|
description: "Ollama Cloud status, balance, accounts, models and rules",
|
|
3191
|
-
input: { hint: "status | usage | balance | accounts | models | rules | test [model]" },
|
|
3555
|
+
input: { hint: "status | usage | balance | accounts | models | rules | test [model] | local [models|ps|show|pull|remove] [model]" },
|
|
3192
3556
|
handler: async (invocation) => {
|
|
3193
3557
|
const raw = invocation.rawInput.trim();
|
|
3194
3558
|
const parts = raw === "" ? ["status"] : raw.split(/\s+/);
|
|
@@ -3229,9 +3593,50 @@ function applyCommands(ctx, deps) {
|
|
|
3229
3593
|
text: result.text
|
|
3230
3594
|
};
|
|
3231
3595
|
}
|
|
3596
|
+
case "local": {
|
|
3597
|
+
const words = arg === "" ? [] : arg.split(/\s+/);
|
|
3598
|
+
const action = (words[0] ?? "models").toLowerCase();
|
|
3599
|
+
const confirmed = words.includes("--yes");
|
|
3600
|
+
const model = words.slice(1).filter((word) => word !== "--yes").join(" ");
|
|
3601
|
+
try {
|
|
3602
|
+
if (action === "models") return {
|
|
3603
|
+
kind: "success",
|
|
3604
|
+
text: await localText(deps)
|
|
3605
|
+
};
|
|
3606
|
+
if (action === "ps") return {
|
|
3607
|
+
kind: "success",
|
|
3608
|
+
text: await localPsText(deps)
|
|
3609
|
+
};
|
|
3610
|
+
if (model === "") return {
|
|
3611
|
+
kind: "error",
|
|
3612
|
+
text: `Usage: /ollama local ${action} <model>`
|
|
3613
|
+
};
|
|
3614
|
+
if (action === "show") return {
|
|
3615
|
+
kind: "success",
|
|
3616
|
+
text: await localShowText(deps, model)
|
|
3617
|
+
};
|
|
3618
|
+
if (action === "pull") return {
|
|
3619
|
+
kind: "success",
|
|
3620
|
+
text: await localPullText(deps, model)
|
|
3621
|
+
};
|
|
3622
|
+
if (action === "remove") return {
|
|
3623
|
+
kind: confirmed ? "success" : "error",
|
|
3624
|
+
text: await localRemoveText(deps, model, confirmed)
|
|
3625
|
+
};
|
|
3626
|
+
return {
|
|
3627
|
+
kind: "error",
|
|
3628
|
+
text: `Unknown local action "${action}". Use models, ps, show, pull, or remove.`
|
|
3629
|
+
};
|
|
3630
|
+
} catch (error) {
|
|
3631
|
+
return {
|
|
3632
|
+
kind: "error",
|
|
3633
|
+
text: error instanceof Error ? error.message : "local command failed"
|
|
3634
|
+
};
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3232
3637
|
default: return {
|
|
3233
3638
|
kind: "error",
|
|
3234
|
-
text: `Unknown /ollama argument "${verb}". Use status, usage, balance, accounts, models, rules,
|
|
3639
|
+
text: `Unknown /ollama argument "${verb}". Use status, usage, balance, accounts, models, rules, test [model], or local.`
|
|
3235
3640
|
};
|
|
3236
3641
|
}
|
|
3237
3642
|
}
|
|
@@ -3958,6 +4363,8 @@ function publicConfig(config) {
|
|
|
3958
4363
|
numCtx: config.numCtx ?? null,
|
|
3959
4364
|
keepAlive: config.keepAlive ?? "",
|
|
3960
4365
|
stop: config.stop ?? [],
|
|
4366
|
+
autoRefresh: config.autoRefresh,
|
|
4367
|
+
refreshMinutes: config.refreshMinutes,
|
|
3961
4368
|
accounts: config.accounts.map((account) => ({
|
|
3962
4369
|
label: typeof account.label === "string" ? account.label : "",
|
|
3963
4370
|
apiKeyEnv: typeof account.apiKeyEnv === "string" ? account.apiKeyEnv : ""
|
|
@@ -4296,6 +4703,8 @@ function configOps(patch) {
|
|
|
4296
4703
|
if ("numCtx" in patch) set("numCtx", patch.numCtx);
|
|
4297
4704
|
if ("keepAlive" in patch) set("keepAlive", patch.keepAlive);
|
|
4298
4705
|
if ("stop" in patch) set("stop", cleanStringArray(patch.stop));
|
|
4706
|
+
if ("autoRefresh" in patch) set("autoRefresh", patch.autoRefresh === true);
|
|
4707
|
+
if ("refreshMinutes" in patch) set("refreshMinutes", patch.refreshMinutes);
|
|
4299
4708
|
if ("accounts" in patch) {
|
|
4300
4709
|
const accounts = cleanAccounts(patch.accounts);
|
|
4301
4710
|
for (const account of accounts) if (account.apiKeyEnv !== "" && !isCredentialRef(account.apiKeyEnv)) throw new Error("invalid credential reference");
|
|
@@ -4626,6 +5035,93 @@ function applyRoutes(ctx, web, deps) {
|
|
|
4626
5035
|
}
|
|
4627
5036
|
await refreshAndState(ctx, deps, res);
|
|
4628
5037
|
});
|
|
5038
|
+
route("/dsh-ollama/local/models", async (req, res) => {
|
|
5039
|
+
if (!await privateRead(req, res)) return;
|
|
5040
|
+
const config = deps.config();
|
|
5041
|
+
if (!isLocalEndpoint(config)) {
|
|
5042
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5043
|
+
return;
|
|
5044
|
+
}
|
|
5045
|
+
try {
|
|
5046
|
+
json(res, 200, await readLocalInventory(config, deps.localFetch));
|
|
5047
|
+
} catch (error) {
|
|
5048
|
+
json(res, 502, { error: error instanceof Error ? error.message : "local models failed" });
|
|
5049
|
+
}
|
|
5050
|
+
});
|
|
5051
|
+
route("/dsh-ollama/local/show", async (req, res) => {
|
|
5052
|
+
if (!await privateRead(req, res)) return;
|
|
5053
|
+
const config = deps.config();
|
|
5054
|
+
if (!isLocalEndpoint(config)) {
|
|
5055
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5056
|
+
return;
|
|
5057
|
+
}
|
|
5058
|
+
const model = new URL(req.url ?? "/", "http://localhost").searchParams.get("model") ?? "";
|
|
5059
|
+
try {
|
|
5060
|
+
json(res, 200, await showLocalModel(config, model, deps.localFetch));
|
|
5061
|
+
} catch (error) {
|
|
5062
|
+
json(res, 400, { error: error instanceof Error ? error.message : "show failed" });
|
|
5063
|
+
}
|
|
5064
|
+
});
|
|
5065
|
+
route("/dsh-ollama/local/pull", async (req, res) => {
|
|
5066
|
+
if (!await requirePost(req, res, verifyHost)) return;
|
|
5067
|
+
const config = deps.config();
|
|
5068
|
+
if (!isLocalEndpoint(config)) {
|
|
5069
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5070
|
+
return;
|
|
5071
|
+
}
|
|
5072
|
+
let body;
|
|
5073
|
+
try {
|
|
5074
|
+
body = await readJson(req);
|
|
5075
|
+
} catch (error) {
|
|
5076
|
+
json(res, 400, { error: error instanceof Error ? error.message : "invalid body" });
|
|
5077
|
+
return;
|
|
5078
|
+
}
|
|
5079
|
+
const model = typeof body.model === "string" ? body.model : "";
|
|
5080
|
+
res.statusCode = 200;
|
|
5081
|
+
res.setHeader("content-type", "application/x-ndjson; charset=utf-8");
|
|
5082
|
+
res.setHeader("cache-control", "no-store");
|
|
5083
|
+
const write = (value) => {
|
|
5084
|
+
res.write(`${JSON.stringify(value)}\n`);
|
|
5085
|
+
};
|
|
5086
|
+
try {
|
|
5087
|
+
write({
|
|
5088
|
+
status: (await pullLocalModel(config, model, write, deps.localFetch)).status,
|
|
5089
|
+
done: true
|
|
5090
|
+
});
|
|
5091
|
+
} catch (error) {
|
|
5092
|
+
write({ error: error instanceof Error ? error.message : "pull failed" });
|
|
5093
|
+
}
|
|
5094
|
+
res.end();
|
|
5095
|
+
});
|
|
5096
|
+
route("/dsh-ollama/local/remove", async (req, res) => {
|
|
5097
|
+
if (!await requirePost(req, res, verifyHost)) return;
|
|
5098
|
+
const config = deps.config();
|
|
5099
|
+
if (!isLocalEndpoint(config)) {
|
|
5100
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5101
|
+
return;
|
|
5102
|
+
}
|
|
5103
|
+
let body;
|
|
5104
|
+
try {
|
|
5105
|
+
body = await readJson(req);
|
|
5106
|
+
} catch (error) {
|
|
5107
|
+
json(res, 400, { error: error instanceof Error ? error.message : "invalid body" });
|
|
5108
|
+
return;
|
|
5109
|
+
}
|
|
5110
|
+
if (body.confirm !== true) {
|
|
5111
|
+
json(res, 400, { error: "confirmation required" });
|
|
5112
|
+
return;
|
|
5113
|
+
}
|
|
5114
|
+
const model = typeof body.model === "string" ? body.model : "";
|
|
5115
|
+
try {
|
|
5116
|
+
await removeLocalModel(config, model, deps.localFetch);
|
|
5117
|
+
json(res, 200, {
|
|
5118
|
+
ok: true,
|
|
5119
|
+
model
|
|
5120
|
+
});
|
|
5121
|
+
} catch (error) {
|
|
5122
|
+
json(res, 502, { error: error instanceof Error ? error.message : "remove failed" });
|
|
5123
|
+
}
|
|
5124
|
+
});
|
|
4629
5125
|
route("/dsh-ollama/test", async (req, res) => {
|
|
4630
5126
|
if (!await requirePost(req, res, verifyHost)) return;
|
|
4631
5127
|
let body;
|
|
@@ -5318,6 +5814,25 @@ function apply(ctx, config) {
|
|
|
5318
5814
|
ctx.effect(() => () => {
|
|
5319
5815
|
flushRequestLog();
|
|
5320
5816
|
}, "dsh-ollama-cloud-provider: flush request log");
|
|
5817
|
+
ctx.effect(() => {
|
|
5818
|
+
const initial = current();
|
|
5819
|
+
const warm = initial.autoRefresh ? setTimeout(() => {
|
|
5820
|
+
const config = current();
|
|
5821
|
+
if (config.autoRefresh) refreshCatalog(config, fetch).catch(() => {});
|
|
5822
|
+
}, 1e3) : void 0;
|
|
5823
|
+
warm?.unref?.();
|
|
5824
|
+
const intervalMs = Math.max(1, initial.refreshMinutes) * 6e4;
|
|
5825
|
+
const timer = initial.autoRefresh && initial.refreshMinutes > 0 ? setInterval(() => {
|
|
5826
|
+
const config = current();
|
|
5827
|
+
if (!config.autoRefresh || config.refreshMinutes <= 0) return;
|
|
5828
|
+
refreshCatalog(config, fetch, true).catch(() => {});
|
|
5829
|
+
}, intervalMs) : void 0;
|
|
5830
|
+
timer?.unref?.();
|
|
5831
|
+
return () => {
|
|
5832
|
+
if (warm !== void 0) clearTimeout(warm);
|
|
5833
|
+
if (timer !== void 0) clearInterval(timer);
|
|
5834
|
+
};
|
|
5835
|
+
}, "dsh-ollama-cloud-provider: catalog refresh scheduler");
|
|
5321
5836
|
ctx.inject(["settings"], (settingsCtx) => {
|
|
5322
5837
|
settingsCtx.settings.configure({ auto: false }, ctx.fiber);
|
|
5323
5838
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-ollama-cloud-provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Ollama Cloud LLM provider plugin for DeepSeek Harness (dsh).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"build": "tsdown",
|
|
74
74
|
"prepare": "tsdown 1>&2",
|
|
75
75
|
"typecheck": "tsc --noEmit",
|
|
76
|
-
"test": "node --import tsx --test tests/core.test.ts tests/usage.test.ts tests/adapter.test.ts tests/routes.test.ts tests/native.test.ts tests/openai-chat.test.ts tests/commands.test.ts tests/tui-settings.test.ts tests/analytics.test.ts tests/apply.test.ts tests/account-rules.test.ts tests/request-log.test.ts tests/image-budget.test.ts tests/tool-schema.test.ts tests/tools.test.ts tests/plugin-updater.test.ts tests/compat.test.ts tests/status.test.ts tests/settings-draft.test.ts tests/update-state.test.ts tests/ui-render.test.tsx tests/update-card-view.test.tsx tests/web.test.ts tests/mock-ollama.test.ts tests/local.test.ts tests/reasoning.test.ts",
|
|
76
|
+
"test": "node --import tsx --test tests/core.test.ts tests/usage.test.ts tests/adapter.test.ts tests/routes.test.ts tests/native.test.ts tests/openai-chat.test.ts tests/commands.test.ts tests/tui-settings.test.ts tests/analytics.test.ts tests/apply.test.ts tests/account-rules.test.ts tests/request-log.test.ts tests/image-budget.test.ts tests/tool-schema.test.ts tests/tools.test.ts tests/plugin-updater.test.ts tests/compat.test.ts tests/status.test.ts tests/settings-draft.test.ts tests/update-state.test.ts tests/ui-render.test.tsx tests/update-card-view.test.tsx tests/web.test.ts tests/mock-ollama.test.ts tests/local.test.ts tests/reasoning.test.ts tests/catalog-cache.test.ts tests/local-models.test.ts",
|
|
77
77
|
"check": "npm run typecheck && npm test && npm run build",
|
|
78
78
|
"release": "npm run check && npm pack",
|
|
79
79
|
"sync:models": "node scripts/sync-models.mjs"
|