@goodandready/dsh-ollama-cloud-provider 0.1.25 → 0.1.26
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 +11 -0
- package/README.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +40 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +153 -42
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.26 — 2026-11-05
|
|
4
|
+
|
|
5
|
+
- Added configurable pre-response retry/backoff (`retryMaxRetries`, base/max
|
|
6
|
+
delay, jitter). Only headers/pre-first-token failures retry; post-token
|
|
7
|
+
streams never retry, and account rotation is not duplicated.
|
|
8
|
+
- Sanitized endpoint URLs, provider errors, status errors and web errors:
|
|
9
|
+
userinfo and secret query parameters are stripped, control characters and
|
|
10
|
+
tokens are redacted, and long messages are bounded before logs/UI.
|
|
11
|
+
- Added retry/backoff and sanitizer tests, plus a 503 retry adapter test;
|
|
12
|
+
137/137.
|
|
13
|
+
|
|
3
14
|
## 0.1.25 — 2026-11-05
|
|
4
15
|
|
|
5
16
|
- Added safe model discovery against an unsaved endpoint with an optional
|
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.
|
|
140
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.26
|
|
141
141
|
# DSH Desktop:
|
|
142
|
-
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
142
|
+
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.26
|
|
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.
|
|
148
|
+
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.tgz
|
|
149
149
|
# DSH Desktop:
|
|
150
|
-
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
150
|
+
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.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.
|
|
106
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.26
|
|
107
107
|
# DSH Desktop:
|
|
108
|
-
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
108
|
+
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.26
|
|
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.
|
|
114
|
+
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.tgz
|
|
115
115
|
# DSH Desktop:
|
|
116
|
-
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
116
|
+
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.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.
|
|
105
|
+
dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.26
|
|
106
106
|
# DSH 桌面端:
|
|
107
|
-
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.
|
|
107
|
+
dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.26
|
|
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.
|
|
113
|
+
dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.tgz
|
|
114
114
|
# DSH 桌面端:
|
|
115
|
-
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.
|
|
115
|
+
dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.26.tgz
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
|
package/lib/client.js
CHANGED
|
@@ -122,6 +122,10 @@ window.__ModuleLoader__.load({
|
|
|
122
122
|
streamIdleTimeoutMs: "Stream idle timeout (ms)",
|
|
123
123
|
attemptTimeoutMs: "Attempt budget (ms, 0 = off)",
|
|
124
124
|
attemptTimeoutHint: "Whole-attempt timeout; a fresh budget is created for every retry.",
|
|
125
|
+
retryMaxRetries: "Retry attempts",
|
|
126
|
+
retryBaseDelayMs: "Retry base delay (ms)",
|
|
127
|
+
retryMaxDelayMs: "Retry max delay (ms)",
|
|
128
|
+
retryJitter: "Retry jitter (0–1)",
|
|
125
129
|
maxOutputTokens: "Output limit (0 = provider default)",
|
|
126
130
|
contextWindow: "Context window override",
|
|
127
131
|
discover: "Discover draft endpoint",
|
|
@@ -369,6 +373,10 @@ window.__ModuleLoader__.load({
|
|
|
369
373
|
streamIdleTimeoutMs: "流空闲超时(毫秒)",
|
|
370
374
|
attemptTimeoutMs: "单次尝试预算(毫秒,0 = 关闭)",
|
|
371
375
|
attemptTimeoutHint: "整次尝试超时;每次重试都会创建新的预算。",
|
|
376
|
+
retryMaxRetries: "重试次数",
|
|
377
|
+
retryBaseDelayMs: "重试基础延迟(毫秒)",
|
|
378
|
+
retryMaxDelayMs: "重试最大延迟(毫秒)",
|
|
379
|
+
retryJitter: "重试抖动(0–1)",
|
|
372
380
|
maxOutputTokens: "输出上限(0 = 提供方默认)",
|
|
373
381
|
contextWindow: "上下文窗口覆盖",
|
|
374
382
|
discover: "发现草稿端点",
|
|
@@ -1732,6 +1740,10 @@ window.__ModuleLoader__.load({
|
|
|
1732
1740
|
requestTimeoutMs: String(state.config.requestTimeoutMs),
|
|
1733
1741
|
streamIdleTimeoutMs: String(state.config.streamIdleTimeoutMs),
|
|
1734
1742
|
attemptTimeoutMs: String(state.config.attemptTimeoutMs ?? 0),
|
|
1743
|
+
retryMaxRetries: String(state.config.retryMaxRetries ?? 0),
|
|
1744
|
+
retryBaseDelayMs: String(state.config.retryBaseDelayMs ?? 250),
|
|
1745
|
+
retryMaxDelayMs: String(state.config.retryMaxDelayMs ?? 2e3),
|
|
1746
|
+
retryJitter: String(state.config.retryJitter ?? .2),
|
|
1735
1747
|
maxOutputTokens: textOf(state.config.maxOutputTokens),
|
|
1736
1748
|
contextWindow: textOf(state.config.contextWindow),
|
|
1737
1749
|
temperature: textOf(state.config.temperature),
|
|
@@ -1814,6 +1826,10 @@ window.__ModuleLoader__.load({
|
|
|
1814
1826
|
requestTimeoutMs: numberOrNull(draft.requestTimeoutMs) ?? 3e5,
|
|
1815
1827
|
streamIdleTimeoutMs: numberOrNull(draft.streamIdleTimeoutMs) ?? 3e5,
|
|
1816
1828
|
attemptTimeoutMs: boundedNumber(draft.attemptTimeoutMs, 0, 36e5, true) ?? 0,
|
|
1829
|
+
retryMaxRetries: boundedNumber(draft.retryMaxRetries, 0, 10, true) ?? 0,
|
|
1830
|
+
retryBaseDelayMs: boundedNumber(draft.retryBaseDelayMs, 0, 6e4, true) ?? 250,
|
|
1831
|
+
retryMaxDelayMs: boundedNumber(draft.retryMaxDelayMs, 0, 12e4, true) ?? 2e3,
|
|
1832
|
+
retryJitter: boundedNumber(draft.retryJitter, 0, 1, false) ?? .2,
|
|
1817
1833
|
maxOutputTokens: numberOrNull(draft.maxOutputTokens),
|
|
1818
1834
|
contextWindow: numberOrNull(draft.contextWindow),
|
|
1819
1835
|
temperature: boundedNumber(draft.temperature, 0, 2, false),
|
|
@@ -3717,6 +3733,30 @@ window.__ModuleLoader__.load({
|
|
|
3717
3733
|
value: draft.attemptTimeoutMs,
|
|
3718
3734
|
onChange: (value) => update({ attemptTimeoutMs: value })
|
|
3719
3735
|
}),
|
|
3736
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
3737
|
+
label: t("retryMaxRetries"),
|
|
3738
|
+
type: "number",
|
|
3739
|
+
value: draft.retryMaxRetries,
|
|
3740
|
+
onChange: (value) => update({ retryMaxRetries: value })
|
|
3741
|
+
}),
|
|
3742
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
3743
|
+
label: t("retryBaseDelayMs"),
|
|
3744
|
+
type: "number",
|
|
3745
|
+
value: draft.retryBaseDelayMs,
|
|
3746
|
+
onChange: (value) => update({ retryBaseDelayMs: value })
|
|
3747
|
+
}),
|
|
3748
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
3749
|
+
label: t("retryMaxDelayMs"),
|
|
3750
|
+
type: "number",
|
|
3751
|
+
value: draft.retryMaxDelayMs,
|
|
3752
|
+
onChange: (value) => update({ retryMaxDelayMs: value })
|
|
3753
|
+
}),
|
|
3754
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
3755
|
+
label: t("retryJitter"),
|
|
3756
|
+
type: "number",
|
|
3757
|
+
value: draft.retryJitter,
|
|
3758
|
+
onChange: (value) => update({ retryJitter: value })
|
|
3759
|
+
}),
|
|
3720
3760
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
|
|
3721
3761
|
label: t("maxOutputTokens"),
|
|
3722
3762
|
type: "number",
|
package/lib/index.d.ts
CHANGED
|
@@ -66,6 +66,12 @@ interface Config {
|
|
|
66
66
|
streamIdleTimeoutMs?: number;
|
|
67
67
|
/** Whole-attempt budget; 0 disables the independent budget. */
|
|
68
68
|
attemptTimeoutMs?: number;
|
|
69
|
+
/** Pre-response retry count; 0 disables internal retries. */
|
|
70
|
+
retryMaxRetries?: number;
|
|
71
|
+
retryBaseDelayMs?: number;
|
|
72
|
+
retryMaxDelayMs?: number;
|
|
73
|
+
/** Jitter fraction, 0..1. */
|
|
74
|
+
retryJitter?: number;
|
|
69
75
|
/** Visible-model allowlist; empty with `showAllModels:false` means none. */
|
|
70
76
|
visibleModels?: string[];
|
|
71
77
|
/** Explicit all-models switch; absent means derive from `visibleModels`. */
|
|
@@ -131,6 +137,10 @@ interface ResolvedConfig {
|
|
|
131
137
|
requestTimeoutMs: number;
|
|
132
138
|
streamIdleTimeoutMs: number;
|
|
133
139
|
attemptTimeoutMs: number;
|
|
140
|
+
retryMaxRetries: number;
|
|
141
|
+
retryBaseDelayMs: number;
|
|
142
|
+
retryMaxDelayMs: number;
|
|
143
|
+
retryJitter: number;
|
|
134
144
|
visibleModels: readonly string[];
|
|
135
145
|
showAllModels: boolean;
|
|
136
146
|
modelVisibility: Readonly<Record<string, boolean>>;
|
package/lib/index.js
CHANGED
|
@@ -33,14 +33,59 @@ function orderKeysForModel(keys, model, rules) {
|
|
|
33
33
|
if (preferred === void 0) return keys;
|
|
34
34
|
return [preferred, ...keys.filter((entry) => entry !== preferred)];
|
|
35
35
|
}
|
|
36
|
+
// src/sanitize.ts
|
|
37
|
+
const SECRET_QUERY = /* @__PURE__ */ new Set([
|
|
38
|
+
"api_key",
|
|
39
|
+
"apikey",
|
|
40
|
+
"key",
|
|
41
|
+
"token",
|
|
42
|
+
"access_token",
|
|
43
|
+
"refresh_token",
|
|
44
|
+
"password",
|
|
45
|
+
"passwd",
|
|
46
|
+
"secret",
|
|
47
|
+
"client_secret",
|
|
48
|
+
"sig",
|
|
49
|
+
"signature",
|
|
50
|
+
"credential",
|
|
51
|
+
"code",
|
|
52
|
+
"auth"
|
|
53
|
+
]);
|
|
54
|
+
const MAX_TEXT = 300;
|
|
55
|
+
function redactText(value, max = MAX_TEXT) {
|
|
56
|
+
let text = value.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, "").replace(/\r?\n/g, " ").replace(/\s+/g, " ").trim();
|
|
57
|
+
text = text.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, "Bearer [redacted]").replace(/\bsk-[A-Za-z0-9_-]{8,}\b/g, "sk-[redacted]").replace(/\b(api[_-]?key|token|secret|password|authorization)\s*[:=]\s*[^\s&,"']+/gi, "$1=[redacted]");
|
|
58
|
+
return text.length > max ? `${text.slice(0, Math.max(0, max - 1))}…` : text;
|
|
59
|
+
}
|
|
60
|
+
function sanitizeUrl(raw) {
|
|
61
|
+
try {
|
|
62
|
+
const url = new URL(raw);
|
|
63
|
+
url.username = "";
|
|
64
|
+
url.password = "";
|
|
65
|
+
url.hash = "";
|
|
66
|
+
for (const key of [...url.searchParams.keys()]) if (SECRET_QUERY.has(key.toLowerCase())) url.searchParams.delete(key);
|
|
67
|
+
return url.toString().replace(/\/$/, "");
|
|
68
|
+
} catch {
|
|
69
|
+
return redactText(raw);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function safeErrorMessage(error, fallback = "request failed") {
|
|
73
|
+
const text = error instanceof Error ? error.message : typeof error === "string" ? error : fallback;
|
|
74
|
+
return redactText(text === "" ? fallback : text);
|
|
75
|
+
}
|
|
36
76
|
// src/best-effort.ts
|
|
77
|
+
/**
|
|
78
|
+
* One place for deliberately ignored failures. Every call names what was
|
|
79
|
+
* skipped; when a host logger is registered the label and message go to debug
|
|
80
|
+
* instead of disappearing.
|
|
81
|
+
*/
|
|
37
82
|
let sink;
|
|
38
83
|
function setBestEffortLogger(logger) {
|
|
39
84
|
sink = logger;
|
|
40
85
|
}
|
|
41
86
|
function bestEffortFailed(label, error) {
|
|
42
87
|
try {
|
|
43
|
-
sink?.debug?.(`${label}: ${error instanceof Error ? error.message : String(error)}`);
|
|
88
|
+
sink?.debug?.(`${label}: ${redactText(error instanceof Error ? error.message : String(error))}`);
|
|
44
89
|
} catch {}
|
|
45
90
|
}
|
|
46
91
|
// src/attempt.ts
|
|
@@ -77,7 +122,7 @@ const DEFAULT_API_BASE = "https://ollama.com";
|
|
|
77
122
|
const DEFAULT_OPENAI_BASE = "https://ollama.com/v1";
|
|
78
123
|
const DEFAULT_USAGE_URL = "https://ollama.com/api/usage";
|
|
79
124
|
const DEFAULT_BALANCE_URL = "https://ollama.com/api/balance";
|
|
80
|
-
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.
|
|
125
|
+
const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.26";
|
|
81
126
|
const DEFAULT_CONTEXT_WINDOW = 131072;
|
|
82
127
|
const DEFAULT_MAX_TOKENS = 32768;
|
|
83
128
|
const DEFAULT_GENERATE_MAX_TOKENS = 131072;
|
|
@@ -97,6 +142,10 @@ const Config = z.object({
|
|
|
97
142
|
requestTimeoutMs: markVolatile(z.number().min(1).max(2147483647).default(3e5)),
|
|
98
143
|
streamIdleTimeoutMs: markVolatile(z.number().min(1).max(2147483647).default(3e5)),
|
|
99
144
|
attemptTimeoutMs: markVolatile(z.number().min(0).max(36e5).step(1).default(0)),
|
|
145
|
+
retryMaxRetries: markVolatile(z.number().min(0).max(10).step(1).default(0)),
|
|
146
|
+
retryBaseDelayMs: markVolatile(z.number().min(0).max(6e4).step(1).default(250)),
|
|
147
|
+
retryMaxDelayMs: markVolatile(z.number().min(0).max(12e4).step(1).default(2e3)),
|
|
148
|
+
retryJitter: markVolatile(z.number().min(0).max(1).default(.2)),
|
|
100
149
|
visibleModels: markVolatile(z.array(z.string()).default([])),
|
|
101
150
|
showAllModels: markVolatile(z.boolean()),
|
|
102
151
|
modelVisibility: markVolatile(z.dict(z.boolean()).default({})),
|
|
@@ -305,6 +354,10 @@ function resolveConfig(config) {
|
|
|
305
354
|
requestTimeoutMs: positiveInt(config.requestTimeoutMs, 3e5),
|
|
306
355
|
streamIdleTimeoutMs: positiveInt(config.streamIdleTimeoutMs, 3e5),
|
|
307
356
|
attemptTimeoutMs: typeof config.attemptTimeoutMs === "number" && Number.isInteger(config.attemptTimeoutMs) && config.attemptTimeoutMs >= 0 && config.attemptTimeoutMs <= 36e5 ? config.attemptTimeoutMs : 0,
|
|
357
|
+
retryMaxRetries: typeof config.retryMaxRetries === "number" && Number.isInteger(config.retryMaxRetries) && config.retryMaxRetries >= 0 && config.retryMaxRetries <= 10 ? config.retryMaxRetries : 0,
|
|
358
|
+
retryBaseDelayMs: positiveInt(config.retryBaseDelayMs, 250),
|
|
359
|
+
retryMaxDelayMs: positiveInt(config.retryMaxDelayMs, 2e3),
|
|
360
|
+
retryJitter: typeof config.retryJitter === "number" && config.retryJitter >= 0 && config.retryJitter <= 1 ? config.retryJitter : .2,
|
|
308
361
|
visibleModels,
|
|
309
362
|
showAllModels: config.showAllModels === true ? true : config.showAllModels === false ? false : visibleModels.length === 0,
|
|
310
363
|
modelVisibility: booleanRecord(config.modelVisibility),
|
|
@@ -1535,7 +1588,7 @@ function isQuotaText(detail) {
|
|
|
1535
1588
|
*/
|
|
1536
1589
|
function classifyResponseError(status, text, headers) {
|
|
1537
1590
|
const body = parseErrorBody(text);
|
|
1538
|
-
const message = body.message ?? (text.trim() === "" ? `HTTP ${status}` : text.trim().slice(0, 500));
|
|
1591
|
+
const message = redactText(body.message ?? (text.trim() === "" ? `HTTP ${status}` : text.trim().slice(0, 500)));
|
|
1539
1592
|
const detail = `${body.type ?? ""} ${message}`.toLowerCase();
|
|
1540
1593
|
const retry = retryAfterMs(headers);
|
|
1541
1594
|
const options = {
|
|
@@ -2042,6 +2095,27 @@ function buildChatBody(options, model, config, images) {
|
|
|
2042
2095
|
...stop === void 0 || stop.length === 0 ? {} : { stop }
|
|
2043
2096
|
};
|
|
2044
2097
|
}
|
|
2098
|
+
// src/retry.ts
|
|
2099
|
+
function retryPolicy(value) {
|
|
2100
|
+
const integer = (number, fallback) => typeof number === "number" && Number.isInteger(number) && number >= 0 ? number : fallback;
|
|
2101
|
+
const jitter = typeof value.retryJitter === "number" && value.retryJitter >= 0 && value.retryJitter <= 1 ? value.retryJitter : .2;
|
|
2102
|
+
const baseDelayMs = integer(value.retryBaseDelayMs, 250);
|
|
2103
|
+
return {
|
|
2104
|
+
maxRetries: integer(value.retryMaxRetries, 0),
|
|
2105
|
+
baseDelayMs,
|
|
2106
|
+
maxDelayMs: Math.max(baseDelayMs, integer(value.retryMaxDelayMs, 2e3)),
|
|
2107
|
+
jitter
|
|
2108
|
+
};
|
|
2109
|
+
}
|
|
2110
|
+
function retryDelay(attempt, policy, random = Math.random) {
|
|
2111
|
+
const exponential = policy.baseDelayMs * 2 ** Math.max(0, attempt);
|
|
2112
|
+
const capped = Math.min(policy.maxDelayMs, exponential);
|
|
2113
|
+
const spread = capped * policy.jitter;
|
|
2114
|
+
return Math.max(0, Math.round(capped - spread + random() * spread * 2));
|
|
2115
|
+
}
|
|
2116
|
+
function isRetryableStatus(status) {
|
|
2117
|
+
return status === 408 || status === 429 || status >= 500;
|
|
2118
|
+
}
|
|
2045
2119
|
// src/provider-ids.ts
|
|
2046
2120
|
/** Provider route owned by this plugin. */
|
|
2047
2121
|
const PROVIDER = "ollama-cloud";
|
|
@@ -3012,7 +3086,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
|
|
|
3012
3086
|
logAttempt(true);
|
|
3013
3087
|
return;
|
|
3014
3088
|
} catch (error) {
|
|
3015
|
-
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 });
|
|
3089
|
+
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 ? redactText(error.message) : "Ollama Cloud request failed", "TRANSPORT", { cause: error });
|
|
3016
3090
|
logAttempt(false, classified.code);
|
|
3017
3091
|
if (started || options.signal?.aborted === true) throw budget.timedOut ? classified : error;
|
|
3018
3092
|
lastError = classified;
|
|
@@ -3128,29 +3202,53 @@ var OllamaCloudAdapter = class extends LlmAdapter {
|
|
|
3128
3202
|
accept: model.transport === "openai-chat" ? "text/event-stream" : "application/x-ndjson",
|
|
3129
3203
|
"user-agent": config.userAgent
|
|
3130
3204
|
};
|
|
3131
|
-
const
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
controller
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3205
|
+
const policy = retryPolicy(config);
|
|
3206
|
+
const wait = async (attempt) => {
|
|
3207
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt, policy)));
|
|
3208
|
+
signal?.throwIfAborted();
|
|
3209
|
+
};
|
|
3210
|
+
for (let attempt = 0;; attempt += 1) {
|
|
3211
|
+
const controller = new AbortController();
|
|
3212
|
+
let timedOut = false;
|
|
3213
|
+
const onAbort = () => controller.abort(signal?.reason);
|
|
3214
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
3215
|
+
const timer = setTimeout(() => {
|
|
3216
|
+
timedOut = true;
|
|
3217
|
+
controller.abort();
|
|
3218
|
+
}, config.requestTimeoutMs);
|
|
3219
|
+
timer.unref?.();
|
|
3220
|
+
try {
|
|
3221
|
+
const response = await this.fetchImpl(url, {
|
|
3222
|
+
method: "POST",
|
|
3223
|
+
headers,
|
|
3224
|
+
body: JSON.stringify(body),
|
|
3225
|
+
signal: controller.signal
|
|
3226
|
+
});
|
|
3227
|
+
if (attempt < policy.maxRetries && isRetryableStatus(response.status)) {
|
|
3228
|
+
await response.body?.cancel();
|
|
3229
|
+
await wait(attempt);
|
|
3230
|
+
continue;
|
|
3231
|
+
}
|
|
3232
|
+
return response;
|
|
3233
|
+
} catch (error) {
|
|
3234
|
+
if (signal?.aborted === true) throw signal.reason ?? error;
|
|
3235
|
+
if (timedOut) {
|
|
3236
|
+
const timeout = new LlmError(`Ollama Cloud did not return response headers within ${config.requestTimeoutMs}ms`, "TIMEOUT", { cause: error });
|
|
3237
|
+
if (attempt < policy.maxRetries) {
|
|
3238
|
+
await wait(attempt);
|
|
3239
|
+
continue;
|
|
3240
|
+
}
|
|
3241
|
+
throw timeout;
|
|
3242
|
+
}
|
|
3243
|
+
if (attempt < policy.maxRetries) {
|
|
3244
|
+
await wait(attempt);
|
|
3245
|
+
continue;
|
|
3246
|
+
}
|
|
3247
|
+
throw error;
|
|
3248
|
+
} finally {
|
|
3249
|
+
clearTimeout(timer);
|
|
3250
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3251
|
+
}
|
|
3154
3252
|
}
|
|
3155
3253
|
}
|
|
3156
3254
|
keyId(key) {
|
|
@@ -3625,7 +3723,7 @@ async function modelsText(deps) {
|
|
|
3625
3723
|
return `- ${model.id} · ${tags.join(" · ")}`;
|
|
3626
3724
|
}).join("\n");
|
|
3627
3725
|
} catch (error) {
|
|
3628
|
-
return `Models unavailable: ${
|
|
3726
|
+
return `Models unavailable: ${safeErrorMessage(error)}`;
|
|
3629
3727
|
}
|
|
3630
3728
|
}
|
|
3631
3729
|
async function testText(deps, model) {
|
|
@@ -3658,7 +3756,7 @@ async function testText(deps, model) {
|
|
|
3658
3756
|
} catch (error) {
|
|
3659
3757
|
return {
|
|
3660
3758
|
ok: false,
|
|
3661
|
-
text: `${model}: failed — ${
|
|
3759
|
+
text: `${model}: failed — ${safeErrorMessage(error)}`
|
|
3662
3760
|
};
|
|
3663
3761
|
}
|
|
3664
3762
|
}
|
|
@@ -3809,7 +3907,7 @@ function applyCommands(ctx, deps) {
|
|
|
3809
3907
|
} catch (error) {
|
|
3810
3908
|
return {
|
|
3811
3909
|
kind: "error",
|
|
3812
|
-
text: error
|
|
3910
|
+
text: safeErrorMessage(error, "local command failed")
|
|
3813
3911
|
};
|
|
3814
3912
|
}
|
|
3815
3913
|
}
|
|
@@ -4566,7 +4664,7 @@ function normalizeBase(raw) {
|
|
|
4566
4664
|
}
|
|
4567
4665
|
if (url.protocol !== "http:" && url.protocol !== "https:") throw new DiscoveryError("endpoint must use http or https");
|
|
4568
4666
|
if (url.username !== "" || url.password !== "") throw new DiscoveryError("endpoint URL must not contain credentials");
|
|
4569
|
-
return value;
|
|
4667
|
+
return sanitizeUrl(value);
|
|
4570
4668
|
}
|
|
4571
4669
|
function isLoopback(url) {
|
|
4572
4670
|
try {
|
|
@@ -4630,15 +4728,19 @@ async function discoverModels(rawBase, key, fetchImpl = fetch) {
|
|
|
4630
4728
|
function publicConfig(config) {
|
|
4631
4729
|
return {
|
|
4632
4730
|
apiKeyEnv: config.apiKeyEnv,
|
|
4633
|
-
apiBase: config.apiBase,
|
|
4634
|
-
openAiBase: config.openAiBase,
|
|
4635
|
-
usageUrl: config.usageUrl,
|
|
4636
|
-
balanceUrl: config.balanceUrl,
|
|
4731
|
+
apiBase: sanitizeUrl(config.apiBase),
|
|
4732
|
+
openAiBase: sanitizeUrl(config.openAiBase),
|
|
4733
|
+
usageUrl: sanitizeUrl(config.usageUrl),
|
|
4734
|
+
balanceUrl: sanitizeUrl(config.balanceUrl),
|
|
4637
4735
|
transport: config.transport,
|
|
4638
4736
|
modelTransports: config.modelTransports,
|
|
4639
4737
|
requestTimeoutMs: config.requestTimeoutMs,
|
|
4640
4738
|
streamIdleTimeoutMs: config.streamIdleTimeoutMs,
|
|
4641
4739
|
attemptTimeoutMs: config.attemptTimeoutMs,
|
|
4740
|
+
retryMaxRetries: config.retryMaxRetries,
|
|
4741
|
+
retryBaseDelayMs: config.retryBaseDelayMs,
|
|
4742
|
+
retryMaxDelayMs: config.retryMaxDelayMs,
|
|
4743
|
+
retryJitter: config.retryJitter,
|
|
4642
4744
|
visibleModels: config.visibleModels,
|
|
4643
4745
|
showAllModels: config.showAllModels,
|
|
4644
4746
|
modelVisibility: config.modelVisibility,
|
|
@@ -4708,7 +4810,7 @@ async function probeService(config, fetchImpl = fetch) {
|
|
|
4708
4810
|
status: null,
|
|
4709
4811
|
latencyMs: Date.now() - started,
|
|
4710
4812
|
checkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4711
|
-
error: controller.signal.aborted ? "timeout" :
|
|
4813
|
+
error: controller.signal.aborted ? "timeout" : safeErrorMessage(error)
|
|
4712
4814
|
};
|
|
4713
4815
|
} finally {
|
|
4714
4816
|
clearTimeout(timer);
|
|
@@ -4843,10 +4945,14 @@ function cleanPrices(value) {
|
|
|
4843
4945
|
// src/routes.ts
|
|
4844
4946
|
const MAX_BODY_BYTES = 262144;
|
|
4845
4947
|
function json(res, status, value) {
|
|
4948
|
+
const safe = typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.error === "string" ? {
|
|
4949
|
+
...value,
|
|
4950
|
+
error: safeErrorMessage(value.error)
|
|
4951
|
+
} : value;
|
|
4846
4952
|
res.statusCode = status;
|
|
4847
4953
|
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
4848
4954
|
res.setHeader("cache-control", "no-store");
|
|
4849
|
-
res.end(JSON.stringify(
|
|
4955
|
+
res.end(JSON.stringify(safe));
|
|
4850
4956
|
}
|
|
4851
4957
|
function sourceHost(value) {
|
|
4852
4958
|
if (value === void 0 || value === "") return void 0;
|
|
@@ -5030,6 +5136,10 @@ function configOps(patch) {
|
|
|
5030
5136
|
if ("requestTimeoutMs" in patch) set("requestTimeoutMs", patch.requestTimeoutMs);
|
|
5031
5137
|
if ("streamIdleTimeoutMs" in patch) set("streamIdleTimeoutMs", patch.streamIdleTimeoutMs);
|
|
5032
5138
|
if ("attemptTimeoutMs" in patch) set("attemptTimeoutMs", patch.attemptTimeoutMs);
|
|
5139
|
+
if ("retryMaxRetries" in patch) set("retryMaxRetries", patch.retryMaxRetries);
|
|
5140
|
+
if ("retryBaseDelayMs" in patch) set("retryBaseDelayMs", patch.retryBaseDelayMs);
|
|
5141
|
+
if ("retryMaxDelayMs" in patch) set("retryMaxDelayMs", patch.retryMaxDelayMs);
|
|
5142
|
+
if ("retryJitter" in patch) set("retryJitter", patch.retryJitter);
|
|
5033
5143
|
if ("visibleModels" in patch) set("visibleModels", cleanStringArray(patch.visibleModels));
|
|
5034
5144
|
if ("showAllModels" in patch) set("showAllModels", patch.showAllModels === true);
|
|
5035
5145
|
if ("modelVisibility" in patch) set("modelVisibility", cleanBooleanRecord(patch.modelVisibility));
|
|
@@ -6062,6 +6172,7 @@ async function postOnce(options, url, payload, caller) {
|
|
|
6062
6172
|
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");
|
|
6063
6173
|
const fetchImpl = options.fetch ?? fetch;
|
|
6064
6174
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
6175
|
+
const safeUrl = sanitizeUrl(url);
|
|
6065
6176
|
const budget = createAttemptBudget(timeoutMs, caller);
|
|
6066
6177
|
let response;
|
|
6067
6178
|
try {
|
|
@@ -6080,15 +6191,15 @@ async function postOnce(options, url, payload, caller) {
|
|
|
6080
6191
|
budget.dispose();
|
|
6081
6192
|
if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
|
|
6082
6193
|
if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
|
|
6083
|
-
if (isRedirectFailure(error)) throw new WebError(`${
|
|
6084
|
-
const detail = error instanceof Error && error.message !== "" ? `: ${error.message}` : "";
|
|
6085
|
-
throw new WebError(`could not reach ${
|
|
6194
|
+
if (isRedirectFailure(error)) throw new WebError(`${safeUrl} attempted a redirect`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
6195
|
+
const detail = error instanceof Error && error.message !== "" ? `: ${redactText(error.message)}` : "";
|
|
6196
|
+
throw new WebError(`could not reach ${safeUrl}${detail}`, "OLLAMA_WEB_TRANSPORT", { cause: error });
|
|
6086
6197
|
}
|
|
6087
6198
|
if (!response.ok) {
|
|
6088
6199
|
budget.dispose();
|
|
6089
6200
|
await response.body?.cancel();
|
|
6090
6201
|
const hint = response.status === 401 || response.status === 403 ? "; check the API key" : "";
|
|
6091
|
-
throw new WebError(`${
|
|
6202
|
+
throw new WebError(`${safeUrl} answered ${response.status}${hint}`, "WEB_PROVIDER_ERROR");
|
|
6092
6203
|
}
|
|
6093
6204
|
try {
|
|
6094
6205
|
return {
|
|
@@ -6098,7 +6209,7 @@ async function postOnce(options, url, payload, caller) {
|
|
|
6098
6209
|
} catch (error) {
|
|
6099
6210
|
if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
|
|
6100
6211
|
if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
|
|
6101
|
-
throw new WebError(`${
|
|
6212
|
+
throw new WebError(`${safeUrl} did not answer with JSON`, "OLLAMA_WEB_BAD_REPLY", { cause: error });
|
|
6102
6213
|
} finally {
|
|
6103
6214
|
budget.dispose();
|
|
6104
6215
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-ollama-cloud-provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
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 tests/attempt.test.ts tests/model-groups.test.tsx tests/discovery.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 tests/model-groups.test.tsx tests/discovery.test.ts tests/sanitize.test.ts tests/retry.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"
|