@goodandready/dsh-ollama-cloud-provider 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +169 -2
- package/lib/index.d.ts +27 -1
- package/lib/index.js +308 -26
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.20 — 2026-11-05
|
|
4
|
+
|
|
5
|
+
- Persisted the catalog snapshot under `$DSH_HOME/cache/dsh-ollama-cloud/`
|
|
6
|
+
with atomic temp+rename writes, schema/endpoint validation, and corrupt-file
|
|
7
|
+
recovery. Offline starts serve the last snapshot immediately.
|
|
8
|
+
- Added `autoRefresh` and `refreshMinutes` controls: mount refresh, periodic
|
|
9
|
+
forced refresh, and a settings UI; turning auto-refresh off leaves the cache
|
|
10
|
+
untouched.
|
|
11
|
+
- Retired models explicitly missing from `/api/show` (404/410), while
|
|
12
|
+
transient show failures keep the previous model.
|
|
13
|
+
- Added cache, offline, retirement and settings tests; 115/115 tests.
|
|
14
|
+
|
|
15
|
+
## 0.1.19 — 2026-11-05
|
|
16
|
+
|
|
17
|
+
- Added configurable native generation defaults: temperature, top_k, top_p,
|
|
18
|
+
min_p, seed, repeat_penalty, repeat_last_n, num_ctx, keep_alive and stop.
|
|
19
|
+
Request options override config; Ollama-only fields are not sent to the
|
|
20
|
+
OpenAI transport. Added settings fields for all values.
|
|
21
|
+
- Normalized thinking ladders: boolean switches become off/high, level lists
|
|
22
|
+
are ordered and deduplicated, and known families get a default effort
|
|
23
|
+
(GLM-5.x/Kimi K3 max, Kimi K2/DeepSeek V4/MiniMax M3 high, GPT-OSS medium,
|
|
24
|
+
Nemotron low) only when that level is offered.
|
|
25
|
+
- Added generation/reasoning tests; 112/112 tests.
|
|
26
|
+
|
|
3
27
|
## 0.1.18 — 2026-11-05
|
|
4
28
|
|
|
5
29
|
- Added local/self-hosted Ollama mode: an explicit empty `apiKeyEnv` means no
|
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.20
|
|
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.20
|
|
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.20.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.20.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.20
|
|
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.20
|
|
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.20.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.20.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.20
|
|
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.20
|
|
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.20.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.20.tgz
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
|
package/lib/client.js
CHANGED
|
@@ -122,6 +122,23 @@ window.__ModuleLoader__.load({
|
|
|
122
122
|
streamIdleTimeoutMs: "Stream idle timeout (ms)",
|
|
123
123
|
maxOutputTokens: "Output limit (0 = provider default)",
|
|
124
124
|
contextWindow: "Context window override",
|
|
125
|
+
generation: "Generation defaults",
|
|
126
|
+
generationHint: "Native Ollama defaults. Empty fields are not sent; request options still win.",
|
|
127
|
+
temperature: "Temperature",
|
|
128
|
+
topK: "Top K",
|
|
129
|
+
topP: "Top P",
|
|
130
|
+
minP: "Min P",
|
|
131
|
+
seed: "Seed",
|
|
132
|
+
repeatPenalty: "Repeat penalty",
|
|
133
|
+
repeatLastN: "Repeat last N",
|
|
134
|
+
numCtx: "num_ctx",
|
|
135
|
+
keepAlive: "Keep alive",
|
|
136
|
+
keepAliveHint: "Ollama keep_alive, for example 5m or -1.",
|
|
137
|
+
stop: "Stop sequences",
|
|
138
|
+
stopHint: "Comma-separated; sent as the native stop list.",
|
|
139
|
+
autoRefresh: "Refresh model catalog automatically",
|
|
140
|
+
refreshMinutes: "Refresh interval (minutes)",
|
|
141
|
+
autoRefreshHint: "Mount refresh plus this interval; 0 keeps the mount refresh only.",
|
|
125
142
|
sidebar: "Sidebar",
|
|
126
143
|
serviceStatus: "Service status",
|
|
127
144
|
serviceStatusHint: "Checks the public Ollama Cloud tag endpoint without using your key or quota.",
|
|
@@ -295,6 +312,23 @@ window.__ModuleLoader__.load({
|
|
|
295
312
|
streamIdleTimeoutMs: "流空闲超时(毫秒)",
|
|
296
313
|
maxOutputTokens: "输出上限(0 = 提供方默认)",
|
|
297
314
|
contextWindow: "上下文窗口覆盖",
|
|
315
|
+
generation: "生成默认值",
|
|
316
|
+
generationHint: "Ollama 原生默认值;空字段不发送,请求参数优先。",
|
|
317
|
+
temperature: "Temperature",
|
|
318
|
+
topK: "Top K",
|
|
319
|
+
topP: "Top P",
|
|
320
|
+
minP: "Min P",
|
|
321
|
+
seed: "Seed",
|
|
322
|
+
repeatPenalty: "Repeat penalty",
|
|
323
|
+
repeatLastN: "Repeat last N",
|
|
324
|
+
numCtx: "num_ctx",
|
|
325
|
+
keepAlive: "Keep alive",
|
|
326
|
+
keepAliveHint: "Ollama keep_alive,例如 5m 或 -1。",
|
|
327
|
+
stop: "Stop sequences",
|
|
328
|
+
stopHint: "逗号分隔,作为原生 stop 列表发送。",
|
|
329
|
+
autoRefresh: "自动刷新模型目录",
|
|
330
|
+
refreshMinutes: "刷新间隔(分钟)",
|
|
331
|
+
autoRefreshHint: "启动时刷新,并按此间隔刷新;0 仅启动时刷新。",
|
|
298
332
|
sidebar: "侧边栏",
|
|
299
333
|
serviceStatus: "服务状态",
|
|
300
334
|
serviceStatusHint: "检查 Ollama Cloud 公共 tag 端点,不使用密钥或额度。",
|
|
@@ -1486,6 +1520,9 @@ window.__ModuleLoader__.load({
|
|
|
1486
1520
|
});
|
|
1487
1521
|
}
|
|
1488
1522
|
// src/client/settings-draft.ts
|
|
1523
|
+
function textOf(value) {
|
|
1524
|
+
return value === null || value === void 0 ? "" : String(value);
|
|
1525
|
+
}
|
|
1489
1526
|
function draftOf(state) {
|
|
1490
1527
|
const allIds = state.models.map((model) => model.id);
|
|
1491
1528
|
return {
|
|
@@ -1497,8 +1534,20 @@ window.__ModuleLoader__.load({
|
|
|
1497
1534
|
transport: state.config.transport,
|
|
1498
1535
|
requestTimeoutMs: String(state.config.requestTimeoutMs),
|
|
1499
1536
|
streamIdleTimeoutMs: String(state.config.streamIdleTimeoutMs),
|
|
1500
|
-
maxOutputTokens:
|
|
1501
|
-
contextWindow:
|
|
1537
|
+
maxOutputTokens: textOf(state.config.maxOutputTokens),
|
|
1538
|
+
contextWindow: textOf(state.config.contextWindow),
|
|
1539
|
+
temperature: textOf(state.config.temperature),
|
|
1540
|
+
topK: textOf(state.config.topK),
|
|
1541
|
+
topP: textOf(state.config.topP),
|
|
1542
|
+
minP: textOf(state.config.minP),
|
|
1543
|
+
seed: textOf(state.config.seed),
|
|
1544
|
+
repeatPenalty: textOf(state.config.repeatPenalty),
|
|
1545
|
+
repeatLastN: textOf(state.config.repeatLastN),
|
|
1546
|
+
numCtx: textOf(state.config.numCtx),
|
|
1547
|
+
keepAlive: state.config.keepAlive ?? "",
|
|
1548
|
+
stop: (state.config.stop ?? []).join(", "),
|
|
1549
|
+
autoRefresh: state.config.autoRefresh !== false,
|
|
1550
|
+
refreshMinutes: String(state.config.refreshMinutes ?? 1440),
|
|
1502
1551
|
showSidebarQuota: state.config.showSidebarQuota,
|
|
1503
1552
|
planLabel: state.config.planLabel,
|
|
1504
1553
|
activeAccount: state.config.activeAccount,
|
|
@@ -1518,6 +1567,16 @@ window.__ModuleLoader__.load({
|
|
|
1518
1567
|
if (!Number.isInteger(value) || value < 0) throw new Error(`Invalid number: ${text}`);
|
|
1519
1568
|
return value;
|
|
1520
1569
|
}
|
|
1570
|
+
function boundedNumber(text, min, max, integer) {
|
|
1571
|
+
const trimmed = text.trim();
|
|
1572
|
+
if (trimmed === "") return null;
|
|
1573
|
+
const value = Number(trimmed);
|
|
1574
|
+
if (!Number.isFinite(value) || value < min || value > max || integer && !Number.isInteger(value)) throw new Error(`Invalid number: ${text}`);
|
|
1575
|
+
return value;
|
|
1576
|
+
}
|
|
1577
|
+
function stopList(text) {
|
|
1578
|
+
return text.split(/[\n,]/).map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
1579
|
+
}
|
|
1521
1580
|
function patchOf(draft) {
|
|
1522
1581
|
return {
|
|
1523
1582
|
apiKeyEnv: draft.apiKeyEnv.trim(),
|
|
@@ -1530,6 +1589,18 @@ window.__ModuleLoader__.load({
|
|
|
1530
1589
|
streamIdleTimeoutMs: numberOrNull(draft.streamIdleTimeoutMs) ?? 3e5,
|
|
1531
1590
|
maxOutputTokens: numberOrNull(draft.maxOutputTokens),
|
|
1532
1591
|
contextWindow: numberOrNull(draft.contextWindow),
|
|
1592
|
+
temperature: boundedNumber(draft.temperature, 0, 2, false),
|
|
1593
|
+
topK: boundedNumber(draft.topK, 1, 1e6, true),
|
|
1594
|
+
topP: boundedNumber(draft.topP, 0, 1, false),
|
|
1595
|
+
minP: boundedNumber(draft.minP, 0, 1, false),
|
|
1596
|
+
seed: boundedNumber(draft.seed, 0, 4294967295, true),
|
|
1597
|
+
repeatPenalty: boundedNumber(draft.repeatPenalty, 0, 2, false),
|
|
1598
|
+
repeatLastN: boundedNumber(draft.repeatLastN, -1, 1e6, true),
|
|
1599
|
+
numCtx: boundedNumber(draft.numCtx, 1, 1e7, true),
|
|
1600
|
+
keepAlive: draft.keepAlive.trim(),
|
|
1601
|
+
stop: stopList(draft.stop),
|
|
1602
|
+
autoRefresh: draft.autoRefresh,
|
|
1603
|
+
refreshMinutes: boundedNumber(draft.refreshMinutes, 0, 10080, true) ?? 1440,
|
|
1533
1604
|
showSidebarQuota: draft.showSidebarQuota,
|
|
1534
1605
|
planLabel: draft.planLabel.trim(),
|
|
1535
1606
|
activeAccount: draft.activeAccount.trim(),
|
|
@@ -2508,6 +2579,102 @@ window.__ModuleLoader__.load({
|
|
|
2508
2579
|
})
|
|
2509
2580
|
]
|
|
2510
2581
|
}),
|
|
2582
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2583
|
+
className: "ocl-card",
|
|
2584
|
+
children: [
|
|
2585
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
2586
|
+
className: "ocl-card-title",
|
|
2587
|
+
children: t("generation")
|
|
2588
|
+
}),
|
|
2589
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2590
|
+
className: "ocl-hint",
|
|
2591
|
+
children: t("generationHint")
|
|
2592
|
+
}),
|
|
2593
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2594
|
+
className: "ocl-grid",
|
|
2595
|
+
children: [
|
|
2596
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2597
|
+
label: t("temperature"),
|
|
2598
|
+
type: "number",
|
|
2599
|
+
value: draft.temperature,
|
|
2600
|
+
onChange: (value) => update({ temperature: value })
|
|
2601
|
+
}),
|
|
2602
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2603
|
+
label: t("topK"),
|
|
2604
|
+
type: "number",
|
|
2605
|
+
value: draft.topK,
|
|
2606
|
+
onChange: (value) => update({ topK: value })
|
|
2607
|
+
}),
|
|
2608
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2609
|
+
label: t("topP"),
|
|
2610
|
+
type: "number",
|
|
2611
|
+
value: draft.topP,
|
|
2612
|
+
onChange: (value) => update({ topP: value })
|
|
2613
|
+
}),
|
|
2614
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2615
|
+
label: t("minP"),
|
|
2616
|
+
type: "number",
|
|
2617
|
+
value: draft.minP,
|
|
2618
|
+
onChange: (value) => update({ minP: value })
|
|
2619
|
+
}),
|
|
2620
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2621
|
+
label: t("seed"),
|
|
2622
|
+
type: "number",
|
|
2623
|
+
value: draft.seed,
|
|
2624
|
+
onChange: (value) => update({ seed: value })
|
|
2625
|
+
}),
|
|
2626
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2627
|
+
label: t("repeatPenalty"),
|
|
2628
|
+
type: "number",
|
|
2629
|
+
value: draft.repeatPenalty,
|
|
2630
|
+
onChange: (value) => update({ repeatPenalty: value })
|
|
2631
|
+
}),
|
|
2632
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2633
|
+
label: t("repeatLastN"),
|
|
2634
|
+
type: "number",
|
|
2635
|
+
value: draft.repeatLastN,
|
|
2636
|
+
onChange: (value) => update({ repeatLastN: value })
|
|
2637
|
+
}),
|
|
2638
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2639
|
+
label: t("numCtx"),
|
|
2640
|
+
type: "number",
|
|
2641
|
+
value: draft.numCtx,
|
|
2642
|
+
onChange: (value) => update({ numCtx: value })
|
|
2643
|
+
}),
|
|
2644
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2645
|
+
label: t("keepAlive"),
|
|
2646
|
+
hint: t("keepAliveHint"),
|
|
2647
|
+
value: draft.keepAlive,
|
|
2648
|
+
onChange: (value) => update({ keepAlive: value })
|
|
2649
|
+
}),
|
|
2650
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2651
|
+
label: t("stop"),
|
|
2652
|
+
hint: t("stopHint"),
|
|
2653
|
+
value: draft.stop,
|
|
2654
|
+
onChange: (value) => update({ stop: value })
|
|
2655
|
+
})
|
|
2656
|
+
]
|
|
2657
|
+
}),
|
|
2658
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
2659
|
+
className: "ocl-row",
|
|
2660
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
2661
|
+
type: "checkbox",
|
|
2662
|
+
checked: draft.autoRefresh,
|
|
2663
|
+
onChange: (event) => update({ autoRefresh: event.target.checked })
|
|
2664
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("autoRefresh") })]
|
|
2665
|
+
}),
|
|
2666
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
2667
|
+
label: t("refreshMinutes"),
|
|
2668
|
+
type: "number",
|
|
2669
|
+
value: draft.refreshMinutes,
|
|
2670
|
+
onChange: (value) => update({ refreshMinutes: value })
|
|
2671
|
+
}),
|
|
2672
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2673
|
+
className: "ocl-hint",
|
|
2674
|
+
children: t("autoRefreshHint")
|
|
2675
|
+
})
|
|
2676
|
+
]
|
|
2677
|
+
}),
|
|
2511
2678
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
2512
2679
|
className: "ocl-card",
|
|
2513
2680
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
package/lib/index.d.ts
CHANGED
|
@@ -58,6 +58,21 @@ interface Config {
|
|
|
58
58
|
contextWindowOverrides?: Record<string, number>;
|
|
59
59
|
/** Per-turn output cap; `0` omits `num_predict`/`max_tokens`. */
|
|
60
60
|
maxOutputTokens?: number;
|
|
61
|
+
/** Optional Ollama native generation defaults. */
|
|
62
|
+
temperature?: number;
|
|
63
|
+
topK?: number;
|
|
64
|
+
topP?: number;
|
|
65
|
+
minP?: number;
|
|
66
|
+
seed?: number;
|
|
67
|
+
repeatPenalty?: number;
|
|
68
|
+
repeatLastN?: number;
|
|
69
|
+
numCtx?: number;
|
|
70
|
+
keepAlive?: string;
|
|
71
|
+
stop?: string[];
|
|
72
|
+
/** Refresh the model catalog at mount and on an interval. */
|
|
73
|
+
autoRefresh?: boolean;
|
|
74
|
+
/** Catalog refresh interval in minutes; 0 = mount only. */
|
|
75
|
+
refreshMinutes?: number;
|
|
61
76
|
/** Extra accounts for rotation. */
|
|
62
77
|
accounts?: AccountConfig[];
|
|
63
78
|
/** Preferred account per model glob; others remain fallbacks. */
|
|
@@ -94,6 +109,18 @@ interface ResolvedConfig {
|
|
|
94
109
|
contextWindow?: number;
|
|
95
110
|
contextWindowOverrides: Readonly<Record<string, number>>;
|
|
96
111
|
maxOutputTokens?: number;
|
|
112
|
+
temperature?: number;
|
|
113
|
+
topK?: number;
|
|
114
|
+
topP?: number;
|
|
115
|
+
minP?: number;
|
|
116
|
+
seed?: number;
|
|
117
|
+
repeatPenalty?: number;
|
|
118
|
+
repeatLastN?: number;
|
|
119
|
+
numCtx?: number;
|
|
120
|
+
keepAlive?: string;
|
|
121
|
+
stop?: readonly string[];
|
|
122
|
+
autoRefresh: boolean;
|
|
123
|
+
refreshMinutes: number;
|
|
97
124
|
accounts: readonly AccountConfig[];
|
|
98
125
|
modelAccountRules: readonly ModelAccountRule[];
|
|
99
126
|
stickySession: boolean;
|
|
@@ -447,7 +474,6 @@ interface ModelProbe {
|
|
|
447
474
|
readonly tools: boolean;
|
|
448
475
|
readonly available: boolean;
|
|
449
476
|
}
|
|
450
|
-
/** Probe one local model via `/api/show`, caching successful answers for five minutes. */
|
|
451
477
|
declare function probeModel(config: ResolvedConfig, model: string, fetchImpl?: typeof fetch): Promise<ModelProbe | undefined>;
|
|
452
478
|
/** Clear all probe entries, or only entries for one endpoint. */
|
|
453
479
|
declare function clearModelProbeCache(baseURL?: string): void;
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
-
import { appendFile, mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { existsSync, readFileSync, statSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { appendFile, mkdir, readFile, readdir, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
6
6
|
import { CONTEXT_WINDOW_EXCEEDED_CODE, LlmAdapter, LlmError, ReasoningEffortId, ToolCallId, attributionHeaders, isContextWindowExceededError, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
@@ -50,7 +50,7 @@ const DEFAULT_API_BASE = "https://ollama.com";
|
|
|
50
50
|
const DEFAULT_OPENAI_BASE = "https://ollama.com/v1";
|
|
51
51
|
const DEFAULT_USAGE_URL = "https://ollama.com/api/usage";
|
|
52
52
|
const DEFAULT_BALANCE_URL = "https://ollama.com/api/balance";
|
|
53
|
-
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.
|
|
53
|
+
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.20";
|
|
54
54
|
const DEFAULT_CONTEXT_WINDOW = 131072;
|
|
55
55
|
const DEFAULT_MAX_TOKENS = 32768;
|
|
56
56
|
const DEFAULT_GENERATE_MAX_TOKENS = 131072;
|
|
@@ -76,6 +76,18 @@ const Config = z.object({
|
|
|
76
76
|
contextWindow: markVolatile(z.number().min(1).max(1e7).step(1)),
|
|
77
77
|
contextWindowOverrides: markVolatile(z.dict(z.number().min(1).max(1e7).step(1)).default({})),
|
|
78
78
|
maxOutputTokens: markVolatile(z.number().min(0).max(1e7).step(1)),
|
|
79
|
+
temperature: markVolatile(z.number().min(0).max(2)),
|
|
80
|
+
topK: markVolatile(z.number().min(1).max(1e6).step(1)),
|
|
81
|
+
topP: markVolatile(z.number().min(0).max(1)),
|
|
82
|
+
minP: markVolatile(z.number().min(0).max(1)),
|
|
83
|
+
seed: markVolatile(z.number().min(0).max(4294967295).step(1)),
|
|
84
|
+
repeatPenalty: markVolatile(z.number().min(0).max(2)),
|
|
85
|
+
repeatLastN: markVolatile(z.number().min(-1).max(1e6).step(1)),
|
|
86
|
+
numCtx: markVolatile(z.number().min(1).max(1e7).step(1)),
|
|
87
|
+
keepAlive: markVolatile(z.string()),
|
|
88
|
+
stop: markVolatile(z.array(z.string())),
|
|
89
|
+
autoRefresh: markVolatile(z.boolean().default(true)),
|
|
90
|
+
refreshMinutes: markVolatile(z.number().min(0).max(10080).step(1).default(1440)),
|
|
79
91
|
accounts: markVolatile(z.array(z.object({
|
|
80
92
|
label: z.string(),
|
|
81
93
|
apiKeyEnv: z.string().role("credential-ref"),
|
|
@@ -109,6 +121,18 @@ function unwrapVolatileConfig(config) {
|
|
|
109
121
|
function positiveInt(value, fallback) {
|
|
110
122
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : fallback;
|
|
111
123
|
}
|
|
124
|
+
function numberInRange(value, min, max) {
|
|
125
|
+
return typeof value === "number" && Number.isFinite(value) && value >= min && value <= max ? value : void 0;
|
|
126
|
+
}
|
|
127
|
+
function integerInRange(value, min, max) {
|
|
128
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) return void 0;
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
function nonEmptyStrings(value) {
|
|
132
|
+
if (!Array.isArray(value)) return void 0;
|
|
133
|
+
const out = value.filter((entry) => typeof entry === "string" && entry.trim() !== "");
|
|
134
|
+
return out.length === 0 ? void 0 : out;
|
|
135
|
+
}
|
|
112
136
|
function recordOf(value) {
|
|
113
137
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
114
138
|
}
|
|
@@ -158,6 +182,15 @@ function ruleList(value) {
|
|
|
158
182
|
function resolveConfig(config) {
|
|
159
183
|
const apiKey = typeof config.apiKey === "string" && config.apiKey.trim() !== "" ? config.apiKey.trim() : void 0;
|
|
160
184
|
const visibleModels = Array.isArray(config.visibleModels) ? config.visibleModels.filter((id) => typeof id === "string" && id !== "") : [];
|
|
185
|
+
const temperature = numberInRange(config.temperature, 0, 2);
|
|
186
|
+
const topK = integerInRange(config.topK, 1, 1e6);
|
|
187
|
+
const topP = numberInRange(config.topP, 0, 1);
|
|
188
|
+
const minP = numberInRange(config.minP, 0, 1);
|
|
189
|
+
const seed = integerInRange(config.seed, 0, 4294967295);
|
|
190
|
+
const repeatPenalty = numberInRange(config.repeatPenalty, 0, 2);
|
|
191
|
+
const repeatLastN = integerInRange(config.repeatLastN, -1, 1e6);
|
|
192
|
+
const numCtx = integerInRange(config.numCtx, 1, 1e7);
|
|
193
|
+
const stop = nonEmptyStrings(config.stop);
|
|
161
194
|
return {
|
|
162
195
|
apiKeyEnv: typeof config.apiKeyEnv === "string" ? config.apiKeyEnv.trim() : DEFAULT_API_KEY_ENV,
|
|
163
196
|
...apiKey === void 0 ? {} : { apiKey },
|
|
@@ -176,6 +209,18 @@ function resolveConfig(config) {
|
|
|
176
209
|
...typeof config.contextWindow === "number" && Number.isInteger(config.contextWindow) && config.contextWindow > 0 ? { contextWindow: config.contextWindow } : {},
|
|
177
210
|
contextWindowOverrides: numberRecord(config.contextWindowOverrides),
|
|
178
211
|
...typeof config.maxOutputTokens === "number" && Number.isInteger(config.maxOutputTokens) && config.maxOutputTokens >= 0 ? { maxOutputTokens: config.maxOutputTokens } : {},
|
|
212
|
+
...temperature === void 0 ? {} : { temperature },
|
|
213
|
+
...topK === void 0 ? {} : { topK },
|
|
214
|
+
...topP === void 0 ? {} : { topP },
|
|
215
|
+
...minP === void 0 ? {} : { minP },
|
|
216
|
+
...seed === void 0 ? {} : { seed },
|
|
217
|
+
...repeatPenalty === void 0 ? {} : { repeatPenalty },
|
|
218
|
+
...repeatLastN === void 0 ? {} : { repeatLastN },
|
|
219
|
+
...numCtx === void 0 ? {} : { numCtx },
|
|
220
|
+
...typeof config.keepAlive === "string" && config.keepAlive.trim() !== "" ? { keepAlive: config.keepAlive.trim() } : {},
|
|
221
|
+
...stop === void 0 ? {} : { stop },
|
|
222
|
+
autoRefresh: config.autoRefresh !== false,
|
|
223
|
+
refreshMinutes: typeof config.refreshMinutes === "number" && Number.isInteger(config.refreshMinutes) && config.refreshMinutes >= 0 && config.refreshMinutes <= 10080 ? config.refreshMinutes : 1440,
|
|
179
224
|
accounts: Array.isArray(config.accounts) ? config.accounts : [],
|
|
180
225
|
modelAccountRules: ruleList(config.modelAccountRules),
|
|
181
226
|
stickySession: config.stickySession !== false,
|
|
@@ -186,6 +231,74 @@ function resolveConfig(config) {
|
|
|
186
231
|
userAgent: typeof config.userAgent === "string" && config.userAgent !== "" ? config.userAgent : DEFAULT_USER_AGENT
|
|
187
232
|
};
|
|
188
233
|
}
|
|
234
|
+
// src/catalog-cache.ts
|
|
235
|
+
const VERSION = 1;
|
|
236
|
+
function catalogCachePath() {
|
|
237
|
+
const home = process.env.DSH_HOME?.trim() || join(homedir(), ".dsh");
|
|
238
|
+
return join(home, "cache", "dsh-ollama-cloud", "catalog.json");
|
|
239
|
+
}
|
|
240
|
+
function isMeta(value) {
|
|
241
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
242
|
+
const record = value;
|
|
243
|
+
return typeof record.id === "string" && typeof record.transport === "string" && typeof record.contextWindow === "number" && Array.isArray(record.input) && Array.isArray(record.reasoning);
|
|
244
|
+
}
|
|
245
|
+
function parse(value) {
|
|
246
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
247
|
+
const record = value;
|
|
248
|
+
if (record.version !== VERSION || typeof record.baseURL !== "string") return void 0;
|
|
249
|
+
if (typeof record.at !== "number" || !Number.isFinite(record.at)) return void 0;
|
|
250
|
+
if (!Array.isArray(record.ids) || !record.ids.every((id) => typeof id === "string" && id !== "")) return void 0;
|
|
251
|
+
if (typeof record.meta !== "object" || record.meta === null || Array.isArray(record.meta)) return void 0;
|
|
252
|
+
const meta = {};
|
|
253
|
+
for (const [id, entry] of Object.entries(record.meta)) if (isMeta(entry) && entry.id === id) meta[id] = entry;
|
|
254
|
+
return {
|
|
255
|
+
version: VERSION,
|
|
256
|
+
baseURL: record.baseURL,
|
|
257
|
+
at: record.at,
|
|
258
|
+
ids: record.ids,
|
|
259
|
+
meta
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async function loadCatalogSnapshot(baseURL) {
|
|
263
|
+
try {
|
|
264
|
+
const parsed = parse(JSON.parse(await readFile(catalogCachePath(), "utf8")));
|
|
265
|
+
if (parsed === void 0 || parsed.baseURL !== baseURL) return void 0;
|
|
266
|
+
return {
|
|
267
|
+
at: parsed.at,
|
|
268
|
+
ids: parsed.ids,
|
|
269
|
+
meta: parsed.meta
|
|
270
|
+
};
|
|
271
|
+
} catch {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function saveCatalogSnapshot(baseURL, ids, meta) {
|
|
276
|
+
const path = catalogCachePath();
|
|
277
|
+
const temp = `${path}.${process.pid}.${createHash("sha1").update(`${Date.now()}`).digest("hex").slice(0, 8)}.tmp`;
|
|
278
|
+
const payload = {
|
|
279
|
+
version: VERSION,
|
|
280
|
+
baseURL,
|
|
281
|
+
at: Date.now(),
|
|
282
|
+
ids,
|
|
283
|
+
meta
|
|
284
|
+
};
|
|
285
|
+
try {
|
|
286
|
+
await mkdir(dirname(path), { recursive: true });
|
|
287
|
+
await writeFile(temp, `${JSON.stringify(payload)}\n`, "utf8");
|
|
288
|
+
await rename(temp, path);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
bestEffortFailed("catalog cache write failed", error);
|
|
291
|
+
try {
|
|
292
|
+
await unlink(temp);
|
|
293
|
+
} catch {}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** Remove the persistent snapshot together with the in-memory cache. */
|
|
297
|
+
function clearCatalogSnapshot() {
|
|
298
|
+
try {
|
|
299
|
+
unlinkSync(catalogCachePath());
|
|
300
|
+
} catch {}
|
|
301
|
+
}
|
|
189
302
|
// src/models.generated.ts
|
|
190
303
|
const GENERATED_MODELS = {
|
|
191
304
|
"beam": {
|
|
@@ -742,11 +855,14 @@ function probeOf(body) {
|
|
|
742
855
|
};
|
|
743
856
|
}
|
|
744
857
|
/** Probe one local model via `/api/show`, caching successful answers for five minutes. */
|
|
745
|
-
async function
|
|
746
|
-
if (!isLocalEndpoint(config)) return
|
|
858
|
+
async function probeModelOutcome(config, model, fetchImpl = fetch) {
|
|
859
|
+
if (!isLocalEndpoint(config)) return { missing: false };
|
|
747
860
|
const key = keyOf(config, model);
|
|
748
861
|
const hit = cache$2.get(key);
|
|
749
|
-
if (hit !== void 0 && Date.now() - hit.at < PROBE_TTL_MS) return
|
|
862
|
+
if (hit !== void 0 && Date.now() - hit.at < PROBE_TTL_MS) return {
|
|
863
|
+
probe: hit.value,
|
|
864
|
+
missing: false
|
|
865
|
+
};
|
|
750
866
|
try {
|
|
751
867
|
const response = await fetchImpl(`${rootFor(config)}/api/show`, {
|
|
752
868
|
method: "POST",
|
|
@@ -758,18 +874,25 @@ async function probeModel(config, model, fetchImpl = fetch) {
|
|
|
758
874
|
body: JSON.stringify({ model }),
|
|
759
875
|
signal: AbortSignal.timeout(1e4)
|
|
760
876
|
});
|
|
761
|
-
if (
|
|
877
|
+
if (response.status === 404 || response.status === 410) return { missing: true };
|
|
878
|
+
if (!response.ok) return { missing: false };
|
|
762
879
|
const value = probeOf(await response.json());
|
|
763
|
-
if (value === void 0) return
|
|
880
|
+
if (value === void 0) return { missing: false };
|
|
764
881
|
cache$2.set(key, {
|
|
765
882
|
at: Date.now(),
|
|
766
883
|
value
|
|
767
884
|
});
|
|
768
|
-
return
|
|
885
|
+
return {
|
|
886
|
+
probe: value,
|
|
887
|
+
missing: false
|
|
888
|
+
};
|
|
769
889
|
} catch {
|
|
770
|
-
return;
|
|
890
|
+
return { missing: false };
|
|
771
891
|
}
|
|
772
892
|
}
|
|
893
|
+
async function probeModel(config, model, fetchImpl = fetch) {
|
|
894
|
+
return (await probeModelOutcome(config, model, fetchImpl)).probe;
|
|
895
|
+
}
|
|
773
896
|
/** Clear all probe entries, or only entries for one endpoint. */
|
|
774
897
|
function clearModelProbeCache(baseURL) {
|
|
775
898
|
if (baseURL === void 0) {
|
|
@@ -863,12 +986,81 @@ function formatUsd(value) {
|
|
|
863
986
|
if (Math.abs(value) >= .01) return `$${value.toFixed(3)}`;
|
|
864
987
|
return `$${value.toFixed(4)}`;
|
|
865
988
|
}
|
|
989
|
+
// src/reasoning.ts
|
|
990
|
+
const EFFORT_ORDER = [
|
|
991
|
+
"off",
|
|
992
|
+
"minimal",
|
|
993
|
+
"low",
|
|
994
|
+
"medium",
|
|
995
|
+
"high",
|
|
996
|
+
"xhigh",
|
|
997
|
+
"max"
|
|
998
|
+
];
|
|
999
|
+
const FAMILY_DEFAULTS = [
|
|
1000
|
+
{
|
|
1001
|
+
prefix: "glm-5.3",
|
|
1002
|
+
effort: "max"
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
prefix: "glm-5.2",
|
|
1006
|
+
effort: "max"
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
prefix: "kimi-k3",
|
|
1010
|
+
effort: "max"
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
prefix: "kimi-k2",
|
|
1014
|
+
effort: "high"
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
prefix: "deepseek-v4",
|
|
1018
|
+
effort: "high"
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
prefix: "minimax-m3",
|
|
1022
|
+
effort: "high"
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
prefix: "gpt-oss",
|
|
1026
|
+
effort: "medium"
|
|
1027
|
+
},
|
|
1028
|
+
{
|
|
1029
|
+
prefix: "nemotron",
|
|
1030
|
+
effort: "low"
|
|
1031
|
+
}
|
|
1032
|
+
];
|
|
1033
|
+
function normalizeEfforts(levels) {
|
|
1034
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1035
|
+
for (const level of levels) {
|
|
1036
|
+
const clean = level.trim().toLowerCase();
|
|
1037
|
+
if (clean !== "") seen.add(clean);
|
|
1038
|
+
}
|
|
1039
|
+
const ordered = EFFORT_ORDER.filter((level) => seen.has(level));
|
|
1040
|
+
const extra = [...seen].filter((level) => !EFFORT_ORDER.includes(level)).sort();
|
|
1041
|
+
return [...ordered, ...extra];
|
|
1042
|
+
}
|
|
1043
|
+
function defaultEffortFor(id, levels) {
|
|
1044
|
+
const family = id.split(":")[0]?.toLowerCase() ?? "";
|
|
1045
|
+
for (const entry of FAMILY_DEFAULTS) if (family.startsWith(entry.prefix) && levels.includes(entry.effort)) return entry.effort;
|
|
1046
|
+
}
|
|
1047
|
+
/** Normalize boolean switches and level ladders, then apply the known family default. */
|
|
1048
|
+
function normalizeThinking(id, levels, toggle, fallback) {
|
|
1049
|
+
const reasoning = normalizeEfforts(levels);
|
|
1050
|
+
if (reasoning.length === 0 && toggle) reasoning.push("off", "high");
|
|
1051
|
+
const candidate = fallback !== void 0 && reasoning.includes(fallback) ? fallback : defaultEffortFor(id, reasoning) ?? (toggle && reasoning.includes("high") ? "high" : void 0);
|
|
1052
|
+
return {
|
|
1053
|
+
reasoning,
|
|
1054
|
+
...candidate === void 0 ? {} : { defaultReasoning: candidate }
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
866
1057
|
// src/catalog.ts
|
|
867
1058
|
const CATALOG_TTL_MS = 6e5;
|
|
868
1059
|
const CATALOG_TIMEOUT_MS = 15e3;
|
|
869
1060
|
const liveMeta = /* @__PURE__ */ new Map();
|
|
870
1061
|
const cache$1 = /* @__PURE__ */ new Map();
|
|
871
1062
|
const inflight = /* @__PURE__ */ new Map();
|
|
1063
|
+
const diskLoaded = /* @__PURE__ */ new Set();
|
|
872
1064
|
let generation = 0;
|
|
873
1065
|
function liveKey(base, id) {
|
|
874
1066
|
return `${base}|${id}`;
|
|
@@ -926,6 +1118,7 @@ function metaFromLive(entry, caps) {
|
|
|
926
1118
|
const toggle = (caps?.has("thinking") === true || levels.length > 0) && levels.length === 0;
|
|
927
1119
|
const modalities = strings(entry.input_modalities);
|
|
928
1120
|
const image = modalities.includes("image") || base?.input.includes("image") === true && modalities.length === 0;
|
|
1121
|
+
const normalized = normalizeThinking(id, levels.length > 0 ? levels : base?.reasoning ?? [], toggle || base?.reasoningToggle === true, str$1(entry.default_reasoning_level) ?? base?.defaultReasoning);
|
|
929
1122
|
return {
|
|
930
1123
|
id,
|
|
931
1124
|
name: str$1(entry.display_name) ?? id,
|
|
@@ -933,12 +1126,12 @@ function metaFromLive(entry, caps) {
|
|
|
933
1126
|
contextWindow: num$1(entry.context_window) ?? num$1(entry.max_context_window) ?? base?.contextWindow ?? 131072,
|
|
934
1127
|
maxTokens: base?.maxTokens ?? 32768,
|
|
935
1128
|
input: image ? ["text", "image"] : ["text"],
|
|
936
|
-
reasoning:
|
|
937
|
-
reasoningToggle: toggle || base?.reasoningToggle === true
|
|
1129
|
+
reasoning: normalized.reasoning,
|
|
1130
|
+
reasoningToggle: toggle || base?.reasoningToggle === true,
|
|
938
1131
|
tools: caps?.has("tools") === true || base?.tools === true || base === void 0,
|
|
939
1132
|
free: base?.free === true,
|
|
940
1133
|
available: entry.supported_in_api !== false && entry.visibility !== "hide",
|
|
941
|
-
...
|
|
1134
|
+
...normalized.defaultReasoning === void 0 ? {} : { defaultReasoning: normalized.defaultReasoning },
|
|
942
1135
|
cost: base?.cost ?? {
|
|
943
1136
|
input: 0,
|
|
944
1137
|
output: 0,
|
|
@@ -949,6 +1142,7 @@ function metaFromLive(entry, caps) {
|
|
|
949
1142
|
function metaFromProbe(id, probe) {
|
|
950
1143
|
if (probe === void 0) return void 0;
|
|
951
1144
|
const base = GENERATED_MODELS[id];
|
|
1145
|
+
const normalized = normalizeThinking(id, probe.reasoning.length > 0 ? probe.reasoning : base?.reasoning ?? [], probe.reasoningToggle || base?.reasoningToggle === true, base?.defaultReasoning);
|
|
952
1146
|
return {
|
|
953
1147
|
id,
|
|
954
1148
|
name: base?.name ?? id,
|
|
@@ -956,12 +1150,12 @@ function metaFromProbe(id, probe) {
|
|
|
956
1150
|
contextWindow: probe.contextWindow ?? base?.contextWindow ?? 131072,
|
|
957
1151
|
maxTokens: base?.maxTokens ?? 32768,
|
|
958
1152
|
input: [...probe.input],
|
|
959
|
-
reasoning:
|
|
1153
|
+
reasoning: normalized.reasoning,
|
|
960
1154
|
reasoningToggle: probe.reasoningToggle || base?.reasoningToggle === true,
|
|
961
1155
|
tools: probe.tools || base?.tools === true,
|
|
962
1156
|
free: base?.free === true,
|
|
963
1157
|
available: probe.available,
|
|
964
|
-
...
|
|
1158
|
+
...normalized.defaultReasoning === void 0 ? {} : { defaultReasoning: normalized.defaultReasoning },
|
|
965
1159
|
cost: base?.cost ?? {
|
|
966
1160
|
input: 0,
|
|
967
1161
|
output: 0,
|
|
@@ -970,11 +1164,27 @@ function metaFromProbe(id, probe) {
|
|
|
970
1164
|
};
|
|
971
1165
|
}
|
|
972
1166
|
async function adoptProbes(config, ids, base, fetchImpl) {
|
|
973
|
-
const
|
|
1167
|
+
const outcomes = await Promise.all(ids.slice(0, 64).map(async (id) => ({
|
|
974
1168
|
id,
|
|
975
|
-
|
|
1169
|
+
outcome: await probeModelOutcome(config, id, fetchImpl)
|
|
976
1170
|
})));
|
|
977
|
-
|
|
1171
|
+
const kept = [];
|
|
1172
|
+
for (const { id, outcome } of outcomes) {
|
|
1173
|
+
if (outcome.missing) continue;
|
|
1174
|
+
kept.push(id);
|
|
1175
|
+
const meta = metaFromProbe(id, outcome.probe);
|
|
1176
|
+
if (meta !== void 0) liveMeta.set(liveKey(base, id), meta);
|
|
1177
|
+
}
|
|
1178
|
+
return kept;
|
|
1179
|
+
}
|
|
1180
|
+
function metaForBase(base) {
|
|
1181
|
+
const out = {};
|
|
1182
|
+
const prefix = `${base}|`;
|
|
1183
|
+
for (const [key, meta] of liveMeta) if (key.startsWith(prefix)) out[key.slice(prefix.length)] = meta;
|
|
1184
|
+
return out;
|
|
1185
|
+
}
|
|
1186
|
+
async function persist(base, ids) {
|
|
1187
|
+
await saveCatalogSnapshot(base, ids, metaForBase(base));
|
|
978
1188
|
}
|
|
979
1189
|
/** Replace the in-memory live metadata for one API base with one successful response. */
|
|
980
1190
|
function adoptLive(models, tags, base) {
|
|
@@ -1017,9 +1227,20 @@ async function fetchJson(url, config, fetchImpl, signal) {
|
|
|
1017
1227
|
*/
|
|
1018
1228
|
async function refreshCatalog(config, fetchImpl = fetch, force = false) {
|
|
1019
1229
|
const key = config.apiBase;
|
|
1230
|
+
if (!diskLoaded.has(key)) {
|
|
1231
|
+
diskLoaded.add(key);
|
|
1232
|
+
const snapshot = await loadCatalogSnapshot(key);
|
|
1233
|
+
if (snapshot !== void 0 && !cache$1.has(key)) {
|
|
1234
|
+
cache$1.set(key, {
|
|
1235
|
+
at: snapshot.at,
|
|
1236
|
+
ids: snapshot.ids
|
|
1237
|
+
});
|
|
1238
|
+
for (const [id, meta] of Object.entries(snapshot.meta)) liveMeta.set(liveKey(key, id), meta);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1020
1241
|
const cached = cache$1.get(key);
|
|
1021
1242
|
if (!force && cached !== void 0) {
|
|
1022
|
-
if (Date.now() - cached.at >= CATALOG_TTL_MS) refreshInBackground(config, fetchImpl, key);
|
|
1243
|
+
if (config.autoRefresh && Date.now() - cached.at >= CATALOG_TTL_MS) refreshInBackground(config, fetchImpl, key);
|
|
1023
1244
|
return cached.ids;
|
|
1024
1245
|
}
|
|
1025
1246
|
return refreshNow(config, fetchImpl, key, cached !== void 0, generation);
|
|
@@ -1039,19 +1260,21 @@ async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
|
|
|
1039
1260
|
at: Date.now(),
|
|
1040
1261
|
ids
|
|
1041
1262
|
});
|
|
1263
|
+
await persist(key, ids);
|
|
1042
1264
|
return ids;
|
|
1043
1265
|
}
|
|
1044
1266
|
}
|
|
1045
1267
|
const fromData = Array.isArray(payload.data) ? payload.data.map((entry) => str$1(entry.id)).filter((id) => id !== void 0) : [];
|
|
1046
1268
|
const fromTags = ((tagsResult.status === "fulfilled" ? tagsResult.value : void 0)?.models ?? []).map((entry) => str$1(entry.name) ?? str$1(entry.model)).filter((id) => id !== void 0);
|
|
1047
|
-
const
|
|
1048
|
-
if (
|
|
1269
|
+
const discovered = fromData.length > 0 ? fromData : fromTags;
|
|
1270
|
+
if (discovered.length > 0) {
|
|
1049
1271
|
for (const liveKey of liveMeta.keys()) if (liveKey.startsWith(`${key}|`)) liveMeta.delete(liveKey);
|
|
1050
|
-
|
|
1272
|
+
const ids = isLocalEndpoint(config) ? await adoptProbes(config, discovered, key, fetchImpl) : discovered;
|
|
1051
1273
|
cache$1.set(key, {
|
|
1052
1274
|
at: Date.now(),
|
|
1053
1275
|
ids
|
|
1054
1276
|
});
|
|
1277
|
+
await persist(key, ids);
|
|
1055
1278
|
return ids;
|
|
1056
1279
|
}
|
|
1057
1280
|
}
|
|
@@ -1078,7 +1301,9 @@ function clearCatalogCache() {
|
|
|
1078
1301
|
cache$1.clear();
|
|
1079
1302
|
inflight.clear();
|
|
1080
1303
|
liveMeta.clear();
|
|
1304
|
+
diskLoaded.clear();
|
|
1081
1305
|
clearModelProbeCache();
|
|
1306
|
+
clearCatalogSnapshot();
|
|
1082
1307
|
}
|
|
1083
1308
|
function baseMeta(id, base) {
|
|
1084
1309
|
const meta = liveMeta.get(liveKey(base, id)) ?? GENERATED_MODELS[id];
|
|
@@ -1516,10 +1741,19 @@ function buildNativeBody(options, model, config, images) {
|
|
|
1516
1741
|
const tools = buildTools(options.tools);
|
|
1517
1742
|
const maxTokens = options.maxTokens ?? effectiveMaxTokens(model, config);
|
|
1518
1743
|
const think = nativeThink(options.reasoningEffort === void 0 ? void 0 : String(options.reasoningEffort), model);
|
|
1744
|
+
const temperature = options.temperature ?? config.temperature;
|
|
1745
|
+
const stop = options.stop ?? config.stop;
|
|
1519
1746
|
const nativeOptions = {
|
|
1520
|
-
...
|
|
1747
|
+
...temperature === void 0 ? {} : { temperature },
|
|
1748
|
+
...config.topK === void 0 ? {} : { top_k: config.topK },
|
|
1749
|
+
...config.topP === void 0 ? {} : { top_p: config.topP },
|
|
1750
|
+
...config.minP === void 0 ? {} : { min_p: config.minP },
|
|
1751
|
+
...config.seed === void 0 ? {} : { seed: config.seed },
|
|
1752
|
+
...config.repeatPenalty === void 0 ? {} : { repeat_penalty: config.repeatPenalty },
|
|
1753
|
+
...config.repeatLastN === void 0 ? {} : { repeat_last_n: config.repeatLastN },
|
|
1754
|
+
...config.numCtx === void 0 ? {} : { num_ctx: config.numCtx },
|
|
1521
1755
|
...maxTokens === void 0 || maxTokens <= 0 ? {} : { num_predict: maxTokens },
|
|
1522
|
-
...
|
|
1756
|
+
...stop === void 0 || stop.length === 0 ? {} : { stop }
|
|
1523
1757
|
};
|
|
1524
1758
|
return {
|
|
1525
1759
|
model: options.model,
|
|
@@ -1527,6 +1761,7 @@ function buildNativeBody(options, model, config, images) {
|
|
|
1527
1761
|
stream: true,
|
|
1528
1762
|
...tools === void 0 ? {} : { tools },
|
|
1529
1763
|
...think === void 0 ? {} : { think },
|
|
1764
|
+
...config.keepAlive === void 0 ? {} : { keep_alive: config.keepAlive },
|
|
1530
1765
|
...Object.keys(nativeOptions).length === 0 ? {} : { options: nativeOptions }
|
|
1531
1766
|
};
|
|
1532
1767
|
}
|
|
@@ -1617,6 +1852,8 @@ function buildChatBody(options, model, config, images) {
|
|
|
1617
1852
|
const maxTokens = options.maxTokens ?? effectiveMaxTokens(model, config);
|
|
1618
1853
|
const effort = options.reasoningEffort === void 0 ? void 0 : String(options.reasoningEffort);
|
|
1619
1854
|
const reasoning = effort === void 0 || effort === "" ? void 0 : effort === "off" ? "none" : effort;
|
|
1855
|
+
const temperature = options.temperature ?? config.temperature;
|
|
1856
|
+
const stop = options.stop ?? config.stop;
|
|
1620
1857
|
return {
|
|
1621
1858
|
model: options.model,
|
|
1622
1859
|
messages: buildChatMessages(options, images),
|
|
@@ -1626,10 +1863,12 @@ function buildChatBody(options, model, config, images) {
|
|
|
1626
1863
|
tools,
|
|
1627
1864
|
tool_choice: "auto"
|
|
1628
1865
|
},
|
|
1629
|
-
...
|
|
1866
|
+
...temperature === void 0 ? {} : { temperature },
|
|
1867
|
+
...config.topP === void 0 ? {} : { top_p: config.topP },
|
|
1868
|
+
...config.seed === void 0 ? {} : { seed: config.seed },
|
|
1630
1869
|
...maxTokens === void 0 || maxTokens <= 0 ? {} : { max_tokens: maxTokens },
|
|
1631
1870
|
...reasoning === void 0 ? {} : { reasoning_effort: reasoning },
|
|
1632
|
-
...
|
|
1871
|
+
...stop === void 0 || stop.length === 0 ? {} : { stop }
|
|
1633
1872
|
};
|
|
1634
1873
|
}
|
|
1635
1874
|
// src/provider-ids.ts
|
|
@@ -3823,6 +4062,18 @@ function publicConfig(config) {
|
|
|
3823
4062
|
contextWindow: config.contextWindow ?? null,
|
|
3824
4063
|
contextWindowOverrides: config.contextWindowOverrides,
|
|
3825
4064
|
maxOutputTokens: config.maxOutputTokens ?? null,
|
|
4065
|
+
temperature: config.temperature ?? null,
|
|
4066
|
+
topK: config.topK ?? null,
|
|
4067
|
+
topP: config.topP ?? null,
|
|
4068
|
+
minP: config.minP ?? null,
|
|
4069
|
+
seed: config.seed ?? null,
|
|
4070
|
+
repeatPenalty: config.repeatPenalty ?? null,
|
|
4071
|
+
repeatLastN: config.repeatLastN ?? null,
|
|
4072
|
+
numCtx: config.numCtx ?? null,
|
|
4073
|
+
keepAlive: config.keepAlive ?? "",
|
|
4074
|
+
stop: config.stop ?? [],
|
|
4075
|
+
autoRefresh: config.autoRefresh,
|
|
4076
|
+
refreshMinutes: config.refreshMinutes,
|
|
3826
4077
|
accounts: config.accounts.map((account) => ({
|
|
3827
4078
|
label: typeof account.label === "string" ? account.label : "",
|
|
3828
4079
|
apiKeyEnv: typeof account.apiKeyEnv === "string" ? account.apiKeyEnv : ""
|
|
@@ -4151,6 +4402,18 @@ function configOps(patch) {
|
|
|
4151
4402
|
if ("contextWindow" in patch) set("contextWindow", patch.contextWindow);
|
|
4152
4403
|
if ("contextWindowOverrides" in patch) set("contextWindowOverrides", cleanNumberRecord(patch.contextWindowOverrides));
|
|
4153
4404
|
if ("maxOutputTokens" in patch) set("maxOutputTokens", patch.maxOutputTokens);
|
|
4405
|
+
if ("temperature" in patch) set("temperature", patch.temperature);
|
|
4406
|
+
if ("topK" in patch) set("topK", patch.topK);
|
|
4407
|
+
if ("topP" in patch) set("topP", patch.topP);
|
|
4408
|
+
if ("minP" in patch) set("minP", patch.minP);
|
|
4409
|
+
if ("seed" in patch) set("seed", patch.seed);
|
|
4410
|
+
if ("repeatPenalty" in patch) set("repeatPenalty", patch.repeatPenalty);
|
|
4411
|
+
if ("repeatLastN" in patch) set("repeatLastN", patch.repeatLastN);
|
|
4412
|
+
if ("numCtx" in patch) set("numCtx", patch.numCtx);
|
|
4413
|
+
if ("keepAlive" in patch) set("keepAlive", patch.keepAlive);
|
|
4414
|
+
if ("stop" in patch) set("stop", cleanStringArray(patch.stop));
|
|
4415
|
+
if ("autoRefresh" in patch) set("autoRefresh", patch.autoRefresh === true);
|
|
4416
|
+
if ("refreshMinutes" in patch) set("refreshMinutes", patch.refreshMinutes);
|
|
4154
4417
|
if ("accounts" in patch) {
|
|
4155
4418
|
const accounts = cleanAccounts(patch.accounts);
|
|
4156
4419
|
for (const account of accounts) if (account.apiKeyEnv !== "" && !isCredentialRef(account.apiKeyEnv)) throw new Error("invalid credential reference");
|
|
@@ -5173,6 +5436,25 @@ function apply(ctx, config) {
|
|
|
5173
5436
|
ctx.effect(() => () => {
|
|
5174
5437
|
flushRequestLog();
|
|
5175
5438
|
}, "dsh-ollama-cloud-provider: flush request log");
|
|
5439
|
+
ctx.effect(() => {
|
|
5440
|
+
const initial = current();
|
|
5441
|
+
const warm = initial.autoRefresh ? setTimeout(() => {
|
|
5442
|
+
const config = current();
|
|
5443
|
+
if (config.autoRefresh) refreshCatalog(config, fetch).catch(() => {});
|
|
5444
|
+
}, 1e3) : void 0;
|
|
5445
|
+
warm?.unref?.();
|
|
5446
|
+
const intervalMs = Math.max(1, initial.refreshMinutes) * 6e4;
|
|
5447
|
+
const timer = initial.autoRefresh && initial.refreshMinutes > 0 ? setInterval(() => {
|
|
5448
|
+
const config = current();
|
|
5449
|
+
if (!config.autoRefresh || config.refreshMinutes <= 0) return;
|
|
5450
|
+
refreshCatalog(config, fetch, true).catch(() => {});
|
|
5451
|
+
}, intervalMs) : void 0;
|
|
5452
|
+
timer?.unref?.();
|
|
5453
|
+
return () => {
|
|
5454
|
+
if (warm !== void 0) clearTimeout(warm);
|
|
5455
|
+
if (timer !== void 0) clearInterval(timer);
|
|
5456
|
+
};
|
|
5457
|
+
}, "dsh-ollama-cloud-provider: catalog refresh scheduler");
|
|
5176
5458
|
ctx.inject(["settings"], (settingsCtx) => {
|
|
5177
5459
|
settingsCtx.settings.configure({ auto: false }, ctx.fiber);
|
|
5178
5460
|
});
|
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.20",
|
|
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",
|
|
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",
|
|
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"
|