@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.
Files changed (62) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +13 -6
  3. package/README.ru.md +13 -6
  4. package/README.zh.md +13 -6
  5. package/lib/account-rules.js +26 -0
  6. package/lib/adapter.d.ts +92 -0
  7. package/lib/adapter.js +566 -0
  8. package/lib/analytics.d.ts +81 -0
  9. package/lib/analytics.js +314 -0
  10. package/lib/attempt.js +29 -0
  11. package/lib/best-effort.js +20 -0
  12. package/lib/catalog-cache.js +81 -0
  13. package/lib/catalog.d.ts +10 -0
  14. package/lib/catalog.js +309 -0
  15. package/lib/commands.d.ts +14 -0
  16. package/lib/commands.js +228 -0
  17. package/lib/config.d.ts +173 -0
  18. package/lib/config.js +280 -0
  19. package/lib/context-override.js +38 -0
  20. package/lib/credentials.d.ts +23 -0
  21. package/lib/credentials.js +105 -0
  22. package/lib/discovery.js +108 -0
  23. package/lib/endpoints.js +58 -0
  24. package/lib/errors.d.ts +9 -0
  25. package/lib/errors.js +72 -0
  26. package/lib/files.js +13 -0
  27. package/lib/images.js +78 -0
  28. package/lib/index.d.ts +10 -521
  29. package/lib/index.js +20 -5921
  30. package/lib/local-host.js +47 -0
  31. package/lib/messages.js +263 -0
  32. package/lib/models.generated.d.ts +26 -0
  33. package/lib/models.generated.js +499 -0
  34. package/lib/plugin-updater.js +320 -0
  35. package/lib/pricing.js +78 -0
  36. package/lib/provider-ids.d.ts +4 -0
  37. package/lib/provider-ids.js +9 -0
  38. package/lib/quota-model.js +66 -0
  39. package/lib/reasoning.js +71 -0
  40. package/lib/request-log.d.ts +38 -0
  41. package/lib/request-log.js +203 -0
  42. package/lib/retry.js +24 -0
  43. package/lib/route-guard.js +25 -0
  44. package/lib/routes-public.js +59 -0
  45. package/lib/routes-values.js +129 -0
  46. package/lib/routes.d.ts +28 -0
  47. package/lib/routes.js +733 -0
  48. package/lib/routing.js +20 -0
  49. package/lib/sanitize.js +43 -0
  50. package/lib/status.js +60 -0
  51. package/lib/tool-schema.js +109 -0
  52. package/lib/tools.js +38 -0
  53. package/lib/transports/native.js +156 -0
  54. package/lib/transports/ndjson.js +73 -0
  55. package/lib/transports/openai-chat.js +278 -0
  56. package/lib/transports/sse.js +57 -0
  57. package/lib/transports/tool-call-id.js +17 -0
  58. package/lib/tui-settings.js +246 -0
  59. package/lib/usage.d.ts +69 -0
  60. package/lib/usage.js +277 -0
  61. package/lib/web.js +143 -0
  62. package/package.json +6 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.39 — 2026-11-15
