@goodandready/dsh-ollama-cloud-provider 0.1.20 → 0.1.22
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 +23 -0
- package/README.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +374 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +516 -29
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.22 — 2026-11-05
|
|
4
|
+
|
|
5
|
+
- Added `/ollama-context` with 4k/8k/16k/32k/64k/128k presets, custom token
|
|
6
|
+
values, follow, status and reset. The override is session-scoped and wins
|
|
7
|
+
over configured `num_ctx`; sessions remain isolated.
|
|
8
|
+
- Added an independent whole-attempt budget (`attemptTimeoutMs`, default off)
|
|
9
|
+
for chat, catalog and web requests. Each retry gets a fresh budget; caller
|
|
10
|
+
cancellation is distinguished from timeout.
|
|
11
|
+
- Added settings for the attempt budget and tests for budget/timeout/session
|
|
12
|
+
isolation; 124/124 tests.
|
|
13
|
+
|
|
14
|
+
## 0.1.21 — 2026-11-05
|
|
15
|
+
|
|
16
|
+
- Added local Ollama model management: `/api/tags` disk inventory, `/api/ps`
|
|
17
|
+
running models and VRAM, `/api/show` details, `/api/pull` progress streaming,
|
|
18
|
+
and confirmed `/api/delete`. Cloud endpoints are rejected.
|
|
19
|
+
- Added `/ollama local [models|ps|show|pull|remove]` CLI commands; removal
|
|
20
|
+
requires `--yes` and never forces a delete.
|
|
21
|
+
- Added the local models settings card with pull progress, disk/running totals,
|
|
22
|
+
details and a two-step remove confirmation.
|
|
23
|
+
- Extended the mock Ollama contract with tags sizes, ps, pull and delete;
|
|
24
|
+
119/119 tests.
|
|
25
|
+
|
|
3
26
|
## 0.1.20 — 2026-11-05
|
|
4
27
|
|
|
5
28
|
- 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.
|
|
140
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.22
|
|
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.22
|
|
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.22.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.22.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.22
|
|
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.22
|
|
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.22.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.22.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.22
|
|
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.22
|
|
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.22.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.22.tgz
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
|
package/lib/client.js
CHANGED
|
@@ -120,6 +120,8 @@ window.__ModuleLoader__.load({
|
|
|
120
120
|
balanceUrl: "Balance endpoint",
|
|
121
121
|
requestTimeoutMs: "Header timeout (ms)",
|
|
122
122
|
streamIdleTimeoutMs: "Stream idle timeout (ms)",
|
|
123
|
+
attemptTimeoutMs: "Attempt budget (ms, 0 = off)",
|
|
124
|
+
attemptTimeoutHint: "Whole-attempt timeout; a fresh budget is created for every retry.",
|
|
123
125
|
maxOutputTokens: "Output limit (0 = provider default)",
|
|
124
126
|
contextWindow: "Context window override",
|
|
125
127
|
generation: "Generation defaults",
|
|
@@ -139,6 +141,26 @@ window.__ModuleLoader__.load({
|
|
|
139
141
|
autoRefresh: "Refresh model catalog automatically",
|
|
140
142
|
refreshMinutes: "Refresh interval (minutes)",
|
|
141
143
|
autoRefreshHint: "Mount refresh plus this interval; 0 keeps the mount refresh only.",
|
|
144
|
+
localModels: "Local Ollama models",
|
|
145
|
+
localModelsHint: "List, inspect, pull and remove models on the configured local endpoint. Remove always asks for confirmation.",
|
|
146
|
+
localDisk: "Disk",
|
|
147
|
+
localRunning: "Running",
|
|
148
|
+
localPullPlaceholder: "model name, for example llama3.2",
|
|
149
|
+
localPull: "Pull",
|
|
150
|
+
localPulling: "Pulling…",
|
|
151
|
+
localRefresh: "Reload",
|
|
152
|
+
localNoModels: "No local models.",
|
|
153
|
+
localRunningBadge: "running",
|
|
154
|
+
localShow: "Details",
|
|
155
|
+
localRemove: "Remove",
|
|
156
|
+
localConfirmRemove: "Confirm remove",
|
|
157
|
+
localCancel: "Cancel",
|
|
158
|
+
localModified: "Modified",
|
|
159
|
+
localCapabilities: "Capabilities",
|
|
160
|
+
localPullFailed: "Pull failed",
|
|
161
|
+
localRemoveDone: "removed",
|
|
162
|
+
localRemoveFailed: "Remove failed",
|
|
163
|
+
localShowFailed: "Details unavailable",
|
|
142
164
|
sidebar: "Sidebar",
|
|
143
165
|
serviceStatus: "Service status",
|
|
144
166
|
serviceStatusHint: "Checks the public Ollama Cloud tag endpoint without using your key or quota.",
|
|
@@ -310,6 +332,8 @@ window.__ModuleLoader__.load({
|
|
|
310
332
|
balanceUrl: "余额端点",
|
|
311
333
|
requestTimeoutMs: "响应头超时(毫秒)",
|
|
312
334
|
streamIdleTimeoutMs: "流空闲超时(毫秒)",
|
|
335
|
+
attemptTimeoutMs: "单次尝试预算(毫秒,0 = 关闭)",
|
|
336
|
+
attemptTimeoutHint: "整次尝试超时;每次重试都会创建新的预算。",
|
|
313
337
|
maxOutputTokens: "输出上限(0 = 提供方默认)",
|
|
314
338
|
contextWindow: "上下文窗口覆盖",
|
|
315
339
|
generation: "生成默认值",
|
|
@@ -329,6 +353,26 @@ window.__ModuleLoader__.load({
|
|
|
329
353
|
autoRefresh: "自动刷新模型目录",
|
|
330
354
|
refreshMinutes: "刷新间隔(分钟)",
|
|
331
355
|
autoRefreshHint: "启动时刷新,并按此间隔刷新;0 仅启动时刷新。",
|
|
356
|
+
localModels: "本地 Ollama 模型",
|
|
357
|
+
localModelsHint: "列出、查看、拉取和删除已配置本地端点上的模型。删除始终需要确认。",
|
|
358
|
+
localDisk: "磁盘",
|
|
359
|
+
localRunning: "运行中",
|
|
360
|
+
localPullPlaceholder: "模型名称,例如 llama3.2",
|
|
361
|
+
localPull: "拉取",
|
|
362
|
+
localPulling: "拉取中…",
|
|
363
|
+
localRefresh: "重新加载",
|
|
364
|
+
localNoModels: "没有本地模型。",
|
|
365
|
+
localRunningBadge: "运行中",
|
|
366
|
+
localShow: "详情",
|
|
367
|
+
localRemove: "删除",
|
|
368
|
+
localConfirmRemove: "确认删除",
|
|
369
|
+
localCancel: "取消",
|
|
370
|
+
localModified: "修改时间",
|
|
371
|
+
localCapabilities: "能力",
|
|
372
|
+
localPullFailed: "拉取失败",
|
|
373
|
+
localRemoveDone: "已删除",
|
|
374
|
+
localRemoveFailed: "删除失败",
|
|
375
|
+
localShowFailed: "详情不可用",
|
|
332
376
|
sidebar: "侧边栏",
|
|
333
377
|
serviceStatus: "服务状态",
|
|
334
378
|
serviceStatusHint: "检查 Ollama Cloud 公共 tag 端点,不使用密钥或额度。",
|
|
@@ -489,6 +533,80 @@ window.__ModuleLoader__.load({
|
|
|
489
533
|
body: "{}"
|
|
490
534
|
});
|
|
491
535
|
}
|
|
536
|
+
function fetchLocalModels() {
|
|
537
|
+
return call("/dsh-ollama/local/models");
|
|
538
|
+
}
|
|
539
|
+
function fetchLocalShow(model) {
|
|
540
|
+
return call(`/dsh-ollama/local/show?model=${encodeURIComponent(model)}`);
|
|
541
|
+
}
|
|
542
|
+
async function pullLocalModel(model, onProgress) {
|
|
543
|
+
const response = await fetch("/dsh-ollama/local/pull", {
|
|
544
|
+
method: "POST",
|
|
545
|
+
credentials: "same-origin",
|
|
546
|
+
headers: {
|
|
547
|
+
accept: "application/x-ndjson",
|
|
548
|
+
"content-type": "application/json"
|
|
549
|
+
},
|
|
550
|
+
body: JSON.stringify({ model })
|
|
551
|
+
});
|
|
552
|
+
if (!response.ok) {
|
|
553
|
+
const body = await response.json().catch(() => ({}));
|
|
554
|
+
throw new Error(body.error ?? `HTTP ${response.status}`);
|
|
555
|
+
}
|
|
556
|
+
if (response.body === null) throw new Error("empty pull stream");
|
|
557
|
+
const reader = response.body.getReader();
|
|
558
|
+
const decoder = new TextDecoder();
|
|
559
|
+
let buffer = "";
|
|
560
|
+
let last = { status: "starting" };
|
|
561
|
+
const consume = (line) => {
|
|
562
|
+
if (line.trim() === "") return;
|
|
563
|
+
let event;
|
|
564
|
+
try {
|
|
565
|
+
event = JSON.parse(line);
|
|
566
|
+
} catch {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (typeof event.error === "string" && event.error !== "") throw new Error(event.error);
|
|
570
|
+
if (typeof event.status === "string") last = event;
|
|
571
|
+
onProgress(event);
|
|
572
|
+
};
|
|
573
|
+
for (;;) {
|
|
574
|
+
const { done, value } = await reader.read();
|
|
575
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
576
|
+
const lines = buffer.split("\n");
|
|
577
|
+
buffer = lines.pop() ?? "";
|
|
578
|
+
for (const line of lines) consume(line);
|
|
579
|
+
if (done) break;
|
|
580
|
+
}
|
|
581
|
+
if (buffer.trim() !== "") consume(buffer);
|
|
582
|
+
return last;
|
|
583
|
+
}
|
|
584
|
+
function removeLocalModel(model) {
|
|
585
|
+
return call("/dsh-ollama/local/remove", {
|
|
586
|
+
method: "POST",
|
|
587
|
+
body: JSON.stringify({
|
|
588
|
+
model,
|
|
589
|
+
confirm: true
|
|
590
|
+
})
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
function formatBytes(bytes) {
|
|
594
|
+
if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
|
|
595
|
+
const units = [
|
|
596
|
+
"B",
|
|
597
|
+
"KB",
|
|
598
|
+
"MB",
|
|
599
|
+
"GB",
|
|
600
|
+
"TB"
|
|
601
|
+
];
|
|
602
|
+
let value = bytes;
|
|
603
|
+
let index = 0;
|
|
604
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
605
|
+
value /= 1024;
|
|
606
|
+
index += 1;
|
|
607
|
+
}
|
|
608
|
+
return `${value >= 10 || index === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[index]}`;
|
|
609
|
+
}
|
|
492
610
|
function saveConfig(patch) {
|
|
493
611
|
return call("/dsh-ollama/config", {
|
|
494
612
|
method: "POST",
|
|
@@ -1534,6 +1652,7 @@ window.__ModuleLoader__.load({
|
|
|
1534
1652
|
transport: state.config.transport,
|
|
1535
1653
|
requestTimeoutMs: String(state.config.requestTimeoutMs),
|
|
1536
1654
|
streamIdleTimeoutMs: String(state.config.streamIdleTimeoutMs),
|
|
1655
|
+
attemptTimeoutMs: String(state.config.attemptTimeoutMs ?? 0),
|
|
1537
1656
|
maxOutputTokens: textOf(state.config.maxOutputTokens),
|
|
1538
1657
|
contextWindow: textOf(state.config.contextWindow),
|
|
1539
1658
|
temperature: textOf(state.config.temperature),
|
|
@@ -1587,6 +1706,7 @@ window.__ModuleLoader__.load({
|
|
|
1587
1706
|
transport: draft.transport,
|
|
1588
1707
|
requestTimeoutMs: numberOrNull(draft.requestTimeoutMs) ?? 3e5,
|
|
1589
1708
|
streamIdleTimeoutMs: numberOrNull(draft.streamIdleTimeoutMs) ?? 3e5,
|
|
1709
|
+
attemptTimeoutMs: boundedNumber(draft.attemptTimeoutMs, 0, 36e5, true) ?? 0,
|
|
1590
1710
|
maxOutputTokens: numberOrNull(draft.maxOutputTokens),
|
|
1591
1711
|
contextWindow: numberOrNull(draft.contextWindow),
|
|
1592
1712
|
temperature: boundedNumber(draft.temperature, 0, 2, false),
|
|
@@ -1633,6 +1753,246 @@ window.__ModuleLoader__.load({
|
|
|
1633
1753
|
function mergeLoadedDraft(current, next, preserve) {
|
|
1634
1754
|
return preserve && current !== null ? current : next;
|
|
1635
1755
|
}
|
|
1756
|
+
// src/client/local-models-card.tsx
|
|
1757
|
+
function isLocalConfig(config) {
|
|
1758
|
+
if (config.apiKeyEnv === "") return true;
|
|
1759
|
+
try {
|
|
1760
|
+
const host = new URL(config.apiBase).hostname;
|
|
1761
|
+
return host === "127.0.0.1" || host === "localhost" || host === "::1" || host === "[::1]";
|
|
1762
|
+
} catch {
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
function LocalModelsCard(props) {
|
|
1767
|
+
const { t, config, onChanged } = props;
|
|
1768
|
+
const [inventory, setInventory] = (0, react.useState)(null);
|
|
1769
|
+
const [details, setDetails] = (0, react.useState)(null);
|
|
1770
|
+
const [error, setError] = (0, react.useState)(null);
|
|
1771
|
+
const [notice, setNotice] = (0, react.useState)(null);
|
|
1772
|
+
const [pullName, setPullName] = (0, react.useState)("");
|
|
1773
|
+
const [pulling, setPulling] = (0, react.useState)(false);
|
|
1774
|
+
const [progress, setProgress] = (0, react.useState)(null);
|
|
1775
|
+
const [confirmRemove, setConfirmRemove] = (0, react.useState)(null);
|
|
1776
|
+
const local = isLocalConfig(config);
|
|
1777
|
+
const load = (0, react.useCallback)(async () => {
|
|
1778
|
+
if (!local) return;
|
|
1779
|
+
try {
|
|
1780
|
+
setInventory(await fetchLocalModels());
|
|
1781
|
+
setError(null);
|
|
1782
|
+
} catch (cause) {
|
|
1783
|
+
setError(cause instanceof Error ? cause.message : "local models failed");
|
|
1784
|
+
}
|
|
1785
|
+
}, [local]);
|
|
1786
|
+
(0, react.useEffect)(() => {
|
|
1787
|
+
load();
|
|
1788
|
+
}, [
|
|
1789
|
+
load,
|
|
1790
|
+
config.apiKeyEnv,
|
|
1791
|
+
config.apiBase
|
|
1792
|
+
]);
|
|
1793
|
+
if (!local) return null;
|
|
1794
|
+
const pull = async () => {
|
|
1795
|
+
const model = pullName.trim();
|
|
1796
|
+
if (model === "" || pulling) return;
|
|
1797
|
+
setPulling(true);
|
|
1798
|
+
setError(null);
|
|
1799
|
+
setNotice(null);
|
|
1800
|
+
setProgress({ status: "starting" });
|
|
1801
|
+
try {
|
|
1802
|
+
const last = await pullLocalModel(model, setProgress);
|
|
1803
|
+
setNotice(`${model}: ${last.status}`);
|
|
1804
|
+
setPullName("");
|
|
1805
|
+
await load();
|
|
1806
|
+
onChanged?.();
|
|
1807
|
+
} catch (cause) {
|
|
1808
|
+
setError(cause instanceof Error ? cause.message : t("localPullFailed"));
|
|
1809
|
+
} finally {
|
|
1810
|
+
setPulling(false);
|
|
1811
|
+
setProgress(null);
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
const remove = async (model) => {
|
|
1815
|
+
setError(null);
|
|
1816
|
+
setNotice(null);
|
|
1817
|
+
try {
|
|
1818
|
+
await removeLocalModel(model);
|
|
1819
|
+
setConfirmRemove(null);
|
|
1820
|
+
setDetails((current) => current?.name === model ? null : current);
|
|
1821
|
+
setNotice(`${model}: ${t("localRemoveDone")}`);
|
|
1822
|
+
await load();
|
|
1823
|
+
onChanged?.();
|
|
1824
|
+
} catch (cause) {
|
|
1825
|
+
setError(cause instanceof Error ? cause.message : t("localRemoveFailed"));
|
|
1826
|
+
}
|
|
1827
|
+
};
|
|
1828
|
+
const show = async (model) => {
|
|
1829
|
+
setError(null);
|
|
1830
|
+
try {
|
|
1831
|
+
setDetails(await fetchLocalShow(model));
|
|
1832
|
+
} catch (cause) {
|
|
1833
|
+
setError(cause instanceof Error ? cause.message : t("localShowFailed"));
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
const running = new Set(inventory?.running.map((entry) => entry.name) ?? []);
|
|
1837
|
+
const percent = progress?.total !== void 0 && progress.total > 0 ? Math.min(100, Math.round((progress.completed ?? 0) / progress.total * 100)) : null;
|
|
1838
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1839
|
+
className: "ocl-card",
|
|
1840
|
+
children: [
|
|
1841
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
1842
|
+
className: "ocl-card-title",
|
|
1843
|
+
children: t("localModels")
|
|
1844
|
+
}),
|
|
1845
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1846
|
+
className: "ocl-hint",
|
|
1847
|
+
children: t("localModelsHint")
|
|
1848
|
+
}),
|
|
1849
|
+
inventory !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1850
|
+
className: "ocl-hint",
|
|
1851
|
+
children: [
|
|
1852
|
+
t("localDisk"),
|
|
1853
|
+
": ",
|
|
1854
|
+
formatBytes(inventory.diskBytes),
|
|
1855
|
+
" · ",
|
|
1856
|
+
t("localRunning"),
|
|
1857
|
+
": ",
|
|
1858
|
+
formatBytes(inventory.runningBytes)
|
|
1859
|
+
]
|
|
1860
|
+
}),
|
|
1861
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1862
|
+
className: "ocl-row",
|
|
1863
|
+
children: [
|
|
1864
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1865
|
+
className: "ocl-input",
|
|
1866
|
+
value: pullName,
|
|
1867
|
+
placeholder: t("localPullPlaceholder"),
|
|
1868
|
+
onChange: (event) => setPullName(event.target.value),
|
|
1869
|
+
onKeyDown: (event) => {
|
|
1870
|
+
if (event.key === "Enter") {
|
|
1871
|
+
event.preventDefault();
|
|
1872
|
+
pull();
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}),
|
|
1876
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1877
|
+
type: "button",
|
|
1878
|
+
className: "ocl-button",
|
|
1879
|
+
disabled: pulling || pullName.trim() === "",
|
|
1880
|
+
onClick: () => {
|
|
1881
|
+
pull();
|
|
1882
|
+
},
|
|
1883
|
+
children: pulling ? t("localPulling") : t("localPull")
|
|
1884
|
+
}),
|
|
1885
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1886
|
+
type: "button",
|
|
1887
|
+
className: "ocl-button",
|
|
1888
|
+
onClick: () => {
|
|
1889
|
+
load();
|
|
1890
|
+
},
|
|
1891
|
+
children: t("localRefresh")
|
|
1892
|
+
})
|
|
1893
|
+
]
|
|
1894
|
+
}),
|
|
1895
|
+
progress !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1896
|
+
className: "ocl-row",
|
|
1897
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1898
|
+
className: "ocl-hint",
|
|
1899
|
+
children: percent === null ? progress.status : `${progress.status} · ${percent}%`
|
|
1900
|
+
})
|
|
1901
|
+
}),
|
|
1902
|
+
notice !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1903
|
+
className: "ocl-notice",
|
|
1904
|
+
children: notice
|
|
1905
|
+
}),
|
|
1906
|
+
error !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1907
|
+
className: "ocl-error",
|
|
1908
|
+
children: error
|
|
1909
|
+
}),
|
|
1910
|
+
inventory !== null && inventory.models.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1911
|
+
className: "ocl-hint",
|
|
1912
|
+
children: t("localNoModels")
|
|
1913
|
+
}),
|
|
1914
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1915
|
+
className: "ocl-models",
|
|
1916
|
+
children: (inventory?.models ?? []).map((model) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1917
|
+
className: "ocl-model",
|
|
1918
|
+
children: [
|
|
1919
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1920
|
+
className: "ocl-model-name",
|
|
1921
|
+
children: model.name
|
|
1922
|
+
}),
|
|
1923
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1924
|
+
className: "ocl-badge",
|
|
1925
|
+
children: formatBytes(model.size)
|
|
1926
|
+
}),
|
|
1927
|
+
running.has(model.name) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1928
|
+
className: "ocl-badge ocl-badge-ok",
|
|
1929
|
+
children: t("localRunningBadge")
|
|
1930
|
+
}),
|
|
1931
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1932
|
+
type: "button",
|
|
1933
|
+
className: "ocl-button",
|
|
1934
|
+
onClick: () => {
|
|
1935
|
+
show(model.name);
|
|
1936
|
+
},
|
|
1937
|
+
children: t("localShow")
|
|
1938
|
+
}),
|
|
1939
|
+
confirmRemove === model.name ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1940
|
+
type: "button",
|
|
1941
|
+
className: "ocl-button ocl-button-danger",
|
|
1942
|
+
onClick: () => {
|
|
1943
|
+
remove(model.name);
|
|
1944
|
+
},
|
|
1945
|
+
children: t("localConfirmRemove")
|
|
1946
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1947
|
+
type: "button",
|
|
1948
|
+
className: "ocl-button",
|
|
1949
|
+
onClick: () => setConfirmRemove(null),
|
|
1950
|
+
children: t("localCancel")
|
|
1951
|
+
})] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1952
|
+
type: "button",
|
|
1953
|
+
className: "ocl-button ocl-button-danger",
|
|
1954
|
+
onClick: () => setConfirmRemove(model.name),
|
|
1955
|
+
children: t("localRemove")
|
|
1956
|
+
})
|
|
1957
|
+
]
|
|
1958
|
+
}, model.name))
|
|
1959
|
+
}),
|
|
1960
|
+
details !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1961
|
+
className: "ocl-model-section",
|
|
1962
|
+
children: [
|
|
1963
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1964
|
+
className: "ocl-model-section-head",
|
|
1965
|
+
children: details.name
|
|
1966
|
+
}),
|
|
1967
|
+
details.modifiedAt !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1968
|
+
className: "ocl-hint",
|
|
1969
|
+
children: [
|
|
1970
|
+
t("localModified"),
|
|
1971
|
+
": ",
|
|
1972
|
+
details.modifiedAt
|
|
1973
|
+
]
|
|
1974
|
+
}),
|
|
1975
|
+
details.details !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1976
|
+
className: "ocl-hint",
|
|
1977
|
+
children: [
|
|
1978
|
+
details.details.family,
|
|
1979
|
+
details.details.parameterSize,
|
|
1980
|
+
details.details.quantization
|
|
1981
|
+
].filter((entry) => entry !== void 0).join(" · ")
|
|
1982
|
+
}),
|
|
1983
|
+
details.capabilities.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1984
|
+
className: "ocl-hint",
|
|
1985
|
+
children: [
|
|
1986
|
+
t("localCapabilities"),
|
|
1987
|
+
": ",
|
|
1988
|
+
details.capabilities.join(", ")
|
|
1989
|
+
]
|
|
1990
|
+
})
|
|
1991
|
+
]
|
|
1992
|
+
})
|
|
1993
|
+
]
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1636
1996
|
// src/client/update-state.ts
|
|
1637
1997
|
function updateBadge(status) {
|
|
1638
1998
|
if (status.latestCheckFailed) return "failed";
|
|
@@ -2579,6 +2939,13 @@ window.__ModuleLoader__.load({
|
|
|
2579
2939
|
})
|
|
2580
2940
|
]
|
|
2581
2941
|
}),
|
|
2942
|
+
state !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LocalModelsCard, {
|
|
2943
|
+
t,
|
|
2944
|
+
config: state.config,
|
|
2945
|
+
onChanged: () => {
|
|
2946
|
+
reloadModels();
|
|
2947
|
+
}
|
|
2948
|
+
}),
|
|
2582
2949
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2583
2950
|
className: "ocl-card",
|
|
2584
2951
|
children: [
|
|
@@ -2746,6 +3113,13 @@ window.__ModuleLoader__.load({
|
|
|
2746
3113
|
value: draft.streamIdleTimeoutMs,
|
|
2747
3114
|
onChange: (value) => update({ streamIdleTimeoutMs: value })
|
|
2748
3115
|
}),
|
|
3116
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
3117
|
+
label: t("attemptTimeoutMs"),
|
|
3118
|
+
hint: t("attemptTimeoutHint"),
|
|
3119
|
+
type: "number",
|
|
3120
|
+
value: draft.attemptTimeoutMs,
|
|
3121
|
+
onChange: (value) => update({ attemptTimeoutMs: value })
|
|
3122
|
+
}),
|
|
2749
3123
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2750
3124
|
label: t("maxOutputTokens"),
|
|
2751
3125
|
type: "number",
|
package/lib/index.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ interface Config {
|
|
|
44
44
|
requestTimeoutMs?: number;
|
|
45
45
|
/** Milliseconds a stream may stall; defaults to 300s. */
|
|
46
46
|
streamIdleTimeoutMs?: number;
|
|
47
|
+
/** Whole-attempt budget; 0 disables the independent budget. */
|
|
48
|
+
attemptTimeoutMs?: number;
|
|
47
49
|
/** Visible-model allowlist; empty with `showAllModels:false` means none. */
|
|
48
50
|
visibleModels?: string[];
|
|
49
51
|
/** Explicit all-models switch; absent means derive from `visibleModels`. */
|
|
@@ -102,6 +104,7 @@ interface ResolvedConfig {
|
|
|
102
104
|
modelTransports: Readonly<Record<string, TransportId>>;
|
|
103
105
|
requestTimeoutMs: number;
|
|
104
106
|
streamIdleTimeoutMs: number;
|
|
107
|
+
attemptTimeoutMs: number;
|
|
105
108
|
visibleModels: readonly string[];
|
|
106
109
|
showAllModels: boolean;
|
|
107
110
|
modelVisibility: Readonly<Record<string, boolean>>;
|
|
@@ -427,6 +430,8 @@ interface RouteDeps {
|
|
|
427
430
|
readonly verifyDesktop?: (req: IncomingMessage) => Promise<boolean>;
|
|
428
431
|
/** Same verifier for private reads; falls back to `verifyDesktop`. */
|
|
429
432
|
readonly verifyHost?: (req: IncomingMessage) => Promise<boolean>;
|
|
433
|
+
/** Test seam for local Ollama inventory and mutation routes. */
|
|
434
|
+
readonly localFetch?: typeof fetch;
|
|
430
435
|
}
|
|
431
436
|
/** Register the Host HTTP surface consumed by the browser settings page. */
|
|
432
437
|
declare function applyRoutes(ctx: Context, web: WebServer, deps: RouteDeps): void;
|
package/lib/index.js
CHANGED
|
@@ -43,6 +43,33 @@ function bestEffortFailed(label, error) {
|
|
|
43
43
|
sink?.debug?.(`${label}: ${error instanceof Error ? error.message : String(error)}`);
|
|
44
44
|
} catch {}
|
|
45
45
|
}
|
|
46
|
+
// src/attempt.ts
|
|
47
|
+
/** One abort/timeout budget for one attempt; callers create a fresh one per retry. */
|
|
48
|
+
function createAttemptBudget(timeoutMs, caller) {
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const budget = {
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
timedOut: false,
|
|
53
|
+
callerAborted: caller?.aborted === true,
|
|
54
|
+
dispose: () => {}
|
|
55
|
+
};
|
|
56
|
+
const onAbort = () => {
|
|
57
|
+
budget.callerAborted = true;
|
|
58
|
+
controller.abort(caller?.reason);
|
|
59
|
+
};
|
|
60
|
+
caller?.addEventListener("abort", onAbort, { once: true });
|
|
61
|
+
if (caller?.aborted === true) controller.abort(caller.reason);
|
|
62
|
+
const timer = timeoutMs !== void 0 && timeoutMs > 0 ? setTimeout(() => {
|
|
63
|
+
budget.timedOut = true;
|
|
64
|
+
controller.abort();
|
|
65
|
+
}, timeoutMs) : void 0;
|
|
66
|
+
timer?.unref?.();
|
|
67
|
+
budget.dispose = () => {
|
|
68
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
69
|
+
caller?.removeEventListener("abort", onAbort);
|
|
70
|
+
};
|
|
71
|
+
return budget;
|
|
72
|
+
}
|
|
46
73
|
// src/config.ts
|
|
47
74
|
const NS = "llm-ollama-cloud";
|
|
48
75
|
const DEFAULT_API_KEY_ENV = "OLLAMA_API_KEY";
|
|
@@ -50,7 +77,7 @@ const DEFAULT_API_BASE = "https://ollama.com";
|
|
|
50
77
|
const DEFAULT_OPENAI_BASE = "https://ollama.com/v1";
|
|
51
78
|
const DEFAULT_USAGE_URL = "https://ollama.com/api/usage";
|
|
52
79
|
const DEFAULT_BALANCE_URL = "https://ollama.com/api/balance";
|
|
53
|
-
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.
|
|
80
|
+
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.22";
|
|
54
81
|
const DEFAULT_CONTEXT_WINDOW = 131072;
|
|
55
82
|
const DEFAULT_MAX_TOKENS = 32768;
|
|
56
83
|
const DEFAULT_GENERATE_MAX_TOKENS = 131072;
|
|
@@ -69,6 +96,7 @@ const Config = z.object({
|
|
|
69
96
|
modelTransports: markVolatile(z.dict(z.union(["native", "openai-chat"])).default({})),
|
|
70
97
|
requestTimeoutMs: markVolatile(z.number().min(1).max(2147483647).default(3e5)),
|
|
71
98
|
streamIdleTimeoutMs: markVolatile(z.number().min(1).max(2147483647).default(3e5)),
|
|
99
|
+
attemptTimeoutMs: markVolatile(z.number().min(0).max(36e5).step(1).default(0)),
|
|
72
100
|
visibleModels: markVolatile(z.array(z.string()).default([])),
|
|
73
101
|
showAllModels: markVolatile(z.boolean()),
|
|
74
102
|
modelVisibility: markVolatile(z.dict(z.boolean()).default({})),
|
|
@@ -133,23 +161,23 @@ function nonEmptyStrings(value) {
|
|
|
133
161
|
const out = value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
|
|
134
162
|
return out.length === 0 ? void 0 : out;
|
|
135
163
|
}
|
|
136
|
-
function recordOf(value) {
|
|
164
|
+
function recordOf$1(value) {
|
|
137
165
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
138
166
|
}
|
|
139
167
|
function numberRecord(value) {
|
|
140
168
|
const out = {};
|
|
141
|
-
for (const [key, entry] of Object.entries(recordOf(value))) if (typeof entry === "number" && Number.isInteger(entry) && entry > 0) out[key] = entry;
|
|
169
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) if (typeof entry === "number" && Number.isInteger(entry) && entry > 0) out[key] = entry;
|
|
142
170
|
return out;
|
|
143
171
|
}
|
|
144
172
|
function booleanRecord(value) {
|
|
145
173
|
const out = {};
|
|
146
|
-
for (const [key, entry] of Object.entries(recordOf(value))) if (typeof entry === "boolean") out[key] = entry;
|
|
174
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) if (typeof entry === "boolean") out[key] = entry;
|
|
147
175
|
return out;
|
|
148
176
|
}
|
|
149
177
|
function priceRecord(value) {
|
|
150
178
|
const out = {};
|
|
151
|
-
for (const [key, entry] of Object.entries(recordOf(value))) {
|
|
152
|
-
const raw = recordOf(entry);
|
|
179
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) {
|
|
180
|
+
const raw = recordOf$1(entry);
|
|
153
181
|
const price = {};
|
|
154
182
|
if (typeof raw.input === "number" && raw.input >= 0) price.input = raw.input;
|
|
155
183
|
if (typeof raw.output === "number" && raw.output >= 0) price.output = raw.output;
|
|
@@ -161,14 +189,14 @@ function priceRecord(value) {
|
|
|
161
189
|
const TRANSPORTS$1 = /* @__PURE__ */ new Set(["native", "openai-chat"]);
|
|
162
190
|
function transportRecord(value) {
|
|
163
191
|
const out = {};
|
|
164
|
-
for (const [key, entry] of Object.entries(recordOf(value))) if (typeof entry === "string" && TRANSPORTS$1.has(entry)) out[key] = entry;
|
|
192
|
+
for (const [key, entry] of Object.entries(recordOf$1(value))) if (typeof entry === "string" && TRANSPORTS$1.has(entry)) out[key] = entry;
|
|
165
193
|
return out;
|
|
166
194
|
}
|
|
167
195
|
function ruleList(value) {
|
|
168
196
|
if (!Array.isArray(value)) return [];
|
|
169
197
|
const out = [];
|
|
170
198
|
for (const entry of value) {
|
|
171
|
-
const raw = recordOf(entry);
|
|
199
|
+
const raw = recordOf$1(entry);
|
|
172
200
|
const pattern = typeof raw.pattern === "string" ? raw.pattern.trim() : "";
|
|
173
201
|
const account = typeof raw.account === "string" ? raw.account.trim() : "";
|
|
174
202
|
if (pattern !== "" && account !== "") out.push({
|
|
@@ -202,6 +230,7 @@ function resolveConfig(config) {
|
|
|
202
230
|
modelTransports: transportRecord(config.modelTransports),
|
|
203
231
|
requestTimeoutMs: positiveInt(config.requestTimeoutMs, 3e5),
|
|
204
232
|
streamIdleTimeoutMs: positiveInt(config.streamIdleTimeoutMs, 3e5),
|
|
233
|
+
attemptTimeoutMs: typeof config.attemptTimeoutMs === "number" && Number.isInteger(config.attemptTimeoutMs) && config.attemptTimeoutMs >= 0 && config.attemptTimeoutMs <= 36e5 ? config.attemptTimeoutMs : 0,
|
|
205
234
|
visibleModels,
|
|
206
235
|
showAllModels: config.showAllModels === true ? true : config.showAllModels === false ? false : visibleModels.length === 0,
|
|
207
236
|
modelVisibility: booleanRecord(config.modelVisibility),
|
|
@@ -1246,8 +1275,14 @@ async function refreshCatalog(config, fetchImpl = fetch, force = false) {
|
|
|
1246
1275
|
return refreshNow(config, fetchImpl, key, cached !== void 0, generation);
|
|
1247
1276
|
}
|
|
1248
1277
|
async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
|
|
1249
|
-
const
|
|
1250
|
-
|
|
1278
|
+
const budget = createAttemptBudget(CATALOG_TIMEOUT_MS);
|
|
1279
|
+
let modelsResult;
|
|
1280
|
+
let tagsResult;
|
|
1281
|
+
try {
|
|
1282
|
+
[modelsResult, tagsResult] = await Promise.allSettled([fetchJson(modelsUrlFor(config), config, fetchImpl, budget.signal), fetchJson(tagsUrlFor(config), config, fetchImpl, budget.signal)]);
|
|
1283
|
+
} finally {
|
|
1284
|
+
budget.dispose();
|
|
1285
|
+
}
|
|
1251
1286
|
if (epoch !== generation) return Object.keys(GENERATED_MODELS);
|
|
1252
1287
|
if (modelsResult.status === "fulfilled") {
|
|
1253
1288
|
const payload = modelsResult.value;
|
|
@@ -1426,6 +1461,41 @@ function classifyStreamError(value, status = 200) {
|
|
|
1426
1461
|
if (value.error === void 0) return void 0;
|
|
1427
1462
|
return classifyResponseError(status, JSON.stringify(value), new Headers());
|
|
1428
1463
|
}
|
|
1464
|
+
// src/context-override.ts
|
|
1465
|
+
const overrides = /* @__PURE__ */ new Map();
|
|
1466
|
+
function sessionKey(sessionId) {
|
|
1467
|
+
return sessionId === void 0 || sessionId === null ? "" : String(sessionId);
|
|
1468
|
+
}
|
|
1469
|
+
function setContextOverride(sessionId, value) {
|
|
1470
|
+
overrides.set(sessionKey(sessionId), value);
|
|
1471
|
+
}
|
|
1472
|
+
function clearContextOverride(sessionId) {
|
|
1473
|
+
overrides.delete(sessionKey(sessionId));
|
|
1474
|
+
}
|
|
1475
|
+
function contextOverrideFor(sessionId) {
|
|
1476
|
+
return overrides.get(sessionKey(sessionId));
|
|
1477
|
+
}
|
|
1478
|
+
/** Session value wins; `follow` and an unset value use the configured num_ctx. */
|
|
1479
|
+
function effectiveNumCtx(config, sessionId) {
|
|
1480
|
+
const override = contextOverrideFor(sessionId);
|
|
1481
|
+
return typeof override === "number" ? override : config.numCtx;
|
|
1482
|
+
}
|
|
1483
|
+
function parseContextValue(raw) {
|
|
1484
|
+
const value = raw.trim().toLowerCase();
|
|
1485
|
+
if (value === "" || value === "status") return void 0;
|
|
1486
|
+
if (value === "follow") return "follow";
|
|
1487
|
+
if (value === "reset") return "reset";
|
|
1488
|
+
const match = /^(\d+)(k|m)?$/.exec(value);
|
|
1489
|
+
if (match === null) return void 0;
|
|
1490
|
+
const number = Number(match[1]) * (match[2] === "k" ? 1024 : match[2] === "m" ? 1048576 : 1);
|
|
1491
|
+
if (!Number.isInteger(number) || number < 1024 || number > 1e7) return void 0;
|
|
1492
|
+
return number;
|
|
1493
|
+
}
|
|
1494
|
+
function describeContext(config, sessionId) {
|
|
1495
|
+
const override = contextOverrideFor(sessionId);
|
|
1496
|
+
const effective = effectiveNumCtx(config, sessionId);
|
|
1497
|
+
return `Context: session=${override === void 0 ? "unset" : override === "follow" ? "follow" : `${override} tokens`}, effective=${effective === void 0 ? "model default" : `${effective} tokens`}`;
|
|
1498
|
+
}
|
|
1429
1499
|
// src/images.ts
|
|
1430
1500
|
const MAX_LONG_EDGE = 1568;
|
|
1431
1501
|
const MAX_BYTES = 1048576;
|
|
@@ -1737,12 +1807,13 @@ function nativeThink(effort, model) {
|
|
|
1737
1807
|
].includes(effort) ? effort : void 0;
|
|
1738
1808
|
}
|
|
1739
1809
|
/** Build the native `/api/chat` request body for one model. */
|
|
1740
|
-
function buildNativeBody(options, model, config, images) {
|
|
1810
|
+
function buildNativeBody(options, model, config, images, numCtxOverride) {
|
|
1741
1811
|
const tools = buildTools(options.tools);
|
|
1742
1812
|
const maxTokens = options.maxTokens ?? effectiveMaxTokens(model, config);
|
|
1743
1813
|
const think = nativeThink(options.reasoningEffort === void 0 ? void 0 : String(options.reasoningEffort), model);
|
|
1744
1814
|
const temperature = options.temperature ?? config.temperature;
|
|
1745
1815
|
const stop = options.stop ?? config.stop;
|
|
1816
|
+
const numCtx = numCtxOverride ?? config.numCtx;
|
|
1746
1817
|
const nativeOptions = {
|
|
1747
1818
|
...temperature === void 0 ? {} : { temperature },
|
|
1748
1819
|
...config.topK === void 0 ? {} : { top_k: config.topK },
|
|
@@ -1751,7 +1822,7 @@ function buildNativeBody(options, model, config, images) {
|
|
|
1751
1822
|
...config.seed === void 0 ? {} : { seed: config.seed },
|
|
1752
1823
|
...config.repeatPenalty === void 0 ? {} : { repeat_penalty: config.repeatPenalty },
|
|
1753
1824
|
...config.repeatLastN === void 0 ? {} : { repeat_last_n: config.repeatLastN },
|
|
1754
|
-
...
|
|
1825
|
+
...numCtx === void 0 ? {} : { num_ctx: numCtx },
|
|
1755
1826
|
...maxTokens === void 0 || maxTokens <= 0 ? {} : { num_predict: maxTokens },
|
|
1756
1827
|
...stop === void 0 || stop.length === 0 ? {} : { stop }
|
|
1757
1828
|
};
|
|
@@ -2768,7 +2839,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
|
|
|
2768
2839
|
tools: limited
|
|
2769
2840
|
};
|
|
2770
2841
|
}
|
|
2771
|
-
const body = model.transport === "openai-chat" ? buildChatBody(bodyOptions, model, config, images) : buildNativeBody(bodyOptions, model, config, images);
|
|
2842
|
+
const body = model.transport === "openai-chat" ? buildChatBody(bodyOptions, model, config, images) : buildNativeBody(bodyOptions, model, config, images, effectiveNumCtx(config, options.sessionId));
|
|
2772
2843
|
let lastError;
|
|
2773
2844
|
let lastAccount = "default";
|
|
2774
2845
|
let loggedAny = false;
|
|
@@ -2793,8 +2864,9 @@ var OllamaCloudAdapter = class extends LlmAdapter {
|
|
|
2793
2864
|
...errorCode === void 0 ? {} : { error: errorCode }
|
|
2794
2865
|
});
|
|
2795
2866
|
};
|
|
2867
|
+
const budget = createAttemptBudget(config.attemptTimeoutMs, options.signal);
|
|
2796
2868
|
try {
|
|
2797
|
-
const response = await this.send(url, entry.key, model, body, config,
|
|
2869
|
+
const response = await this.send(url, entry.key, model, body, config, budget.signal);
|
|
2798
2870
|
if (!response.ok) {
|
|
2799
2871
|
const text = await response.text().catch(() => "");
|
|
2800
2872
|
const error = classifyResponseError(response.status, text, response.headers);
|
|
@@ -2826,7 +2898,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
|
|
|
2826
2898
|
fallback: false,
|
|
2827
2899
|
ok: true
|
|
2828
2900
|
});
|
|
2829
|
-
const chunks = model.transport === "openai-chat" ? parseChatStream(response, config.streamIdleTimeoutMs,
|
|
2901
|
+
const chunks = model.transport === "openai-chat" ? parseChatStream(response, config.streamIdleTimeoutMs, budget.signal) : parseNativeStream(response, config.streamIdleTimeoutMs, budget.signal);
|
|
2830
2902
|
for await (const chunk of chunks) {
|
|
2831
2903
|
if (firstChunkAt === void 0) firstChunkAt = Date.now();
|
|
2832
2904
|
started = true;
|
|
@@ -2835,9 +2907,9 @@ var OllamaCloudAdapter = class extends LlmAdapter {
|
|
|
2835
2907
|
logAttempt(true);
|
|
2836
2908
|
return;
|
|
2837
2909
|
} catch (error) {
|
|
2838
|
-
const classified = error instanceof LlmError ? error : new LlmError(error instanceof Error ? error.message : "Ollama Cloud request failed", "TRANSPORT", { cause: error });
|
|
2910
|
+
const classified = budget.timedOut ? new LlmError(`Ollama Cloud attempt exceeded ${config.attemptTimeoutMs}ms`, "TIMEOUT", { cause: error }) : error instanceof LlmError ? error : new LlmError(error instanceof Error ? error.message : "Ollama Cloud request failed", "TRANSPORT", { cause: error });
|
|
2839
2911
|
logAttempt(false, classified.code);
|
|
2840
|
-
if (started || options.signal?.aborted === true) throw error;
|
|
2912
|
+
if (started || options.signal?.aborted === true) throw budget.timedOut ? classified : error;
|
|
2841
2913
|
lastError = classified;
|
|
2842
2914
|
const transient = this.isTransient(classified);
|
|
2843
2915
|
const canRotate = index < keys.length - 1 && (transient || this.modelScoped(classified));
|
|
@@ -2849,6 +2921,8 @@ var OllamaCloudAdapter = class extends LlmAdapter {
|
|
|
2849
2921
|
}
|
|
2850
2922
|
if (!responseFailure && (canRotate || credentialOrQuota)) this.markCooldown(entry.key, 0);
|
|
2851
2923
|
if (!canRotate) throw classified;
|
|
2924
|
+
} finally {
|
|
2925
|
+
budget.dispose();
|
|
2852
2926
|
}
|
|
2853
2927
|
}
|
|
2854
2928
|
const finalError = lastError ?? new LlmError("llm-ollama-cloud: every configured account is cooling down after provider rejections", "RATE_LIMIT");
|
|
@@ -3170,6 +3244,205 @@ function windowRows(report) {
|
|
|
3170
3244
|
}
|
|
3171
3245
|
].filter((entry) => entry !== void 0);
|
|
3172
3246
|
}
|
|
3247
|
+
// src/local-models.ts
|
|
3248
|
+
const LOCAL_TIMEOUT_MS = 15e3;
|
|
3249
|
+
const MODEL_NAME = /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/;
|
|
3250
|
+
function formatBytes(bytes) {
|
|
3251
|
+
if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
|
|
3252
|
+
const units = [
|
|
3253
|
+
"B",
|
|
3254
|
+
"KB",
|
|
3255
|
+
"MB",
|
|
3256
|
+
"GB",
|
|
3257
|
+
"TB"
|
|
3258
|
+
];
|
|
3259
|
+
let value = bytes;
|
|
3260
|
+
let index = 0;
|
|
3261
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
3262
|
+
value /= 1024;
|
|
3263
|
+
index += 1;
|
|
3264
|
+
}
|
|
3265
|
+
return `${value >= 10 || index === 0 ? value.toFixed(0) : value.toFixed(1)} ${units[index]}`;
|
|
3266
|
+
}
|
|
3267
|
+
function assertLocal(config) {
|
|
3268
|
+
if (!isLocalEndpoint(config)) throw new Error("local endpoint required");
|
|
3269
|
+
}
|
|
3270
|
+
function assertModelName(model) {
|
|
3271
|
+
const name = model.trim();
|
|
3272
|
+
if (name === "" || name.includes("..") || !MODEL_NAME.test(name)) throw new Error("invalid model name");
|
|
3273
|
+
return name;
|
|
3274
|
+
}
|
|
3275
|
+
function recordOf(value) {
|
|
3276
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
3277
|
+
}
|
|
3278
|
+
function stringOf(value) {
|
|
3279
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
3280
|
+
}
|
|
3281
|
+
function numberOf(value) {
|
|
3282
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
3283
|
+
}
|
|
3284
|
+
function detailsOf(value) {
|
|
3285
|
+
const record = recordOf(value);
|
|
3286
|
+
if (record === void 0) return void 0;
|
|
3287
|
+
const family = stringOf(record.family);
|
|
3288
|
+
const parameterSize = stringOf(record.parameter_size);
|
|
3289
|
+
const quantization = stringOf(record.quantization_level);
|
|
3290
|
+
const out = {
|
|
3291
|
+
...family === void 0 ? {} : { family },
|
|
3292
|
+
...parameterSize === void 0 ? {} : { parameterSize },
|
|
3293
|
+
...quantization === void 0 ? {} : { quantization }
|
|
3294
|
+
};
|
|
3295
|
+
return Object.keys(out).length === 0 ? void 0 : out;
|
|
3296
|
+
}
|
|
3297
|
+
async function localJson(config, path, init, fetchImpl) {
|
|
3298
|
+
const response = await fetchImpl(`${rootFor(config)}${path}`, {
|
|
3299
|
+
...init,
|
|
3300
|
+
headers: {
|
|
3301
|
+
accept: "application/json",
|
|
3302
|
+
"content-type": "application/json",
|
|
3303
|
+
"user-agent": config.userAgent,
|
|
3304
|
+
...init.headers
|
|
3305
|
+
},
|
|
3306
|
+
signal: AbortSignal.timeout(LOCAL_TIMEOUT_MS)
|
|
3307
|
+
});
|
|
3308
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
3309
|
+
return response.json();
|
|
3310
|
+
}
|
|
3311
|
+
async function readLocalInventory(config, fetchImpl = fetch) {
|
|
3312
|
+
assertLocal(config);
|
|
3313
|
+
const [tagsPayload, psPayload] = await Promise.all([localJson(config, "/api/tags", { method: "GET" }, fetchImpl), localJson(config, "/api/ps", { method: "GET" }, fetchImpl).catch(() => void 0)]);
|
|
3314
|
+
const tags = recordOf(tagsPayload);
|
|
3315
|
+
const models = [];
|
|
3316
|
+
for (const entry of Array.isArray(tags?.models) ? tags.models : []) {
|
|
3317
|
+
const record = recordOf(entry);
|
|
3318
|
+
if (record === void 0) continue;
|
|
3319
|
+
const name = stringOf(record.name) ?? stringOf(record.model);
|
|
3320
|
+
if (name === void 0) continue;
|
|
3321
|
+
const size = numberOf(record.size) ?? 0;
|
|
3322
|
+
const digest = stringOf(record.digest);
|
|
3323
|
+
const modifiedAt = stringOf(record.modified_at);
|
|
3324
|
+
const details = detailsOf(record.details);
|
|
3325
|
+
models.push({
|
|
3326
|
+
name,
|
|
3327
|
+
size,
|
|
3328
|
+
...digest === void 0 ? {} : { digest },
|
|
3329
|
+
...modifiedAt === void 0 ? {} : { modifiedAt },
|
|
3330
|
+
...details === void 0 ? {} : { details }
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
models.sort((a, b) => a.name.localeCompare(b.name));
|
|
3334
|
+
const running = [];
|
|
3335
|
+
const ps = recordOf(psPayload);
|
|
3336
|
+
for (const entry of Array.isArray(ps?.models) ? ps.models : []) {
|
|
3337
|
+
const record = recordOf(entry);
|
|
3338
|
+
if (record === void 0) continue;
|
|
3339
|
+
const name = stringOf(record.name) ?? stringOf(record.model);
|
|
3340
|
+
if (name === void 0) continue;
|
|
3341
|
+
const digest = stringOf(record.digest);
|
|
3342
|
+
const expiresAt = stringOf(record.expires_at);
|
|
3343
|
+
running.push({
|
|
3344
|
+
name,
|
|
3345
|
+
size: numberOf(record.size) ?? 0,
|
|
3346
|
+
sizeVram: numberOf(record.size_vram) ?? 0,
|
|
3347
|
+
...digest === void 0 ? {} : { digest },
|
|
3348
|
+
...expiresAt === void 0 ? {} : { expiresAt }
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
running.sort((a, b) => a.name.localeCompare(b.name));
|
|
3352
|
+
return {
|
|
3353
|
+
models,
|
|
3354
|
+
running,
|
|
3355
|
+
diskBytes: models.reduce((sum, model) => sum + model.size, 0),
|
|
3356
|
+
runningBytes: running.reduce((sum, model) => sum + model.sizeVram, 0)
|
|
3357
|
+
};
|
|
3358
|
+
}
|
|
3359
|
+
async function showLocalModel(config, model, fetchImpl = fetch) {
|
|
3360
|
+
assertLocal(config);
|
|
3361
|
+
const name = assertModelName(model);
|
|
3362
|
+
const payload = recordOf(await localJson(config, "/api/show", {
|
|
3363
|
+
method: "POST",
|
|
3364
|
+
body: JSON.stringify({ model: name })
|
|
3365
|
+
}, fetchImpl));
|
|
3366
|
+
if (payload === void 0) throw new Error("invalid show response");
|
|
3367
|
+
const capabilities = Array.isArray(payload.capabilities) ? payload.capabilities.filter((entry) => typeof entry === "string") : [];
|
|
3368
|
+
const modifiedAt = stringOf(payload.modified_at);
|
|
3369
|
+
const details = detailsOf(payload.details);
|
|
3370
|
+
const parameters = stringOf(payload.parameters);
|
|
3371
|
+
return {
|
|
3372
|
+
name,
|
|
3373
|
+
...modifiedAt === void 0 ? {} : { modifiedAt },
|
|
3374
|
+
...details === void 0 ? {} : { details },
|
|
3375
|
+
capabilities,
|
|
3376
|
+
...parameters === void 0 ? {} : { parameters }
|
|
3377
|
+
};
|
|
3378
|
+
}
|
|
3379
|
+
async function pullLocalModel(config, model, onProgress = () => {}, fetchImpl = fetch, signal) {
|
|
3380
|
+
assertLocal(config);
|
|
3381
|
+
const name = assertModelName(model);
|
|
3382
|
+
const response = await fetchImpl(`${rootFor(config)}/api/pull`, {
|
|
3383
|
+
method: "POST",
|
|
3384
|
+
headers: {
|
|
3385
|
+
accept: "application/x-ndjson",
|
|
3386
|
+
"content-type": "application/json",
|
|
3387
|
+
"user-agent": config.userAgent
|
|
3388
|
+
},
|
|
3389
|
+
body: JSON.stringify({
|
|
3390
|
+
model: name,
|
|
3391
|
+
stream: true
|
|
3392
|
+
}),
|
|
3393
|
+
...signal === void 0 ? {} : { signal }
|
|
3394
|
+
});
|
|
3395
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
3396
|
+
if (response.body === null) throw new Error("empty pull stream");
|
|
3397
|
+
const reader = response.body.getReader();
|
|
3398
|
+
const decoder = new TextDecoder();
|
|
3399
|
+
let buffer = "";
|
|
3400
|
+
let last = { status: "starting" };
|
|
3401
|
+
const consume = (line) => {
|
|
3402
|
+
if (line.trim() === "") return;
|
|
3403
|
+
const entry = recordOf(JSON.parse(line));
|
|
3404
|
+
if (entry === void 0) return;
|
|
3405
|
+
if (typeof entry.error === "string" && entry.error !== "") throw new Error(entry.error);
|
|
3406
|
+
if (typeof entry.status === "string") {
|
|
3407
|
+
const digest = stringOf(entry.digest);
|
|
3408
|
+
const completed = numberOf(entry.completed);
|
|
3409
|
+
const total = numberOf(entry.total);
|
|
3410
|
+
last = {
|
|
3411
|
+
status: entry.status,
|
|
3412
|
+
...digest === void 0 ? {} : { digest },
|
|
3413
|
+
...completed === void 0 ? {} : { completed },
|
|
3414
|
+
...total === void 0 ? {} : { total }
|
|
3415
|
+
};
|
|
3416
|
+
onProgress(last);
|
|
3417
|
+
}
|
|
3418
|
+
};
|
|
3419
|
+
for (;;) {
|
|
3420
|
+
const { done, value } = await reader.read();
|
|
3421
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
3422
|
+
const lines = buffer.split("\n");
|
|
3423
|
+
buffer = lines.pop() ?? "";
|
|
3424
|
+
for (const line of lines) consume(line);
|
|
3425
|
+
if (done) break;
|
|
3426
|
+
}
|
|
3427
|
+
if (buffer.trim() !== "") consume(buffer);
|
|
3428
|
+
return last;
|
|
3429
|
+
}
|
|
3430
|
+
/** Delete one local model. Callers must obtain explicit confirmation first. */
|
|
3431
|
+
async function removeLocalModel(config, model, fetchImpl = fetch) {
|
|
3432
|
+
assertLocal(config);
|
|
3433
|
+
const name = assertModelName(model);
|
|
3434
|
+
const response = await fetchImpl(`${rootFor(config)}/api/delete`, {
|
|
3435
|
+
method: "DELETE",
|
|
3436
|
+
headers: {
|
|
3437
|
+
accept: "application/json",
|
|
3438
|
+
"content-type": "application/json",
|
|
3439
|
+
"user-agent": config.userAgent
|
|
3440
|
+
},
|
|
3441
|
+
body: JSON.stringify({ model: name }),
|
|
3442
|
+
signal: AbortSignal.timeout(LOCAL_TIMEOUT_MS)
|
|
3443
|
+
});
|
|
3444
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
3445
|
+
}
|
|
3173
3446
|
// src/commands.ts
|
|
3174
3447
|
function bar(percent, width = 10) {
|
|
3175
3448
|
const clamped = Math.max(0, Math.min(100, percent));
|
|
@@ -3284,6 +3557,57 @@ async function testText(deps, model) {
|
|
|
3284
3557
|
};
|
|
3285
3558
|
}
|
|
3286
3559
|
}
|
|
3560
|
+
async function localText(deps) {
|
|
3561
|
+
const config = deps.config();
|
|
3562
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3563
|
+
const inventory = await readLocalInventory(config);
|
|
3564
|
+
const running = new Map(inventory.running.map((entry) => [entry.name, entry]));
|
|
3565
|
+
const lines = [`Local Ollama · disk ${formatBytes(inventory.diskBytes)} · running ${formatBytes(inventory.runningBytes)}`];
|
|
3566
|
+
if (inventory.models.length === 0) return [...lines, "No local models."].join("\n");
|
|
3567
|
+
for (const model of inventory.models) {
|
|
3568
|
+
const active = running.get(model.name);
|
|
3569
|
+
const details = model.details === void 0 ? "" : [
|
|
3570
|
+
model.details.family,
|
|
3571
|
+
model.details.parameterSize,
|
|
3572
|
+
model.details.quantization
|
|
3573
|
+
].filter((entry) => entry !== void 0).join(" ");
|
|
3574
|
+
lines.push(`- ${model.name} · ${formatBytes(model.size)}${active === void 0 ? "" : " · RUNNING"}${details === "" ? "" : ` · ${details}`}`);
|
|
3575
|
+
}
|
|
3576
|
+
return lines.join("\n");
|
|
3577
|
+
}
|
|
3578
|
+
async function localPsText(deps) {
|
|
3579
|
+
const config = deps.config();
|
|
3580
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3581
|
+
const inventory = await readLocalInventory(config);
|
|
3582
|
+
if (inventory.running.length === 0) return "No running models.";
|
|
3583
|
+
return inventory.running.map((entry) => `- ${entry.name} · VRAM ${formatBytes(entry.sizeVram)}${entry.expiresAt === void 0 ? "" : ` · expires ${entry.expiresAt}`}`).join("\n");
|
|
3584
|
+
}
|
|
3585
|
+
async function localShowText(deps, model) {
|
|
3586
|
+
const config = deps.config();
|
|
3587
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3588
|
+
const show = await showLocalModel(config, model);
|
|
3589
|
+
const lines = [`Local model: ${show.name}`];
|
|
3590
|
+
if (show.modifiedAt !== void 0) lines.push(`Modified: ${show.modifiedAt}`);
|
|
3591
|
+
if (show.details !== void 0) lines.push(`Details: ${show.details.family ?? "?"} ${show.details.parameterSize ?? ""} ${show.details.quantization ?? ""}`.trim());
|
|
3592
|
+
if (show.capabilities.length > 0) lines.push(`Capabilities: ${show.capabilities.join(", ")}`);
|
|
3593
|
+
if (show.parameters !== void 0) lines.push(`Parameters:\n${show.parameters.slice(0, 2e3)}`);
|
|
3594
|
+
return lines.join("\n");
|
|
3595
|
+
}
|
|
3596
|
+
async function localPullText(deps, model) {
|
|
3597
|
+
const config = deps.config();
|
|
3598
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3599
|
+
let fraction = 0;
|
|
3600
|
+
return `${model}: ${(await pullLocalModel(config, model, (progress) => {
|
|
3601
|
+
if (progress.total !== void 0 && progress.total > 0) fraction = (progress.completed ?? 0) / progress.total;
|
|
3602
|
+
})).status}${fraction > 0 ? ` · ${Math.round(fraction * 100)}%` : ""}`;
|
|
3603
|
+
}
|
|
3604
|
+
async function localRemoveText(deps, model, confirmed) {
|
|
3605
|
+
if (!confirmed) return `Refusing to remove ${model}: add --yes to confirm.`;
|
|
3606
|
+
const config = deps.config();
|
|
3607
|
+
if (!isLocalEndpoint(config)) return "Local models are available only with a local Ollama endpoint.";
|
|
3608
|
+
await removeLocalModel(config, model);
|
|
3609
|
+
return `${model}: removed.`;
|
|
3610
|
+
}
|
|
3287
3611
|
async function statusText(deps) {
|
|
3288
3612
|
const config = deps.config();
|
|
3289
3613
|
const rules = config.modelAccountRules.length === 0 ? "none" : config.modelAccountRules.map((rule) => `${rule.pattern} → ${rule.account}`).join(", ");
|
|
@@ -3302,7 +3626,7 @@ function applyCommands(ctx, deps) {
|
|
|
3302
3626
|
ctx.commands.register({
|
|
3303
3627
|
name: "ollama",
|
|
3304
3628
|
description: "Ollama Cloud status, balance, accounts, models and rules",
|
|
3305
|
-
input: { hint: "status | usage | balance | accounts | models | rules | test [model]" },
|
|
3629
|
+
input: { hint: "status | usage | balance | accounts | models | rules | test [model] | local [models|ps|show|pull|remove] [model]" },
|
|
3306
3630
|
handler: async (invocation) => {
|
|
3307
3631
|
const raw = invocation.rawInput.trim();
|
|
3308
3632
|
const parts = raw === "" ? ["status"] : raw.split(/\s+/);
|
|
@@ -3343,11 +3667,85 @@ function applyCommands(ctx, deps) {
|
|
|
3343
3667
|
text: result.text
|
|
3344
3668
|
};
|
|
3345
3669
|
}
|
|
3670
|
+
case "local": {
|
|
3671
|
+
const words = arg === "" ? [] : arg.split(/\s+/);
|
|
3672
|
+
const action = (words[0] ?? "models").toLowerCase();
|
|
3673
|
+
const confirmed = words.includes("--yes");
|
|
3674
|
+
const model = words.slice(1).filter((word) => word !== "--yes").join(" ");
|
|
3675
|
+
try {
|
|
3676
|
+
if (action === "models") return {
|
|
3677
|
+
kind: "success",
|
|
3678
|
+
text: await localText(deps)
|
|
3679
|
+
};
|
|
3680
|
+
if (action === "ps") return {
|
|
3681
|
+
kind: "success",
|
|
3682
|
+
text: await localPsText(deps)
|
|
3683
|
+
};
|
|
3684
|
+
if (model === "") return {
|
|
3685
|
+
kind: "error",
|
|
3686
|
+
text: `Usage: /ollama local ${action} <model>`
|
|
3687
|
+
};
|
|
3688
|
+
if (action === "show") return {
|
|
3689
|
+
kind: "success",
|
|
3690
|
+
text: await localShowText(deps, model)
|
|
3691
|
+
};
|
|
3692
|
+
if (action === "pull") return {
|
|
3693
|
+
kind: "success",
|
|
3694
|
+
text: await localPullText(deps, model)
|
|
3695
|
+
};
|
|
3696
|
+
if (action === "remove") return {
|
|
3697
|
+
kind: confirmed ? "success" : "error",
|
|
3698
|
+
text: await localRemoveText(deps, model, confirmed)
|
|
3699
|
+
};
|
|
3700
|
+
return {
|
|
3701
|
+
kind: "error",
|
|
3702
|
+
text: `Unknown local action "${action}". Use models, ps, show, pull, or remove.`
|
|
3703
|
+
};
|
|
3704
|
+
} catch (error) {
|
|
3705
|
+
return {
|
|
3706
|
+
kind: "error",
|
|
3707
|
+
text: error instanceof Error ? error.message : "local command failed"
|
|
3708
|
+
};
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3346
3711
|
default: return {
|
|
3347
3712
|
kind: "error",
|
|
3348
|
-
text: `Unknown /ollama argument "${verb}". Use status, usage, balance, accounts, models, rules,
|
|
3713
|
+
text: `Unknown /ollama argument "${verb}". Use status, usage, balance, accounts, models, rules, test [model], or local.`
|
|
3714
|
+
};
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
});
|
|
3718
|
+
ctx.commands.register({
|
|
3719
|
+
name: "ollama-context",
|
|
3720
|
+
description: "Set the native Ollama context size for this session",
|
|
3721
|
+
input: { hint: "status | 4k | 8k | 16k | 32k | 64k | 128k | <tokens> | follow | reset" },
|
|
3722
|
+
handler: async (invocation) => {
|
|
3723
|
+
const config = deps.config();
|
|
3724
|
+
const sessionId = invocation.agent.id;
|
|
3725
|
+
const raw = invocation.rawInput.trim();
|
|
3726
|
+
const value = parseContextValue(raw);
|
|
3727
|
+
if (raw !== "" && raw.toLowerCase() !== "status" && value === void 0) return {
|
|
3728
|
+
kind: "error",
|
|
3729
|
+
text: "Usage: /ollama-context status | 4k | 8k | 16k | 32k | 64k | 128k | <tokens> | follow | reset"
|
|
3730
|
+
};
|
|
3731
|
+
if (value === "reset") {
|
|
3732
|
+
clearContextOverride(sessionId);
|
|
3733
|
+
return {
|
|
3734
|
+
kind: "success",
|
|
3735
|
+
text: `${describeContext(config, sessionId)}\nSession override cleared.`
|
|
3349
3736
|
};
|
|
3350
3737
|
}
|
|
3738
|
+
if (value !== void 0) {
|
|
3739
|
+
setContextOverride(sessionId, value);
|
|
3740
|
+
return {
|
|
3741
|
+
kind: "success",
|
|
3742
|
+
text: describeContext(config, sessionId)
|
|
3743
|
+
};
|
|
3744
|
+
}
|
|
3745
|
+
return {
|
|
3746
|
+
kind: "success",
|
|
3747
|
+
text: describeContext(config, sessionId)
|
|
3748
|
+
};
|
|
3351
3749
|
}
|
|
3352
3750
|
});
|
|
3353
3751
|
}
|
|
@@ -4055,6 +4453,7 @@ function publicConfig(config) {
|
|
|
4055
4453
|
modelTransports: config.modelTransports,
|
|
4056
4454
|
requestTimeoutMs: config.requestTimeoutMs,
|
|
4057
4455
|
streamIdleTimeoutMs: config.streamIdleTimeoutMs,
|
|
4456
|
+
attemptTimeoutMs: config.attemptTimeoutMs,
|
|
4058
4457
|
visibleModels: config.visibleModels,
|
|
4059
4458
|
showAllModels: config.showAllModels,
|
|
4060
4459
|
modelVisibility: config.modelVisibility,
|
|
@@ -4395,6 +4794,7 @@ function configOps(patch) {
|
|
|
4395
4794
|
if ("modelTransports" in patch) set("modelTransports", cleanTransports(patch.modelTransports));
|
|
4396
4795
|
if ("requestTimeoutMs" in patch) set("requestTimeoutMs", patch.requestTimeoutMs);
|
|
4397
4796
|
if ("streamIdleTimeoutMs" in patch) set("streamIdleTimeoutMs", patch.streamIdleTimeoutMs);
|
|
4797
|
+
if ("attemptTimeoutMs" in patch) set("attemptTimeoutMs", patch.attemptTimeoutMs);
|
|
4398
4798
|
if ("visibleModels" in patch) set("visibleModels", cleanStringArray(patch.visibleModels));
|
|
4399
4799
|
if ("showAllModels" in patch) set("showAllModels", patch.showAllModels === true);
|
|
4400
4800
|
if ("modelVisibility" in patch) set("modelVisibility", cleanBooleanRecord(patch.modelVisibility));
|
|
@@ -4744,6 +5144,93 @@ function applyRoutes(ctx, web, deps) {
|
|
|
4744
5144
|
}
|
|
4745
5145
|
await refreshAndState(ctx, deps, res);
|
|
4746
5146
|
});
|
|
5147
|
+
route("/dsh-ollama/local/models", async (req, res) => {
|
|
5148
|
+
if (!await privateRead(req, res)) return;
|
|
5149
|
+
const config = deps.config();
|
|
5150
|
+
if (!isLocalEndpoint(config)) {
|
|
5151
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5152
|
+
return;
|
|
5153
|
+
}
|
|
5154
|
+
try {
|
|
5155
|
+
json(res, 200, await readLocalInventory(config, deps.localFetch));
|
|
5156
|
+
} catch (error) {
|
|
5157
|
+
json(res, 502, { error: error instanceof Error ? error.message : "local models failed" });
|
|
5158
|
+
}
|
|
5159
|
+
});
|
|
5160
|
+
route("/dsh-ollama/local/show", async (req, res) => {
|
|
5161
|
+
if (!await privateRead(req, res)) return;
|
|
5162
|
+
const config = deps.config();
|
|
5163
|
+
if (!isLocalEndpoint(config)) {
|
|
5164
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5165
|
+
return;
|
|
5166
|
+
}
|
|
5167
|
+
const model = new URL(req.url ?? "/", "http://localhost").searchParams.get("model") ?? "";
|
|
5168
|
+
try {
|
|
5169
|
+
json(res, 200, await showLocalModel(config, model, deps.localFetch));
|
|
5170
|
+
} catch (error) {
|
|
5171
|
+
json(res, 400, { error: error instanceof Error ? error.message : "show failed" });
|
|
5172
|
+
}
|
|
5173
|
+
});
|
|
5174
|
+
route("/dsh-ollama/local/pull", async (req, res) => {
|
|
5175
|
+
if (!await requirePost(req, res, verifyHost)) return;
|
|
5176
|
+
const config = deps.config();
|
|
5177
|
+
if (!isLocalEndpoint(config)) {
|
|
5178
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5179
|
+
return;
|
|
5180
|
+
}
|
|
5181
|
+
let body;
|
|
5182
|
+
try {
|
|
5183
|
+
body = await readJson(req);
|
|
5184
|
+
} catch (error) {
|
|
5185
|
+
json(res, 400, { error: error instanceof Error ? error.message : "invalid body" });
|
|
5186
|
+
return;
|
|
5187
|
+
}
|
|
5188
|
+
const model = typeof body.model === "string" ? body.model : "";
|
|
5189
|
+
res.statusCode = 200;
|
|
5190
|
+
res.setHeader("content-type", "application/x-ndjson; charset=utf-8");
|
|
5191
|
+
res.setHeader("cache-control", "no-store");
|
|
5192
|
+
const write = (value) => {
|
|
5193
|
+
res.write(`${JSON.stringify(value)}\n`);
|
|
5194
|
+
};
|
|
5195
|
+
try {
|
|
5196
|
+
write({
|
|
5197
|
+
status: (await pullLocalModel(config, model, write, deps.localFetch)).status,
|
|
5198
|
+
done: true
|
|
5199
|
+
});
|
|
5200
|
+
} catch (error) {
|
|
5201
|
+
write({ error: error instanceof Error ? error.message : "pull failed" });
|
|
5202
|
+
}
|
|
5203
|
+
res.end();
|
|
5204
|
+
});
|
|
5205
|
+
route("/dsh-ollama/local/remove", async (req, res) => {
|
|
5206
|
+
if (!await requirePost(req, res, verifyHost)) return;
|
|
5207
|
+
const config = deps.config();
|
|
5208
|
+
if (!isLocalEndpoint(config)) {
|
|
5209
|
+
json(res, 400, { error: "local endpoint required" });
|
|
5210
|
+
return;
|
|
5211
|
+
}
|
|
5212
|
+
let body;
|
|
5213
|
+
try {
|
|
5214
|
+
body = await readJson(req);
|
|
5215
|
+
} catch (error) {
|
|
5216
|
+
json(res, 400, { error: error instanceof Error ? error.message : "invalid body" });
|
|
5217
|
+
return;
|
|
5218
|
+
}
|
|
5219
|
+
if (body.confirm !== true) {
|
|
5220
|
+
json(res, 400, { error: "confirmation required" });
|
|
5221
|
+
return;
|
|
5222
|
+
}
|
|
5223
|
+
const model = typeof body.model === "string" ? body.model : "";
|
|
5224
|
+
try {
|
|
5225
|
+
await removeLocalModel(config, model, deps.localFetch);
|
|
5226
|
+
json(res, 200, {
|
|
5227
|
+
ok: true,
|
|
5228
|
+
model
|
|
5229
|
+
});
|
|
5230
|
+
} catch (error) {
|
|
5231
|
+
json(res, 502, { error: error instanceof Error ? error.message : "remove failed" });
|
|
5232
|
+
}
|
|
5233
|
+
});
|
|
4747
5234
|
route("/dsh-ollama/test", async (req, res) => {
|
|
4748
5235
|
if (!await requirePost(req, res, verifyHost)) return;
|
|
4749
5236
|
let body;
|
|
@@ -5312,17 +5799,12 @@ function isRedirectFailure(error) {
|
|
|
5312
5799
|
}
|
|
5313
5800
|
return false;
|
|
5314
5801
|
}
|
|
5315
|
-
function abortReason(caller, own) {
|
|
5316
|
-
if (caller?.aborted === true) return "caller";
|
|
5317
|
-
return own.aborted ? "timeout" : void 0;
|
|
5318
|
-
}
|
|
5319
5802
|
async function postOnce(options, url, payload, caller) {
|
|
5320
5803
|
const apiKey = await options.resolveApiKey();
|
|
5321
5804
|
if (apiKey === void 0) throw new WebError("ollama-cloud web capabilities need an API key; configure the credential reference through plugin settings", "OLLAMA_WEB_MISSING_CREDENTIAL");
|
|
5322
5805
|
const fetchImpl = options.fetch ?? fetch;
|
|
5323
5806
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
5324
|
-
const
|
|
5325
|
-
const signal = caller === void 0 ? own : AbortSignal.any([caller, own]);
|
|
5807
|
+
const budget = createAttemptBudget(timeoutMs, caller);
|
|
5326
5808
|
let response;
|
|
5327
5809
|
try {
|
|
5328
5810
|
response = await fetchImpl(url, {
|
|
@@ -5334,17 +5816,18 @@ async function postOnce(options, url, payload, caller) {
|
|
|
5334
5816
|
},
|
|
5335
5817
|
body: JSON.stringify(payload),
|
|
5336
5818
|
redirect: "error",
|
|
5337
|
-
signal
|
|
5819
|
+
signal: budget.signal
|
|
5338
5820
|
});
|
|
5339
5821
|
} catch (error) {
|
|
5340
|
-
|
|
5341
|
-
if (
|
|
5342
|
-
if (
|
|
5822
|
+
budget.dispose();
|
|
5823
|
+
if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
|
|
5824
|
+
if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
|
|
5343
5825
|
if (isRedirectFailure(error)) throw new WebError(`${url} attempted a redirect`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
5344
5826
|
const detail = error instanceof Error && error.message !== "" ? `: ${error.message}` : "";
|
|
5345
5827
|
throw new WebError(`could not reach ${url}${detail}`, "OLLAMA_WEB_TRANSPORT", { cause: error });
|
|
5346
5828
|
}
|
|
5347
5829
|
if (!response.ok) {
|
|
5830
|
+
budget.dispose();
|
|
5348
5831
|
await response.body?.cancel();
|
|
5349
5832
|
const hint = response.status === 401 || response.status === 403 ? "; check the API key" : "";
|
|
5350
5833
|
throw new WebError(`${url} answered ${response.status}${hint}`, "WEB_PROVIDER_ERROR");
|
|
@@ -5355,7 +5838,11 @@ async function postOnce(options, url, payload, caller) {
|
|
|
5355
5838
|
body: await response.json()
|
|
5356
5839
|
};
|
|
5357
5840
|
} catch (error) {
|
|
5841
|
+
if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
|
|
5842
|
+
if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
|
|
5358
5843
|
throw new WebError(`${url} did not answer with JSON`, "OLLAMA_WEB_BAD_REPLY", { cause: error });
|
|
5844
|
+
} finally {
|
|
5845
|
+
budget.dispose();
|
|
5359
5846
|
}
|
|
5360
5847
|
}
|
|
5361
5848
|
async function postJson(options, suffix, payload, caller) {
|
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.22",
|
|
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 tests/attempt.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"
|