@goodandready/dsh-ollama-cloud-provider 0.1.35 → 0.1.36

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,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.36 — 2026-11-09
4
+
5
+ - Resilience: shortened 401/403 credential rejection cooldown from 24 hours to 5 minutes, added explicit reset endpoint (`POST /dsh-ollama/cooldowns/reset`) and "Reset cooldowns" UI action in settings page, and surfaced exact remaining wait time and root cause (`INVALID_CREDENTIAL`, `QUOTA`, `RATE_LIMIT`) when all keys are cooling (#117).
6
+ - Security & Hygiene: untracked internal agent instructions (`AGENTS.md`), project metadata (`index.md`), Gitea templates (`.gitea/`), and internal design/audit documentation (`docs/`) from git mirror trees and added them to `.gitignore`, preventing public leakage to external mirrors (#118).
7
+ - Security: added `trustedHost` check to `readOnly` route validation, rejecting DNS rebinding attacks on `/dsh-ollama/health` and `/dsh-ollama/status` when non-local `Host` headers are supplied (#119).
8
+ - Protocol Conformance: prioritized token exhaustion `done_reason === 'length'` (`max-tokens`) over partial in-band tool call markers in native transport streaming (`src/transports/native.ts`) (#120).
9
+ - State Persistence: replaced direct file writes with atomic file write (`atomicWriteFile` using temp file + `rename`) for `cooldowns.json` and `sticky.json` to prevent file corruption on unexpected crashes (#121).
10
+ - Plugin Identifier: updated Cordis plugin export `name` in `src/index.ts` to match the canonical package name `@goodandready/dsh-ollama-cloud-provider` (#122).
11
+ - Worktree & Branch Hygiene: pruned 20 merged stale worktrees and 26 merged local branches to eliminate ~1.4 GB repository bloat while preserving active and uncommitted branches (#123).
12
+
3
13
  ## 0.1.35 — 2026-11-09
4
14
 
5
15
  - Security: enforce host authentication check (`verifyHost`) across all loopback write routes (`/config`, `/key`), closing unauthenticated mutation bypass on non-desktop browser requests (#111).
package/README.md CHANGED
@@ -183,7 +183,7 @@ Create a key at <https://ollama.com/settings/keys>. Keys do not expire; `x-api-k
183
183
 
184
184
  Add a second account in **Settings → Ollama Cloud → Accounts**: give it a name and a credential reference (for example `OLLAMA_API_KEY_2`), paste its key, then Save. The default account always serves first unless `activeAccount` pins another one.
185
185
 
186
- Rotation happens **before any content is streamed**. When the serving key is rejected with an invalid credential, a rate limit or an exhausted quota, the adapter marks that key and retries the same request with the next usable account. A request that already started streaming is not replayed. Cooldowns are stored in `~/.dsh/storages/dsh-ollama/cooldowns.json` keyed by a SHA-256 fingerprint — raw keys are never written.
186
+ Rotation happens **before any content is streamed**. When the serving key is rejected with an invalid credential, a rate limit or an exhausted quota, the adapter marks that key and retries the same request with the next usable account. A request that already started streaming is not replayed. Cooldowns are stored in `~/.dsh/storages/dsh-ollama/cooldowns.json` keyed by a SHA-256 fingerprint — raw keys are never written. Authentication rejections (401/403) cool keys for 5 minutes instead of locking them for a day, and quota rejections follow provider Retry-After headers. Cooldowns can be cleared at any time via the **Reset cooldowns** button in the Accounts card or by sending `POST /dsh-ollama/cooldowns/reset`.
187
187
 
188
188
  ### Model → account rules
189
189
 
@@ -210,7 +210,7 @@ Open **Settings → Ollama Cloud**:
210
210
 
211
211
  - **Key** — status, paste a key, clear it, run **Test connection** against a chosen model. The probe disables thinking so the reply is visible.
212
212
  - **Balance and usage** — credit bar or legacy windows, spend windows, warning at 80 % and exhausted at 95 %.
213
- - **Accounts** — extra keys, per-account spend, pin, remove, set a key.
213
+ - **Accounts** — extra keys, per-account spend, pin, remove, set a key, reset cooldowns.
214
214
  - **Model → account rules** — glob rules.
215
215
  - **Routing** — sticky session per conversation.
216
216
  - **Models** — search, refresh the live catalog, hide models, override the wire transport per model, see price, context and capabilities.
package/README.ru.md CHANGED
@@ -160,7 +160,7 @@ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud
160
160
 
161
161
  Дополнительный аккаунт добавляется в **Настройки → Ollama Cloud → Аккаунты**: укажите имя метки и credential reference (например, `OLLAMA_API_KEY_2`), вставьте токен и сохраните. Ротация происходит **строго до начала генерации потока**: отклонённый ключ получает cooldown, а запрос повторяется со следующим готовым аккаунтом.
162
162
 
163
- Состояния cooldown сохраняются в `~/.dsh/storages/dsh-ollama/cooldowns.json` по SHA-256 хешу ключа.
163
+ Состояния cooldown сохраняются в `~/.dsh/storages/dsh-ollama/cooldowns.json` по SHA-256 хешу ключа. Ошибки авторизации (401/403) охлаждают ключ на 5 минут вместо суток, ошибки квоты учитывают Retry-After. Сбросить охлаждение всех ключей можно кнопкой «Сбросить охлаждение» в карточке аккаунтов или вызовом `POST /dsh-ollama/cooldowns/reset`.
164
164
 
165
165
  ### Правила привязки «модель ➔ аккаунт»
166
166
 
package/README.zh.md CHANGED
@@ -155,6 +155,10 @@ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud
155
155
 
156
156
  密钥可在官方后台生成:<https://ollama.com/settings/keys>。云端网关仅接受 `Authorization: Bearer` 请求头。
157
157
 
158
+ ### 多账号轮换与冷却重置
159
+
160
+ 多账号在首字输出前自动轮换。鉴权失败(401/403)进入 5 分钟冷却期,配额错误遵循 Retry-After 响应头。可在设置页中通过「重置冷却」按钮或调用 `POST /dsh-ollama/cooldowns/reset` 随时清除冷却状态。
161
+
158
162
  ### 模型到账号路由规则
159
163
 
160
164
  ```yaml
package/lib/client.js CHANGED
@@ -71,6 +71,8 @@ window.__ModuleLoader__.load({
71
71
  removeAccount: "Remove",
72
72
  addAccount: "Add account",
73
73
  checkAllAccounts: "Check all accounts",
74
+ resetCooldowns: "Reset cooldowns",
75
+ cooldownsReset: "Cooldowns reset",
74
76
  activeAccount: "Active account",
75
77
  active: "active",
76
78
  auto: "Automatic",
@@ -316,6 +318,8 @@ window.__ModuleLoader__.load({
316
318
  removeAccount: "移除",
317
319
  addAccount: "添加账号",
318
320
  checkAllAccounts: "检查所有账号",
321
+ resetCooldowns: "重置冷却",
322
+ cooldownsReset: "冷却已重置",
319
323
  activeAccount: "当前账号",
320
324
  active: "当前",
321
325
  auto: "自动",
@@ -608,6 +612,12 @@ window.__ModuleLoader__.load({
608
612
  })
609
613
  });
610
614
  }
615
+ function resetCooldowns() {
616
+ return call("/dsh-ollama/cooldowns/reset", {
617
+ method: "POST",
618
+ body: "{}"
619
+ });
620
+ }
611
621
  function saveConfig(patch) {
612
622
  return call("/dsh-ollama/config", {
613
623
  method: "POST",
@@ -2377,6 +2387,15 @@ window.__ModuleLoader__.load({
2377
2387
  setError(caught instanceof Error ? caught.message : t("failed"));
2378
2388
  }
2379
2389
  }, [t]);
2390
+ const handleResetCooldowns = (0, react.useCallback)(async () => {
2391
+ try {
2392
+ await resetCooldowns();
2393
+ setNotice(t("cooldownsReset"));
2394
+ await refresh();
2395
+ } catch (caught) {
2396
+ setError(caught instanceof Error ? caught.message : t("failed"));
2397
+ }
2398
+ }, [refresh, t]);
2380
2399
  const reloadModels = (0, react.useCallback)(async () => {
2381
2400
  try {
2382
2401
  const next = await refreshModels();
@@ -2888,6 +2907,14 @@ window.__ModuleLoader__.load({
2888
2907
  },
2889
2908
  children: t("checkAllAccounts")
2890
2909
  }),
2910
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
2911
+ type: "button",
2912
+ className: "ocl-button",
2913
+ onClick: () => {
2914
+ handleResetCooldowns();
2915
+ },
2916
+ children: t("resetCooldowns")
2917
+ }),
2891
2918
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2892
2919
  className: "ocl-badge",
2893
2920
  children: [
package/lib/index.d.ts CHANGED
@@ -306,6 +306,8 @@ declare class OllamaCloudAdapter extends LlmAdapter {
306
306
  } | undefined;
307
307
  /** Await pending cooldown persistence writes (tests and shutdown). */
308
308
  flushCooldowns(): Promise<void>;
309
+ /** Manually clear all active account and model cooldowns. */
310
+ clearCooldowns(): void;
309
311
  private loadCooldowns;
310
312
  private pruneCooldowns;
311
313
  private persistCooldowns;
@@ -517,7 +519,7 @@ interface EffectiveModel extends OllamaCloudModelMeta {
517
519
  }
518
520
  declare function effectiveModel(id: string, config: ResolvedConfig): EffectiveModel;
519
521
  declare function describeModel(meta: EffectiveModel, config: ResolvedConfig): string;
520
- declare const name = "llm-ollama-cloud";
522
+ declare const name = "@goodandready/dsh-ollama-cloud-provider";
521
523
  declare const inject: string[];
522
524
  /**
523
525
  * Register the `ollama-cloud` route against the dsh `llm` service. Requests
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { createHash } from "node:crypto";
1
+ import { createHash, randomUUID } from "node:crypto";
2
2
  import { existsSync, readFileSync, statSync, unlinkSync } from "node:fs";
3
- import { appendFile, mkdir, readFile, readdir, rename, stat, unlink, writeFile } from "node:fs/promises";
4
- import { homedir } from "node:os";
3
+ import { appendFile, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
4
+ import { homedir, networkInterfaces } 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";
7
7
  import z from "@deepseek-ai/schemastery";
@@ -2284,8 +2284,8 @@ function text(value) {
2284
2284
  return typeof value === "string" ? value : "";
2285
2285
  }
2286
2286
  function finishReasonOf$1(raw, hasToolCalls) {
2287
- if (hasToolCalls) return { kind: "tool-calls" };
2288
2287
  if (raw === "length") return { kind: "max-tokens" };
2288
+ if (hasToolCalls) return { kind: "tool-calls" };
2289
2289
  return { kind: "stop" };
2290
2290
  }
2291
2291
  function usageOf(chunk) {
@@ -2757,6 +2757,18 @@ function effortName(id) {
2757
2757
  if (id === "off" || id === "none") return "Off";
2758
2758
  return id.charAt(0).toUpperCase() + id.slice(1);
2759
2759
  }
2760
+ async function atomicWriteFile(filePath, data) {
2761
+ const dir = dirname(filePath);
2762
+ await mkdir(dir, { recursive: true });
2763
+ const tmp = join(dir, `.${basename(filePath)}.${randomUUID()}.tmp`);
2764
+ try {
2765
+ await writeFile(tmp, data, "utf8");
2766
+ await rename(tmp, filePath);
2767
+ } catch (error) {
2768
+ await rm(tmp, { force: true }).catch(() => {});
2769
+ throw error;
2770
+ }
2771
+ }
2760
2772
  var OllamaCloudAdapter = class extends LlmAdapter {
2761
2773
  deps;
2762
2774
  fetchImpl;
@@ -2981,7 +2993,18 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2981
2993
  budget.dispose();
2982
2994
  }
2983
2995
  }
2984
- const finalError = lastError ?? new LlmError("llm-ollama-cloud: every configured account is cooling down after provider rejections", "RATE_LIMIT");
2996
+ const cooldownEntries = rawKeys.map((entry) => this.cooldowns.get(this.keyId(entry.key))).filter((entry) => entry !== void 0 && entry.until > Date.now());
2997
+ let finalError = lastError;
2998
+ if (finalError === void 0) {
2999
+ if (cooldownEntries.length > 0) {
3000
+ const minUntil = Math.min(...cooldownEntries.map((e) => e.until));
3001
+ const remainingMinutes = Math.max(1, Math.ceil((minUntil - Date.now()) / 6e4));
3002
+ const reasons = new Set(cooldownEntries.map((e) => e.reason));
3003
+ if (reasons.has("invalid-credential") && reasons.size === 1) finalError = new LlmError(`llm-ollama-cloud: every configured account is cooling down due to invalid credentials (retry in ${remainingMinutes}m)`, "INVALID_CREDENTIAL");
3004
+ else if (reasons.has("quota") && !reasons.has("rate-limit")) finalError = new LlmError(`llm-ollama-cloud: every configured account is cooling down due to quota limits (retry in ${remainingMinutes}m)`, "QUOTA");
3005
+ else finalError = new LlmError(`llm-ollama-cloud: every configured account is cooling down after provider rejections (retry in ${remainingMinutes}m)`, "RATE_LIMIT");
3006
+ } else finalError = new LlmError("llm-ollama-cloud: every configured account is cooling down after provider rejections", "RATE_LIMIT");
3007
+ }
2985
3008
  if (!loggedAny) record(options.provider, options.model, options.purpose, lastAccount, reason, {
2986
3009
  at: runStartedAt,
2987
3010
  ok: false,
@@ -3063,8 +3086,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3063
3086
  this.pruneSticky();
3064
3087
  const payload = JSON.stringify({ sticky: Object.fromEntries(this.sticky) });
3065
3088
  this.stickyWrites = this.stickyWrites.then(async () => {
3066
- await mkdir(dirname(this.stickyPath), { recursive: true });
3067
- await writeFile(this.stickyPath, payload, "utf8");
3089
+ await atomicWriteFile(this.stickyPath, payload);
3068
3090
  }).catch(() => {});
3069
3091
  }
3070
3092
  pushTrace(entry) {
@@ -3195,6 +3217,12 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3195
3217
  async flushCooldowns() {
3196
3218
  await this.cooldownWrites;
3197
3219
  }
3220
+ /** Manually clear all active account and model cooldowns. */
3221
+ clearCooldowns() {
3222
+ this.cooldowns.clear();
3223
+ this.modelCooldowns.clear();
3224
+ this.persistCooldowns();
3225
+ }
3198
3226
  loadCooldowns() {
3199
3227
  try {
3200
3228
  const entries = JSON.parse(readFileSync(this.cooldownPath, "utf8")).cooldowns;
@@ -3227,8 +3255,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3227
3255
  this.pruneCooldowns();
3228
3256
  const payload = JSON.stringify({ cooldowns: Object.fromEntries(this.cooldowns) });
3229
3257
  this.cooldownWrites = this.cooldownWrites.then(async () => {
3230
- await mkdir(dirname(this.cooldownPath), { recursive: true });
3231
- await writeFile(this.cooldownPath, payload, "utf8");
3258
+ await atomicWriteFile(this.cooldownPath, payload);
3232
3259
  }).catch(() => {});
3233
3260
  }
3234
3261
  markCooldown(key, status, headers, code) {
@@ -3239,7 +3266,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3239
3266
  delayMs = Number.isFinite(seconds) && seconds > 0 ? seconds * 1e3 : 6e5;
3240
3267
  reason = "quota";
3241
3268
  } else if (status === 401 || status === 403) {
3242
- delayMs = 864e5;
3269
+ delayMs = 3e5;
3243
3270
  reason = "invalid-credential";
3244
3271
  } else if (status === 429) {
3245
3272
  const seconds = Number(headers?.get("retry-after") ?? NaN);
@@ -4326,6 +4353,39 @@ async function discoverModels(rawBase, key, fetchImpl = fetch, options = {}) {
4326
4353
  models: [...new Set(idsOf(payload))]
4327
4354
  };
4328
4355
  }
4356
+ // src/local-host.ts
4357
+ const LOOPBACK = /* @__PURE__ */ new Set([
4358
+ "localhost",
4359
+ "localhost.",
4360
+ "::1",
4361
+ "[::1]"
4362
+ ]);
4363
+ function normalize(value) {
4364
+ return value.toLowerCase().replace(/^\[|\]$/g, "").replace(/%.+$/, "");
4365
+ }
4366
+ function isLoopbackHostname(value) {
4367
+ const hostname = normalize(value);
4368
+ return LOOPBACK.has(hostname) || hostname.startsWith("127.") || hostname.startsWith("::ffff:127.");
4369
+ }
4370
+ function localAddresses() {
4371
+ const addresses = /* @__PURE__ */ new Set();
4372
+ for (const entries of Object.values(networkInterfaces())) for (const entry of entries ?? []) addresses.add(normalize(entry.address));
4373
+ return addresses;
4374
+ }
4375
+ function isLocalHostname(value) {
4376
+ const hostname = normalize(value);
4377
+ if (isLoopbackHostname(hostname)) return true;
4378
+ if (isIP(hostname) === 0) return false;
4379
+ return localAddresses().has(hostname);
4380
+ }
4381
+ function authorityHostname(value) {
4382
+ if (value === void 0 || value === "") return void 0;
4383
+ try {
4384
+ return normalize(new URL(`http://${value}`).hostname);
4385
+ } catch {
4386
+ return;
4387
+ }
4388
+ }
4329
4389
  // src/routes-public.ts
4330
4390
  function publicConfig(config) {
4331
4391
  return {
@@ -4640,6 +4700,10 @@ function allowedOrigin(req) {
4640
4700
  * while the socket reaches loopback. Write endpoints accept only a literal
4641
4701
  * loopback Host.
4642
4702
  */
4703
+ function trustedHost(req) {
4704
+ const hostname = authorityHostname(req.headers.host);
4705
+ return hostname !== void 0 && isLocalHostname(hostname);
4706
+ }
4643
4707
  function loopbackHost(req) {
4644
4708
  const host = req.headers.host;
4645
4709
  if (host === void 0 || host === "") return false;
@@ -4919,6 +4983,10 @@ function applyRoutes(ctx, web, deps) {
4919
4983
  json(res, 405, { error: "GET required" });
4920
4984
  return false;
4921
4985
  }
4986
+ if (!trustedHost(req)) {
4987
+ json(res, 403, { error: "non-local Host refused" });
4988
+ return false;
4989
+ }
4922
4990
  if (!allowedOrigin(req)) {
4923
4991
  json(res, 403, { error: "cross-origin request refused" });
4924
4992
  return false;
@@ -5006,6 +5074,11 @@ function applyRoutes(ctx, web, deps) {
5006
5074
  json(res, 500, { error: error instanceof Error ? error.message : "balance failed" });
5007
5075
  }
5008
5076
  });
5077
+ route("/dsh-ollama/cooldowns/reset", async (req, res) => {
5078
+ if (!await requirePost(req, res, verifyHost)) return;
5079
+ deps.adapter.clearCooldowns?.();
5080
+ json(res, 200, { ok: true });
5081
+ });
5009
5082
  route("/dsh-ollama/config", async (req, res) => {
5010
5083
  if (!await requirePost(req, res, verifyHost)) return;
5011
5084
  const settings = getSettings(ctx);
@@ -5832,7 +5905,7 @@ var OllamaWebFetchProvider = class extends OllamaWebEndpoint {
5832
5905
  }
5833
5906
  };
5834
5907
  // src/index.ts
5835
- const name = "llm-ollama-cloud";
5908
+ const name = "@goodandready/dsh-ollama-cloud-provider";
5836
5909
  const inject = ["llm"];
5837
5910
  /**
5838
5911
  * Register the `ollama-cloud` route against the dsh `llm` service. Requests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-ollama-cloud-provider",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "Ollama Cloud LLM provider plugin for DeepSeek Harness (dsh).",
5
5
  "license": "MIT",
6
6
  "type": "module",