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

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.37 — 2026-11-11
4
+
5
+ - Session Integrity & Tool Calls: eliminated tool-call ID collisions across multiple steps and turns by minting globally unique UUID-based identifiers (`call_${randomUUID()}`) whenever Ollama Cloud omits `id` or returns an empty string, across both native and OpenAI-compatible transports (`src/transports/tool-call-id.ts`, `native.ts`, `openai-chat.ts`). Preserves upstream `call.id` when supplied by Ollama. Prevents session log corruption (`SessionFormatError: PTC dispatch repeats subCallId`) that previously caused multi-step conversations to silently disappear on DSH startup (GitHub #2, Gitea #125).
6
+
7
+ ## 0.1.36 — 2026-11-09
8
+
9
+ - 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).
10
+ - 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).
11
+ - 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).
12
+ - 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).
13
+ - 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).
14
+ - Plugin Identifier: updated Cordis plugin export `name` in `src/index.ts` to match the canonical package name `@goodandready/dsh-ollama-cloud-provider` (#122).
15
+ - 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).
16
+
3
17
  ## 0.1.35 — 2026-11-09
4
18
 
5
19
  - 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
@@ -93,6 +93,7 @@ graph LR
93
93
 
94
94
  - **Two wire transports** chosen per model: the native Ollama API (NDJSON) and the OpenAI-compatible gateway (SSE).
95
95
  - **Text, thinking, tool calls, images, usage and finish reasons** on both transports.
96
+ - **Unique tool-call IDs** minted across steps and turns, preventing session log collisions when upstream omits an id.
96
97
  - **Live catalog** from `GET /v1/models`, enriched with capability flags from `GET /api/tags`.
97
98
  - **Accurate limits** for the dsh picker: context window, input modalities, reasoning levels and their default, tool support, and API visibility.
98
99
  - **Balance and usage** from the official `/api/balance` and `/api/usage` endpoints: included credits, purchased credits, 24-hour / 7-day / 30-day spend, and spend by model.
@@ -183,7 +184,7 @@ Create a key at <https://ollama.com/settings/keys>. Keys do not expire; `x-api-k
183
184
 
184
185
  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
186
 
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.
187
+ 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
188
 
188
189
  ### Model → account rules
189
190
 
@@ -210,7 +211,7 @@ Open **Settings → Ollama Cloud**:
210
211
 
211
212
  - **Key** — status, paste a key, clear it, run **Test connection** against a chosen model. The probe disables thinking so the reply is visible.
212
213
  - **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.
214
+ - **Accounts** — extra keys, per-account spend, pin, remove, set a key, reset cooldowns.
214
215
  - **Model → account rules** — glob rules.
215
216
  - **Routing** — sticky session per conversation.
216
217
  - **Models** — search, refresh the live catalog, hide models, override the wire transport per model, see price, context and capabilities.
package/README.ru.md CHANGED
@@ -76,6 +76,7 @@ graph LR
76
76
 
77
77
  - **Два транспорта**, выбираемые индивидуально для каждой модели: нативный протокол Ollama API (NDJSON) и совместимый шлюз OpenAI (SSE).
78
78
  - **Поддержка всех режимов**: текст, reasoning/thinking, вызовы функций/инструментов, изображения (vision), подсчёт токенов и finish reasons на обоих транспортах.
79
+ - **Уникальные идентификаторы вызовов инструментов**: генерация глобально уникальных ID для каждого шага исключает коллизии в мультишаговых сессиях агентов и защищает журнал сессий DSH от повреждения.
79
80
  - **Живой каталог моделей**: автоматическое чтение `GET /v1/models`, дополненное флагами возможностей `capabilities` (`tools`, `thinking`, `vision`) из `GET /api/tags`.
80
81
  - **Точные лимиты и метаданные**: контекстное окно, входные модальности, уровни reasoning и значение по умолчанию, статус поддержки инструментов и видимость в API.
81
82
  - **Баланс и аналитика расхода**: интеграция с официальными облачными эндпоинтами `/api/balance` и `/api/usage` — включённые и купленные кредиты, расход за 24 часа / 7 дней / 30 дней, а также группировка по моделям.
