@goodandready/dsh-ollama-cloud-provider 0.1.19 → 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 +12 -0
- package/README.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +28 -0
- package/lib/index.d.ts +6 -1
- package/lib/index.js +154 -17
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
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
|
+
|
|
3
15
|
## 0.1.19 — 2026-11-05
|
|
4
16
|
|
|
5
17
|
- Added configurable native generation defaults: temperature, top_k, top_p,
|
package/README.md
CHANGED
|
@@ -137,17 +137,17 @@ npm pack
|
|
|
137
137
|
Install the published package:
|
|
138
138
|
|
|
139
139
|
```bash
|
|
140
|
-
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
140
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.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
|
@@ -136,6 +136,9 @@ window.__ModuleLoader__.load({
|
|
|
136
136
|
keepAliveHint: "Ollama keep_alive, for example 5m or -1.",
|
|
137
137
|
stop: "Stop sequences",
|
|
138
138
|
stopHint: "Comma-separated; sent as the native stop list.",
|
|
139
|
+
autoRefresh: "Refresh model catalog automatically",
|
|
140
|
+
refreshMinutes: "Refresh interval (minutes)",
|
|
141
|
+
autoRefreshHint: "Mount refresh plus this interval; 0 keeps the mount refresh only.",
|
|
139
142
|
sidebar: "Sidebar",
|
|
140
143
|
serviceStatus: "Service status",
|
|
141
144
|
serviceStatusHint: "Checks the public Ollama Cloud tag endpoint without using your key or quota.",
|
|
@@ -323,6 +326,9 @@ window.__ModuleLoader__.load({
|
|
|
323
326
|
keepAliveHint: "Ollama keep_alive,例如 5m 或 -1。",
|
|
324
327
|
stop: "Stop sequences",
|
|
325
328
|
stopHint: "逗号分隔,作为原生 stop 列表发送。",
|
|
329
|
+
autoRefresh: "自动刷新模型目录",
|
|
330
|
+
refreshMinutes: "刷新间隔(分钟)",
|
|
331
|
+
autoRefreshHint: "启动时刷新,并按此间隔刷新;0 仅启动时刷新。",
|
|
326
332
|
sidebar: "侧边栏",
|
|
327
333
|
serviceStatus: "服务状态",
|
|
328
334
|
serviceStatusHint: "检查 Ollama Cloud 公共 tag 端点,不使用密钥或额度。",
|
|
@@ -1540,6 +1546,8 @@ window.__ModuleLoader__.load({
|
|
|
1540
1546
|
numCtx: textOf(state.config.numCtx),
|
|
1541
1547
|
keepAlive: state.config.keepAlive ?? "",
|
|
1542
1548
|
stop: (state.config.stop ?? []).join(", "),
|
|
1549
|
+
autoRefresh: state.config.autoRefresh !== false,
|
|
1550
|
+
refreshMinutes: String(state.config.refreshMinutes ?? 1440),
|
|
1543
1551
|
showSidebarQuota: state.config.showSidebarQuota,
|
|
1544
1552
|
planLabel: state.config.planLabel,
|
|
1545
1553
|
activeAccount: state.config.activeAccount,
|
|
@@ -1591,6 +1599,8 @@ window.__ModuleLoader__.load({
|
|
|
1591
1599
|
numCtx: boundedNumber(draft.numCtx, 1, 1e7, true),
|
|
1592
1600
|
keepAlive: draft.keepAlive.trim(),
|
|
1593
1601
|
stop: stopList(draft.stop),
|
|
1602
|
+
autoRefresh: draft.autoRefresh,
|
|
1603
|
+
refreshMinutes: boundedNumber(draft.refreshMinutes, 0, 10080, true) ?? 1440,
|
|
1594
1604
|
showSidebarQuota: draft.showSidebarQuota,
|
|
1595
1605
|
planLabel: draft.planLabel.trim(),
|
|
1596
1606
|
activeAccount: draft.activeAccount.trim(),
|
|
@@ -2644,6 +2654,24 @@ window.__ModuleLoader__.load({
|
|
|
2644
2654
|
onChange: (value) => update({ stop: value })
|
|
2645
2655
|
})
|
|
2646
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")
|
|
2647
2675
|
})
|
|
2648
2676
|
]
|
|
2649
2677
|
}),
|
package/lib/index.d.ts
CHANGED
|
@@ -69,6 +69,10 @@ interface Config {
|
|
|
69
69
|
numCtx?: number;
|
|
70
70
|
keepAlive?: string;
|
|
71
71
|
stop?: string[];
|
|
72
|
+
/** Refresh the model catalog at mount and on an interval. */
|
|
73
|
+
autoRefresh?: boolean;
|
|
74
|
+
/** Catalog refresh interval in minutes; 0 = mount only. */
|
|
75
|
+
refreshMinutes?: number;
|
|
72
76
|
/** Extra accounts for rotation. */
|
|
73
77
|
accounts?: AccountConfig[];
|
|
74
78
|
/** Preferred account per model glob; others remain fallbacks. */
|
|
@@ -115,6 +119,8 @@ interface ResolvedConfig {
|
|
|
115
119
|
numCtx?: number;
|
|
116
120
|
keepAlive?: string;
|
|
117
121
|
stop?: readonly string[];
|
|
122
|
+
autoRefresh: boolean;
|
|
123
|
+
refreshMinutes: number;
|
|
118
124
|
accounts: readonly AccountConfig[];
|
|
119
125
|
modelAccountRules: readonly ModelAccountRule[];
|
|
120
126
|
stickySession: boolean;
|
|
@@ -468,7 +474,6 @@ interface ModelProbe {
|
|
|
468
474
|
readonly tools: boolean;
|
|
469
475
|
readonly available: boolean;
|
|
470
476
|
}
|
|
471
|
-
/** Probe one local model via `/api/show`, caching successful answers for five minutes. */
|
|
472
477
|
declare function probeModel(config: ResolvedConfig, model: string, fetchImpl?: typeof fetch): Promise<ModelProbe | undefined>;
|
|
473
478
|
/** Clear all probe entries, or only entries for one endpoint. */
|
|
474
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;
|
|
@@ -86,6 +86,8 @@ const Config = z.object({
|
|
|
86
86
|
numCtx: markVolatile(z.number().min(1).max(1e7).step(1)),
|
|
87
87
|
keepAlive: markVolatile(z.string()),
|
|
88
88
|
stop: markVolatile(z.array(z.string())),
|
|
89
|
+
autoRefresh: markVolatile(z.boolean().default(true)),
|
|
90
|
+
refreshMinutes: markVolatile(z.number().min(0).max(10080).step(1).default(1440)),
|
|
89
91
|
accounts: markVolatile(z.array(z.object({
|
|
90
92
|
label: z.string(),
|
|
91
93
|
apiKeyEnv: z.string().role("credential-ref"),
|
|
@@ -217,6 +219,8 @@ function resolveConfig(config) {
|
|
|
217
219
|
...numCtx === void 0 ? {} : { numCtx },
|
|
218
220
|
...typeof config.keepAlive === "string" && config.keepAlive.trim() !== "" ? { keepAlive: config.keepAlive.trim() } : {},
|
|
219
221
|
...stop === void 0 ? {} : { stop },
|
|
222
|
+
autoRefresh: config.autoRefresh !== false,
|
|
223
|
+
refreshMinutes: typeof config.refreshMinutes === "number" && Number.isInteger(config.refreshMinutes) && config.refreshMinutes >= 0 && config.refreshMinutes <= 10080 ? config.refreshMinutes : 1440,
|
|
220
224
|
accounts: Array.isArray(config.accounts) ? config.accounts : [],
|
|
221
225
|
modelAccountRules: ruleList(config.modelAccountRules),
|
|
222
226
|
stickySession: config.stickySession !== false,
|
|
@@ -227,6 +231,74 @@ function resolveConfig(config) {
|
|
|
227
231
|
userAgent: typeof config.userAgent === "string" && config.userAgent !== "" ? config.userAgent : DEFAULT_USER_AGENT
|
|
228
232
|
};
|
|
229
233
|
}
|
|
234
|
+
// src/catalog-cache.ts
|
|
235
|
+
const VERSION = 1;
|
|
236
|
+
function catalogCachePath() {
|
|
237
|
+
const home = process.env.DSH_HOME?.trim() || join(homedir(), ".dsh");
|
|
238
|
+
return join(home, "cache", "dsh-ollama-cloud", "catalog.json");
|
|
239
|
+
}
|
|
240
|
+
function isMeta(value) {
|
|
241
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
242
|
+
const record = value;
|
|
243
|
+
return typeof record.id === "string" && typeof record.transport === "string" && typeof record.contextWindow === "number" && Array.isArray(record.input) && Array.isArray(record.reasoning);
|
|
244
|
+
}
|
|
245
|
+
function parse(value) {
|
|
246
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
247
|
+
const record = value;
|
|
248
|
+
if (record.version !== VERSION || typeof record.baseURL !== "string") return void 0;
|
|
249
|
+
if (typeof record.at !== "number" || !Number.isFinite(record.at)) return void 0;
|
|
250
|
+
if (!Array.isArray(record.ids) || !record.ids.every((id) => typeof id === "string" && id !== "")) return void 0;
|
|
251
|
+
if (typeof record.meta !== "object" || record.meta === null || Array.isArray(record.meta)) return void 0;
|
|
252
|
+
const meta = {};
|
|
253
|
+
for (const [id, entry] of Object.entries(record.meta)) if (isMeta(entry) && entry.id === id) meta[id] = entry;
|
|
254
|
+
return {
|
|
255
|
+
version: VERSION,
|
|
256
|
+
baseURL: record.baseURL,
|
|
257
|
+
at: record.at,
|
|
258
|
+
ids: record.ids,
|
|
259
|
+
meta
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async function loadCatalogSnapshot(baseURL) {
|
|
263
|
+
try {
|
|
264
|
+
const parsed = parse(JSON.parse(await readFile(catalogCachePath(), "utf8")));
|
|
265
|
+
if (parsed === void 0 || parsed.baseURL !== baseURL) return void 0;
|
|
266
|
+
return {
|
|
267
|
+
at: parsed.at,
|
|
268
|
+
ids: parsed.ids,
|
|
269
|
+
meta: parsed.meta
|
|
270
|
+
};
|
|
271
|
+
} catch {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function saveCatalogSnapshot(baseURL, ids, meta) {
|
|
276
|
+
const path = catalogCachePath();
|
|
277
|
+
const temp = `${path}.${process.pid}.${createHash("sha1").update(`${Date.now()}`).digest("hex").slice(0, 8)}.tmp`;
|
|
278
|
+
const payload = {
|
|
279
|
+
version: VERSION,
|
|
280
|
+
baseURL,
|
|
281
|
+
at: Date.now(),
|
|
282
|
+
ids,
|
|
283
|
+
meta
|
|
284
|
+
};
|
|
285
|
+
try {
|
|
286
|
+
await mkdir(dirname(path), { recursive: true });
|
|
287
|
+
await writeFile(temp, `${JSON.stringify(payload)}\n`, "utf8");
|
|
288
|
+
await rename(temp, path);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
bestEffortFailed("catalog cache write failed", error);
|
|
291
|
+
try {
|
|
292
|
+
await unlink(temp);
|
|
293
|
+
} catch {}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** Remove the persistent snapshot together with the in-memory cache. */
|
|
297
|
+
function clearCatalogSnapshot() {
|
|
298
|
+
try {
|
|
299
|
+
unlinkSync(catalogCachePath());
|
|
300
|
+
} catch {}
|
|
301
|
+
}
|
|
230
302
|
// src/models.generated.ts
|
|
231
303
|
const GENERATED_MODELS = {
|
|
232
304
|
"beam": {
|
|
@@ -783,11 +855,14 @@ function probeOf(body) {
|
|
|
783
855
|
};
|
|
784
856
|
}
|
|
785
857
|
/** Probe one local model via `/api/show`, caching successful answers for five minutes. */
|
|
786
|
-
async function
|
|
787
|
-
if (!isLocalEndpoint(config)) return
|
|
858
|
+
async function probeModelOutcome(config, model, fetchImpl = fetch) {
|
|
859
|
+
if (!isLocalEndpoint(config)) return { missing: false };
|
|
788
860
|
const key = keyOf(config, model);
|
|
789
861
|
const hit = cache$2.get(key);
|
|
790
|
-
if (hit !== void 0 && Date.now() - hit.at < PROBE_TTL_MS) return
|
|
862
|
+
if (hit !== void 0 && Date.now() - hit.at < PROBE_TTL_MS) return {
|
|
863
|
+
probe: hit.value,
|
|
864
|
+
missing: false
|
|
865
|
+
};
|
|
791
866
|
try {
|
|
792
867
|
const response = await fetchImpl(`${rootFor(config)}/api/show`, {
|
|
793
868
|
method: "POST",
|
|
@@ -799,18 +874,25 @@ async function probeModel(config, model, fetchImpl = fetch) {
|
|
|
799
874
|
body: JSON.stringify({ model }),
|
|
800
875
|
signal: AbortSignal.timeout(1e4)
|
|
801
876
|
});
|
|
802
|
-
if (
|
|
877
|
+
if (response.status === 404 || response.status === 410) return { missing: true };
|
|
878
|
+
if (!response.ok) return { missing: false };
|
|
803
879
|
const value = probeOf(await response.json());
|
|
804
|
-
if (value === void 0) return
|
|
880
|
+
if (value === void 0) return { missing: false };
|
|
805
881
|
cache$2.set(key, {
|
|
806
882
|
at: Date.now(),
|
|
807
883
|
value
|
|
808
884
|
});
|
|
809
|
-
return
|
|
885
|
+
return {
|
|
886
|
+
probe: value,
|
|
887
|
+
missing: false
|
|
888
|
+
};
|
|
810
889
|
} catch {
|
|
811
|
-
return;
|
|
890
|
+
return { missing: false };
|
|
812
891
|
}
|
|
813
892
|
}
|
|
893
|
+
async function probeModel(config, model, fetchImpl = fetch) {
|
|
894
|
+
return (await probeModelOutcome(config, model, fetchImpl)).probe;
|
|
895
|
+
}
|
|
814
896
|
/** Clear all probe entries, or only entries for one endpoint. */
|
|
815
897
|
function clearModelProbeCache(baseURL) {
|
|
816
898
|
if (baseURL === void 0) {
|
|
@@ -978,6 +1060,7 @@ const CATALOG_TIMEOUT_MS = 15e3;
|
|
|
978
1060
|
const liveMeta = /* @__PURE__ */ new Map();
|
|
979
1061
|
const cache$1 = /* @__PURE__ */ new Map();
|
|
980
1062
|
const inflight = /* @__PURE__ */ new Map();
|
|
1063
|
+
const diskLoaded = /* @__PURE__ */ new Set();
|
|
981
1064
|
let generation = 0;
|
|
982
1065
|
function liveKey(base, id) {
|
|
983
1066
|
return `${base}|${id}`;
|
|
@@ -1081,11 +1164,27 @@ function metaFromProbe(id, probe) {
|
|
|
1081
1164
|
};
|
|
1082
1165
|
}
|
|
1083
1166
|
async function adoptProbes(config, ids, base, fetchImpl) {
|
|
1084
|
-
const
|
|
1167
|
+
const outcomes = await Promise.all(ids.slice(0, 64).map(async (id) => ({
|
|
1085
1168
|
id,
|
|
1086
|
-
|
|
1169
|
+
outcome: await probeModelOutcome(config, id, fetchImpl)
|
|
1087
1170
|
})));
|
|
1088
|
-
|
|
1171
|
+
const kept = [];
|
|
1172
|
+
for (const { id, outcome } of outcomes) {
|
|
1173
|
+
if (outcome.missing) continue;
|
|
1174
|
+
kept.push(id);
|
|
1175
|
+
const meta = metaFromProbe(id, outcome.probe);
|
|
1176
|
+
if (meta !== void 0) liveMeta.set(liveKey(base, id), meta);
|
|
1177
|
+
}
|
|
1178
|
+
return kept;
|
|
1179
|
+
}
|
|
1180
|
+
function metaForBase(base) {
|
|
1181
|
+
const out = {};
|
|
1182
|
+
const prefix = `${base}|`;
|
|
1183
|
+
for (const [key, meta] of liveMeta) if (key.startsWith(prefix)) out[key.slice(prefix.length)] = meta;
|
|
1184
|
+
return out;
|
|
1185
|
+
}
|
|
1186
|
+
async function persist(base, ids) {
|
|
1187
|
+
await saveCatalogSnapshot(base, ids, metaForBase(base));
|
|
1089
1188
|
}
|
|
1090
1189
|
/** Replace the in-memory live metadata for one API base with one successful response. */
|
|
1091
1190
|
function adoptLive(models, tags, base) {
|
|
@@ -1128,9 +1227,20 @@ async function fetchJson(url, config, fetchImpl, signal) {
|
|
|
1128
1227
|
*/
|
|
1129
1228
|
async function refreshCatalog(config, fetchImpl = fetch, force = false) {
|
|
1130
1229
|
const key = config.apiBase;
|
|
1230
|
+
if (!diskLoaded.has(key)) {
|
|
1231
|
+
diskLoaded.add(key);
|
|
1232
|
+
const snapshot = await loadCatalogSnapshot(key);
|
|
1233
|
+
if (snapshot !== void 0 && !cache$1.has(key)) {
|
|
1234
|
+
cache$1.set(key, {
|
|
1235
|
+
at: snapshot.at,
|
|
1236
|
+
ids: snapshot.ids
|
|
1237
|
+
});
|
|
1238
|
+
for (const [id, meta] of Object.entries(snapshot.meta)) liveMeta.set(liveKey(key, id), meta);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1131
1241
|
const cached = cache$1.get(key);
|
|
1132
1242
|
if (!force && cached !== void 0) {
|
|
1133
|
-
if (Date.now() - cached.at >= CATALOG_TTL_MS) refreshInBackground(config, fetchImpl, key);
|
|
1243
|
+
if (config.autoRefresh && Date.now() - cached.at >= CATALOG_TTL_MS) refreshInBackground(config, fetchImpl, key);
|
|
1134
1244
|
return cached.ids;
|
|
1135
1245
|
}
|
|
1136
1246
|
return refreshNow(config, fetchImpl, key, cached !== void 0, generation);
|
|
@@ -1150,19 +1260,21 @@ async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
|
|
|
1150
1260
|
at: Date.now(),
|
|
1151
1261
|
ids
|
|
1152
1262
|
});
|
|
1263
|
+
await persist(key, ids);
|
|
1153
1264
|
return ids;
|
|
1154
1265
|
}
|
|
1155
1266
|
}
|
|
1156
1267
|
const fromData = Array.isArray(payload.data) ? payload.data.map((entry) => str$1(entry.id)).filter((id) => id !== void 0) : [];
|
|
1157
1268
|
const fromTags = ((tagsResult.status === "fulfilled" ? tagsResult.value : void 0)?.models ?? []).map((entry) => str$1(entry.name) ?? str$1(entry.model)).filter((id) => id !== void 0);
|
|
1158
|
-
const
|
|
1159
|
-
if (
|
|
1269
|
+
const discovered = fromData.length > 0 ? fromData : fromTags;
|
|
1270
|
+
if (discovered.length > 0) {
|
|
1160
1271
|
for (const liveKey of liveMeta.keys()) if (liveKey.startsWith(`${key}|`)) liveMeta.delete(liveKey);
|
|
1161
|
-
|
|
1272
|
+
const ids = isLocalEndpoint(config) ? await adoptProbes(config, discovered, key, fetchImpl) : discovered;
|
|
1162
1273
|
cache$1.set(key, {
|
|
1163
1274
|
at: Date.now(),
|
|
1164
1275
|
ids
|
|
1165
1276
|
});
|
|
1277
|
+
await persist(key, ids);
|
|
1166
1278
|
return ids;
|
|
1167
1279
|
}
|
|
1168
1280
|
}
|
|
@@ -1189,7 +1301,9 @@ function clearCatalogCache() {
|
|
|
1189
1301
|
cache$1.clear();
|
|
1190
1302
|
inflight.clear();
|
|
1191
1303
|
liveMeta.clear();
|
|
1304
|
+
diskLoaded.clear();
|
|
1192
1305
|
clearModelProbeCache();
|
|
1306
|
+
clearCatalogSnapshot();
|
|
1193
1307
|
}
|
|
1194
1308
|
function baseMeta(id, base) {
|
|
1195
1309
|
const meta = liveMeta.get(liveKey(base, id)) ?? GENERATED_MODELS[id];
|
|
@@ -3958,6 +4072,8 @@ function publicConfig(config) {
|
|
|
3958
4072
|
numCtx: config.numCtx ?? null,
|
|
3959
4073
|
keepAlive: config.keepAlive ?? "",
|
|
3960
4074
|
stop: config.stop ?? [],
|
|
4075
|
+
autoRefresh: config.autoRefresh,
|
|
4076
|
+
refreshMinutes: config.refreshMinutes,
|
|
3961
4077
|
accounts: config.accounts.map((account) => ({
|
|
3962
4078
|
label: typeof account.label === "string" ? account.label : "",
|
|
3963
4079
|
apiKeyEnv: typeof account.apiKeyEnv === "string" ? account.apiKeyEnv : ""
|
|
@@ -4296,6 +4412,8 @@ function configOps(patch) {
|
|
|
4296
4412
|
if ("numCtx" in patch) set("numCtx", patch.numCtx);
|
|
4297
4413
|
if ("keepAlive" in patch) set("keepAlive", patch.keepAlive);
|
|
4298
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);
|
|
4299
4417
|
if ("accounts" in patch) {
|
|
4300
4418
|
const accounts = cleanAccounts(patch.accounts);
|
|
4301
4419
|
for (const account of accounts) if (account.apiKeyEnv !== "" && !isCredentialRef(account.apiKeyEnv)) throw new Error("invalid credential reference");
|
|
@@ -5318,6 +5436,25 @@ function apply(ctx, config) {
|
|
|
5318
5436
|
ctx.effect(() => () => {
|
|
5319
5437
|
flushRequestLog();
|
|
5320
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");
|
|
5321
5458
|
ctx.inject(["settings"], (settingsCtx) => {
|
|
5322
5459
|
settingsCtx.settings.configure({ auto: false }, ctx.fiber);
|
|
5323
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 tests/reasoning.test.ts",
|
|
76
|
+
"test": "node --import tsx --test tests/core.test.ts tests/usage.test.ts tests/adapter.test.ts tests/routes.test.ts tests/native.test.ts tests/openai-chat.test.ts tests/commands.test.ts tests/tui-settings.test.ts tests/analytics.test.ts tests/apply.test.ts tests/account-rules.test.ts tests/request-log.test.ts tests/image-budget.test.ts tests/tool-schema.test.ts tests/tools.test.ts tests/plugin-updater.test.ts tests/compat.test.ts tests/status.test.ts tests/settings-draft.test.ts tests/update-state.test.ts tests/ui-render.test.tsx tests/update-card-view.test.tsx tests/web.test.ts tests/mock-ollama.test.ts tests/local.test.ts tests/reasoning.test.ts tests/catalog-cache.test.ts",
|
|
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"
|