dsh-vision-router 3.1.3 → 3.1.4

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/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
  > **Data leaves your machine by default.** When a cloud vision model is used, Vision Router sends the image (or a derived crop), the vision prompt and related request metadata to that provider. A fresh install has an anonymous OVHcloud vision fallback enabled, so "free" and "no key" do **not** mean offline. Do not use the cloud chain for confidential, regulated or classified material. See [Data flow and strict local-only use](#data-flow-and-strict-local-only-use).
23
23
 
24
24
  > [!WARNING]
25
- > **v3.1.3 release candidate:** Fix optional dynamic image→text model routing on DSH 0.2.2-rc.1 by selecting models before Agent pre-step; preserve the default tool-only mode and legacy Host behavior. RC1 requires Node >=24.9; small-context models may need Host compaction headroom configuration for model switching. Update the CI-only HOL scanner pin without changing security thresholds. See [v3.1.3 notes](docs/releases/v3.1.3.md). Verify publication through [GitHub Releases](https://github.com/ysr666/dsh-vision-router/releases/latest) or npm.
25
+ > **v3.1.4 stability patch candidate:** Fix cross-plugin script mutation (#793), visual fallback on empty recognition and bounded whole-turn timeouts (#794). Add Desktop bootstrap source-leak regression detection (#795) and canary maintenance (#790); **the specific user-reported 550/503 origins and #792 screenshot root cause are not confirmed**. No settings migration or support-floor change. See [v3.1.4 notes](docs/releases/v3.1.4.md). Verify publication through [GitHub Releases](https://github.com/ysr666/dsh-vision-router/releases/latest) or npm.
26
26
 
27
27
  ## Start here
28
28
 
package/README.zh.md CHANGED
@@ -22,7 +22,7 @@
22
22
  > **默认配置会让数据出网。** 使用云端视觉模型时,Vision Router 会将图片(或由它裁剪出的局部)、识图提示词及相关请求元数据发送给对应供应商。新安装默认开启 OVHcloud 匿名视觉兜底,因此“免费”和“免 Key”不等于离线。涉密、涉案、内部或其他受限材料请勿使用云端链路。详见[数据流向与严格纯本地配置](#数据流向与严格纯本地配置)。
23
23
 
24
24
  > [!WARNING]
25
- > **v3.1.3 候选版更新说明:** 修复 DSH 0.2.2-rc.1 下可选的图片轮次动态模型切换与后续纯文本回切问题,模型选择提前到 Agent pre-step 之前;默认工具识图模式及旧版 Host 兼容行为不变。RC1 本身要求 Node ≥24.9;上下文窗口较小的模型在跨模型切换时可能需要调整 Host 压缩预留量。同步更新 CI 专用安全扫描器,不降低安全门槛。详见[v3.1.3 更新说明](docs/releases/v3.1.3.md)。正式可安装版本以 [GitHub Releases](https://github.com/ysr666/dsh-vision-router/releases/latest) 或 npm 为准。
25
+ > **v3.1.4 稳定性补丁候选版:** 修复跨插件脚本误改写(#793)、空识图结果的后端回退与整轮识图超时卡住(#794),补充 Desktop 启动源码外露检测(#795)及 CI canary 维护(#790)。**用户所报 550/503 的真实来源及 #792 截图根因尚未确认**。不修改配置格式或 Host/Node 支持下限。详见 [v3.1.4 更新说明](docs/releases/v3.1.4.md)。正式可安装版本以 [GitHub Releases](https://github.com/ysr666/dsh-vision-router/releases/latest) 或 npm 为准。
26
26
 
27
27
  ## 先用起来
28
28
 
@@ -0,0 +1,24 @@
1
+ # v3.1.4 — Stability and cross-plugin compatibility / 稳定性与跨插件兼容补丁
2
+
3
+ **Candidate release notes / 候选发布说明。** This document describes the code changes proposed for the v3.1.4 patch; publication is complete only when the protected release workflow verifies the exact `main` SHA, immutable tag, npm registry tarball identity, OIDC provenance and GitHub Release attachments. / 本文为待发布版本的源码变更说明;须经受保护发布流程核验精确主分支 SHA、不可变标签、npm 包体、OIDC 来源证明与 GitHub Release 附件,才能视为完成正式发布。
4
+
5
+ ## Fixes / 已修复问题
6
+
7
+ - **#793 — Cross-plugin script ownership / 跨插件脚本隔离:** The index-injection hardening step now only rewrites DVR-owned scripts. It no longer edits unrelated client scripts from other plugins. A real pre-fix foreign-script mutation was reproduced and covered by tests. / 注入脚本加固只改写 DVR 自有脚本,避免误改写其他插件 JavaScript。已复现旧版缺陷,并加入回归测试。
8
+ - **#794 — Image fallback correctness / 识图回退正确性:** An image model yielding HTTP success but an empty answer no longer ends the chain and caches a misleading successful placeholder. The next eligible model may be tried under the same shared budget. Both tool-only and opt-in whole-turn routing are covered; failed-model partial text is not allowed to contaminate later candidates. / 视觉模型成功返回空内容时,不再提前终止和缓存伪成功,允许在原预算内继续尝试后端;覆盖默认工具识图与可选整轮路由,并隔离失败候选输出。
9
+ - **#794 — Bounded whole-turn execution / 整轮识图时限:** An image-bearing turn now has a bounded preflight and streaming execution even when a third-party adapter does not cooperate with abort or never settles its async iterator. Explicit Host/user cancellation remains distinguished. / 视觉整轮的模型预检查与流式等待均纳入总时限,即使第三方适配器不响应取消或流迭代不返回,也不会无限挂起;保留明确的用户/Host 取消行为。
10
+
11
+ ## Non-runtime safeguards / 非运行时防护
12
+
13
+ - **#795 — Desktop renderer gate / Desktop 启动渲染门禁:** Real Desktop E2E now catches bootstrap JS/CSS unintentionally becoming visible document text, including through exposed head/script/style elements, and checks injection markup delimiters. This is **not** a proven fix of issue #792. / 真实 Desktop E2E 检测启动 JS/CSS 意外外露与注入标签边界;**不是** #792 的已确认根因修复。
14
+ - **#790 — Latest-canary maintenance / 上游 canary 维护:** Keeps DSH latest-canary and Settings seam drift checks aligned. No production runtime behavior changed. / 维护上游 canary 及 Settings 接缝漂移检测,不修改正式运行时。
15
+
16
+ ## Acceptance / 验收边界
17
+
18
+ - Underlying fixes were reviewed with Node 22/24 and exact-source DSH Host/real Desktop gates. The **v3.1.4 release commit** must separately complete its own CI/security/Host tests and the protected publication workflow before it may be called published. / 源码修复已针对 Node 22/24 与真实 DSH Host/Desktop 门禁验收;**v3.1.4 发布提交**仍需独立通过 CI、安全、Host 测试及受保护发布流程。
19
+ - No change to default tool-only routing, user Settings schemas, Node/DSH support range, public API, runtime providers, remote privilege policy, or default cloud image-egress/privacy policy. / 默认工具识图、设置结构、Node/DSH 支持范围、公共 API、运行时模型提供商、远程权限与默认云端图片外发策略均未改变。
20
+ - **Still open:** #791's original 550/503 provider/HTTP source remains unverified. #792's startup raw-source window and possible multi-plugin conflict are not assigned a proven root cause; the regression gate does not certify a field resolution. / **仍在追踪:** #791 用户现场 550/503 来源不明;#792 启动窗口源码外露及可能的多插件冲突尚未确认根因,不宣称已经解决。
21
+
22
+ ## Upgrade / 升级
23
+
24
+ After the trusted release is verified on npm/GitHub, update the DVR plugin to `dsh-vision-router@3.1.4` using the existing profile's normal plugin manager or explicit-version install, then restart/reload DSH as appropriate. Back up existing profile configuration before changing the plugin set; never delete conversation history to troubleshoot. / 正式发布确认后,按现有 profile 的插件管理方式升级到 `dsh-vision-router@3.1.4` 并根据环境重载;排错前备份配置,不要求删除聊天记录。
package/index.js CHANGED
@@ -40,6 +40,56 @@ function throwIfVisionTaskAborted(signal, error) {
40
40
  throw aborted
41
41
  }
42
42
 
43
+ // A provider may ignore AbortSignal and leave iterator.next() pending forever.
44
+ // For whole-turn routing this adapter is the Agent stream itself (unlike
45
+ // vision_describe, it is not protected by the tool execution timeout wrapper).
46
+ // Race each next() with the task signal, and do not await a noncooperative
47
+ // iterator's return() while unwinding: the user's turn must always settle.
48
+ async function* streamVisionWithAbort(source, signal) {
49
+ const iterator = source?.[Symbol.asyncIterator]?.()
50
+ if (!iterator) throw new TypeError('vision chain expected an asynchronous stream')
51
+ let completed = false
52
+ try {
53
+ for (;;) {
54
+ throwIfVisionTaskAborted(signal)
55
+ let onAbort
56
+ const aborted = signal
57
+ ? new Promise((_, reject) => {
58
+ onAbort = () => reject(
59
+ signal.reason instanceof Error
60
+ ? signal.reason
61
+ : Object.assign(new Error('vision stream aborted'), { name: 'AbortError', code: 'ABORT_ERR' }),
62
+ )
63
+ signal.addEventListener('abort', onAbort, { once: true })
64
+ if (signal.aborted) onAbort()
65
+ })
66
+ : undefined
67
+ let step
68
+ try {
69
+ // A late rejection remains observed by Promise.race even if cancellation
70
+ // wins, avoiding unhandled rejection in a provider that later wakes.
71
+ const next = Promise.resolve().then(() => iterator.next())
72
+ step = await (aborted ? Promise.race([next, aborted]) : next)
73
+ } finally {
74
+ if (onAbort) signal.removeEventListener('abort', onAbort)
75
+ }
76
+ if (step.done) {
77
+ completed = true
78
+ return
79
+ }
80
+ yield step.value
81
+ }
82
+ } finally {
83
+ if (!completed && typeof iterator.return === 'function') {
84
+ try {
85
+ // The underlying adapter might never settle. Attempt cleanup, but
86
+ // never block the Agent waiting for a broken third-party stream.
87
+ void Promise.resolve(iterator.return()).catch(() => {})
88
+ } catch { /* noncooperative iterator; outer turn is already settling */ }
89
+ }
90
+ }
91
+ }
92
+
43
93
  export * from './lib/vision-resilience.js'
44
94
 
45
95
  import z from '@deepseek-ai/schemastery'
@@ -1942,7 +1992,6 @@ export function apply(ctx, config = {}, runtime = {}) {
1942
1992
  }
1943
1993
  if (imageIds.length > 0) break
1944
1994
  }
1945
- let finalText = ''
1946
1995
  const chainPairs = routingPairs()
1947
1996
  const chainHttpEntries = new Map(httpEntries().map((entry) => [entry.id, entry]))
1948
1997
  // Fit the conversation into the target model's context window: a long
@@ -1968,7 +2017,19 @@ export function apply(ctx, config = {}, runtime = {}) {
1968
2017
  (sum, pair) => sum + routingPairWeight(pair, chainHttpEntries),
1969
2018
  0,
1970
2019
  )
2020
+ // Streaming a failed candidate is irreversible for the Host. When a
2021
+ // fallback exists, stage its events until a successful finish so a
2022
+ // second backend never appends to a broken first answer. Single-route
2023
+ // and legacy text-only streams keep their existing streaming UX.
2024
+ const holdCandidateEvents = imageIds.length > 0 && chainPairs.length > 1
2025
+ const maxHeldEventBytes = 8 * 1024 * 1024
2026
+ const maxHeldEvents = 32768
1971
2027
  for (const pair of chainPairs) {
2028
+ // Keep result text isolated by candidate; a failed stream's partial
2029
+ // output must never count as recognition by the next backend.
2030
+ let finalText = ''
2031
+ const heldEvents = []
2032
+ let heldBytes = 0
1972
2033
  const candidateWeight = routingPairWeight(pair, chainHttpEntries)
1973
2034
  const weightAtStart = Math.max(candidateWeight, remainingWeight)
1974
2035
  remainingWeight = Math.max(0, remainingWeight - candidateWeight)
@@ -2035,6 +2096,7 @@ export function apply(ctx, config = {}, runtime = {}) {
2035
2096
  let succeeded = false
2036
2097
  let failed = false
2037
2098
  let failMessage = 'unknown error'
2099
+ let failCode
2038
2100
  try {
2039
2101
  // Local backends get an independent anti-hang budget: a hung local
2040
2102
  // service must not consume the whole deadline and starve the
@@ -2086,7 +2148,7 @@ export function apply(ctx, config = {}, runtime = {}) {
2086
2148
  }
2087
2149
  yield { type: 'finish', reason: { kind: 'stop' } }
2088
2150
  }
2089
- for await (const chunk of streamPair()) {
2151
+ for await (const chunk of streamVisionWithAbort(streamPair(), attemptSignal)) {
2090
2152
  if (chunk && chunk.type === 'finish') {
2091
2153
  const kind = chunk.reason && chunk.reason.kind
2092
2154
  if (kind === 'error' || kind === 'aborted') {
@@ -2095,7 +2157,16 @@ export function apply(ctx, config = {}, runtime = {}) {
2095
2157
  failed = true
2096
2158
  break
2097
2159
  }
2098
- // 'stop' / 'max-tokens' / 'tool-calls' are success.
2160
+ // Tool-call handoffs may legitimately have no text, but a
2161
+ // completed recognition with no text is not a usable answer.
2162
+ // It must not suppress fallback or cache an earlier failed
2163
+ // candidate's partial output as this backend's result.
2164
+ if (imageIds.length > 0 && (kind === 'stop' || kind === 'max-tokens') && finalText.trim() === '') {
2165
+ failed = true
2166
+ failCode = 'EMPTY_RESPONSE'
2167
+ failMessage = 'vision chain backend returned empty content'
2168
+ break
2169
+ }
2099
2170
  succeeded = true
2100
2171
  // 视觉链成功留痕:谁识别了几张图、写入跨轮缓存——排障时
2101
2172
  // "这张图的描述是谁生成的"一眼可查(原版此处静默)。
@@ -2108,18 +2179,41 @@ export function apply(ctx, config = {}, runtime = {}) {
2108
2179
  const record = finalText.trim()
2109
2180
  for (const id of imageIds) imageMemorySet(imageMemory, id, record)
2110
2181
  }
2182
+ if (holdCandidateEvents) {
2183
+ for (const event of heldEvents) yield event
2184
+ }
2111
2185
  yield chunk
2112
2186
  break
2113
2187
  }
2114
2188
  if (chunk && typeof chunk.text === 'string') finalText += chunk.text
2115
- yield chunk
2189
+ if (holdCandidateEvents) {
2190
+ const bytes = Buffer.byteLength(JSON.stringify(chunk) ?? '', 'utf8')
2191
+ if (heldEvents.length >= maxHeldEvents || heldBytes + bytes > maxHeldEventBytes) {
2192
+ failCode = 'VISION_CHAIN_BUFFER_LIMIT'
2193
+ throw new Error('vision chain candidate output exceeded safe fallback buffer limit')
2194
+ }
2195
+ heldEvents.push(chunk)
2196
+ heldBytes += bytes
2197
+ } else {
2198
+ yield chunk
2199
+ }
2200
+ }
2201
+ if (!succeeded && !failed && imageIds.length > 0) {
2202
+ // An adapter can end iteration without emitting the mandatory
2203
+ // terminal finish. Do not silently close the Agent stream and
2204
+ // strand a later model that could recover the visual answer.
2205
+ failed = true
2206
+ failCode = 'EMPTY_RESPONSE'
2207
+ failMessage = 'vision chain backend ended without a finish event'
2116
2208
  }
2117
2209
  } catch (error) {
2118
2210
  failed = true
2119
2211
  failMessage = error && error.message ? error.message : String(error)
2120
2212
  }
2121
2213
  if (failed) {
2122
- const classification = classifyVisionFailure(failMessage)
2214
+ const classification = classifyVisionFailure(
2215
+ failCode ? { code: failCode, message: failMessage } : failMessage,
2216
+ )
2123
2217
  visionBreaker.record(backendKey, fingerprint, classification, 'chain')
2124
2218
  failures.push(`${pair.provider}/${pair.model}: ${failMessage}`)
2125
2219
  ctx.logger?.warn('vision-router: chain fallback (%s) -> %s', classification.kind, failMessage)
@@ -2139,6 +2233,50 @@ export function apply(ctx, config = {}, runtime = {}) {
2139
2233
  }
2140
2234
  },
2141
2235
  }
2236
+
2237
+ // The chain's own deadline starts after initial model-info preflight.
2238
+ // A noncooperative discovery/capability adapter can therefore keep the
2239
+ // entire Agent turn pending before the first streamed chunk. Protect the
2240
+ // COMPLETE image-bearing stream, not only individual model iterator.next()
2241
+ // calls. Text-only legacy routes retain their existing semantics.
2242
+ const innerChainStream = chainAdapter.stream
2243
+ chainAdapter.stream = async function* boundedVisionChainStream(options) {
2244
+ const imageBearing = collectImageBlocks(options?.messages ?? [])
2245
+ .some(({ block }) => !isOffloadedImageBlock(block))
2246
+ if (!imageBearing) {
2247
+ yield* innerChainStream.call(this, options)
2248
+ return
2249
+ }
2250
+ const budgetSignal = AbortSignal.timeout(visionTaskTimeoutMs())
2251
+ const signal = combineSignals(options?.signal, budgetSignal)
2252
+ try {
2253
+ for await (const chunk of streamVisionWithAbort(
2254
+ innerChainStream.call(this, { ...options, signal }),
2255
+ signal,
2256
+ )) {
2257
+ yield chunk
2258
+ // The Host only accepts one terminal event. Do not remain blocked in
2259
+ // a broken iterator's post-finish cleanup, or emit an error later.
2260
+ if (chunk?.type === 'finish') return
2261
+ }
2262
+ } catch (error) {
2263
+ if (!signal.aborted) throw error
2264
+ if (options?.signal?.aborted) {
2265
+ yield { type: 'finish', reason: { kind: 'aborted' } }
2266
+ return
2267
+ }
2268
+ yield {
2269
+ type: 'finish',
2270
+ reason: {
2271
+ kind: 'error',
2272
+ failure: {
2273
+ code: 'VISION_CHAIN_EXHAUSTED',
2274
+ message: 'vision task timed out before the model finished preparing or responding',
2275
+ },
2276
+ },
2277
+ }
2278
+ }
2279
+ }
2142
2280
  }
2143
2281
 
2144
2282
  // ── reactive routing mounts ────────────────────────────────────────────────
@@ -2976,9 +3114,13 @@ ctx.logger?.info(
2976
3114
  if (cacheEnabled()) cache.set(key, text)
2977
3115
  return text
2978
3116
  }
2979
- const empty = '(the vision model returned empty content)'
2980
- if (cacheEnabled()) cache.set(key, empty)
2981
- return empty
3117
+ // A successfully transported but empty answer is not visual evidence.
3118
+ // In particular, reasoning models can exhaust their output budget
3119
+ // before emitting any content. Never cache a fabricated success or
3120
+ // suppress a healthy later backend in the configured chain.
3121
+ const empty = new Error('vision_describe backend returned empty content')
3122
+ empty.code = 'EMPTY_RESPONSE'
3123
+ throw empty
2982
3124
  } catch (error) {
2983
3125
  const classification = classifyVisionFailure(error)
2984
3126
  visionBreaker.record(backendKey, fingerprint, classification, scope)
@@ -3107,6 +3249,11 @@ ctx.logger?.info(
3107
3249
  if (cacheEnabled()) cache.set(key, text)
3108
3250
  return text
3109
3251
  }
3252
+ // Mirror the adapter-backed branch: this HTTP response is a
3253
+ // backend failure, not a valid zero-length recognition result.
3254
+ const empty = new Error(`http provider "${provider.name}": vision response was empty`)
3255
+ empty.code = 'EMPTY_RESPONSE'
3256
+ throw empty
3110
3257
  } catch (error) {
3111
3258
  const classification = classifyVisionFailure(error)
3112
3259
  visionBreaker.record(backendKey, fingerprint, classification, scope)
@@ -467,9 +467,20 @@ export function hardenVisionClientSource(source) {
467
467
  return next
468
468
  }
469
469
 
470
+ // Only DVR-owned carriers may be rewritten. Other plugins can register
471
+ // arbitrary index-injection scripts with identical helper source text; editing
472
+ // those scripts silently changes their behavior and can break Desktop boot.
473
+ const OWNED_STRUCTURED_SCRIPT = /^\s*\/\*\s*data-vision-router-[a-z0-9:-]+\s*\*\//
474
+ const OWNED_HTML_SCRIPT = /(<script\s+data-vision-router-[a-z0-9:-]+>)([\s\S]*?)(<\/script\s*>)/gi
475
+
476
+ function hardenOwnedClientHtml(html) {
477
+ return html.replace(OWNED_HTML_SCRIPT, (_match, opening, source, closing) =>
478
+ `${opening}${hardenVisionClientSource(source)}${closing}`)
479
+ }
480
+
470
481
  export function hardenVisionToggleHtml(html) {
471
482
  if (typeof html !== 'string') return html
472
- let next = hardenVisionClientSource(html)
483
+ let next = hardenOwnedClientHtml(html)
473
484
 
474
485
  if (!next.includes(OWNERSHIP_MARK)) {
475
486
  const safe = CLIENT_PRELUDE.replace(/<\/script/gi, '<\\/script')
@@ -519,7 +530,8 @@ export function createVisionToggleRootHardening(ctx, config = {}) {
519
530
  webCtx.on('webserver/index-inject', (table) => {
520
531
  if (!Array.isArray(table)) return
521
532
  for (const row of table) {
522
- if (row?.kind === 'script' && typeof row.text === 'string') {
533
+ if (row?.kind === 'script' && typeof row.text === 'string'
534
+ && OWNED_STRUCTURED_SCRIPT.test(row.text)) {
523
535
  row.text = hardenVisionClientSource(row.text)
524
536
  }
525
537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-vision-router",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "Eyes for text-only DeepSeek Harness agents: built-in free vision chain + pixel-level tools. Remote vision providers, including the default free fallback, receive image content unless strict local-only use is configured.",
5
5
  "license": "MIT",
6
6
  "repository": {