@goodandready/dsh-ollama-cloud-provider 0.1.37 → 0.1.39
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 +21 -0
- package/README.md +13 -6
- package/README.ru.md +13 -6
- package/README.zh.md +13 -6
- package/lib/account-rules.js +26 -0
- package/lib/adapter.d.ts +92 -0
- package/lib/adapter.js +566 -0
- package/lib/analytics.d.ts +81 -0
- package/lib/analytics.js +314 -0
- package/lib/attempt.js +29 -0
- package/lib/best-effort.js +20 -0
- package/lib/catalog-cache.js +81 -0
- package/lib/catalog.d.ts +10 -0
- package/lib/catalog.js +309 -0
- package/lib/commands.d.ts +14 -0
- package/lib/commands.js +228 -0
- package/lib/config.d.ts +173 -0
- package/lib/config.js +280 -0
- package/lib/context-override.js +38 -0
- package/lib/credentials.d.ts +23 -0
- package/lib/credentials.js +105 -0
- package/lib/discovery.js +108 -0
- package/lib/endpoints.js +58 -0
- package/lib/errors.d.ts +9 -0
- package/lib/errors.js +72 -0
- package/lib/files.js +13 -0
- package/lib/images.js +78 -0
- package/lib/index.d.ts +10 -521
- package/lib/index.js +20 -5921
- package/lib/local-host.js +47 -0
- package/lib/messages.js +263 -0
- package/lib/models.generated.d.ts +26 -0
- package/lib/models.generated.js +499 -0
- package/lib/plugin-updater.js +320 -0
- package/lib/pricing.js +78 -0
- package/lib/provider-ids.d.ts +4 -0
- package/lib/provider-ids.js +9 -0
- package/lib/quota-model.js +66 -0
- package/lib/reasoning.js +71 -0
- package/lib/request-log.d.ts +38 -0
- package/lib/request-log.js +203 -0
- package/lib/retry.js +24 -0
- package/lib/route-guard.js +25 -0
- package/lib/routes-public.js +59 -0
- package/lib/routes-values.js +129 -0
- package/lib/routes.d.ts +28 -0
- package/lib/routes.js +733 -0
- package/lib/routing.js +20 -0
- package/lib/sanitize.js +43 -0
- package/lib/status.js +60 -0
- package/lib/tool-schema.js +109 -0
- package/lib/tools.js +38 -0
- package/lib/transports/native.js +156 -0
- package/lib/transports/ndjson.js +73 -0
- package/lib/transports/openai-chat.js +278 -0
- package/lib/transports/sse.js +57 -0
- package/lib/transports/tool-call-id.js +17 -0
- package/lib/tui-settings.js +246 -0
- package/lib/usage.d.ts +69 -0
- package/lib/usage.js +277 -0
- package/lib/web.js +143 -0
- package/package.json +6 -5
package/lib/usage.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { PROVIDER } from "./provider-ids.js";
|
|
2
|
+
import { isRetryableStatus, retryDelay, retryPolicy } from "./retry.js";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
// src/usage.ts
|
|
5
|
+
const BALANCE_TTL_MS = 6e4;
|
|
6
|
+
const USAGE_TTL_MS = 12e4;
|
|
7
|
+
const FAILURE_TTL_MS = 3e4;
|
|
8
|
+
const USAGE_TIMEOUT_MS = 2e4;
|
|
9
|
+
/** `/api/usage` is limited to 10 requests per minute per user. */
|
|
10
|
+
const USAGE_WINDOW_MS = 6e4;
|
|
11
|
+
const USAGE_WINDOW_LIMIT = 9;
|
|
12
|
+
function obj(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
14
|
+
}
|
|
15
|
+
function num(value) {
|
|
16
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
17
|
+
}
|
|
18
|
+
function str(value) {
|
|
19
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
20
|
+
}
|
|
21
|
+
function fingerprint(key) {
|
|
22
|
+
return createHash("sha256").update(key).digest("hex").slice(0, 16);
|
|
23
|
+
}
|
|
24
|
+
function totalsOf(value) {
|
|
25
|
+
const raw = obj(value);
|
|
26
|
+
return {
|
|
27
|
+
requests: num(raw.request_count),
|
|
28
|
+
usd: num(raw.usage_usd),
|
|
29
|
+
inputTokens: num(raw.input_tokens),
|
|
30
|
+
cachedInputTokens: num(raw.cached_input_tokens),
|
|
31
|
+
outputTokens: num(raw.output_tokens)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function legacyWindow(value) {
|
|
35
|
+
const raw = obj(value);
|
|
36
|
+
if (raw.remaining_percent === void 0 && raw.percent === void 0) return void 0;
|
|
37
|
+
const remaining = num(raw.remaining_percent);
|
|
38
|
+
const used = raw.remaining_percent === void 0 ? num(raw.percent) : 100 - remaining;
|
|
39
|
+
const resets = str(raw.resets_at) ?? str(raw.resetsAt);
|
|
40
|
+
const status = str(raw.status);
|
|
41
|
+
return {
|
|
42
|
+
percentUsed: Math.max(0, Math.min(100, used)),
|
|
43
|
+
...status === void 0 ? {} : { status },
|
|
44
|
+
...resets === void 0 ? {} : { resetsAt: resets }
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function normalizeBalance(payload) {
|
|
48
|
+
const included = obj(obj(payload).included);
|
|
49
|
+
const purchased = obj(obj(payload).purchased);
|
|
50
|
+
const allowance = num(included.allowance_usd);
|
|
51
|
+
const remaining = num(included.balance_usd);
|
|
52
|
+
if (included.allowance_usd !== void 0 || included.balance_usd !== void 0) {
|
|
53
|
+
const period = obj(included.period);
|
|
54
|
+
return {
|
|
55
|
+
kind: "credits",
|
|
56
|
+
credits: {
|
|
57
|
+
includedRemaining: remaining,
|
|
58
|
+
includedAllowance: allowance,
|
|
59
|
+
purchased: num(purchased.balance_usd),
|
|
60
|
+
...str(period.from) === void 0 ? {} : { periodFrom: str(period.from) },
|
|
61
|
+
...str(period.until) === void 0 ? {} : { periodUntil: str(period.until) }
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const fiveHour = legacyWindow(included.session);
|
|
66
|
+
const weekly = legacyWindow(included.weekly);
|
|
67
|
+
return {
|
|
68
|
+
kind: "legacy",
|
|
69
|
+
legacy: {
|
|
70
|
+
...fiveHour === void 0 ? {} : { fiveHour },
|
|
71
|
+
...weekly === void 0 ? {} : { weekly }
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function normalizeUsage(payload, range) {
|
|
76
|
+
const root = obj(payload);
|
|
77
|
+
const groups = [];
|
|
78
|
+
for (const entry of Array.isArray(root.groups) ? root.groups : []) {
|
|
79
|
+
const outer = obj(entry);
|
|
80
|
+
const inner = Object.keys(obj(outer.group)).length > 0 ? obj(outer.group) : outer;
|
|
81
|
+
const model = str(inner.model) ?? str(outer.model) ?? str(inner.name) ?? str(outer.name);
|
|
82
|
+
if (model === void 0) continue;
|
|
83
|
+
groups.push({
|
|
84
|
+
model,
|
|
85
|
+
...totalsOf(inner)
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
totals: totalsOf(root.totals),
|
|
90
|
+
byModel: groups.sort((a, b) => b.usd - a.usd)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Cached reader for Ollama Cloud balance and usage. Fail-open by design. */
|
|
94
|
+
function createUsageReader(config, resolveKey, fetchImpl = fetch) {
|
|
95
|
+
const cache = /* @__PURE__ */ new Map();
|
|
96
|
+
const lastGood = /* @__PURE__ */ new Map();
|
|
97
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
98
|
+
const usageCalls = [];
|
|
99
|
+
let generation = 0;
|
|
100
|
+
const keyFor = async (explicit) => {
|
|
101
|
+
if (explicit !== void 0 && explicit !== "") return explicit;
|
|
102
|
+
try {
|
|
103
|
+
return (await resolveKey(PROVIDER)).key;
|
|
104
|
+
} catch {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const cached = (key) => {
|
|
109
|
+
const hit = cache.get(key);
|
|
110
|
+
if (hit === void 0) return void 0;
|
|
111
|
+
const ttl = hit.report === void 0 ? FAILURE_TTL_MS : USAGE_TTL_MS;
|
|
112
|
+
return Date.now() - hit.checkedAt < ttl ? hit : void 0;
|
|
113
|
+
};
|
|
114
|
+
const request = async (url, key) => {
|
|
115
|
+
const current = config();
|
|
116
|
+
const policy = retryPolicy({
|
|
117
|
+
...current,
|
|
118
|
+
retryMaxRetries: Math.max(2, current.retryMaxRetries)
|
|
119
|
+
});
|
|
120
|
+
for (let attempt = 0;; attempt += 1) {
|
|
121
|
+
let response;
|
|
122
|
+
try {
|
|
123
|
+
response = await fetchImpl(url, {
|
|
124
|
+
headers: {
|
|
125
|
+
authorization: `Bearer ${key}`,
|
|
126
|
+
accept: "application/json",
|
|
127
|
+
"user-agent": current.userAgent
|
|
128
|
+
},
|
|
129
|
+
signal: AbortSignal.timeout(USAGE_TIMEOUT_MS)
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (attempt < policy.maxRetries) {
|
|
133
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt, policy)));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
if (attempt < policy.maxRetries && isRetryableStatus(response.status)) {
|
|
139
|
+
await response.body?.cancel();
|
|
140
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay(attempt, policy)));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
return response;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const readBalance = async (key) => {
|
|
147
|
+
if (key === "") return void 0;
|
|
148
|
+
const current = config();
|
|
149
|
+
try {
|
|
150
|
+
const response = await request(current.balanceUrl, key);
|
|
151
|
+
if (!response.ok) return void 0;
|
|
152
|
+
return normalizeBalance(await response.json());
|
|
153
|
+
} catch {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const readUsage = async (key, range, epoch) => {
|
|
158
|
+
if (key === "") return void 0;
|
|
159
|
+
const current = config();
|
|
160
|
+
const cacheKey = `${fingerprint(key)}:${range}`;
|
|
161
|
+
const hit = cached(cacheKey);
|
|
162
|
+
if (hit !== void 0) {
|
|
163
|
+
if (hit.report === void 0) return void 0;
|
|
164
|
+
const totals = hit.report.windows[range === "24h" ? "d24" : range === "7d" ? "d7" : "d30"];
|
|
165
|
+
return totals === void 0 ? void 0 : {
|
|
166
|
+
totals,
|
|
167
|
+
byModel: hit.report.byModel
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const now = Date.now();
|
|
171
|
+
const recent = usageCalls.filter((at) => now - at < USAGE_WINDOW_MS);
|
|
172
|
+
if (recent.length >= USAGE_WINDOW_LIMIT) return void 0;
|
|
173
|
+
recent.push(now);
|
|
174
|
+
usageCalls.length = 0;
|
|
175
|
+
usageCalls.push(...recent);
|
|
176
|
+
try {
|
|
177
|
+
const url = new URL(current.usageUrl);
|
|
178
|
+
url.searchParams.set("range", range);
|
|
179
|
+
url.searchParams.set("group_by", "model");
|
|
180
|
+
const response = await request(url.toString(), key);
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
if (epoch === generation) cache.set(cacheKey, {
|
|
183
|
+
error: `usage endpoint returned HTTP ${response.status}`,
|
|
184
|
+
checkedAt: Date.now()
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
return normalizeUsage(await response.json(), range);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (epoch === generation) cache.set(cacheKey, {
|
|
191
|
+
error: error instanceof Error ? error.message : "usage request failed",
|
|
192
|
+
checkedAt: Date.now()
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const compose = async (key, range, epoch) => {
|
|
198
|
+
const [balance, usage] = await Promise.all([readBalance(key), readUsage(key, range, epoch)]);
|
|
199
|
+
const reportKey = `${fingerprint(key)}:report:${range}`;
|
|
200
|
+
if (balance === void 0 && usage === void 0) {
|
|
201
|
+
const result = {
|
|
202
|
+
error: "usage and balance are unavailable",
|
|
203
|
+
checkedAt: Date.now()
|
|
204
|
+
};
|
|
205
|
+
const previous = lastGood.get(reportKey);
|
|
206
|
+
if (epoch === generation) cache.set(reportKey, result);
|
|
207
|
+
return previous === void 0 ? result : {
|
|
208
|
+
...previous,
|
|
209
|
+
stale: true,
|
|
210
|
+
...result.error === void 0 ? {} : { error: result.error }
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const windowKey = range === "24h" ? "d24" : range === "7d" ? "d7" : "d30";
|
|
214
|
+
const result = {
|
|
215
|
+
report: {
|
|
216
|
+
kind: balance?.kind ?? "credits",
|
|
217
|
+
...balance?.credits === void 0 ? {} : { credits: balance.credits },
|
|
218
|
+
...balance?.legacy === void 0 ? {} : { legacy: balance.legacy },
|
|
219
|
+
windows: usage === void 0 ? {} : {
|
|
220
|
+
[windowKey]: usage.totals,
|
|
221
|
+
...range === "24h" ? { session: usage.totals } : {},
|
|
222
|
+
...range === "7d" ? { weekly: usage.totals } : {},
|
|
223
|
+
...range === "30d" ? { monthly: usage.totals } : {}
|
|
224
|
+
},
|
|
225
|
+
byModel: usage?.byModel ?? [],
|
|
226
|
+
...usage === void 0 ? {} : { byWindow: { [range]: usage.byModel } },
|
|
227
|
+
range
|
|
228
|
+
},
|
|
229
|
+
checkedAt: Date.now()
|
|
230
|
+
};
|
|
231
|
+
if (epoch === generation) {
|
|
232
|
+
cache.set(reportKey, result);
|
|
233
|
+
if (usage !== void 0) {
|
|
234
|
+
cache.set(`${fingerprint(key)}:${range}`, result);
|
|
235
|
+
lastGood.set(reportKey, result);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
};
|
|
240
|
+
const reader = async (range, explicitKey) => {
|
|
241
|
+
const key = await keyFor(explicitKey);
|
|
242
|
+
if (key === void 0) return {
|
|
243
|
+
error: "no credential",
|
|
244
|
+
checkedAt: Date.now()
|
|
245
|
+
};
|
|
246
|
+
const cacheKey = `${fingerprint(key)}:report:${range}`;
|
|
247
|
+
const hit = cache.get(cacheKey);
|
|
248
|
+
const ttl = hit?.report === void 0 ? FAILURE_TTL_MS : BALANCE_TTL_MS;
|
|
249
|
+
if (hit !== void 0 && Date.now() - hit.checkedAt < ttl) {
|
|
250
|
+
if (hit.report === void 0) {
|
|
251
|
+
const previous = lastGood.get(cacheKey);
|
|
252
|
+
if (previous !== void 0) return {
|
|
253
|
+
...previous,
|
|
254
|
+
stale: true,
|
|
255
|
+
...hit.error === void 0 ? {} : { error: hit.error }
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return hit;
|
|
259
|
+
}
|
|
260
|
+
const existing = inflight.get(cacheKey);
|
|
261
|
+
if (existing !== void 0) return existing;
|
|
262
|
+
const task = compose(key, range, generation).finally(() => inflight.delete(cacheKey));
|
|
263
|
+
inflight.set(cacheKey, task);
|
|
264
|
+
return task;
|
|
265
|
+
};
|
|
266
|
+
reader.read = (key) => reader("7d", key);
|
|
267
|
+
reader.usage = (range, key) => reader(range, key);
|
|
268
|
+
reader.clear = () => {
|
|
269
|
+
generation += 1;
|
|
270
|
+
cache.clear();
|
|
271
|
+
inflight.clear();
|
|
272
|
+
};
|
|
273
|
+
return reader;
|
|
274
|
+
}
|
|
275
|
+
export { createUsageReader, normalizeBalance, normalizeUsage };
|
|
276
|
+
|
|
277
|
+
//# sourceMappingURL=usage.js.map
|
package/lib/web.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { createAttemptBudget } from "./attempt.js";
|
|
2
|
+
import { redactText, sanitizeUrl } from "./sanitize.js";
|
|
3
|
+
import { WebError } from "@deepseek-ai/dsh-web";
|
|
4
|
+
// src/web.ts
|
|
5
|
+
const OLLAMA_WEB_PROVIDER_ID = "ollama-cloud";
|
|
6
|
+
const MAX_FETCH_CHARS = 262144;
|
|
7
|
+
const WEB_TIMEOUT_MS = 15e3;
|
|
8
|
+
function decodeSearchResponse(body) {
|
|
9
|
+
const results = body?.results;
|
|
10
|
+
if (!Array.isArray(results)) throw new WebError("ollama-cloud web search answered without a \"results\" array", "OLLAMA_WEB_BAD_REPLY");
|
|
11
|
+
const sources = [];
|
|
12
|
+
for (const entry of results) {
|
|
13
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
14
|
+
const record = entry;
|
|
15
|
+
if (typeof record.url !== "string" || record.url === "") continue;
|
|
16
|
+
sources.push({
|
|
17
|
+
url: record.url,
|
|
18
|
+
...typeof record.title === "string" && record.title !== "" ? { title: record.title } : {},
|
|
19
|
+
...typeof record.content === "string" && record.content !== "" ? { snippet: record.content } : {}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
sources,
|
|
24
|
+
truncated: false
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function decodeFetchResponse(body) {
|
|
28
|
+
const content = body?.content;
|
|
29
|
+
if (typeof content !== "string") throw new WebError("ollama-cloud web fetch answered without text \"content\"", "OLLAMA_WEB_BAD_REPLY");
|
|
30
|
+
return content.length > 262144 ? {
|
|
31
|
+
content: content.slice(0, MAX_FETCH_CHARS),
|
|
32
|
+
truncated: true
|
|
33
|
+
} : {
|
|
34
|
+
content,
|
|
35
|
+
truncated: false
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function isRedirectFailure(error) {
|
|
39
|
+
let current = error;
|
|
40
|
+
while (current instanceof Error) {
|
|
41
|
+
if (/redirect/i.test(current.message)) return true;
|
|
42
|
+
current = current.cause;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
async function postOnce(options, url, payload, caller) {
|
|
47
|
+
const apiKey = await options.resolveApiKey();
|
|
48
|
+
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");
|
|
49
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
50
|
+
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
51
|
+
const safeUrl = sanitizeUrl(url);
|
|
52
|
+
const budget = createAttemptBudget(timeoutMs, caller);
|
|
53
|
+
let response;
|
|
54
|
+
try {
|
|
55
|
+
response = await fetchImpl(url, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
"content-type": "application/json",
|
|
59
|
+
accept: "application/json",
|
|
60
|
+
...apiKey === "" ? {} : { authorization: `Bearer ${apiKey}` }
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify(payload),
|
|
63
|
+
redirect: "error",
|
|
64
|
+
signal: budget.signal
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
budget.dispose();
|
|
68
|
+
if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
|
|
69
|
+
if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
|
|
70
|
+
if (isRedirectFailure(error)) throw new WebError(`${safeUrl} attempted a redirect`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
71
|
+
const detail = error instanceof Error && error.message !== "" ? `: ${redactText(error.message)}` : "";
|
|
72
|
+
throw new WebError(`could not reach ${safeUrl}${detail}`, "OLLAMA_WEB_TRANSPORT", { cause: error });
|
|
73
|
+
}
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
budget.dispose();
|
|
76
|
+
await response.body?.cancel();
|
|
77
|
+
const hint = response.status === 401 || response.status === 403 ? "; check the API key" : "";
|
|
78
|
+
throw new WebError(`${safeUrl} answered ${response.status}${hint}`, "WEB_PROVIDER_ERROR");
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return {
|
|
82
|
+
status: response.status,
|
|
83
|
+
body: await response.json()
|
|
84
|
+
};
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (budget.callerAborted) throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
|
|
87
|
+
if (budget.timedOut) throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
|
|
88
|
+
throw new WebError(`${safeUrl} did not answer with JSON`, "OLLAMA_WEB_BAD_REPLY", { cause: error });
|
|
89
|
+
} finally {
|
|
90
|
+
budget.dispose();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function postJson(options, suffix, payload, caller) {
|
|
94
|
+
const base = options.baseURL().replace(/\/+$/, "");
|
|
95
|
+
if (!URL.canParse(base)) throw new WebError("ollama-cloud web capabilities need a valid API base URL", "WEB_PROVIDER_ERROR");
|
|
96
|
+
const url = `${base}${suffix}`;
|
|
97
|
+
try {
|
|
98
|
+
return await postOnce(options, url, payload, caller);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (!(error instanceof WebError && (error.code === "OLLAMA_WEB_TIMEOUT" || error.code === "OLLAMA_WEB_TRANSPORT")) || caller?.aborted === true) throw error;
|
|
101
|
+
}
|
|
102
|
+
return postOnce(options, url, payload, caller);
|
|
103
|
+
}
|
|
104
|
+
var OllamaWebEndpoint = class {
|
|
105
|
+
options;
|
|
106
|
+
id = OLLAMA_WEB_PROVIDER_ID;
|
|
107
|
+
constructor(options) {
|
|
108
|
+
this.options = options;
|
|
109
|
+
}
|
|
110
|
+
available() {
|
|
111
|
+
return URL.canParse(this.options.baseURL());
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var OllamaWebSearchProvider = class extends OllamaWebEndpoint {
|
|
115
|
+
async search(request, signal) {
|
|
116
|
+
const { body } = await postJson(this.options, "/api/web_search", {
|
|
117
|
+
query: request.query,
|
|
118
|
+
...request.maxResults === void 0 ? {} : { max_results: Math.min(request.maxResults, 10) }
|
|
119
|
+
}, signal);
|
|
120
|
+
return decodeSearchResponse(body);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var OllamaWebFetchProvider = class extends OllamaWebEndpoint {
|
|
124
|
+
async fetch(request, signal) {
|
|
125
|
+
if (!URL.canParse(request.url)) throw new WebError("invalid web fetch URL", "INVALID_URL");
|
|
126
|
+
const parsed = new URL(request.url);
|
|
127
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new WebError("only http: and https: protocols are supported for web fetch", "UNSUPPORTED_PROTOCOL");
|
|
128
|
+
const { status, body } = await postJson(this.options, "/api/web_fetch", { url: request.url }, signal);
|
|
129
|
+
const decoded = decodeFetchResponse(body);
|
|
130
|
+
return {
|
|
131
|
+
url: request.url,
|
|
132
|
+
statusCode: status,
|
|
133
|
+
body: {
|
|
134
|
+
kind: "text",
|
|
135
|
+
content: decoded.content
|
|
136
|
+
},
|
|
137
|
+
truncated: decoded.truncated
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
export { MAX_FETCH_CHARS, OLLAMA_WEB_PROVIDER_ID, OllamaWebFetchProvider, OllamaWebSearchProvider, WEB_TIMEOUT_MS, decodeFetchResponse, decodeSearchResponse };
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=web.js.map
|
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.39",
|
|
4
4
|
"description": "Ollama Cloud LLM provider plugin for DeepSeek Harness (dsh).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -73,10 +73,11 @@
|
|
|
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 tests/tool-call-id.test.ts",
|
|
77
|
-
"check": "npm run typecheck && npm test && npm run build",
|
|
78
|
-
"release": "npm run check && npm pack",
|
|
79
|
-
"sync:models": "node scripts/sync-models.mjs"
|
|
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 tests/deploy-script.test.ts tests/endpoints.test.ts tests/route-guard.test.ts",
|
|
77
|
+
"check": "npm run typecheck && npm test && npm run build && npm run pack:check",
|
|
78
|
+
"release": "npm run check && mkdir -p dist && npm pack --pack-destination dist",
|
|
79
|
+
"sync:models": "node scripts/sync-models.mjs",
|
|
80
|
+
"pack:check": "node scripts/pack-check.mjs"
|
|
80
81
|
},
|
|
81
82
|
"keywords": [
|
|
82
83
|
"dsh",
|