4
+
5
+ - Security: loopback Host detection now requires an IP literal, so a DNS-rebinding page can no longer pass the read host gate or the update endpoint (#135).
6
+ - Security: endpoint URLs (`apiBase`, `openAiBase`, `usageUrl`, `balanceUrl`) must be absolute `http(s)` without embedded credentials or fragments; link-local and metadata addresses are refused, and an unsafe value falls back to the default (#136).
7
+ - Security: update status requires a local Host and same-origin Origin, while refresh, model refresh, connection test and endpoint discovery are single-flight and rate-limited; `/status` is cached for 10 seconds (#137).
8
+ - Reliability: HTTP 504/408 responses now rotate to the next account instead of failing the turn, matching the exception path (#138).
9
+ - Reliability: request-log compaction writes through a temporary file and renames it, so a concurrent reader never sees an empty or partial log (#142).
10
+ - Tooling: `deploy.sh install` works again (`local` outside a function aborted it), and `verify` fails instead of warning when `/health` is not 200 (#143).
11
+ - Documentation: added a Security section to all three READMEs and fixed the escaped version ranges in Requirements.
12
+
13
+ 175 tests.
14
+
15
+ ## 0.1.38 — 2026-11-12
16
+
17
+ - Architecture & Contracts: established canonical `docs/design/DESIGN.md` (following `project-design-contract`), `AGENTS.md`, `index.md`, `deploy.sh`, and `docs/deployment/DEPLOYMENT.md` (#127).
18
+ - Artifact Guard & Packaging: implemented automated pack guard `scripts/pack-check.mjs` preventing root release tarballs and enforcing DSH Store file size limit (<256 KiB) as part of `npm run check` and `npm run release` (#128, #131).
19
+ - Publication Boundary: established `.gitattributes` publication layer with `export-ignore` excluding internal documents, deployment scripts, plans, and `scripts/` from public exports while maintaining git tracking (#130).
20
+ - Error Diagnostics & Health: replaced 10 unmonitored silent catches across adapter, catalog, index, routes, and transports with `bestEffortFailed` logging via `ctx.logger`; augmented `GET /dsh-ollama/health` with provider error surfacing (`ok: false` and `error` field) on discovery failures (#131).
21
+ - Modularity: decomposed monolithic 6033-line `lib/index.js` into clean domain-separated modules (`routes.js`, `adapter.js`, `config.js`, etc.) with `tsdown` unbundling, reducing primary entry point to ~150 lines (#131).
22
+ - Repository Hygiene: audited and pruned 12 stale and detached worktrees, documenting SHAs and ancestor relationships (#129).
23
+
3
24
  ## 0.1.37 — 2026-11-11
4
25
 
5
26
  - Session Integrity & Tool Calls: eliminated tool-call ID collisions across multiple steps and turns by minting globally unique UUID-based identifiers (`call_${randomUUID()}`) whenever Ollama Cloud omits `id` or returns an empty string, across both native and OpenAI-compatible transports (`src/transports/tool-call-id.ts`, `native.ts`, `openai-chat.ts`). Preserves upstream `call.id` when supplied by Ollama. Prevents session log corruption (`SessionFormatError: PTC dispatch repeats subCallId`) that previously caused multi-step conversations to silently disappear on DSH startup (GitHub #2, Gitea #125).
package/README.md CHANGED
@@ -111,8 +111,8 @@ graph LR
111
111
 
112
112
  ## Requirements
113
113
 
114
- - **DeepSeek Harness**: \0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0\ (desktop and web profiles).
115
- - **Node.js**: \>=22.0.0\.
114
+ - **DeepSeek Harness**: `0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0` (desktop and web profiles).
115
+ - **Node.js**: `>=22.0.0`.
116
116
  - **Ollama Cloud Account**: one or more active API keys from Ollama Cloud or a compatible proxy endpoint.
117
117
 
118
118
  ## Install
@@ -128,17 +128,17 @@ npm pack
128
128
  Install the published package:
129
129
 
130
130
  ```bash
131
- dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.34
131
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.39
132
132
  # DSH Desktop:
133
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.34
133
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.39
134
134
  ```
135
135
 
136
136
  Or install the packed tarball into a profile:
137
137
 
138
138
  ```bash
139
- dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.34.tgz
139
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.39.tgz
140
140
  # DSH Desktop:
141
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.34.tgz
141
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.39.tgz
142
142
  ```
143
143
 
144
144
  Restart dsh (or DSH Desktop), then pick **Ollama Cloud** in the model picker.
@@ -263,6 +263,13 @@ The Ollama Cloud settings page in DSH Desktop (dark theme): configured credentia
263
263
 
264
264
  ![Ollama Cloud settings](media/visual-verification.png)
265
265
 
266
+ ## Security
267
+
268
+ - Write routes require a loopback socket, a same-origin `Origin`/`Referer` and the host authentication check; a DNS name is never treated as loopback.
269
+ - API keys are resolved through the DSH credential service; the browser only learns whether a key is configured, never its value.
270
+ - Custom endpoint URLs must be absolute `http(s)` without embedded credentials or fragments; link-local and metadata addresses are refused.
271
+ - `/status` is cached for 10 seconds, while refresh, test and endpoint-discovery routes are single-flight and rate-limited.
272
+
266
273
  ## Limitations
267
274
 
268
275
  - **Cloud only.** Local `http://localhost:11434` is not registered as a route.
package/README.ru.md CHANGED
@@ -93,8 +93,8 @@ graph LR
93
93
 
94
94
  ## Requirements / Требования
95
95
 
96
- - **DeepSeek Harness**: \0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0\ (профили desktop и web).
97
- - **Node.js**: \>=22.0.0\.
96
+ - **DeepSeek Harness**: `0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0` (профили desktop и web).
97
+ - **Node.js**: `>=22.0.0`.
98
98
  - **Аккаунт Ollama Cloud**: один или несколько действующих API-ключей Ollama Cloud или совместимого прокси.
99
99
 
100
100
  ## Установка
@@ -110,17 +110,17 @@ npm pack
110
110
  Установка опубликованного пакета из npm:
111
111
 
112
112
  ```bash
113
- dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.34
113
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.39
114
114
  # DSH Desktop:
115
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.34
115
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.39
116
116
  ```
117
117
 
118
118
  Либо установка из упакованного tarball:
119
119
 
120
120
  ```bash
121
- dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.34.tgz
121
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.39.tgz
122
122
  # DSH Desktop:
123
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.34.tgz
123
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.39.tgz
124
124
  ```
125
125
 
126
126
  После установки перезапустите dsh (или DSH Desktop) и выберите **Ollama Cloud** в списке моделей.
@@ -216,6 +216,13 @@ modelAccountRules:
216
216
  - Нативный `/api/chat` передает NDJSON с подробной статистикой токенов в финальном объекте.
217
217
  - Совместимый эндпоинт OpenAI `/v1/chat/completions` поддерживает стриминг, инструменты, зрение (vision) и `reasoning_effort`.
218
218
 
219
+ ## Безопасность
220
+
221
+ - Write-маршруты требуют loopback-сокет, same-origin `Origin`/`Referer` и проверку подлинности хоста; DNS-имя никогда не считается loopback.
222
+ - Ключи читаются через сервис учётных данных DSH; браузер узнаёт только факт наличия ключа, но не его значение.
223
+ - Собственные адреса эндпоинтов должны быть абсолютными `http(s)` без встроенных учётных данных и фрагментов; link-local и metadata-адреса отклоняются.
224
+ - `/status` кэшируется на 10 секунд, а маршруты обновления, теста и поиска эндпоинтов ограничены по частоте и выполняются в единственном экземпляре.
225
+
219
226
  ## Ограничения
220
227
 
221
228
  - Только Ollama Cloud; локальный сервис `http://localhost:11434` данным плагином не регистрируется.
package/README.zh.md CHANGED
@@ -92,8 +92,8 @@ graph LR
92
92
 
93
93
  ## Requirements / 系统要求
94
94
 
95
- - **DeepSeek Harness**: \0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0\(桌面版与 Web 配置文件)。
96
- - **Node.js**: \>=22.0.0\。
95
+ - **DeepSeek Harness**: `0.2.0-rc.2 || >=0.2.1-rc.2 <0.2.3-0 || >=0.2.2-0 <0.2.3-0`(桌面版与 Web 配置文件)。
96
+ - **Node.js**: `>=22.0.0`。
97
97
  - **Ollama Cloud 账户**: 一个或多个有效的 Ollama Cloud API Key 或兼容的代理端点。
98
98
 
99
99
  ## 安装指南
@@ -109,17 +109,17 @@ npm pack
109
109
  从 npm 安装已发布版本:
110
110
 
111
111
  ```bash
112
- dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.34
112
+ dsh plugin --profile web add @goodandready/dsh-ollama-cloud-provider@0.1.39
113
113
  # DSH 桌面端:
114
- dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.34
114
+ dsh plugin --profile desktop add @goodandready/dsh-ollama-cloud-provider@0.1.39
115
115
  ```
116
116
 
117
117
  或通过打包文件安装:
118
118
 
119
119
  ```bash
120
- dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.34.tgz
120
+ dsh plugin --profile web add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.39.tgz
121
121
  # DSH 桌面端:
122
- dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.34.tgz
122
+ dsh plugin --profile desktop add /absolute/path/to/goodandready-dsh-ollama-cloud-provider-0.1.39.tgz
123
123
  ```
124
124
 
125
125
  安装完成后重启 dsh 或 DSH 桌面端,在模型列表中选择 **Ollama Cloud** 即可。
@@ -186,6 +186,13 @@ DSH Desktop(暗黑主题)中的 Ollama Cloud 设置与用量面板:
186
186
  /ollama test [model] # 发送连通性测试请求
187
187
  ```
188
188
 
189
+ ## 安全说明
190
+
191
+ - 写入路由要求 loopback 套接字、同源 `Origin`/`Referer` 以及宿主机认证;DNS 名称永远不会被视为 loopback。
192
+ - API 密钥通过 DSH 凭据服务解析;浏览器只能获知是否已配置,无法读取密钥值。
193
+ - 自定义端点必须是完整的 `http(s)` 地址,不得包含账号密码或片段;link-local 与 metadata 地址会被拒绝。
194
+ - `/status` 缓存 10 秒;刷新、测试与端点发现路由为单飞并限流。
195
+
189
196
  ## 限制与注意事项
190
197
 
191
198
  - 仅支持 Ollama Cloud 云端模型;不会注册本地 `http://localhost:11434` 路由。
@@ -0,0 +1,26 @@
1
+ // src/account-rules.ts
2
+ function glob(pattern) {
3
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
4
+ return new RegExp(`^${escaped}$`, "i");
5
+ }
6
+ /** First matching rule wins; an empty pattern or account is ignored. */
7
+ function matchModelAccount(model, rules) {
8
+ for (const rule of rules) {
9
+ if (rule.pattern === "" || rule.account === "") continue;
10
+ if (glob(rule.pattern).test(model)) return rule.account;
11
+ }
12
+ }
13
+ /**
14
+ * Pin the matching account first, keeping the rest as fallbacks. A rule that
15
+ * names an account not present in the pool is a no-op.
16
+ */
17
+ function orderKeysForModel(keys, model, rules) {
18
+ const account = matchModelAccount(model, rules);
19
+ if (account === void 0) return keys;
20
+ const preferred = keys.find((entry) => (entry.label ?? "default") === account);
21
+ if (preferred === void 0) return keys;
22
+ return [preferred, ...keys.filter((entry) => entry !== preferred)];
23
+ }
24
+ export { matchModelAccount, orderKeysForModel };
25
+
26
+ //# sourceMappingURL=account-rules.js.map
@@ -0,0 +1,92 @@
1
+ import { ResolvedConfig } from "./config.js";
2
+ import { KeyResolver, ResolvedKey } from "./credentials.js";
3
+ import { RequestOutcome } from "./request-log.js";
4
+ import { GenerateOptions, LlmAdapter, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, ResolvedRetryPolicy, StreamChunk } from "@deepseek-ai/dsh-llm";
5
+ import { AttachmentStore } from "@deepseek-ai/dsh-attachment";
6
+ type RoutingReason = 'rule' | 'sticky' | 'pinned' | 'default' | 'rotation';
7
+ interface RoutingTraceEntry {
8
+ readonly at: number;
9
+ readonly provider: string;
10
+ readonly model: string;
11
+ readonly account: string;
12
+ readonly reason: RoutingReason;
13
+ readonly fallback: boolean;
14
+ readonly ok: boolean;
15
+ readonly error?: string;
16
+ }
17
+ interface OllamaCloudAdapterDeps {
18
+ readonly config: () => ResolvedConfig;
19
+ readonly resolveKey: KeyResolver;
20
+ readonly resolveKeys?: (provider: string) => Promise<readonly ResolvedKey[]>;
21
+ readonly resolveAttachments?: () => AttachmentStore | undefined;
22
+ readonly fetchImpl?: typeof fetch;
23
+ /** Test seam; defaults to the local append-only request log. */
24
+ readonly recordRequest?: (provider: string, model: string, purpose?: string, account?: string, reason?: string, outcome?: RequestOutcome) => void;
25
+ /** Test seam; defaults to ~/.dsh/storages/dsh-ollama/cooldowns.json. */
26
+ readonly cooldownPath?: string;
27
+ /** Test seam; defaults to ~/.dsh/storages/dsh-ollama/sticky.json. */
28
+ readonly stickyPath?: string;
29
+ /** Receives a one-time warning when the provider tool limit drops tools. */
30
+ readonly warn?: (message: string) => void;
31
+ }
32
+ declare class OllamaCloudAdapter extends LlmAdapter {
33
+ private readonly deps;
34
+ private readonly fetchImpl;
35
+ private readonly cooldownPath;
36
+ private readonly stickyPath;
37
+ private cooldownWrites;
38
+ private stickyWrites;
39
+ /** key fingerprint → cooldown deadline and the rejection that caused it. */
40
+ private readonly cooldowns;
41
+ /** key fingerprint + model → short preference mark for model-scoped rejections. */
42
+ private readonly modelCooldowns;
43
+ private readonly sticky;
44
+ private readonly routing;
45
+ private warnedTools;
46
+ constructor(deps: OllamaCloudAdapterDeps);
47
+ providerInfo(provider: string): LlmProviderInfo;
48
+ providerRetryPolicy(_provider: string): ResolvedRetryPolicy;
49
+ listModels(provider: string, opts?: {
50
+ unfiltered?: boolean;
51
+ }): Promise<readonly LlmModelInfo[]>;
52
+ /** Recent routing decisions, newest first; no keys or prompt content. */
53
+ routingTrace(): readonly RoutingTraceEntry[];
54
+ resolveModel(provider: string, model: string, signal?: AbortSignal): Promise<LlmResolvedModelInfo>;
55
+ stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
56
+ private run;
57
+ private rememberSticky;
58
+ /** Await pending sticky persistence writes (tests and shutdown). */
59
+ flushSticky(): Promise<void>;
60
+ private loadSticky;
61
+ private pruneSticky;
62
+ private persistSticky;
63
+ private pushTrace;
64
+ private send;
65
+ private keyId;
66
+ private coolingDown;
67
+ private modelKey;
68
+ private modelCoolingDown;
69
+ private markModelCooldown;
70
+ /**
71
+ * A model-scoped rejection says nothing about the key's other models:
72
+ * `:free` models and other paid models may still work on the same account.
73
+ * Only account-wide quota, credential and rate-limit responses cool the key.
74
+ */
75
+ private modelScoped;
76
+ /** Current cooldown for one resolved key, if any. */
77
+ accountHealth(key: string): {
78
+ coolingUntil: number;
79
+ reason: string;
80
+ } | undefined;
81
+ /** Await pending cooldown persistence writes (tests and shutdown). */
82
+ flushCooldowns(): Promise<void>;
83
+ /** Manually clear all active account and model cooldowns. */
84
+ clearCooldowns(): void;
85
+ private loadCooldowns;
86
+ private pruneCooldowns;
87
+ private persistCooldowns;
88
+ private markCooldown;
89
+ private isTransient;
90
+ }
91
+ export { OllamaCloudAdapter, OllamaCloudAdapterDeps, RoutingReason, RoutingTraceEntry };
92
+ //# sourceMappingURL=adapter.d.ts.map