@goodandready/dsh-ollama-cloud-provider 0.1.26 → 0.1.27

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.27 — 2026-11-05
4
+
5
+ - Usage reader keeps the last good snapshot per key/range and returns it as
6
+ `stale` when balance and usage later fail; the card marks stale data instead
7
+ of losing the meters.
8
+ - Usage requests retry transient/429/5xx failures with bounded backoff.
9
+ - Added session/weekly/monthly aliases and per-window model activity
10
+ (`byWindow`) alongside the existing 24h/7d/30d windows and sidebar meters.
11
+ - Added last-good, retry and window tests; 138/138.
12
+
3
13
  ## 0.1.26 — 2026-11-05
4
14
 
5
15
  - Added configurable pre-response retry/backoff (`retryMaxRetries`, base/max
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.26
140
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.27
141
141
  # DSH Desktop:
142
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.26
142
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.27
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.26.tgz
148
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.27.tgz
149
149
  # DSH Desktop:
150
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.tgz
150
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.27.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.26
106
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.27
107
107
  # DSH Desktop:
108
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.26
108
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.27
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.26.tgz
114
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.27.tgz
115
115
  # DSH Desktop:
116
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.tgz
116
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.27.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.26
105
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.27
106
106
  # DSH 桌面端:
107
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.26
107
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.27
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.26.tgz
113
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.27.tgz
114
114
  # DSH 桌面端:
115
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.tgz
115
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.27.tgz
116
116
  ```
117
117
 
118
118
  安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
package/lib/client.js CHANGED
@@ -40,6 +40,7 @@ window.__ModuleLoader__.load({
40
40
  quotaCardName: "Ollama Cloud",
41
41
  noUsage: "No quota data",
42
42
  usageError: "Quota unavailable",
43
+ lastGoodUsage: "Showing the last good usage snapshot.",
43
44
  quotaHint: "Balance and usage come from the official /api/balance and /api/usage endpoints. Spend is metered in dollars, not requests.",
44
45
  quotaExhausted: "Included credits are nearly exhausted.",
45
46
  quotaWarning: "More than 80% of the included credits are used.",
@@ -291,6 +292,7 @@ window.__ModuleLoader__.load({
291
292
  quotaCardName: "Ollama Cloud",
292
293
  noUsage: "没有配额数据",
293
294
  usageError: "配额不可用",
295
+ lastGoodUsage: "正在显示上次可用的用量快照。",
294
296
  quotaHint: "余额和用量来自官方 /api/balance 与 /api/usage。费用按美元计量,而不是按请求数。",
295
297
  quotaExhausted: "包含额度即将用完。",
296
298
  quotaWarning: "已使用超过 80% 的包含额度。",
@@ -1377,7 +1379,7 @@ window.__ModuleLoader__.load({
1377
1379
  const worst = worstUsedPercent(report);
1378
1380
  const plan = state?.config.planLabel?.trim() ?? "";
1379
1381
  const name = plan === "" ? t("quotaCardName") : `${t("quotaCardName")} · ${plan}`;
1380
- const detail = bars.map((entry) => `${entry.labelKey === void 0 ? entry.label : t(entry.labelKey)}: ${entry.remainingPercent.toFixed(0)}% ${t("remaining")}`).join(" · ");
1382
+ const detail = bars.map((entry) => `${entry.labelKey === void 0 ? entry.label : t(entry.labelKey)}: ${entry.remainingPercent.toFixed(0)}% ${t("remaining")}`).join(" · ") + (state?.usage?.stale === true ? ` · ${t("lastGoodUsage")}` : "");
1381
1383
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1382
1384
  type: "button",
1383
1385
  className: "ocl-foot",
@@ -1460,6 +1462,7 @@ window.__ModuleLoader__.load({
1460
1462
  const bars = quotaBars(activeReport);
1461
1463
  const rows = windowRows(activeReport);
1462
1464
  const activeAccount = state?.accounts.find((account) => account.active);
1465
+ const stale = usage?.stale === true || state?.usage?.stale === true;
1463
1466
  const refresh = () => {
1464
1467
  setBusy(true);
1465
1468
  refreshState().then(() => load()).finally(() => setBusy(false));
@@ -1551,6 +1554,10 @@ window.__ModuleLoader__.load({
1551
1554
  usage.error
1552
1555
  ]
1553
1556
  }),
1557
+ stale ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1558
+ className: "ocl-notice",
1559
+ children: t("lastGoodUsage")
1560
+ }) : null,
1554
1561
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageBars, {
1555
1562
  bars,
1556
1563
  t
package/lib/index.d.ts CHANGED
@@ -345,16 +345,23 @@ interface UsageReport {
345
345
  d24?: UsageTotals;
346
346
  d7?: UsageTotals;
347
347
  d30?: UsageTotals;
348
+ session?: UsageTotals;
349
+ weekly?: UsageTotals;
350
+ monthly?: UsageTotals;
348
351
  };
349
352
  byModel: Array<{
350
353
  model: string;
351
354
  } & UsageTotals>;
355
+ byWindow?: Partial<Record<UsageRange, Array<{
356
+ model: string;
357
+ } & UsageTotals>>>;
352
358
  range: UsageRange;
353
359
  }
354
360
  interface UsageResult {
355
361
  report?: UsageReport;
356
362
  error?: string;
357
363
  checkedAt: number;
364
+ stale?: boolean;
358
365
  }
359
366
  interface UsageReader {
360
367
  /** Balance plus the 7-day spend window for one key. */
package/lib/index.js CHANGED
@@ -122,7 +122,7 @@ const DEFAULT_API_BASE = "https://ollama.com";
122
122
  const DEFAULT_OPENAI_BASE = "https://ollama.com/v1";
123
123
  const DEFAULT_USAGE_URL = "https://ollama.com/api/usage";
124
124
  const DEFAULT_BALANCE_URL = "https://ollama.com/api/balance";
125
- const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.26";
125
+ const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.27";
126
126
  const DEFAULT_CONTEXT_WINDOW = 131072;
127
127
  const DEFAULT_MAX_TOKENS = 32768;
128
128
  const DEFAULT_GENERATE_MAX_TOKENS = 131072;
@@ -5991,6 +5991,7 @@ function normalizeUsage(payload, range) {
5991
5991
  /** Cached reader for Ollama Cloud balance and usage. Fail-open by design. */
5992
5992
  function createUsageReader(config, resolveKey, fetchImpl = fetch) {
5993
5993
  const cache = /* @__PURE__ */ new Map();
5994
+ const lastGood = /* @__PURE__ */ new Map();
5994
5995
  const inflight = /* @__PURE__ */ new Map();
5995
5996
  const usageCalls = [];
5996
5997
  let generation = 0;
@@ -6010,14 +6011,35 @@ function createUsageReader(config, resolveKey, fetchImpl = fetch) {
6010
6011
  };
6011
6012
  const request = async (url, key) => {
6012
6013
  const current = config();
6013
- return fetchImpl(url, {
6014
- headers: {
6015
- authorization: `Bearer ${key}`,
6016
- accept: "application/json",
6017
- "user-agent": current.userAgent
6018
- },
6019
- signal: AbortSignal.timeout(USAGE_TIMEOUT_MS)
6014
+ const policy = retryPolicy({
6015
+ ...current,
6016
+ retryMaxRetries: Math.max(2, current.retryMaxRetries)
6020
6017
  });
6018
+ for (let attempt = 0;; attempt += 1) {
6019
+ let response;
6020
+ try {
6021
+ response = await fetchImpl(url, {
6022
+ headers: {
6023
+ authorization: `Bearer ${key}`,
6024
+ accept: "application/json",
6025
+ "user-agent": current.userAgent
6026
+ },
6027
+ signal: AbortSignal.timeout(USAGE_TIMEOUT_MS)
6028
+ });
6029
+ } catch (error) {
6030
+ if (attempt < policy.maxRetries) {
6031
+ await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt, policy)));
6032
+ continue;
6033
+ }
6034
+ throw error;
6035
+ }
6036
+ if (attempt < policy.maxRetries && isRetryableStatus(response.status)) {
6037
+ await response.body?.cancel();
6038
+ await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt, policy)));
6039
+ continue;
6040
+ }
6041
+ return response;
6042
+ }
6021
6043
  };
6022
6044
  const readBalance = async (key) => {
6023
6045
  if (key === "") return void 0;
@@ -6072,32 +6094,44 @@ function createUsageReader(config, resolveKey, fetchImpl = fetch) {
6072
6094
  };
6073
6095
  const compose = async (key, range, epoch) => {
6074
6096
  const [balance, usage] = await Promise.all([readBalance(key), readUsage(key, range, epoch)]);
6097
+ const reportKey = `${fingerprint(key)}:report:${range}`;
6075
6098
  if (balance === void 0 && usage === void 0) {
6076
6099
  const result = {
6077
6100
  error: "usage and balance are unavailable",
6078
6101
  checkedAt: Date.now()
6079
6102
  };
6080
- if (epoch === generation) cache.set(`${fingerprint(key)}:report:${range}`, result);
6081
- return result;
6103
+ const previous = lastGood.get(reportKey);
6104
+ if (epoch === generation) cache.set(reportKey, result);
6105
+ return previous === void 0 ? result : {
6106
+ ...previous,
6107
+ stale: true,
6108
+ ...result.error === void 0 ? {} : { error: result.error }
6109
+ };
6082
6110
  }
6111
+ const windowKey = range === "24h" ? "d24" : range === "7d" ? "d7" : "d30";
6083
6112
  const result = {
6084
6113
  report: {
6085
6114
  kind: balance?.kind ?? "credits",
6086
6115
  ...balance?.credits === void 0 ? {} : { credits: balance.credits },
6087
6116
  ...balance?.legacy === void 0 ? {} : { legacy: balance.legacy },
6088
6117
  windows: usage === void 0 ? {} : {
6089
- ...range === "24h" ? { d24: usage.totals } : {},
6090
- ...range === "7d" ? { d7: usage.totals } : {},
6091
- ...range === "30d" ? { d30: usage.totals } : {}
6118
+ [windowKey]: usage.totals,
6119
+ ...range === "24h" ? { session: usage.totals } : {},
6120
+ ...range === "7d" ? { weekly: usage.totals } : {},
6121
+ ...range === "30d" ? { monthly: usage.totals } : {}
6092
6122
  },
6093
6123
  byModel: usage?.byModel ?? [],
6124
+ ...usage === void 0 ? {} : { byWindow: { [range]: usage.byModel } },
6094
6125
  range
6095
6126
  },
6096
6127
  checkedAt: Date.now()
6097
6128
  };
6098
6129
  if (epoch === generation) {
6099
- cache.set(`${fingerprint(key)}:report:${range}`, result);
6100
- if (usage !== void 0) cache.set(`${fingerprint(key)}:${range}`, result);
6130
+ cache.set(reportKey, result);
6131
+ if (usage !== void 0) {
6132
+ cache.set(`${fingerprint(key)}:${range}`, result);
6133
+ lastGood.set(reportKey, result);
6134
+ }
6101
6135
  }
6102
6136
  return result;
6103
6137
  };
@@ -6110,7 +6144,17 @@ function createUsageReader(config, resolveKey, fetchImpl = fetch) {
6110
6144
  const cacheKey = `${fingerprint(key)}:report:${range}`;
6111
6145
  const hit = cache.get(cacheKey);
6112
6146
  const ttl = hit?.report === void 0 ? FAILURE_TTL_MS : BALANCE_TTL_MS;
6113
- if (hit !== void 0 && Date.now() - hit.checkedAt < ttl) return hit;
6147
+ if (hit !== void 0 && Date.now() - hit.checkedAt < ttl) {
6148
+ if (hit.report === void 0) {
6149
+ const previous = lastGood.get(cacheKey);
6150
+ if (previous !== void 0) return {
6151
+ ...previous,
6152
+ stale: true,
6153
+ ...hit.error === void 0 ? {} : { error: hit.error }
6154
+ };
6155
+ }
6156
+ return hit;
6157
+ }
6114
6158
  const existing = inflight.get(cacheKey);
6115
6159
  if (existing !== void 0) return existing;
6116
6160
  const task = compose(key, range, generation).finally(() => inflight.delete(cacheKey));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-ollama-cloud-provider",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "Ollama Cloud LLM provider plugin for DeepSeek Harness (dsh).",
5
5
  "license": "MIT",
6
6
  "type": "module",