@goodandready/dsh-ollama-cloud-provider 0.1.21 → 0.1.22

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,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.22 — 2026-11-05
4
+
5
+ - Added `/ollama-context` with 4k/8k/16k/32k/64k/128k presets, custom token
6
+ values, follow, status and reset. The override is session-scoped and wins
7
+ over configured `num_ctx`; sessions remain isolated.
8
+ - Added an independent whole-attempt budget (`attemptTimeoutMs`, default off)
9
+ for chat, catalog and web requests. Each retry gets a fresh budget; caller
10
+ cancellation is distinguished from timeout.
11
+ - Added settings for the attempt budget and tests for budget/timeout/session
12
+ isolation; 124/124 tests.
13
+
3
14
  ## 0.1.21 — 2026-11-05
4
15
 
5
16
  - Added local Ollama model management: `/api/tags` disk inventory, `/api/ps`
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.21
140
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.22
141
141
  # DSH Desktop:
142
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.21
142
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.22
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.21.tgz
148
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.22.tgz
149
149
  # DSH Desktop:
150
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
150
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.22.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.21
106
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.22
107
107
  # DSH Desktop:
108
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.21
108
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.22
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.21.tgz
114
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.22.tgz
115
115
  # DSH Desktop:
116
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
116
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.22.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.21
105
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.22
106
106
  # DSH 桌面端:
107
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.21
107
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.22
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.21.tgz
113
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.22.tgz
114
114
  # DSH 桌面端:
115
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.21.tgz
115
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.22.tgz
116
116
  ```
117
117
 
118
118
  安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
package/lib/client.js CHANGED
@@ -120,6 +120,8 @@ window.__ModuleLoader__.load({
120
120
  balanceUrl: "Balance endpoint",
121
121
  requestTimeoutMs: "Header timeout (ms)",
122
122
  streamIdleTimeoutMs: "Stream idle timeout (ms)",
123
+ attemptTimeoutMs: "Attempt budget (ms, 0 = off)",
124
+ attemptTimeoutHint: "Whole-attempt timeout; a fresh budget is created for every retry.",
123
125
  maxOutputTokens: "Output limit (0 = provider default)",
124
126
  contextWindow: "Context window override",
125
127
  generation: "Generation defaults",
@@ -330,6 +332,8 @@ window.__ModuleLoader__.load({
330
332
  balanceUrl: "余额端点",
331
333
  requestTimeoutMs: "响应头超时(毫秒)",
332
334
  streamIdleTimeoutMs: "流空闲超时(毫秒)",
335
+ attemptTimeoutMs: "单次尝试预算(毫秒,0 = 关闭)",
336
+ attemptTimeoutHint: "整次尝试超时;每次重试都会创建新的预算。",
333
337
  maxOutputTokens: "输出上限(0 = 提供方默认)",
334
338
  contextWindow: "上下文窗口覆盖",
335
339
  generation: "生成默认值",
@@ -1648,6 +1652,7 @@ window.__ModuleLoader__.load({
1648
1652
  transport: state.config.transport,
1649
1653
  requestTimeoutMs: String(state.config.requestTimeoutMs),
1650
1654
  streamIdleTimeoutMs: String(state.config.streamIdleTimeoutMs),
1655
+ attemptTimeoutMs: String(state.config.attemptTimeoutMs ?? 0),
1651
1656
  maxOutputTokens: textOf(state.config.maxOutputTokens),
1652
1657
  contextWindow: textOf(state.config.contextWindow),
1653
1658
  temperature: textOf(state.config.temperature),
@@ -1701,6 +1706,7 @@ window.__ModuleLoader__.load({
1701
1706
  transport: draft.transport,
1702
1707
  requestTimeoutMs: numberOrNull(draft.requestTimeoutMs) ?? 3e5,
1703
1708
  streamIdleTimeoutMs: numberOrNull(draft.streamIdleTimeoutMs) ?? 3e5,
1709
+ attemptTimeoutMs: boundedNumber(draft.attemptTimeoutMs, 0, 36e5, true) ?? 0,
1704
1710
  maxOutputTokens: numberOrNull(draft.maxOutputTokens),
1705
1711
  contextWindow: numberOrNull(draft.contextWindow),
1706
1712
  temperature: boundedNumber(draft.temperature, 0, 2, false),
@@ -3107,6 +3113,13 @@ window.__ModuleLoader__.load({
3107
3113
  value: draft.streamIdleTimeoutMs,
3108
3114
  onChange: (value) => update({ streamIdleTimeoutMs: value })
3109
3115
  }),
3116
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
3117
+ label: t("attemptTimeoutMs"),
3118
+ hint: t("attemptTimeoutHint"),
3119
+ type: "number",
3120
+ value: draft.attemptTimeoutMs,
3121
+ onChange: (value) => update({ attemptTimeoutMs: value })
3122
+ }),
3110
3123
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
3111
3124
  label: t("maxOutputTokens"),
3112
3125
  type: "number",
package/lib/index.d.ts CHANGED
@@ -44,6 +44,8 @@ interface Config {
44
44
  requestTimeoutMs?: number;
45
45
  /** Milliseconds a stream may stall; defaults to 300s. */
46
46
  streamIdleTimeoutMs?: number;
47
+ /** Whole-attempt budget; 0 disables the independent budget. */
48
+ attemptTimeoutMs?: number;
47
49
  /** Visible-model allowlist; empty with `showAllModels:false` means none. */
48
50
  visibleModels?: string[];
49
51
  /** Explicit all-models switch; absent means derive from `visibleModels`. */
@@ -102,6 +104,7 @@ interface ResolvedConfig {
102
104
  modelTransports: Readonly<Record<string, TransportId>>;
103
105
  requestTimeoutMs: number;
104
106
  streamIdleTimeoutMs: number;
107
+ attemptTimeoutMs: number;
105
108
  visibleModels: readonly string[];
106
109
  showAllModels: boolean;
107
110
  modelVisibility: Readonly<Record<string, boolean>>;
package/lib/index.js CHANGED
@@ -43,6 +43,33 @@ function bestEffortFailed(label, error) {
43
43
  sink?.debug?.(`${label}: ${error instanceof Error ? error.message : String(error)}`);
44
44
  } catch {}
45
45
  }
46
+ // src/attempt.ts
47
+ /** One abort/timeout budget for one attempt; callers create a fresh one per retry. */
48
+ function createAttemptBudget(timeoutMs, caller) {
49
+ const controller = new AbortController();
50
+ const budget = {
51
+ signal: controller.signal,
52
+ timedOut: false,
53
+ callerAborted: caller?.aborted === true,
54
+ dispose: () => {}
55
+ };
56
+ const onAbort = () => {
57
+ budget.callerAborted = true;
58
+ controller.abort(caller?.reason);
59
+ };
60
+ caller?.addEventListener("abort", onAbort, { once: true });
61
+ if (caller?.aborted === true) controller.abort(caller.reason);
62
+ const timer = timeoutMs !== void 0 && timeoutMs > 0 ? setTimeout(() => {
63
+ budget.timedOut = true;
64
+ controller.abort();
65
+ }, timeoutMs) : void 0;
66
+ timer?.unref?.();
67
+ budget.dispose = () => {
68
+ if (timer !== void 0) clearTimeout(timer);
69
+ caller?.removeEventListener("abort", onAbort);
70
+ };
71
+ return budget;
72
+ }
46
73
  // src/config.ts
47
74
  const NS = "llm-ollama-cloud";
48
75
  const DEFAULT_API_KEY_ENV = "OLLAMA_API_KEY";
@@ -50,7 +77,7 @@ const DEFAULT_API_BASE = "https://ollama.com";
50
77
  const DEFAULT_OPENAI_BASE = "https://ollama.com/v1";
51
78
  const DEFAULT_USAGE_URL = "https://ollama.com/api/usage";
52
79
  const DEFAULT_BALANCE_URL = "https://ollama.com/api/balance";
53
- const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.21";
80
+ const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.22";
54
81
  const DEFAULT_CONTEXT_WINDOW = 131072;
55
82
  const DEFAULT_MAX_TOKENS = 32768;
56
83
  const DEFAULT_GENERATE_MAX_TOKENS = 131072;
@@ -69,6 +96,7 @@ const Config = z.object({
69
96
  modelTransports: markVolatile(z.dict(z.union(["native", "openai-chat"])).default({})),
70
97
  requestTimeoutMs: markVolatile(z.number().min(1).max(2147483647).default(3e5)),
71
98
  streamIdleTimeoutMs: markVolatile(z.number().min(1).max(2147483647).default(3e5)),
99
+ attemptTimeoutMs: markVolatile(z.number().min(0).max(36e5).step(1).default(0)),
72
100
  visibleModels: markVolatile(z.array(z.string()).default([])),
73
101
  showAllModels: markVolatile(z.boolean()),
74
102
  modelVisibility: markVolatile(z.dict(z.boolean()).default({})),
@@ -202,6 +230,7 @@ function resolveConfig(config) {
202
230
  modelTransports: transportRecord(config.modelTransports),
203
231
  requestTimeoutMs: positiveInt(config.requestTimeoutMs, 3e5),
204
232
  streamIdleTimeoutMs: positiveInt(config.streamIdleTimeoutMs, 3e5),
233
+ attemptTimeoutMs: typeof config.attemptTimeoutMs === "number" && Number.isInteger(config.attemptTimeoutMs) && config.attemptTimeoutMs >= 0 && config.attemptTimeoutMs <= 36e5 ? config.attemptTimeoutMs : 0,
205
234
  visibleModels,
206
235
  showAllModels: config.showAllModels === true ? true : config.showAllModels === false ? false : visibleModels.length === 0,
207
236
  modelVisibility: booleanRecord(config.modelVisibility),
@@ -1246,8 +1275,14 @@ async function refreshCatalog(config, fetchImpl = fetch, force = false) {
1246
1275
  return refreshNow(config, fetchImpl, key, cached !== void 0, generation);
1247
1276
  }
1248
1277
  async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
1249
- const signal = AbortSignal.timeout(CATALOG_TIMEOUT_MS);
1250
- const [modelsResult, tagsResult] = await Promise.allSettled([fetchJson(modelsUrlFor(config), config, fetchImpl, signal), fetchJson(tagsUrlFor(config), config, fetchImpl, signal)]);
1278
+ const budget = createAttemptBudget(CATALOG_TIMEOUT_MS);
1279
+ let modelsResult;
1280
+ let tagsResult;
1281
+ try {
1282
+ [modelsResult, tagsResult] = await Promise.allSettled([fetchJson(modelsUrlFor(config), config, fetchImpl, budget.signal), fetchJson(tagsUrlFor(config), config, fetchImpl, budget.signal)]);
1283
+ } finally {
1284
+ budget.dispose();
1285
+ }
1251
1286
  if (epoch !== generation) return Object.keys(GENERATED_MODELS);
1252
1287
  if (modelsResult.status === "fulfilled") {
1253
1288
  const payload = modelsResult.value;
@@ -1426,6 +1461,41 @@ function classifyStreamError(value, status = 200) {
1426
1461
  if (value.error === void 0) return void 0;
1427
1462
  return classifyResponseError(status, JSON.stringify(value), new Headers());
1428
1463
  }
1464
+ // src/context-override.ts
1465
+ const overrides = /* @__PURE__ */ new Map();
1466
+ function sessionKey(sessionId) {
1467
+ return sessionId === void 0 || sessionId === null ? "" : String(sessionId);
1468
+ }
1469
+ function setContextOverride(sessionId, value) {
1470
+ overrides.set(sessionKey(sessionId), value);
1471
+ }
1472
+ function clearContextOverride(sessionId) {
1473
+ overrides.delete(sessionKey(sessionId));
1474
+ }
1475
+ function contextOverrideFor(sessionId) {
1476
+ return overrides.get(sessionKey(sessionId));
1477
+ }
1478
+ /** Session value wins; `follow` and an unset value use the configured num_ctx. */
1479
+ function effectiveNumCtx(config, sessionId) {
1480
+ const override = contextOverrideFor(sessionId);
1481
+ return typeof override === "number" ? override : config.numCtx;
1482
+ }
1483
+ function parseContextValue(raw) {
1484
+ const value = raw.trim().toLowerCase();
1485
+ if (value === "" || value === "status") return void 0;
1486
+ if (value === "follow") return "follow";
1487
+ if (value === "reset") return "reset";
1488
+ const match = /^(\d+)(k|m)?$/.exec(value);
1489
+ if (match === null) return void 0;
1490
+ const number = Number(match[1]) * (match[2] === "k" ? 1024 : match[2] === "m" ? 1048576 : 1);
1491
+ if (!Number.isInteger(number) || number < 1024 || number > 1e7) return void 0;
1492
+ return number;
1493
+ }
1494
+ function describeContext(config, sessionId) {
1495
+ const override = contextOverrideFor(sessionId);
1496
+ const effective = effectiveNumCtx(config, sessionId);
1497
+ return `Context: session=${override === void 0 ? "unset" : override === "follow" ? "follow" : `${override} tokens`}, effective=${effective === void 0 ? "model default" : `${effective} tokens`}`;
1498
+ }
1429
1499
  // src/images.ts
1430
1500
  const MAX_LONG_EDGE = 1568;
1431
1501
  const MAX_BYTES = 1048576;
@@ -1737,12 +1807,13 @@ function nativeThink(effort, model) {
1737
1807
  ].includes(effort) ? effort : void 0;
1738
1808
  }
1739
1809
  /** Build the native `/api/chat` request body for one model. */
1740
- function buildNativeBody(options, model, config, images) {
1810
+ function buildNativeBody(options, model, config, images, numCtxOverride) {
1741
1811
  const tools = buildTools(options.tools);
1742
1812
  const maxTokens = options.maxTokens ?? effectiveMaxTokens(model, config);
1743
1813
  const think = nativeThink(options.reasoningEffort === void 0 ? void 0 : String(options.reasoningEffort), model);
1744
1814
  const temperature = options.temperature ?? config.temperature;
1745
1815
  const stop = options.stop ?? config.stop;
1816
+ const numCtx = numCtxOverride ?? config.numCtx;
1746
1817
  const nativeOptions = {
1747
1818
  ...temperature === void 0 ? {} : { temperature },
1748
1819
  ...config.topK === void 0 ? {} : { top_k: config.topK },
@@ -1751,7 +1822,7 @@ function buildNativeBody(options, model, config, images) {
1751
1822
  ...config.seed === void 0 ? {} : { seed: config.seed },
1752
1823
  ...config.repeatPenalty === void 0 ? {} : { repeat_penalty: config.repeatPenalty },
1753
1824
  ...config.repeatLastN === void 0 ? {} : { repeat_last_n: config.repeatLastN },
1754
- ...config.numCtx === void 0 ? {} : { num_ctx: config.numCtx },
1825
+ ...numCtx === void 0 ? {} : { num_ctx: numCtx },
1755
1826
  ...maxTokens === void 0 || maxTokens <= 0 ? {} : { num_predict: maxTokens },
1756
1827
  ...stop === void 0 || stop.length === 0 ? {} : { stop }
1757
1828
  };
@@ -2768,7 +2839,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2768
2839
  tools: limited
2769
2840
  };
2770
2841
  }
2771
- const body = model.transport === "openai-chat" ? buildChatBody(bodyOptions, model, config, images) : buildNativeBody(bodyOptions, model, config, images);
2842
+ const body = model.transport === "openai-chat" ? buildChatBody(bodyOptions, model, config, images) : buildNativeBody(bodyOptions, model, config, images, effectiveNumCtx(config, options.sessionId));
2772
2843
  let lastError;
2773
2844
  let lastAccount = "default";
2774
2845
  let loggedAny = false;
@@ -2793,8 +2864,9 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2793
2864
  ...errorCode === void 0 ? {} : { error: errorCode }
2794
2865
  });
2795
2866
  };
2867
+ const budget = createAttemptBudget(config.attemptTimeoutMs, options.signal);
2796
2868
  try {
2797
- const response = await this.send(url, entry.key, model, body, config, options.signal);
2869
+ const response = await this.send(url, entry.key, model, body, config, budget.signal);
2798
2870
  if (!response.ok) {
2799
2871
  const text = await response.text().catch(() => "");
2800
2872
  const error = classifyResponseError(response.status, text, response.headers);
@@ -2826,7 +2898,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2826
2898
  fallback: false,
2827
2899
  ok: true
2828
2900
  });
2829
- const chunks = model.transport === "openai-chat" ? parseChatStream(response, config.streamIdleTimeoutMs, options.signal) : parseNativeStream(response, config.streamIdleTimeoutMs, options.signal);
2901
+ const chunks = model.transport === "openai-chat" ? parseChatStream(response, config.streamIdleTimeoutMs, budget.signal) : parseNativeStream(response, config.streamIdleTimeoutMs, budget.signal);
2830
2902
  for await (const chunk of chunks) {
2831
2903
  if (firstChunkAt === void 0) firstChunkAt = Date.now();
2832
2904
  started = true;
@@ -2835,9 +2907,9 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2835
2907
  logAttempt(true);
2836
2908
  return;
2837
2909
  } catch (error) {
2838
- const classified = error instanceof LlmError ? error : new LlmError(error instanceof Error ? error.message : "Ollama Cloud request failed", "TRANSPORT", { cause: error });
2910
+ const classified = budget.timedOut ? new LlmError(`Ollama Cloud attempt exceeded ${config.attemptTimeoutMs}ms`, "TIMEOUT", { cause: error }) : error instanceof LlmError ? error : new LlmError(error instanceof Error ? error.message : "Ollama Cloud request failed", "TRANSPORT", { cause: error });
2839
2911
  logAttempt(false, classified.code);
2840
- if (started || options.signal?.aborted === true) throw error;
2912
+ if (started || options.signal?.aborted === true) throw budget.timedOut ? classified : error;
2841
2913
  lastError = classified;
2842
2914
  const transient = this.isTransient(classified);
2843
2915
  const canRotate = index < keys.length - 1 && (transient || this.modelScoped(classified));
@@ -2849,6 +2921,8 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2849
2921
  }
2850
2922
  if (!responseFailure && (canRotate || credentialOrQuota)) this.markCooldown(entry.key, 0);
2851
2923
  if (!canRotate) throw classified;
2924
+ } finally {
2925
+ budget.dispose();
2852
2926
  }
2853
2927
  }
2854
2928
  const finalError = lastError ?? new LlmError("llm-ollama-cloud: every configured account is cooling down after provider rejections", "RATE_LIMIT");
@@ -3641,6 +3715,39 @@ function applyCommands(ctx, deps) {
3641
3715
  }
3642
3716
  }
3643
3717
  });
3718
+ ctx.commands.register({
3719
+ name: "ollama-context",
3720
+ description: "Set the native Ollama context size for this session",
3721
+ input: { hint: "status | 4k | 8k | 16k | 32k | 64k | 128k | <tokens> | follow | reset" },
3722
+ handler: async (invocation) => {
3723
+ const config = deps.config();
3724
+ const sessionId = invocation.agent.id;
3725
+ const raw = invocation.rawInput.trim();
3726
+ const value = parseContextValue(raw);
3727
+ if (raw !== "" && raw.toLowerCase() !== "status" && value === void 0) return {
3728
+ kind: "error",
3729
+ text: "Usage: /ollama-context status | 4k | 8k | 16k | 32k | 64k | 128k | <tokens> | follow | reset"
3730
+ };
3731
+ if (value === "reset") {
3732
+ clearContextOverride(sessionId);
3733
+ return {
3734
+ kind: "success",
3735
+ text: `${describeContext(config, sessionId)}\nSession override cleared.`
3736
+ };
3737
+ }
3738
+ if (value !== void 0) {
3739
+ setContextOverride(sessionId, value);
3740
+ return {
3741
+ kind: "success",
3742
+ text: describeContext(config, sessionId)
3743
+ };
3744
+ }
3745
+ return {
3746
+ kind: "success",
3747
+ text: describeContext(config, sessionId)
3748
+ };
3749
+ }
3750
+ });
3644
3751
  }
3645
3752
  // src/credentials.ts
3646
3753
  async function resolveRef(ctx, refName) {
@@ -4346,6 +4453,7 @@ function publicConfig(config) {
4346
4453
  modelTransports: config.modelTransports,
4347
4454
  requestTimeoutMs: config.requestTimeoutMs,
4348
4455
  streamIdleTimeoutMs: config.streamIdleTimeoutMs,
4456
+ attemptTimeoutMs: config.attemptTimeoutMs,
4349
4457
  visibleModels: config.visibleModels,
4350
4458
  showAllModels: config.showAllModels,
4351
4459
  modelVisibility: config.modelVisibility,
@@ -4686,6 +4794,7 @@ function configOps(patch) {
4686
4794
  if ("modelTransports" in patch) set("modelTransports", cleanTransports(patch.modelTransports));
4687
4795
  if ("requestTimeoutMs" in patch) set("requestTimeoutMs", patch.requestTimeoutMs);
4688
4796
  if ("streamIdleTimeoutMs" in patch) set("streamIdleTimeoutMs", patch.streamIdleTimeoutMs);
4797
+ if ("attemptTimeoutMs" in patch) set("attemptTimeoutMs", patch.attemptTimeoutMs);
4689
4798
  if ("visibleModels" in patch) set("visibleModels", cleanStringArray(patch.visibleModels));
4690
4799
  if ("showAllModels" in patch) set("showAllModels", patch.showAllModels === true);
4691
4800
  if ("modelVisibility" in patch) set("modelVisibility", cleanBooleanRecord(patch.modelVisibility));
@@ -5690,17 +5799,12 @@ function isRedirectFailure(error) {
5690
5799
  }
5691
5800
  return false;
5692
5801
  }
5693
- function abortReason(caller, own) {
5694
- if (caller?.aborted === true) return "caller";
5695
- return own.aborted ? "timeout" : void 0;
5696
- }
5697
5802
  async function postOnce(options, url, payload, caller) {
5698
5803
  const apiKey = await options.resolveApiKey();
5699
5804
  if (apiKey === void 0) throw new WebError("ollama-cloud web capabilities need an API key; configure the credential reference through plugin settings", "OLLAMA_WEB_MISSING_CREDENTIAL");
5700
5805
  const fetchImpl = options.fetch ?? fetch;
5701
5806
  const timeoutMs = options.timeoutMs ?? 15e3;
5702
- const own = AbortSignal.timeout(timeoutMs);
5703
- const signal = caller === void 0 ? own : AbortSignal.any([caller, own]);
5807
+ const budget = createAttemptBudget(timeoutMs, caller);
5704
5808
  let response;
5705
5809
  try {
5706
5810
  response = await fetchImpl(url, {
@@ -5712,17 +5816,18 @@ async function postOnce(options, url, payload, caller) {
5712
5816
  },
5713
5817
  body: JSON.stringify(payload),
5714
5818
  redirect: "error",
5715
- signal
5819
+ signal: budget.signal
5716
5820
  });
5717
5821
  } catch (error) {
5718
- const reason = abortReason(caller, own);
5719
- if (reason === "caller") throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
5720
- if (reason === "timeout") throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
5822
+ budget.dispose();
5823
+ if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
5824
+ if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
5721
5825
  if (isRedirectFailure(error)) throw new WebError(`${url} attempted a redirect`, "WEB_PROVIDER_ERROR", { cause: error });
5722
5826
  const detail = error instanceof Error && error.message !== "" ? `: ${error.message}` : "";
5723
5827
  throw new WebError(`could not reach ${url}${detail}`, "OLLAMA_WEB_TRANSPORT", { cause: error });
5724
5828
  }
5725
5829
  if (!response.ok) {
5830
+ budget.dispose();
5726
5831
  await response.body?.cancel();
5727
5832
  const hint = response.status === 401 || response.status === 403 ? "; check the API key" : "";
5728
5833
  throw new WebError(`${url} answered ${response.status}${hint}`, "WEB_PROVIDER_ERROR");
@@ -5733,7 +5838,11 @@ async function postOnce(options, url, payload, caller) {
5733
5838
  body: await response.json()
5734
5839
  };
5735
5840
  } catch (error) {
5841
+ if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
5842
+ if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
5736
5843
  throw new WebError(`${url} did not answer with JSON`, "OLLAMA_WEB_BAD_REPLY", { cause: error });
5844
+ } finally {
5845
+ budget.dispose();
5737
5846
  }
5738
5847
  }
5739
5848
  async function postJson(options, suffix, payload, caller) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-ollama-cloud-provider",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
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 tests/catalog-cache.test.ts tests/local-models.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 tests/local-models.test.ts tests/attempt.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"