@@ -160,7 +161,7 @@ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud
160
161
 
161
162
  Дополнительный аккаунт добавляется в **Настройки → Ollama Cloud → Аккаунты**: укажите имя метки и credential reference (например, `OLLAMA_API_KEY_2`), вставьте токен и сохраните. Ротация происходит **строго до начала генерации потока**: отклонённый ключ получает cooldown, а запрос повторяется со следующим готовым аккаунтом.
162
163
 
163
- Состояния cooldown сохраняются в `~/.dsh/storages/dsh-ollama/cooldowns.json` по SHA-256 хешу ключа.
164
+ Состояния cooldown сохраняются в `~/.dsh/storages/dsh-ollama/cooldowns.json` по SHA-256 хешу ключа. Ошибки авторизации (401/403) охлаждают ключ на 5 минут вместо суток, ошибки квоты учитывают Retry-After. Сбросить охлаждение всех ключей можно кнопкой «Сбросить охлаждение» в карточке аккаунтов или вызовом `POST /dsh-ollama/cooldowns/reset`.
164
165
 
165
166
  ### Правила привязки «модель ➔ аккаунт»
166
167
 
package/README.zh.md CHANGED
@@ -76,6 +76,7 @@ graph LR
76
76
 
77
77
  - **两种底层传输协议**:按模型选择 Ollama 原生协议(NDJSON)或 OpenAI 兼容协议(SSE)。
78
78
  - **全要素流式交互**:文本、深度思考(thinking)、工具调用、多模态图像、Token 统计与 finish reasons。
79
+ - **全局唯一工具调用 ID**:自动生成跨步不重复的工具调用标识符,彻底防止多步对话(如 PTC 预设)因 ID 冲突导致 DSH 会话日志校验失败。
79
80
  - **实时模型目录**:自动从 `GET /v1/models` 获取模型列表,并结合 `GET /api/tags` 补全能力标记(`tools`、`thinking`、`vision`)。
80
81
  - **精准模型元数据**:上下文长度、输入模态、推理等级与默认配置、工具支持状态及 API 开放性。
81
82
  - **官方余额与用量分析**:集成官方 `/api/balance` 与 `/api/usage`,呈现可用额度、已购额度、24小时/7天/30天支出及按模型细分报表。
@@ -155,6 +156,10 @@ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud
155
156
 
156
157
  密钥可在官方后台生成:<https://ollama.com/settings/keys>。云端网关仅接受 `Authorization: Bearer` 请求头。
157
158
 
159
+ ### 多账号轮换与冷却重置
160
+
161
+ 多账号在首字输出前自动轮换。鉴权失败(401/403)进入 5 分钟冷却期,配额错误遵循 Retry-After 响应头。可在设置页中通过「重置冷却」按钮或调用 `POST /dsh-ollama/cooldowns/reset` 随时清除冷却状态。
162
+
158
163
  ### 模型到账号路由规则
159
164
 
