@goodandready/dsh-ollama-cloud-provider 0.1.38 → 0.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.40 — 2026-11-21
4
+
5
+ - Settings: an empty numeric field is now unset (`null`) instead of being replaced by a default, invalid values are reported per field and block the save, and `configWritable` disables Save on a read-only host (#140).
6
+ - Settings: manual-model rows keep a stable identity while editing, account key buffers are tied to the row, and a cancelled drag clears its state (#141).
7
+ - Catalog: cold loads are single-flight, a failed refresh is stored with a zero timestamp instead of looking fresh, and one scheduler reads `autoRefresh`/`refreshMinutes` on every tick (#139).
8
+ - Diagnostics: a catalog failure surfaces as `providerError` instead of an empty model list, the local usage rate limit is reported as a rate limit, and quota refresh errors are shown (#144).
9
+ - Transports: tool-call ids stay stable within a block even when the upstream id arrives late, NDJSON/SSE frames are capped at 1 MiB, idle timeouts keep their `TIMEOUT` code, and readers are cancelled cleanly (#145, #152).
10
+ - Security: `redirect: 'error'` on every key-bearing request, `0600/0700` state files, prototype keys ignored, discovery pinned to the validated IP, `providerError`/`source` redacted (#152).
11
+
12
+ 194 tests.
13
+
14
+ ## 0.1.39 — 2026-11-15
15
+
16
+ - Security: loopback Host detection now requires an IP literal, so a DNS-rebinding page can no longer pass the read host gate or the update endpoint (#135).
17
+ - Security: endpoint URLs (`apiBase`, `openAiBase`, `usageUrl`, `balanceUrl`) must be absolute `http(s)` without embedded credentials or fragments; link-local and metadata addresses are refused, and an unsafe value falls back to the default (#136).
18
+ - Security: update status requires a local Host and same-origin Origin, while refresh, model refresh, connection test and endpoint discovery are single-flight and rate-limited; `/status` is cached for 10 seconds (#137).
19
+ - Reliability: HTTP 504/408 responses now rotate to the next account instead of failing the turn, matching the exception path (#138).
20
+ - Reliability: request-log compaction writes through a temporary file and renames it, so a concurrent reader never sees an empty or partial log (#142).
21
+ - Tooling: `deploy.sh install` works again (`local` outside a function aborted it), and `verify` fails instead of warning when `/health` is not 200 (#143).
22
+ - Documentation: added a Security section to all three READMEs and fixed the escaped version ranges in Requirements.
23
+
24
+ 175 tests.
25
+
3
26
  ## 0.1.38 — 2026-11-12
4
27
 
5
28
  - Architecture & Contracts: established canonical `docs/design/DESIGN.md` (following `project-design-contract`), `AGENTS.md`, `index.md`, `deploy.sh`, and `docs/deployment/DEPLOYMENT.md` (#127).
package/README.md CHANGED
@@ -111,8 +111,8 @@ graph LR
111
111
 
112
112
  ## Requirements
113
113
 
114
- - **DeepSeek Harness**: \0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0\ (desktop and web profiles).
115
- - **Node.js**: \>=22.0.0\.
114
+ - **DeepSeek Harness**: `0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0` (desktop and web profiles).
115
+ - **Node.js**: `>=22.0.0`.
116
116
  - **Ollama Cloud Account**: one or more active API keys from Ollama Cloud or a compatible proxy endpoint.
117
117
 
118
118
  ## Install
@@ -128,17 +128,17 @@ npm pack
128
128
  Install the published package:
129
129
 
130
130
  ```bash
131
- dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.38
131
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.40
132
132
  # DSH Desktop:
133
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.38
133
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.40
134
134
  ```
135
135
 
136
136
  Or install the packed tarball into a profile:
137
137
 
138
138
  ```bash
139
- dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.38.tgz
139
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.40.tgz
140
140
  # DSH Desktop:
141
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.38.tgz
141
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.40.tgz
142
142
  ```
143
143
 
144
144
  Restart dsh (or DSH Desktop), then pick **Ollama Cloud** in the model picker.
@@ -263,6 +263,13 @@ The Ollama Cloud settings page in DSH Desktop (dark theme): configured credentia
263
263
 
264
264
  ![Ollama Cloud settings](media/visual-verification.png)
265
265
 
266
+ ## Security
267
+
268
+ - Write routes require a loopback socket, a same-origin `Origin`/`Referer` and the host authentication check; a DNS name is never treated as loopback.
269
+ - API keys are resolved through the DSH credential service; the browser only learns whether a key is configured, never its value.
270
+ - Custom endpoint URLs must be absolute `http(s)` without embedded credentials or fragments; link-local and metadata addresses are refused.
271
+ - `/status` is cached for 10 seconds, while refresh, test and endpoint-discovery routes are single-flight and rate-limited.
272
+
266
273
  ## Limitations
267
274
 
268
275
  - **Cloud only.** Local `http://localhost:11434` is not registered as a route.
package/README.ru.md CHANGED
@@ -93,8 +93,8 @@ graph LR
93
93
 
94
94
  ## Requirements / Требования
95
95
 
96
- - **DeepSeek Harness**: \0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0\ (профили desktop и web).
97
- - **Node.js**: \>=22.0.0\.
96
+ - **DeepSeek Harness**: `0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0` (профили desktop и web).
97
+ - **Node.js**: `>=22.0.0`.
98
98
  - **Аккаунт Ollama Cloud**: один или несколько действующих API-ключей Ollama Cloud или совместимого прокси.
99
99
 
100
100
  ## Установка
@@ -110,17 +110,17 @@ npm pack
110
110
  Установка опубликованного пакета из npm:
111
111
 
112
112
  ```bash
113
- dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.38
113
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.40
114
114
  # DSH Desktop:
115
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.38
115
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.40
116
116
  ```
117
117
 
118
118
  Либо установка из упакованного tarball:
119
119
 
120
120
  ```bash
121
- dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.38.tgz
121
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.40.tgz
122
122
  # DSH Desktop:
123
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.38.tgz
123
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.40.tgz
124
124
  ```
125
125
 
126
126
  После установки перезапустите dsh (или DSH Desktop) и выберите **Ollama Cloud** в списке моделей.
@@ -216,6 +216,13 @@ modelAccountRules:
216
216
  - Нативный `/api/chat` передает NDJSON с подробной статистикой токенов в финальном объекте.
217
217
  - Совместимый эндпоинт OpenAI `/v1/chat/completions` поддерживает стриминг, инструменты, зрение (vision) и `reasoning_effort`.
218
218
 
219
+ ## Безопасность
220
+
221
+ - Write-маршруты требуют loopback-сокет, same-origin `Origin`/`Referer` и проверку подлинности хоста; DNS-имя никогда не считается loopback.
222
+ - Ключи читаются через сервис учётных данных DSH; браузер узнаёт только факт наличия ключа, но не его значение.
223
+ - Собственные адреса эндпоинтов должны быть абсолютными `http(s)` без встроенных учётных данных и фрагментов; link-local и metadata-адреса отклоняются.
224
+ - `/status` кэшируется на 10 секунд, а маршруты обновления, теста и поиска эндпоинтов ограничены по частоте и выполняются в единственном экземпляре.
225
+
219
226
  ## Ограничения
220
227
 
221
228
  - Только Ollama Cloud; локальный сервис `http://localhost:11434` данным плагином не регистрируется.
package/README.zh.md CHANGED
@@ -92,8 +92,8 @@ graph LR
92
92
 
93
93
  ## Requirements / 系统要求
94
94
 
95
- - **DeepSeek Harness**: \0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0\(桌面版与 Web 配置文件)。
96
- - **Node.js**: \>=22.0.0\。
95
+ - **DeepSeek Harness**: `0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0`(桌面版与 Web 配置文件)。
96
+ - **Node.js**: `>=22.0.0`。
97
97
  - **Ollama Cloud 账户**: 一个或多个有效的 Ollama Cloud API Key 或兼容的代理端点。
98
98
 
99
99
  ## 安装指南
@@ -109,17 +109,17 @@ npm pack
109
109
  从 npm 安装已发布版本:
110
110
 
111
111
  ```bash
112
- dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.38
112
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.40
113
113
  # DSH 桌面端:
114
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.38
114
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.40
115
115
  ```
116
116
 
117
117
  或通过打包文件安装:
118
118
 
119
119
  ```bash
120
- dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.38.tgz
120
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.40.tgz
121
121
  # DSH 桌面端:
122
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.38.tgz
122
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.40.tgz
123
123
  ```
124
124
 
125
125
  安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
@@ -186,6 +186,13 @@ DSH Desktop(暗黑主题)中的 Ollama Cloud 设置与用量面板:
186
186
  /ollama test [model] # 发送连通性测试请求
187
187
  ```
188
188
 
189
+ ## 安全说明
190
+
191
+ - 写入路由要求 loopback 套接字、同源 `Origin`/`Referer` 以及宿主机认证;DNS 名称永远不会被视为 loopback。
192
+ - API 密钥通过 DSH 凭据服务解析;浏览器只能获知是否已配置,无法读取密钥值。
193
+ - 自定义端点必须是完整的 `http(s)` 地址,不得包含账号密码或片段;link-local 与 metadata 地址会被拒绝。
194
+ - `/status` 缓存 10 秒;刷新、测试与端点发现路由为单飞并限流。
195
+
189
196
  ## 限制与注意事项
190
197
 
191
198
  - 仅支持 Ollama Cloud 云端模型;不会注册本地 `http://localhost:11434` 路由。
package/lib/adapter.js CHANGED
@@ -31,10 +31,16 @@ function effortName(id) {
31
31
  }
32
32
  async function atomicWriteFile(filePath, data) {
33
33
  const dir = dirname(filePath);
34
- await mkdir(dir, { recursive: true });
34
+ await mkdir(dir, {
35
+ recursive: true,
36
+ mode: 448
37
+ });
35
38
  const tmp = join(dir, `.${basename(filePath)}.${randomUUID()}.tmp`);
36
39
  try {
37
- await writeFile(tmp, data, "utf8");
40
+ await writeFile(tmp, data, {
41
+ encoding: "utf8",
42
+ mode: 384
43
+ });
38
44
  await rename(tmp, filePath);
39
45
  } catch (error) {
40
46
  await rm(tmp, { force: true }).catch((err) => bestEffortFailed("atomicWriteFile:rm-tmp", err));
@@ -220,7 +226,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
220
226
  if (canRotate) continue;
221
227
  throw error;
222
228
  }
223
- const retryable = error.code === "INVALID_CREDENTIAL" || error.code === "RATE_LIMIT" || error.code === "QUOTA" || error.code === "SERVER";
229
+ const retryable = this.isTransient(error) || error.code === "INVALID_CREDENTIAL";
224
230
  const credentialOrQuota = error.code === "INVALID_CREDENTIAL" || error.code === "RATE_LIMIT" || error.code === "QUOTA";
225
231
  if (retryable) {
226
232
  if (canRotate || credentialOrQuota) this.markCooldown(entry.key, response.status, response.headers, error.code);
@@ -394,6 +400,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
394
400
  method: "POST",
395
401
  headers,
396
402
  body: JSON.stringify(body),
403
+ redirect: "error",
397
404
  signal: controller.signal
398
405
  });
399
406
  if (attempt < policy.maxRetries && isRetryableStatus(response.status)) {
@@ -56,8 +56,14 @@ async function saveCatalogSnapshot(baseURL, ids, meta) {
56
56
  meta
57
57
  };
58
58
  try {
59
- await mkdir(dirname(path), { recursive: true });
60
- await writeFile(temp, `${JSON.stringify(payload)}\n`, "utf8");
59
+ await mkdir(dirname(path), {
60
+ recursive: true,
61
+ mode: 448
62
+ });
63
+ await writeFile(temp, `${JSON.stringify(payload)}\n`, {
64
+ encoding: "utf8",
65
+ mode: 384
66
+ });
61
67
  await rename(temp, path);
62
68
  } catch (error) {
63
69
  bestEffortFailed("catalog cache write failed", error);
@@ -0,0 +1,34 @@
1
+ // src/catalog-scheduler.ts
2
+ /**
3
+ * The single owner of periodic catalog refresh. It re-reads the live settings on
4
+ * every tick, so changing `autoRefresh` or `refreshMinutes` applies without a
5
+ * restart, and it never runs two refreshes for the same due moment.
6
+ */
7
+ function createCatalogScheduler(options) {
8
+ const now = options.now ?? Date.now;
9
+ let last = now();
10
+ const check = () => {
11
+ try {
12
+ const config = options.current();
13
+ if (!config.autoRefresh) return;
14
+ const minutes = Math.floor(config.refreshMinutes);
15
+ if (!Number.isFinite(minutes) || minutes <= 0) return;
16
+ const at = now();
17
+ if (at - last < minutes * 6e4) return;
18
+ last = at;
19
+ const result = options.refresh();
20
+ if (result !== void 0) Promise.resolve(result).catch((error) => options.onError?.(error));
21
+ } catch (error) {
22
+ options.onError?.(error);
23
+ }
24
+ };
25
+ const timer = setInterval(check, options.tickMs ?? 6e4);
26
+ timer.unref?.();
27
+ return {
28
+ check,
29
+ dispose: () => clearInterval(timer)
30
+ };
31
+ }
32
+ export { createCatalogScheduler };
33
+
34
+ //# sourceMappingURL=catalog-scheduler.js.map
package/lib/catalog.js CHANGED
@@ -7,7 +7,6 @@ import { formatPrice, priceFor } from "./pricing.js";
7
7
  import { normalizeThinking } from "./reasoning.js";
8
8
  import { modelsUrlFor, tagsUrlFor } from "./routing.js";
9
9
  // src/catalog.ts
10
- const CATALOG_TTL_MS = 6e5;
11
10
  const CATALOG_TIMEOUT_MS = 15e3;
12
11
  const liveMeta = /* @__PURE__ */ new Map();
13
12
  const cache = /* @__PURE__ */ new Map();
@@ -125,6 +124,7 @@ async function fetchJson(url, config, fetchImpl, signal) {
125
124
  accept: "application/json",
126
125
  "user-agent": config.userAgent
127
126
  },
127
+ redirect: "error",
128
128
  signal
129
129
  });
130
130
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
@@ -154,10 +154,27 @@ async function refreshCatalog(config, fetchImpl = fetch, force = false) {
154
154
  }
155
155
  const cached = cache.get(key);
156
156
  if (!force && cached !== void 0) {
157
- if (config.autoRefresh && Date.now() - cached.at >= CATALOG_TTL_MS) refreshInBackground(config, fetchImpl, key);
157
+ const ttl = catalogTtlMs(config);
158
+ if (ttl > 0 && (cached.at === 0 || Date.now() - cached.at >= ttl)) refreshShared(config, fetchImpl, key, true);
158
159
  return cached.ids;
159
160
  }
160
- return refreshNow(config, fetchImpl, key, cached !== void 0, generation);
161
+ return refreshShared(config, fetchImpl, key, cached !== void 0);
162
+ }
163
+ function catalogTtlMs(config) {
164
+ if (!config.autoRefresh || config.refreshMinutes <= 0) return 0;
165
+ return Math.max(1, Math.floor(config.refreshMinutes)) * 6e4;
166
+ }
167
+ function refreshShared(config, fetchImpl, key, keepOnFailure) {
168
+ const existing = inflight.get(key);
169
+ if (existing !== void 0) return existing;
170
+ const task = refreshNow(config, fetchImpl, key, keepOnFailure, generation).catch((error) => {
171
+ bestEffortFailed("catalog:fetchModels", error);
172
+ return cache.get(key)?.ids ?? Object.keys(GENERATED_MODELS);
173
+ }).finally(() => {
174
+ if (inflight.get(key) === task) inflight.delete(key);
175
+ });
176
+ inflight.set(key, task);
177
+ return task;
161
178
  }
162
179
  async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
163
180
  const budget = createAttemptBudget(CATALOG_TIMEOUT_MS);
@@ -176,6 +193,7 @@ async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
176
193
  if (live.length > 0) {
177
194
  const ids = adoptLive(live, tags, key);
178
195
  if (ids.length > 0) {
196
+ if (epoch !== generation) return ids;
179
197
  cache.set(key, {
180
198
  at: Date.now(),
181
199
  ids
@@ -190,6 +208,7 @@ async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
190
208
  if (discovered.length > 0) {
191
209
  for (const liveKey of liveMeta.keys()) if (liveKey.startsWith(`${key}|`)) liveMeta.delete(liveKey);
192
210
  const ids = discovered;
211
+ if (epoch !== generation) return ids;
193
212
  cache.set(key, {
194
213
  at: Date.now(),
195
214
  ids
@@ -204,21 +223,11 @@ async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
204
223
  }
205
224
  const fallback = Object.keys(GENERATED_MODELS);
206
225
  if (epoch === generation) cache.set(key, {
207
- at: Date.now(),
226
+ at: 0,
208
227
  ids: fallback
209
228
  });
210
229
  return fallback;
211
230
  }
212
- function refreshInBackground(config, fetchImpl, key) {
213
- if (inflight.has(key)) return;
214
- const task = refreshNow(config, fetchImpl, key, true, generation).catch((err) => {
215
- bestEffortFailed("catalog:fetchModels", err);
216
- return cache.get(key)?.ids ?? Object.keys(GENERATED_MODELS);
217
- }).finally(() => {
218
- inflight.delete(key);
219
- });
220
- inflight.set(key, task);
221
- }
222
231
  function clearCatalogCache() {
223
232
  generation += 1;
224
233
  cache.clear();