@goodandready/dsh-ollama-cloud-provider 0.1.16 → 0.1.18

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,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.18 — 2026-11-05
4
+
5
+ - Added local/self-hosted Ollama mode: an explicit empty `apiKeyEnv` means no
6
+ authentication. Native and OpenAI requests omit `Authorization`, the key pool
7
+ returns a synthetic empty credential, and usage/balance requests are skipped.
8
+ - `/api/show` probing enriches local model discovery with context window,
9
+ vision, tools and thinking capabilities; successful probes are cached for five
10
+ minutes and cleared with the catalog cache or explicitly.
11
+ - Catalog discovery now falls back to `/api/tags` ids when `/v1/models` is
12
+ empty and adopts `/api/show` metadata for local endpoints.
13
+ - Added local-mode, probe-cache and no-auth tests; 109/109 tests.
14
+
15
+ ## 0.1.17 — 2026-11-05
16
+
17
+ - Added Ollama web capabilities behind `ctx.web`: a search provider and a fetch
18
+ provider with id `ollama-cloud`, using `POST /api/web_search` and
19
+ `POST /api/web_fetch` with the configured credential.
20
+ - Web requests fail closed on redirects, use a 15s per-attempt timeout, retry
21
+ one pre-response transport/timeout failure, cap search results at 10 and
22
+ bound fetched bodies at 256 KiB with a `truncated` result.
23
+ - Registered the providers only when the `web` service exists; selecting them is
24
+ a profile policy (`web.searchProvider` / `web.fetchProvider`).
25
+ - Added a deterministic mock Ollama contract server and tests for
26
+ `/api/tags`, `/api/show`, `/api/chat`, `/api/web_search` and `/api/web_fetch`.
27
+
3
28
  ## 0.1.16 — 2026-11-04
4
29
 
5
30
  - Added DSH 0.2.2 support: `0.2.2-alpha.2`, `0.2.2-alpha.3` and `0.2.2-rc.1`
package/README.md CHANGED
@@ -35,6 +35,39 @@ It registers one native LLM route, `ollama-cloud`, served by `https://ollama.com
35
35
 
36
36
  Requests resolve the key per call, so a changed credential reaches the next request without a restart.
37
37
 
38
+ ## Web search and fetch
39
+
40
+ When the `web` service is present, the plugin registers Ollama Cloud as both a
41
+ search and a fetch provider (`id: ollama-cloud`). It calls
42
+ `POST <apiBase>/api/web_search` and `POST <apiBase>/api/web_fetch` with the same
43
+ credential reference as chat. Requests fail closed on redirects, retry one
44
+ transport/timeout failure, cap search results at 10 and fetched text at 256 KiB.
45
+
46
+ Select it in the profile:
47
+
48
+ ```yaml
49
+ - id: web
50
+ config:
51
+ searchProvider: ollama-cloud
52
+ fetchProvider: ollama-cloud
53
+ ```
54
+
55
+ ## Local Ollama
56
+
57
+ Set `apiKeyEnv` to an empty string and point `apiBase` at the local or
58
+ self-hosted Ollama server. No `Authorization` header is sent, and cloud
59
+ usage/balance reads are skipped.
60
+
61
+ ```yaml
62
+ - id: llm-ollama-cloud
63
+ config:
64
+ apiKeyEnv: ''
65
+ apiBase: http://127.0.0.1:11434
66
+ ```
67
+
68
+ Local model discovery uses `/api/tags` and enriches each model through
69
+ `/api/show`; successful capability probes are cached for five minutes.
70
+
38
71
  ## Architecture
39
72
 
40
73
  ```mermaid
@@ -104,17 +137,17 @@ npm pack
104
137
  Install the published package:
105
138
 
106
139
  ```bash
107
- dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.16
140
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.18
108
141
  # DSH Desktop:
109
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.16
142
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.18
110
143
  ```
111
144
 
112
145
  Or install the packed tarball into a profile:
113
146
 