160
165
  ```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";
@@ -2276,6 +2276,18 @@ async function* ndjsonObjects(body, idleTimeoutMs, signal) {
2276
2276
  reader.releaseLock();
2277
2277
  }
2278
2278
  }
2279
+ // src/transports/tool-call-id.ts
2280
+ /**
2281
+ * Ensures tool-call ids are globally unique across steps and turns in a session.
2282
+ * Reusing ids breaks DSH session log validation with "PTC dispatch repeats subCallId".
2283
+ */
2284
+ function uniqueToolCallId(raw) {
2285
+ if (typeof raw === "string") {
2286
+ const trimmed = raw.trim();
2287
+ if (trimmed !== "") return ToolCallId(trimmed);
2288
+ }
2289
+ return ToolCallId(`call_${randomUUID()}`);
2290
+ }
2279
2291
  // src/transports/native.ts
2280
2292
  function count$1(value) {
2281
2293
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.trunc(value) : void 0;
@@ -2284,8 +2296,8 @@ function text(value) {
2284
2296
  return typeof value === "string" ? value : "";
2285
2297
  }
2286
2298
  function finishReasonOf$1(raw, hasToolCalls) {
2287
- if (hasToolCalls) return { kind: "tool-calls" };
2288
2299
  if (raw === "length") return { kind: "max-tokens" };
2300
+ if (hasToolCalls) return { kind: "tool-calls" };
2289
2301
  return { kind: "stop" };
2290
2302
  }
2291
2303
  function usageOf(chunk) {
@@ -2360,7 +2372,7 @@ async function* parseNativeStream(response, idleTimeoutMs, signal) {
2360
2372
  const rawArguments = call.function?.arguments;
2361
2373
  const argumentsText = typeof rawArguments === "string" ? rawArguments : JSON.stringify(rawArguments ?? {});
2362
2374
  const index = nextIndex++;
2363
- const id = `call_${toolBlocks.length}`;
2375
+ const id = uniqueToolCallId(call.id);
2364
2376
  toolBlocks.push({
2365
2377
  index,
2366
2378
  id,
@@ -2376,7 +2388,7 @@ async function* parseNativeStream(response, idleTimeoutMs, signal) {
2376
2388
  yield {
2377
2389
  type: "tool-call-delta",
2378
2390
  index,
2379
- id: ToolCallId(id),
2391
+ id,
2380
2392
  ...name === "" ? {} : { name },
2381
2393
  argumentsDelta: argumentsText
2382
2394
  };
@@ -2582,14 +2594,14 @@ async function* parseChatStream(response, idleTimeoutMs, signal) {
2582
2594
  if (entry === void 0) {
2583
2595
  entry = {
2584
2596
  dshIndex: nextIndex++,
2585
- id: toolCall.id ?? `call_${key}`,
2597
+ id: uniqueToolCallId(toolCall.id),
2586
2598
  name: "",
2587
2599
  args: "",
2588
2600
  started: false
2589
2601
  };
2590
2602
  toolCalls.set(key, entry);
2591
2603
  }
2592
- if (toolCall.id !== void 0 && toolCall.id !== "") entry.id = toolCall.id;
2604
+ if (typeof toolCall.id === "string" && toolCall.id.trim() !== "") entry.id = ToolCallId(toolCall.id.trim());
2593
2605
  if (toolCall.function?.name !== void 0 && toolCall.function.name !== "") entry.name = toolCall.function.name;
2594
2606
  if (!entry.started) {
2595
2607
  entry.started = true;
@@ -2710,7 +2722,7 @@ async function* parseCompletion(chunk) {
2710
2722
  sawContent = true;
2711
2723
  }
2712
2724
  for (const call of message?.tool_calls ?? []) {
2713
- const id = ToolCallId(call.id ?? `call_${index}`);
2725
+ const id = uniqueToolCallId(call.id);
2714
2726
  const name = call.function?.name ?? "";
2715
2727
  const args = call.function?.arguments ?? "{}";
2716
2728
  yield {
@@ -2757,6 +2769,18 @@ function effortName(id) {
2757
2769
  if (id === "off" || id === "none") return "Off";
2758
2770
  return id.charAt(0).toUpperCase() + id.slice(1);
2759
2771
  }
2772
+ async function atomicWriteFile(filePath, data) {
2773
+ const dir = dirname(filePath);
2774
+ await mkdir(dir, { recursive: true });
2775
+ const tmp = join(dir, `.${basename(filePath)}.${randomUUID()}.tmp`);
2776
+ try {
2777
+ await writeFile(tmp, data, "utf8");
2778
+ await rename(tmp, filePath);
2779
+ } catch (error) {
2780
+ await rm(tmp, { force: true }).catch(() => {});
2781
+ throw error;
2782
+ }
2783
+ }
2760
2784
  var OllamaCloudAdapter = class extends LlmAdapter {
2761
2785
  deps;
2762
2786
  fetchImpl;
@@ -2981,7 +3005,18 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2981
3005
  budget.dispose();
2982
3006
  }
2983
3007
  }
2984
- const finalError = lastError ?? new LlmError("llm-ollama-cloud: every configured account is cooling down after provider rejections", "RATE_LIMIT");
3008
+ const cooldownEntries = rawKeys.map((entry) => this.cooldowns.get(this.keyId(entry.key))).filter((entry) => entry !== void 0 && entry.until > Date.now());
3009
+ let finalError = lastError;
3010
+ if (finalError === void 0) {
3011
+ if (cooldownEntries.length > 0) {
3012
+ const minUntil = Math.min(...cooldownEntries.map((e) => e.until));
3013
+ const remainingMinutes = Math.max(1, Math.ceil((minUntil - Date.now()) / 6e4));
3014
+ const reasons = new Set(cooldownEntries.map((e) => e.reason));
3015
+ 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");
3016
+ 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");
3017
+ else finalError = new LlmError(`llm-ollama-cloud: every configured account is cooling down after provider rejections (retry in ${remainingMinutes}m)`, "RATE_LIMIT");
3018
+ } else finalError = new LlmError("llm-ollama-cloud: every configured account is cooling down after provider rejections", "RATE_LIMIT");
3019
+ }
2985
3020
  if (!loggedAny) record(options.provider, options.model, options.purpose, lastAccount, reason, {
2986
3021
  at: runStartedAt,
2987
3022
  ok: false,
@@ -3063,8 +3098,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3063
3098
  this.pruneSticky();
3064
3099
  const payload = JSON.stringify({ sticky: Object.fromEntries(this.sticky) });
3065
3100
  this.stickyWrites = this.stickyWrites.then(async () => {
3066
- await mkdir(dirname(this.stickyPath), { recursive: true });
3067
- await writeFile(this.stickyPath, payload, "utf8");
3101
+ await atomicWriteFile(this.stickyPath, payload);
3068
3102
  }).catch(() => {});
3069
3103
  }
3070
3104
  pushTrace(entry) {
@@ -3195,6 +3229,12 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3195
3229
  async flushCooldowns() {
3196
3230
  await this.cooldownWrites;
3197
3231
  }
3232
+ /** Manually clear all active account and model cooldowns. */
3233
+ clearCooldowns() {
3234
+ this.cooldowns.clear();
3235
+ this.modelCooldowns.clear();
3236
+ this.persistCooldowns();
3237
+ }
3198
3238
  loadCooldowns() {
3199
3239
  try {
3200
3240
  const entries = JSON.parse(readFileSync(this.cooldownPath, "utf8")).cooldowns;
@@ -3227,8 +3267,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3227
3267
  this.pruneCooldowns();
3228
3268
  const payload = JSON.stringify({ cooldowns: Object.fromEntries(this.cooldowns) });
3229
3269
  this.cooldownWrites = this.cooldownWrites.then(async () => {
3230
- await mkdir(dirname(this.cooldownPath), { recursive: true });
3231
- await writeFile(this.cooldownPath, payload, "utf8");
3270
+ await atomicWriteFile(this.cooldownPath, payload);
3232
3271
  }).catch(() => {});
3233
3272
  }
3234
3273
  markCooldown(key, status, headers, code) {
@@ -3239,7 +3278,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
3239
3278
  delayMs = Number.isFinite(seconds) && seconds > 0 ? seconds * 1e3 : 6e5;
3240
3279
  reason = "quota";
3241
3280
  } else if (status === 401 || status === 403) {
3242
- delayMs = 864e5;
3281
+ delayMs = 3e5;
3243
3282
  reason = "invalid-credential";
3244
3283
  } else if (status === 429) {
3245
3284
  const seconds = Number(headers?.get("retry-after") ?? NaN);
@@ -4326,6 +4365,39 @@ async function discoverModels(rawBase, key, fetchImpl = fetch, options = {}) {
4326
4365
  models: [...new Set(idsOf(payload))]
4327
4366
  };
4328
4367
  }
4368
+ // src/local-host.ts
4369
+ const LOOPBACK = /* @__PURE__ */ new Set([
4370
+ "localhost",
4371
+ "localhost.",
4372
+ "::1",
4373
+ "[::1]"
4374
+ ]);
4375
+ function normalize(value) {
4376
+ return value.toLowerCase().replace(/^\[|\]$/g, "").replace(/%.+$/, "");
4377
+ }
4378
+ function isLoopbackHostname(value) {
4379
+ const hostname = normalize(value);
4380
+ return LOOPBACK.has(hostname) || hostname.startsWith("127.") || hostname.startsWith("::ffff:127.");
4381
+ }
4382
+ function localAddresses() {
4383
+ const addresses = /* @__PURE__ */ new Set();
4384
+ for (const entries of Object.values(networkInterfaces())) for (const entry of entries ?? []) addresses.add(normalize(entry.address));
4385
+ return addresses;
4386
+ }
4387
+ function isLocalHostname(value) {
4388
+ const hostname = normalize(value);
4389
+ if (isLoopbackHostname(hostname)) return true;
4390
+ if (isIP(hostname) === 0) return false;
4391
+ return localAddresses().has(hostname);
4392
+ }
4393
+ function authorityHostname(value) {
4394
+ if (value === void 0 || value === "") return void 0;
4395
+ try {
4396
+ return normalize(new URL(`http://${value}`).hostname);
4397
+ } catch {
4398
+ return;
4399
+ }
4400
+ }
4329
4401
  // src/routes-public.ts
