@goodandready/dsh-ollama-cloud-provider 0.1.20 → 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 CHANGED
@@ -1,5 +1,17 @@
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
+
3
15
  ## 0.1.20 — 2026-11-05
4
16
 
5
17
  - Persisted the catalog snapshot under `$DSH_HOME/cache/dsh-ollama-cloud/`
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.20
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.20
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.20.tgz
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.20.tgz
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.20
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.20
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.20.tgz
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.20.tgz
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.20
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.20
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.20.tgz
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.20.tgz
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
@@ -139,6 +139,26 @@ window.__ModuleLoader__.load({
139
139
  autoRefresh: "Refresh model catalog automatically",
140
140
  refreshMinutes: "Refresh interval (minutes)",
141
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",
142
162
  sidebar: "Sidebar",
143
163
  serviceStatus: "Service status",
144
164
  serviceStatusHint: "Checks the public Ollama Cloud tag endpoint without using your key or quota.",
@@ -329,6 +349,26 @@ window.__ModuleLoader__.load({
329
349
  autoRefresh: "自动刷新模型目录",
330
350
  refreshMinutes: "刷新间隔(分钟)",
331
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: "详情不可用",
332
372
  sidebar: "侧边栏",
333
373
  serviceStatus: "服务状态",
334
374
  serviceStatusHint: "检查 Ollama Cloud 公共 tag 端点,不使用密钥或额度。",
@@ -489,6 +529,80 @@ window.__ModuleLoader__.load({
489
529
  body: "{}"
490
530
  });
491
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
+ }
492
606
  function saveConfig(patch) {
493
607
  return call("/dsh-ollama/config", {
494
608
  method: "POST",
@@ -1633,6 +1747,246 @@ window.__ModuleLoader__.load({
1633
1747
  function mergeLoadedDraft(current, next, preserve) {
1634
1748
  return preserve && current !== null ? current : next;
1635
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
+ }
1636
1990
  // src/client/update-state.ts
1637
1991
  function updateBadge(status) {
1638
1992
  if (status.latestCheckFailed) return "failed";
@@ -2579,6 +2933,13 @@ window.__ModuleLoader__.load({
2579
2933
  })
2580
2934
  ]
2581
2935
  }),
2936
+ state !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LocalModelsCard, {
2937
+ t,
2938
+ config: state.config,
2939
+ onChanged: () => {
2940
+ reloadModels();
2941
+ }
2942
+ }),
2582
2943
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
2583
2944
  className: "ocl-card",
2584
2945
  children: [
package/lib/index.d.ts CHANGED
@@ -427,6 +427,8 @@ interface RouteDeps {
427
427
  readonly verifyDesktop?: (req: IncomingMessage) => Promise<boolean>;
428
428
  /** Same verifier for private reads; falls back to `verifyDesktop`. */
429
429
  readonly verifyHost?: (req: IncomingMessage) => Promise<boolean>;
430
+ /** Test seam for local Ollama inventory and mutation routes. */
431
+ readonly localFetch?: typeof fetch;
430
432
  }
431
433
  /** Register the Host HTTP surface consumed by the browser settings page. */
432
434
  declare function applyRoutes(ctx: Context, web: WebServer, deps: RouteDeps): void;
package/lib/index.js CHANGED
@@ -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.20";
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;
@@ -133,23 +133,23 @@ function nonEmptyStrings(value) {
133
133
  const out = value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
134
134
  return out.length === 0 ? void 0 : out;
135
135
  }
136
- function recordOf(value) {
136
+ function recordOf$1(value) {
137
137
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
138
138
  }
139
139
  function numberRecord(value) {
140
140
  const out = {};
141
- 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;
142
142
  return out;
143
143
  }
144
144
  function booleanRecord(value) {
145
145
  const out = {};
146
- 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;
147
147
  return out;
148
148
  }
149
149
  function priceRecord(value) {
150
150
  const out = {};
151
- for (const [key, entry] of Object.entries(recordOf(value))) {
152
- const raw = recordOf(entry);
151
+ for (const [key, entry] of Object.entries(recordOf$1(value))) {
152
+ const raw = recordOf$1(entry);
153
153
  const price = {};
154
154
  if (typeof raw.input === "number" && raw.input >= 0) price.input = raw.input;
155
155
  if (typeof raw.output === "number" && raw.output >= 0) price.output = raw.output;
@@ -161,14 +161,14 @@ function priceRecord(value) {
161
161
  const TRANSPORTS$1 = /* @__PURE__ */ new Set(["native", "openai-chat"]);
162
162
  function transportRecord(value) {
163
163
  const out = {};
164
- 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;
165
165
  return out;
166
166
  }
167
167
  function ruleList(value) {
168
168
  if (!Array.isArray(value)) return [];
169
169
  const out = [];
170
170
  for (const entry of value) {
171
- const raw = recordOf(entry);
171
+ const raw = recordOf$1(entry);
172
172
  const pattern = typeof raw.pattern === "string" ? raw.pattern.trim() : "";
173
173
  const account = typeof raw.account === "string" ? raw.account.trim() : "";
174
174
  if (pattern !== "" && account !== "") out.push({
@@ -3170,6 +3170,205 @@ function windowRows(report) {
3170
3170
  }
3171
3171
  ].filter((entry) => entry !== void 0);
3172
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
+ }
3173
3372
  // src/commands.ts
3174
3373
  function bar(percent, width = 10) {
3175
3374
  const clamped = Math.max(0, Math.min(100, percent));
@@ -3284,6 +3483,57 @@ async function testText(deps, model) {
3284
3483
  };
3285
3484
  }
3286
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
+ }
3287
3537
  async function statusText(deps) {
3288
3538
  const config = deps.config();
3289
3539
  const rules = config.modelAccountRules.length === 0 ? "none" : config.modelAccountRules.map((rule) => `${rule.pattern} → ${rule.account}`).join(", ");
@@ -3302,7 +3552,7 @@ function applyCommands(ctx, deps) {
3302
3552
  ctx.commands.register({
3303
3553
  name: "ollama",
3304
3554
  description: "Ollama Cloud status, balance, accounts, models and rules",
3305
- 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]" },
3306
3556
  handler: async (invocation) => {
3307
3557
  const raw = invocation.rawInput.trim();
3308
3558
  const parts = raw === "" ? ["status"] : raw.split(/\s+/);
@@ -3343,9 +3593,50 @@ function applyCommands(ctx, deps) {
3343
3593
  text: result.text
3344
3594
  };
3345
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
+ }
3346
3637
  default: return {
3347
3638
  kind: "error",
3348
- text: `Unknown /ollama argument "${verb}". Use status, usage, balance, accounts, models, rules, or test [model].`
3639
+ text: `Unknown /ollama argument "${verb}". Use status, usage, balance, accounts, models, rules, test [model], or local.`
3349
3640
  };
3350
3641
  }
3351
3642
  }
@@ -4744,6 +5035,93 @@ function applyRoutes(ctx, web, deps) {
4744
5035
  }
4745
5036
  await refreshAndState(ctx, deps, res);
4746
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
+ });
4747
5125
  route("/dsh-ollama/test", async (req, res) => {
4748
5126
  if (!await requirePost(req, res, verifyHost)) return;
4749
5127
  let body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-ollama-cloud-provider",
3
- "version": "0.1.20",
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 tests/catalog-cache.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"