114
147
  ```bash
115
- dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.16.tgz
148
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.18.tgz
116
149
  # DSH Desktop:
117
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.16.tgz
150
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.18.tgz
118
151
  ```
119
152
 
120
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.16
106
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.18
107
107
  # DSH Desktop:
108
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.16
108
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.18
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.16.tgz
114
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.18.tgz
115
115
  # DSH Desktop:
116
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.16.tgz
116
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.18.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.16
105
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.18
106
106
  # DSH 桌面端:
107
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.16
107
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.18
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.16.tgz
113
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.18.tgz
114
114
  # DSH 桌面端:
115
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.16.tgz
115
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.18.tgz
116
116
  ```
117
117
 
118
118
  安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
package/lib/index.d.ts CHANGED
@@ -439,6 +439,23 @@ interface EffectiveModel extends OllamaCloudModelMeta {
439
439
  }
440
440
  declare function effectiveModel(id: string, config: ResolvedConfig): EffectiveModel;
441
441
  declare function describeModel(meta: EffectiveModel, config: ResolvedConfig): string;
442
+ interface ModelProbe {
443
+ readonly contextWindow?: number;
444
+ readonly input: readonly ('text' | 'image')[];
445
+ readonly reasoning: readonly string[];
446
+ readonly reasoningToggle: boolean;
447
+ readonly tools: boolean;
448
+ readonly available: boolean;
449
+ }
450
+ /** Probe one local model via `/api/show`, caching successful answers for five minutes. */
451
+ declare function probeModel(config: ResolvedConfig, model: string, fetchImpl?: typeof fetch): Promise<ModelProbe | undefined>;
452
+ /** Clear all probe entries, or only entries for one endpoint. */
453
+ declare function clearModelProbeCache(baseURL?: string): void;
454
+ declare function modelProbeCacheInfo(): Array<{
455
+ baseURL: string;
456
+ model: string;
457
+ at: number;
458
+ }>;
442
459
  declare const name = "llm-ollama-cloud";
443
460
  declare const inject: string[];
444
461
  /**
@@ -447,5 +464,5 @@ declare const inject: string[];
447
464
  * without a restart.
448
465
  */
449
466
  declare function apply(ctx: Context, config: Config): void;
450
- export { type CommandDeps, Config, type Config as OllamaCloudConfig, OllamaCloudAdapter, type OllamaCloudAdapterDeps, PROVIDER, type ResolvedConfig, type ResolvedKey, type RouteDeps, type TransportId, type UsageReport, type UsageResult, type UsageWindow, apply, applyCommands, applyRoutes, classifyResponseError, clearCatalogCache, createKeyPool, createKeyResolver, createUsageReader, describeModel, effectiveModel, inject, name, normalizeBalance, normalizeUsage, resolveConfig };
467
+ export { type CommandDeps, Config, type Config as OllamaCloudConfig, OllamaCloudAdapter, type OllamaCloudAdapterDeps, PROVIDER, type ResolvedConfig, type ResolvedKey, type RouteDeps, type TransportId, type UsageReport, type UsageResult, type UsageWindow, apply, applyCommands, applyRoutes, classifyResponseError, clearCatalogCache, clearModelProbeCache, createKeyPool, createKeyResolver, createUsageReader, describeModel, effectiveModel, inject, modelProbeCacheInfo, name, normalizeBalance, normalizeUsage, probeModel, resolveConfig };
451
468
  //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ import { credentialRef } from "@deepseek-ai/dsh-credentials";
9
9
  import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
10
10
  import { spawn } from "node:child_process";
11
11
  import { fileURLToPath } from "node:url";
12
+ import { WebError } from "@deepseek-ai/dsh-web";
12
13
  // src/account-rules.ts
13
14
  function glob(pattern) {
14
15
  const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
@@ -49,7 +50,7 @@ const DEFAULT_API_BASE = "https://ollama.com";
49
50
  const DEFAULT_OPENAI_BASE = "https://ollama.com/v1";
50
51
  const DEFAULT_USAGE_URL = "https://ollama.com/api/usage";
51
52
  const DEFAULT_BALANCE_URL = "https://ollama.com/api/balance";
52
- const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.16";
53
+ const DEFAULT_USER_AGENT = "dsh-ollama-cloud-provider/0.1.18";
53
54
  const DEFAULT_CONTEXT_WINDOW = 131072;
54
55
  const DEFAULT_MAX_TOKENS = 32768;
55
56
  const DEFAULT_GENERATE_MAX_TOKENS = 131072;
@@ -158,7 +159,7 @@ function resolveConfig(config) {
158
159
  const apiKey = typeof config.apiKey === "string" && config.apiKey.trim() !== "" ? config.apiKey.trim() : void 0;
159
160
  const visibleModels = Array.isArray(config.visibleModels) ? config.visibleModels.filter((id) => typeof id === "string" && id !== "") : [];
160
161
  return {
161
- apiKeyEnv: typeof config.apiKeyEnv === "string" && config.apiKeyEnv.trim() !== "" ? config.apiKeyEnv.trim() : DEFAULT_API_KEY_ENV,
162
+ apiKeyEnv: typeof config.apiKeyEnv === "string" ? config.apiKeyEnv.trim() : DEFAULT_API_KEY_ENV,
162
163
  ...apiKey === void 0 ? {} : { apiKey },
163
164
  apiBase: typeof config.apiBase === "string" && config.apiBase !== "" ? config.apiBase : DEFAULT_API_BASE,
164
165
  openAiBase: typeof config.openAiBase === "string" && config.openAiBase !== "" ? config.openAiBase : DEFAULT_OPENAI_BASE,
@@ -681,6 +682,113 @@ const GENERATED_MODELS = {
681
682
  }
682
683
  }
683
684
  };
685
+ // src/routing.ts
686
+ function trim(url) {
687
+ return url.replace(/\/+$/, "");
688
+ }
689
+ function rootFor(config) {
690
+ return trim(config.apiBase);
691
+ }
692
+ function modelsUrlFor(config) {
693
+ return `${rootFor(config)}/v1/models`;
694
+ }
695
+ function tagsUrlFor(config) {
696
+ return `${rootFor(config)}/api/tags`;
697
+ }
698
+ /** Endpoint for one model and one wire protocol. */
699
+ function endpointFor(transport, config) {
700
+ return transport === "openai-chat" ? `${trim(config.openAiBase)}/chat/completions` : `${rootFor(config)}/api/chat`;
701
+ }
702
+ // src/model-probe.ts
703
+ const PROBE_TTL_MS = 3e5;
704
+ const cache$2 = /* @__PURE__ */ new Map();
705
+ function keyOf(config, model) {
706
+ return `${rootFor(config)}|${model}`;
707
+ }
708
+ function isLocalEndpoint(config) {
709
+ if (config.apiKeyEnv === "") return true;
710
+ try {
711
+ const host = new URL(config.apiBase).hostname;
712
+ return host === "127.0.0.1" || host === "localhost" || host === "::1" || host === "[::1]";
713
+ } catch {
714
+ return false;
715
+ }
716
+ }
717
+ function contextOf(info) {
718
+ let best;
719
+ for (const [key, value] of Object.entries(info)) {
720
+ if (!key.endsWith(".context_length")) continue;
721
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) continue;
722
+ best = best === void 0 ? value : Math.max(best, value);
723
+ }
724
+ return best === void 0 ? void 0 : Math.trunc(best);
725
+ }
726
+ function probeOf(body) {
727
+ if (typeof body !== "object" || body === null || Array.isArray(body)) return void 0;
728
+ const record = body;
729
+ const info = typeof record.model_info === "object" && record.model_info !== null ? record.model_info : {};
730
+ const capabilities = Array.isArray(record.capabilities) ? record.capabilities.filter((entry) => typeof entry === "string") : [];
731
+ const thinking = capabilities.includes("thinking");
732
+ const vision = capabilities.includes("vision");
733
+ const contextWindow = contextOf(info);
734
+ const input = vision ? ["text", "image"] : ["text"];
735
+ return {
736
+ ...contextWindow === void 0 ? {} : { contextWindow },
737
+ input,
738
+ reasoning: thinking ? ["off", "high"] : [],
739
+ reasoningToggle: thinking,
740
+ tools: capabilities.includes("tools"),
741
+ available: true
742
+ };
743
+ }
744
+ /** Probe one local model via `/api/show`, caching successful answers for five minutes. */
745
+ async function probeModel(config, model, fetchImpl = fetch) {
746
+ if (!isLocalEndpoint(config)) return void 0;
747
+ const key = keyOf(config, model);
748
+ const hit = cache$2.get(key);
749
+ if (hit !== void 0 && Date.now() - hit.at < PROBE_TTL_MS) return hit.value;
750
+ try {
751
+ const response = await fetchImpl(`${rootFor(config)}/api/show`, {
752
+ method: "POST",
753
+ headers: {
754
+ accept: "application/json",
755
+ "content-type": "application/json",
756
+ "user-agent": config.userAgent
757
+ },
758
+ body: JSON.stringify({ model }),
759
+ signal: AbortSignal.timeout(1e4)
760
+ });
761
+ if (!response.ok) return void 0;
762
+ const value = probeOf(await response.json());
763
+ if (value === void 0) return void 0;
764
+ cache$2.set(key, {
765
+ at: Date.now(),
766
+ value
767
+ });
768
+ return value;
769
+ } catch {
770
+ return;
771
+ }
772
+ }
773
+ /** Clear all probe entries, or only entries for one endpoint. */
774
+ function clearModelProbeCache(baseURL) {
775
+ if (baseURL === void 0) {
776
+ cache$2.clear();
777
+ return;
778
+ }
779
+ const prefix = `${baseURL.replace(/\/+$/, "")}|`;
780
+ for (const key of cache$2.keys()) if (key.startsWith(prefix)) cache$2.delete(key);
781
+ }
782
+ function modelProbeCacheInfo() {
783
+ return [...cache$2.entries()].map(([key, entry]) => {
784
+ const separator = key.indexOf("|");
785
+ return {
786
+ baseURL: key.slice(0, separator),
787
+ model: key.slice(separator + 1),
788
+ at: entry.at
789
+ };
790
+ });
791
+ }
684
792
  // src/pricing.ts
685
793
  /** `gpt-oss:120b` → `gpt-oss`; used as the second lookup key. */
686
794
  function baseIdOf(id) {
@@ -755,23 +863,6 @@ function formatUsd(value) {
755
863
  if (Math.abs(value) >= .01) return `$${value.toFixed(3)}`;
756
864
  return `$${value.toFixed(4)}`;
757
865
  }
758
- // src/routing.ts
759
- function trim(url) {
760
- return url.replace(/\/+$/, "");
761
- }
762
- function rootFor(config) {
763
- return trim(config.apiBase);
764
- }
765
- function modelsUrlFor(config) {
766
- return `${rootFor(config)}/v1/models`;
767
- }
768
- function tagsUrlFor(config) {
769
- return `${rootFor(config)}/api/tags`;
770
- }
771
- /** Endpoint for one model and one wire protocol. */
772
- function endpointFor(transport, config) {
773
- return transport === "openai-chat" ? `${trim(config.openAiBase)}/chat/completions` : `${rootFor(config)}/api/chat`;
774
- }
775
866
  // src/catalog.ts
776
867
  const CATALOG_TTL_MS = 6e5;
777
868
  const CATALOG_TIMEOUT_MS = 15e3;
@@ -855,6 +946,36 @@ function metaFromLive(entry, caps) {
855
946
  }
856
947
  };
857
948
  }
949
+ function metaFromProbe(id, probe) {
950
+ if (probe === void 0) return void 0;
951
+ const base = GENERATED_MODELS[id];
952
+ return {
953
+ id,
954
+ name: base?.name ?? id,
955
+ transport: base?.transport ?? "native",
956
+ contextWindow: probe.contextWindow ?? base?.contextWindow ?? 131072,
957
+ maxTokens: base?.maxTokens ?? 32768,
958
+ input: [...probe.input],
959
+ reasoning: probe.reasoning.length > 0 ? [...probe.reasoning] : base?.reasoning ?? [],
960
+ reasoningToggle: probe.reasoningToggle || base?.reasoningToggle === true,
961
+ tools: probe.tools || base?.tools === true,
962
+ free: base?.free === true,
963
+ available: probe.available,
964
+ ...base?.defaultReasoning === void 0 ? {} : { defaultReasoning: base.defaultReasoning },
965
+ cost: base?.cost ?? {
966
+ input: 0,
967
+ output: 0,
968
+ cacheRead: 0
969
+ }
970
+ };
971
+ }
972
+ async function adoptProbes(config, ids, base, fetchImpl) {
973
+ const probes = await Promise.all(ids.slice(0, 64).map(async (id) => ({
974
+ id,
975
+ meta: metaFromProbe(id, await probeModel(config, id, fetchImpl))
976
+ })));
977
+ for (const { id, meta } of probes) if (meta !== void 0) liveMeta.set(liveKey(base, id), meta);
978
+ }
858
979
  /** Replace the in-memory live metadata for one API base with one successful response. */
859
980
  function adoptLive(models, tags, base) {
860
981
  const caps = capabilitiesByModel(tags);
@@ -922,13 +1043,16 @@ async function refreshNow(config, fetchImpl, key, keepOnFailure, epoch) {
922
1043
  }
923
1044
  }
924
1045
  const fromData = Array.isArray(payload.data) ? payload.data.map((entry) => str$1(entry.id)).filter((id) => id !== void 0) : [];
925
- if (fromData.length > 0) {
1046
+ const fromTags = ((tagsResult.status === "fulfilled" ? tagsResult.value : void 0)?.models ?? []).map((entry) => str$1(entry.name) ?? str$1(entry.model)).filter((id) => id !== void 0);
1047
+ const ids = fromData.length > 0 ? fromData : fromTags;
1048
+ if (ids.length > 0) {
926
1049
  for (const liveKey of liveMeta.keys()) if (liveKey.startsWith(`${key}|`)) liveMeta.delete(liveKey);
1050
+ if (isLocalEndpoint(config)) await adoptProbes(config, ids, key, fetchImpl);
927
1051
  cache$1.set(key, {
928
1052
  at: Date.now(),
929
- ids: fromData
1053
+ ids
930
1054
  });
931
- return fromData;
1055
+ return ids;
932
1056
  }
933
1057
  }
934
1058
  if (keepOnFailure) {
@@ -954,6 +1078,7 @@ function clearCatalogCache() {
954
1078
  cache$1.clear();
955
1079
  inflight.clear();
956
1080
  liveMeta.clear();
1081
+ clearModelProbeCache();
957
1082
  }
958
1083
  function baseMeta(id, base) {
959
1084
  const meta = liveMeta.get(liveKey(base, id)) ?? GENERATED_MODELS[id];
@@ -2580,7 +2705,7 @@ var OllamaCloudAdapter = class extends LlmAdapter {
2580
2705
  async send(url, key, model, body, config, signal) {
2581
2706
  const headers = {
2582
2707
  ...attributionHeaders(),
2583
- authorization: `Bearer ${key}`,
2708
+ ...key === "" ? {} : { authorization: `Bearer ${key}` },
2584
2709
  "content-type": "application/json",
2585
2710
  accept: model.transport === "openai-chat" ? "text/event-stream" : "application/x-ndjson",
2586
2711
  "user-agent": config.userAgent
@@ -3046,6 +3171,12 @@ async function resolveSlot(ctx, slot) {
3046
3171
  function createKeyPool(ctx, config) {
3047
3172
  const all = async () => {
3048
3173
  const current = config();
3174
+ const hasConfiguredKey = current.apiKey !== void 0 || current.accounts.some((account) => typeof account.apiKey === "string" && account.apiKey.trim() !== "" || typeof account.apiKeyEnv === "string" && account.apiKeyEnv.trim() !== "");
3175
+ if (current.apiKeyEnv === "" && !hasConfiguredKey) return [{
3176
+ key: "",
3177
+ source: "none",
3178
+ label: "default"
3179
+ }];
3049
3180
  const pinned = current.activeAccount.trim();
3050
3181
  const slots = slotsOf(current);
3051
3182
  if (pinned !== "") {
@@ -3998,6 +4129,7 @@ function configOps(patch) {
3998
4129
  };
3999
4130
  if ("apiKeyEnv" in patch) {
4000
4131
  if (patch.apiKeyEnv === null || patch.apiKeyEnv === void 0) set("apiKeyEnv", void 0);
4132
+ else if (typeof patch.apiKeyEnv === "string" && patch.apiKeyEnv.trim() === "") set("apiKeyEnv", "");
4001
4133
  else {
4002
4134
  const ref = normalizeCredentialRef(patch.apiKeyEnv);
4003
4135
  if (ref === void 0) throw new Error("invalid credential reference");
@@ -4770,6 +4902,7 @@ function createUsageReader(config, resolveKey, fetchImpl = fetch) {
4770
4902
  });
4771
4903
  };
4772
4904
  const readBalance = async (key) => {
4905
+ if (key === "") return void 0;
4773
4906
  const current = config();
4774
4907
  try {
4775
4908
  const response = await request(current.balanceUrl, key);
@@ -4780,6 +4913,7 @@ function createUsageReader(config, resolveKey, fetchImpl = fetch) {
4780
4913
  }
4781
4914
  };
4782
4915
  const readUsage = async (key, range, epoch) => {
4916
+ if (key === "") return void 0;
4783
4917
  const current = config();
4784
4918
  const cacheKey = `${fingerprint(key)}:${range}`;
4785
4919
  const hit = cached(cacheKey);
@@ -4874,6 +5008,138 @@ function createUsageReader(config, resolveKey, fetchImpl = fetch) {
4874
5008
  };
4875
5009
  return reader;
4876
5010
  }
5011
+ // src/web.ts
5012
+ const OLLAMA_WEB_PROVIDER_ID = "ollama-cloud";
5013
+ const MAX_FETCH_CHARS = 262144;
5014
+ function decodeSearchResponse(body) {
5015
+ const results = body?.results;
5016
+ if (!Array.isArray(results)) throw new WebError("ollama-cloud web search answered without a \"results\" array", "OLLAMA_WEB_BAD_REPLY");
5017
+ const sources = [];
5018
+ for (const entry of results) {
5019
+ if (entry === null || typeof entry !== "object") continue;
5020
+ const record = entry;
5021
+ if (typeof record.url !== "string" || record.url === "") continue;
5022
+ sources.push({
5023
+ url: record.url,
5024
+ ...typeof record.title === "string" && record.title !== "" ? { title: record.title } : {},
5025
+ ...typeof record.content === "string" && record.content !== "" ? { snippet: record.content } : {}
5026
+ });
5027
+ }
5028
+ return {
5029
+ sources,
5030
+ truncated: false
5031
+ };
5032
+ }
5033
+ function decodeFetchResponse(body) {
5034
+ const content = body?.content;
5035
+ if (typeof content !== "string") throw new WebError("ollama-cloud web fetch answered without text \"content\"", "OLLAMA_WEB_BAD_REPLY");
5036
+ return content.length > 262144 ? {
5037
+ content: content.slice(0, MAX_FETCH_CHARS),
5038
+ truncated: true
5039
+ } : {
5040
+ content,
5041
+ truncated: false
5042
+ };
5043
+ }
5044
+ function isRedirectFailure(error) {
5045
+ let current = error;
5046
+ while (current instanceof Error) {
5047
+ if (/redirect/i.test(current.message)) return true;
5048
+ current = current.cause;
5049
+ }
5050
+ return false;
5051
+ }
5052
+ function abortReason(caller, own) {
5053
+ if (caller?.aborted === true) return "caller";
5054
+ return own.aborted ? "timeout" : void 0;
5055
+ }
5056
+ async function postOnce(options, url, payload, caller) {
5057
+ const apiKey = await options.resolveApiKey();
5058
+ 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");
5059
+ const fetchImpl = options.fetch ?? fetch;
5060
+ const timeoutMs = options.timeoutMs ?? 15e3;
5061
+ const own = AbortSignal.timeout(timeoutMs);
5062
+ const signal = caller === void 0 ? own : AbortSignal.any([caller, own]);
5063
+ let response;
5064
+ try {
5065
+ response = await fetchImpl(url, {
5066
+ method: "POST",
5067
+ headers: {
5068
+ "content-type": "application/json",
5069
+ accept: "application/json",
5070
+ ...apiKey === "" ? {} : { authorization: `Bearer ${apiKey}` }
5071
+ },
5072
+ body: JSON.stringify(payload),
5073
+ redirect: "error",
5074
+ signal
5075
+ });
5076
+ } catch (error) {
5077
+ const reason = abortReason(caller, own);
5078
+ if (reason === "caller") throw new WebError("ollama-cloud web request aborted by caller", "ABORTED", { cause: error });
5079
+ if (reason === "timeout") throw new WebError(`ollama-cloud web request timed out after ${timeoutMs}ms`, "OLLAMA_WEB_TIMEOUT", { cause: error });
5080
+ if (isRedirectFailure(error)) throw new WebError(`${url} attempted a redirect`, "WEB_PROVIDER_ERROR", { cause: error });
5081
+ const detail = error instanceof Error && error.message !== "" ? `: ${error.message}` : "";
5082
+ throw new WebError(`could not reach ${url}${detail}`, "OLLAMA_WEB_TRANSPORT", { cause: error });
5083
+ }
5084
+ if (!response.ok) {
5085
+ await response.body?.cancel();
5086
+ const hint = response.status === 401 || response.status === 403 ? "; check the API key" : "";
5087
+ throw new WebError(`${url} answered ${response.status}${hint}`, "WEB_PROVIDER_ERROR");
5088
+ }
5089
+ try {
5090
+ return {
5091
+ status: response.status,
5092
+ body: await response.json()
5093
+ };
5094
+ } catch (error) {
5095
+ throw new WebError(`${url} did not answer with JSON`, "OLLAMA_WEB_BAD_REPLY", { cause: error });
5096
+ }
5097
+ }
5098
+ async function postJson(options, suffix, payload, caller) {
5099
+ const base = options.baseURL().replace(/\/+$/, "");
5100
+ if (!URL.canParse(base)) throw new WebError("ollama-cloud web capabilities need a valid API base URL", "WEB_PROVIDER_ERROR");
5101
+ const url = `${base}${suffix}`;
5102
+ try {
5103
+ return await postOnce(options, url, payload, caller);
5104
+ } catch (error) {
5105
+ if (!(error instanceof WebError && (error.code === "OLLAMA_WEB_TIMEOUT" || error.code === "OLLAMA_WEB_TRANSPORT")) || caller?.aborted === true) throw error;
5106
+ }
5107
+ return postOnce(options, url, payload, caller);
5108
+ }
5109
+ var OllamaWebEndpoint = class {
5110
+ options;
5111
+ id = OLLAMA_WEB_PROVIDER_ID;
5112
+ constructor(options) {
5113
+ this.options = options;
5114
+ }
5115
+ available() {
5116
+ return URL.canParse(this.options.baseURL());
5117
+ }
5118
+ };
5119
+ var OllamaWebSearchProvider = class extends OllamaWebEndpoint {
5120
+ async search(request, signal) {
5121
+ const { body } = await postJson(this.options, "/api/web_search", {
5122
+ query: request.query,
5123
+ ...request.maxResults === void 0 ? {} : { max_results: Math.min(request.maxResults, 10) }
5124
+ }, signal);
5125
+ return decodeSearchResponse(body);
5126
+ }
5127
+ };
5128
+ var OllamaWebFetchProvider = class extends OllamaWebEndpoint {
5129
+ async fetch(request, signal) {
5130
+ const { status, body } = await postJson(this.options, "/api/web_fetch", { url: request.url }, signal);
5131
+ const decoded = decodeFetchResponse(body);
5132
+ return {
5133
+ url: request.url,
5134
+ statusCode: status,
5135
+ body: {
5136
+ kind: "text",
5137
+ content: decoded.content
5138
+ },
5139
+ truncated: decoded.truncated
5140
+ };
5141
+ }
5142
+ };
4877
5143
  // src/index.ts
4878
5144
  const name = "llm-ollama-cloud";
4879
5145
  const inject = ["llm"];
@@ -4938,6 +5204,20 @@ function apply(ctx, config) {
4938
5204
  planLabel: () => current().planLabel
4939
5205
  });
4940
5206
  });
5207
+ ctx.inject(["web"], (webCtx) => {
5208
+ const options = {
5209
+ baseURL: () => current().apiBase,
5210
+ resolveApiKey: async () => {
5211
+ try {
5212
+ return (await keys.resolve(PROVIDER)).key;
5213
+ } catch {
5214
+ return;
5215
+ }
5216
+ }
5217
+ };
5218
+ webCtx.effect(() => webCtx.web.registerSearchProvider(new OllamaWebSearchProvider(options)), "dsh-ollama-cloud-provider: web search provider");
5219
+ webCtx.effect(() => webCtx.web.registerFetchProvider(new OllamaWebFetchProvider(options)), "dsh-ollama-cloud-provider: web fetch provider");
5220
+ });
4941
5221
  ctx.inject(["webServer"], (webCtx) => {
4942
5222
  applyRoutes(webCtx, webCtx.webServer, {
4943
5223
  config: current,
@@ -4954,6 +5234,6 @@ function apply(ctx, config) {
4954
5234
  }), "dsh-ollama-cloud-provider: plugin updater");
4955
5235
  });
4956
5236
  }
4957
- export { Config, OllamaCloudAdapter, PROVIDER, apply, applyCommands, applyRoutes, classifyResponseError, clearCatalogCache, createKeyPool, createKeyResolver, createUsageReader, describeModel, effectiveModel, inject, name, normalizeBalance, normalizeUsage, resolveConfig };
5237
+ export { Config, OllamaCloudAdapter, PROVIDER, apply, applyCommands, applyRoutes, classifyResponseError, clearCatalogCache, clearModelProbeCache, createKeyPool, createKeyResolver, createUsageReader, describeModel, effectiveModel, inject, modelProbeCacheInfo, name, normalizeBalance, normalizeUsage, probeModel, resolveConfig };
4958
5238
 
4959
5239
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-ollama-cloud-provider",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
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",
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",
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"
@@ -99,6 +99,7 @@
99
99
  "@deepseek-ai/dsh-launch-environment": "0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0",
100
100
  "@deepseek-ai/dsh-llm": "0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0",
101
101
  "@deepseek-ai/dsh-settings": "0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0",
102
+ "@deepseek-ai/dsh-web": "0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0",
102
103
  "@deepseek-ai/schemastery": "~3.18.4 || ~3.18.5 || ~3.18.6-alpha.1 || ~3.19.0",
103
104
  "react": "^18.2.0"
104
105
  },
@@ -115,6 +116,7 @@
115
116
  "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.1",
116
117
  "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
117
118
  "@deepseek-ai/dsh-settings": "0.2.2-rc.1",
119
+ "@deepseek-ai/dsh-web": "0.2.2-rc.1",
118
120
  "@deepseek-ai/schemastery": "~3.19.0",
119
121
  "@types/node": "^22.0.0",
120
122
  "@types/react": "^18.3.1",