4330
4402
  function publicConfig(config) {
4331
4403
  return {
@@ -4640,6 +4712,10 @@ function allowedOrigin(req) {
4640
4712
  * while the socket reaches loopback. Write endpoints accept only a literal
4641
4713
  * loopback Host.
4642
4714
  */
4715
+ function trustedHost(req) {
4716
+ const hostname = authorityHostname(req.headers.host);
4717
+ return hostname !== void 0 && isLocalHostname(hostname);
4718
+ }
4643
4719
  function loopbackHost(req) {
4644
4720
  const host = req.headers.host;
4645
4721
  if (host === void 0 || host === "") return false;
@@ -4919,6 +4995,10 @@ function applyRoutes(ctx, web, deps) {
4919
4995
  json(res, 405, { error: "GET required" });
4920
4996
  return false;
4921
4997
  }
4998
+ if (!trustedHost(req)) {
4999
+ json(res, 403, { error: "non-local Host refused" });
5000
+ return false;
5001
+ }
4922
5002
  if (!allowedOrigin(req)) {
4923
5003
  json(res, 403, { error: "cross-origin request refused" });
4924
5004
  return false;
@@ -5006,6 +5086,11 @@ function applyRoutes(ctx, web, deps) {
5006
5086
  json(res, 500, { error: error instanceof Error ? error.message : "balance failed" });
5007
5087
  }
5008
5088
  });
5089
+ route("/dsh-ollama/cooldowns/reset", async (req, res) => {
5090
+ if (!await requirePost(req, res, verifyHost)) return;
5091
+ deps.adapter.clearCooldowns?.();
5092
+ json(res, 200, { ok: true });
5093
+ });
5009
5094
  route("/dsh-ollama/config", async (req, res) => {
5010
5095
  if (!await requirePost(req, res, verifyHost)) return;
5011
5096
  const settings = getSettings(ctx);
@@ -5832,7 +5917,7 @@ var OllamaWebFetchProvider = class extends OllamaWebEndpoint {
5832
5917
  }
5833
5918
  };
5834
5919
  // src/index.ts
5835
- const name = "llm-ollama-cloud";
5920
+ const name = "@goodandready/dsh-ollama-cloud-provider";
5836
5921
  const inject = ["llm"];
5837
5922
  /**
5838
5923
  * 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.37",
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 --test-concurrency=1 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/reasoning.test.ts tests/catalog-cache.test.ts tests/attempt.test.ts tests/model-groups.test.tsx tests/discovery.test.ts tests/sanitize.test.ts tests/retry.test.ts tests/provider-card.test.tsx tests/host-verification.test.ts tests/ui-actions.test.tsx",
76
+ "test": "node --import tsx --test --test-concurrency=1 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/reasoning.test.ts tests/catalog-cache.test.ts tests/attempt.test.ts tests/model-groups.test.tsx tests/discovery.test.ts tests/sanitize.test.ts tests/retry.test.ts tests/provider-card.test.tsx tests/host-verification.test.ts tests/ui-actions.test.tsx tests/tool-call-id.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"