dsh-vision-router 3.1.4 → 3.2.0

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.
@@ -0,0 +1,118 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import path from 'node:path'
4
+ import { createRequire } from 'node:module'
5
+ import { pathToFileURL } from 'node:url'
6
+ import { Config } from '../entry.js'
7
+ import { mutateLocalRemoteSettingsPermission } from '../lib/local-remote-settings-permission.js'
8
+
9
+ function minimumHostSettingsRoot() {
10
+ const root = process.env.DSH_MINIMUM_SETTINGS_ROOT
11
+ assert.equal(
12
+ typeof root,
13
+ 'string',
14
+ 'DSH_MINIMUM_SETTINGS_ROOT must point at the isolated minimum-supported Host @deepseek-ai/dsh-settings package',
15
+ )
16
+ assert.notEqual(root.trim(), '', 'DSH_MINIMUM_SETTINGS_ROOT must not be blank')
17
+ return path.resolve(root)
18
+ }
19
+
20
+ test('minimum supported Host SettingsProvider persists allowRemoteSettings in the raw user section', async () => {
21
+ const settingsRoot = minimumHostSettingsRoot()
22
+ const settingsModule = await import(pathToFileURL(path.join(settingsRoot, 'lib/index.js')).href)
23
+ const peerRequire = createRequire(path.join(settingsRoot, 'package.json'))
24
+ const cordisEntry = peerRequire.resolve('@deepseek-ai/cordis')
25
+ const { Context } = await import(pathToFileURL(cordisEntry).href)
26
+
27
+ class MemorySettings extends settingsModule.SettingsProvider {
28
+ constructor(ctx) {
29
+ super(ctx)
30
+ this.doc = {}
31
+ }
32
+ get writable() { return true }
33
+ load() { return Promise.resolve(structuredClone(this.doc)) }
34
+ persist(ns, section) {
35
+ this.doc[ns] = structuredClone(section)
36
+ return Promise.resolve()
37
+ }
38
+ }
39
+
40
+ const ctx = new Context()
41
+ const fiber = ctx.plugin(MemorySettings)
42
+ await fiber
43
+ const provider = ctx.get('settings')
44
+ provider.register('vision-router', Config)
45
+
46
+ const before = provider.describe({ redactSecrets: true }).find((entry) => entry.ns === 'vision-router')
47
+ assert.ok(before)
48
+ assert.equal(before.user, undefined)
49
+ assert.equal(before.value.allowRemoteSettings, false)
50
+
51
+ const result = await mutateLocalRemoteSettingsPermission(provider, {
52
+ operation: 'set',
53
+ value: true,
54
+ expectedRevision: before.revision,
55
+ })
56
+ assert.equal(result.ok, true)
57
+
58
+ const after = provider.describe({ redactSecrets: true }).find((entry) => entry.ns === 'vision-router')
59
+ assert.ok(after)
60
+ assert.equal(after.user.allowRemoteSettings, true)
61
+ assert.equal(after.value.allowRemoteSettings, true)
62
+ assert.equal(provider.doc['vision-router'].allowRemoteSettings, true)
63
+ assert.ok(after.revision > before.revision)
64
+
65
+ await fiber.dispose()
66
+ })
67
+
68
+ test('minimum supported Host SettingsProvider preserves prototype routing fields without product authority', async () => {
69
+ const settingsRoot = minimumHostSettingsRoot()
70
+ const settingsModule = await import(pathToFileURL(path.join(settingsRoot, 'lib/index.js')).href)
71
+ const peerRequire = createRequire(path.join(settingsRoot, 'package.json'))
72
+ const cordisEntry = peerRequire.resolve('@deepseek-ai/cordis')
73
+ const { Context } = await import(pathToFileURL(cordisEntry).href)
74
+
75
+ class MemorySettings extends settingsModule.SettingsProvider {
76
+ constructor(ctx) {
77
+ super(ctx)
78
+ this.doc = {
79
+ 'vision-router': {
80
+ capabilityRoutingShadow: true,
81
+ capabilityRoutingStrategy: 'privacy',
82
+ },
83
+ }
84
+ }
85
+ get writable() { return true }
86
+ load() { return Promise.resolve(structuredClone(this.doc)) }
87
+ persist(ns, section) {
88
+ this.doc[ns] = structuredClone(section)
89
+ return Promise.resolve()
90
+ }
91
+ }
92
+
93
+ const ctx = new Context()
94
+ const fiber = ctx.plugin(MemorySettings)
95
+ await fiber
96
+ const provider = ctx.get('settings')
97
+ provider.register('vision-router', Config)
98
+
99
+ const before = provider.describe({ redactSecrets: true }).find((entry) => entry.ns === 'vision-router')
100
+ assert.ok(before)
101
+ const fields = before.schema.refs[String(before.schema.uid)].dict
102
+ assert.equal(Object.hasOwn(fields, 'capabilityRoutingShadow'), false)
103
+ assert.equal(Object.hasOwn(fields, 'capabilityRoutingStrategy'), false)
104
+ assert.equal(before.user.capabilityRoutingShadow, true)
105
+ assert.equal(before.user.capabilityRoutingStrategy, 'privacy')
106
+ assert.equal(before.value.routingMode, 'ordered')
107
+ assert.equal(before.value.routingPreference, 'balanced')
108
+
109
+ await provider.mutate('vision-router', [
110
+ { op: 'set', path: ['routingMode'], value: 'auto' },
111
+ ], before.revision)
112
+ assert.equal(provider.doc['vision-router'].capabilityRoutingShadow, true)
113
+ assert.equal(provider.doc['vision-router'].capabilityRoutingStrategy, 'privacy')
114
+ assert.equal(provider.get('vision-router').routingMode, 'auto')
115
+ assert.equal(provider.get('vision-router').routingPreference, 'balanced')
116
+
117
+ await fiber.dispose()
118
+ })
@@ -29,6 +29,8 @@ Vision Router 默认让完整视觉工具表从会话开始就保持稳定。正
29
29
 
30
30
  开启后,平时只暴露 `vision_activate`,首次需要时再挂载完整视觉工具;默认关闭时,完整视觉工具从一开始就常驻。视觉工具本身的能力不变。
31
31
 
32
+ **重要时序约束(DSH 0.2.x):** 宿主会在模型步骤开始前冻结本批可执行工具列表。因此纯文字任务中请先单独调用 `vision_activate`,等待该次调用完成,再在**下一模型步骤**调用 `vision_describe` 等深度工具;同一批并行调用会被宿主拒绝为 `UNKNOWN_TOOL`。图片消息正常会在模型步骤前提前挂载工具。首次激活完成后,工具注册会保持到插件 Fiber 卸载,并非仅对当前会话单独挂载。
33
+
32
34
  ## English
33
35
 
34
36
  Vision Router keeps the complete vision tool schema stable from the beginning of a session by default. Normal DSH bundle installs provide this composition layer:
@@ -55,3 +57,5 @@ Progressive exposure remains available as an advanced opt-in. If minimizing the
55
57
  `progressiveTools` determines which tools are registered at plugin startup, so it is a **boot-time setting**; do not rely on changing this field through live Web settings. Restart DSH after changing the profile patch.
56
58
 
57
59
  When enabled, only `vision_activate` is exposed initially and the complete vision tool set mounts on first use. With the default disabled mode, the complete vision tool set is present from the start. The vision capabilities themselves are unchanged.
60
+
61
+ **DSH 0.2.x step-snapshot contract:** The Host freezes the callable tool set at the start of each model step. On text-only turns, call `vision_activate` **alone**, wait for its result, and use `vision_describe` or another deep tool **in the next model step**. Batching the activation and deep-tool calls together produces Host `UNKNOWN_TOOL`. Image turns normally mount the tools before step admission. Once mounted, registration persists until the plugin Fiber is disposed; it is not scoped only to the current conversation.
@@ -0,0 +1,27 @@
1
+ # v3.1.5 — Vision reliability and model routing / 视觉稳定性与模型路由
2
+
3
+ **Publication status / 发布状态:** This document describes the v3.1.5 source contents; publication is proven only by a matching immutable GitHub Release, npm tarball and provenance from the protected Release workflow. Before that verification it is a candidate, not a released artifact. / 本文描述 v3.1.5 的源代码内容;只有受保护工作流形成并验证对应的不可变 GitHub Release、npm 包体及来源证明,才算正式发布。在验收完成之前仅为候选代码。
4
+
5
+ ## Runtime fixes / 运行时修复
6
+
7
+ - **#798: responsive cancellation / 取消后及时结束。** Vision Chain, direct `vision-http` and DVR-owned transparent adapters now bound waits on noncooperative visual iterators and cap abort cleanup at 1 second. Empty/whitespace/JSON-null answers are no longer cached as valid recognition. / 识图流遇到不响应取消的后端时不再无限等待;空白或 JSON 空结果不再写入成功缓存。
8
+ - **#799: cancellation is not backend failure / 主动取消不触发后端熔断。** A user/Host abort no longer records a provider failure in the breaker or turn-scoped memory. Actual HTTP 550/503 and timeouts retain failure classification. / 主动停止不会污染本轮后端故障记忆,真实错误处理规则保持不变。
9
+ - **#800: fair fallback budgets / 备用模型保留超时预算。** For multiple visual backends, `vision_describe`, vision OCR and opt-in whole-turn remote Vision Chain give later candidates a bounded opportunity after an earlier model hangs. Slow single-provider success and text-only routing preserve existing timeouts. / 前一个识图模型卡住时仍可尝试后续健康模型,覆盖视觉 OCR 和整轮视觉路由,不无故缩短单模型与纯文本超时。
10
+ - **#801: injected composite model dispatch / 注入模型正确分发。** A model-picker composite visual entry matching a live configured routing pair is dispatched through the registered `vision-chain`, with image blocks preserved, rather than sent as a foreign model ID to `deepseek-official`. Ordinary DeepSeek mirror models remain unchanged. / 模型列表中的有效视觉复合模型走实际视觉链,普通 DeepSeek 模型仍使用原委托路径。
11
+ - **#804 and #805: bounded server-error recovery / 有界服务端故障恢复。** Repeated HTTP 5xx failures, including status codes exposed as unbranded adapter text, no longer allow a silent vision fallback to consume the full request budget. / 连续 5xx 错误和不响应取消的视觉兜底请求会有界结束,兼容仅通过异常文本报告状态码的适配器。
12
+ - **#810: OCR and grounding fallback recovery / OCR 与定位回退恢复。** The same timeout guard also covers `vision_ocr`, `vision_ground`, `vision_pixel_diff` and shared visual-evidence helpers. / OCR、视觉定位、像素比对等工具同样受有界回退保护。
13
+ - **#809: progressive mount status / 渐进式工具挂载状态。** Use the Core-owned deferred Host-Fiber mount state to distinguish tools that have actually mounted from an i18n proxy that missed registration. This corrects an erroneous “unavailable” message but does not establish the original macOS reporter’s Vision-ON `UNKNOWN_TOOL` failure was fully resolved. / 正确识别延迟 Host Fiber 已挂载的深看工具,修复误报不可用;原用户 macOS 工具不可见现场仍未证实恢复。
14
+
15
+ ## Offline doctor / 离线诊断
16
+
17
+ - **#802 / issue #797: potential Host-core shadowing / Host 核心依赖覆盖风险。** A bounded, read-only scan reports profile-local `@deepseek-ai/dsh-*` manifests and third-party plugins declaring direct runtime Host-core dependencies. Findings are **possible/unverified**, not proof of actual Host module resolution. No automatic removal or profile mutation. Shareable reports contain only safe counts, not package paths or raw configuration. / 只读有界检查可疑核心包及第三方运行时依赖,仅作未验证风险提示,不自动修改用户文件;可分享报告只输出安全统计。
18
+
19
+ ## Open user reports / 尚未确认的现场反馈
20
+
21
+ - **#791 remains open:** The original reporter's 550 → 503 source is unknown and their restored image recognition was achieved independently; the fixes above address separately reproduced bugs, not proven provenance of those errors. / 原用户 550、503 的供应商或 Host 来源尚不确定,不能声称本版已确认解决原始问题。
22
+ - **#792 remains open:** Windows Desktop raw JS/CSS display has no verified field root cause. The prior renderer regression gate and new doctor advisory do not prove it is fixed. / Windows Desktop 启动源码外露的现场根因未确认,不能将检测门禁或诊断告警当作已修复证据。
23
+ - No Settings migration, new runtime dependencies/providers, public API break, Node/DSH support floor rise, broader permissions, or change to the default cloud image-egress/privacy policy. / 不变更设置结构、运行时依赖、公共 API、最低支持窗口、权限和默认云端识图外发政策。
24
+
25
+ ## Upgrade / 升级
26
+
27
+ **Only after verified publication**, update through the existing DSH profile plugin manager or an explicit `dsh-vision-router@3.1.5` install. Back up configuration before plugin changes; preserve all session data. / **仅在确认正式发布后**,通过原有插件管理器或指定版本升级,不需要删除配置或聊天历史。
@@ -0,0 +1,16 @@
1
+ # v3.2.0-rc.0 — Host and Node compatibility retirement
2
+
3
+ **Pre-release publication status:** This document describes the 3.2.0-rc.0 candidate. It becomes a published opt-in prerelease **only after** the protected workflow verifies the exact npm `next` tarball, immutable GitHub prerelease, assets and provenance. A branch name or source tag alone is not a published upgrade. This RC does not replace npm stable `latest`.
4
+
5
+ - Minimum DSH 0.2.1-rc.5 and Node.js 24.9.0; currently recommended DSH 0.2.2-rc.1.
6
+ - DSH 0.1.x and 0.2.0, earlier 0.2.1 RCs and Node 22 are retired from this new DVR minor.
7
+ - DSH exclusively owns Host Connection authentication, API and trustedHosts; DVR private readiness bridge removed. A minimal webServer injection-order patch remains to preserve third-party RPC routes (Windows 405 regression).
8
+ - The modules/webServer ordering shim and DVR recompose guard remain until separately qualified.
9
+ - Retire the conflicting anonymous-user-id and storage-domain optional peer declarations, but **retain one optional DSH LLM peer** as a legacy refusal guard: official DSH 0.2.0-rc.2 ignores `engines.dsh` and otherwise incorrectly admits this new plugin. Supported rc5/rc1 Hosts gate by `engines.dsh`. Strict pnpm installs with either RC now pass without manually adding anonymous-user-id; `sharp` stays optional.
10
+ - Historic session, Settings and attachment data are not deleted; user-owned custom profile patches require separate review.
11
+ - **Host historical data caveat:** DSH 0.2.1-rc.5 may reject released v0 `subagent/descriptor` version-2 records, and 0.2.2-rc.1 still rejects unnormalized legacy `permission/preset.origin` records. These are separate upstream persistence-reader issues, not DVR migration fixes. Never assert full history compatibility without a target-Host read-only migration acceptance test; do not edit live session logs.
12
+ - Release workflow validation now uses Node 24.21 instead of retired Node 22. RC builds use npm `next` plus GitHub prerelease, not `latest`; unreviewed prerelease channels fail before immutable Git tagging. A green PR does not authorize a real publish.
13
+ - Verified on the candidate branch: 66 GitHub CI checks succeeded (two conditionally skipped; SHA c142fcb) for DSH rc5/rc1 and three OSes; an additional manually dispatched Linux/macOS/Windows 100MP stress matrix passed on the same commit. These are engineering results, not a published release.
14
+ - Existing profiles with manual Connection overrides must pass the new **`doctor --upgrade-preflight` (fail-closed on known profile blockers)** and the [read-only upgrade preflight](../architecture/dvr32-host-retirement.md#upgrade-preflight-and-safe-rollback-for-existing-profiles). This Host-retirement change itself does not rewrite user-owned profile patches, session, image or Settings stores.
15
+ - Windows real-Host reload probes return the expected HTTP statuses within a 5-second bound, with isolated 1.5–2.1-second tail latencies; UI bundle switch can render an intermediate state before a subsequent read converges. Neither is evidence of a persistent 404 or permanent inverse switch.
16
+ - **Opt-in release boundary:** Protected prerelease workflow and exact-commit verification are mandatory before any publication claim. Users must not auto-migrate existing Profiles or historical Session data to validate this RC. #792 screenshot root cause is still unconfirmed; upstream #806 stale-Fiber HMR remains open even though the DVR-specific 404 trigger is mitigated.
@@ -0,0 +1,38 @@
1
+ # v3.2.0 — Host and Node compatibility retirement / Host 与 Node 兼容窗口调整
2
+
3
+ This is the curated **stable** v3.2.0 release note. Actual publication is established only by the successful protected Release workflow, the immutable GitHub Release and the matching npm `latest` artifact; a source branch or tag alone is not a publication. / 本文是 3.2.0 正式版发布说明,是否发布成功须以受保护 Release 流水线、GitHub Release 和 npm `latest` 同一构建产物核验为准。
4
+
5
+ ## Compatibility / 兼容性
6
+
7
+ - Minimum DSH `>=0.2.1-rc.5 <0.3.0-0` and Node.js `>=24.9.0`. Validated exact Host sources include DSH 0.2.1-rc.5 and 0.2.2-rc.1. Supported version-range admission is **not** a claim that every future DSH build has been tested.
8
+ - DSH 0.1.x, 0.2.0, earlier 0.2.1 RCs and Node 22 are no longer supported **by DVR 3.2**. Existing DVR 3.1.5 users can remain on their current working version while preparing the Host migration.
9
+ - DSH retains ownership of Connection authorization, API and trustedHosts. DVR removes its private readiness bridge and retains only a minimal `webStartup`/`webServer` injection-order patch required for independent third-party RPC routes; fully removing that ordering patch produced a reproducible Windows HTTP 405.
10
+ - One optional DSH LLM peer remains to prevent installation under old DSH 0.2.0-rc.2, which ignores `engines.dsh`. Strict pnpm dependency checks passed for both pinned supported Host lines.
11
+
12
+ ## Stability and release security / 稳定性与发布安全
13
+
14
+ - Includes visual-provider timeout and cancellation safeguards, proper fallback and model routing, progressive vision deep-tool activation, bounded grounding checks, and Windows/macOS/Linux real Host / Desktop regressions.
15
+ - Release verification tests, reproducible build, exact-source cross-platform Host gates, CodeQL and HOL security passed on the candidate main commit, subject to fresh checks on the final release-only metadata commit.
16
+ - The preceding v3.2.0-rc.0 publication **failed before npm**: the OIDC-only publish job had no `node_modules` while `scripts/release-channel.mjs` imported `semver`. PR #813 made the CLI dependency-free; PR #817 closed macOS/Windows path-alias silent-success risks. The preexisting `v3.2.0-rc.0` tag stays immutable and is not republished.
17
+ - Stable v3.2.0 must use the protected `Release` workflow with `tag=v3.2.0` and an exact, fully checked `main` SHA. The workflow maps stable versions to npm `latest`, verifies the tarball against the pre-tag candidate, signs/checks provenance, then publishes the GitHub Release with matching assets. Never publish manually to bypass these gates.
18
+
19
+ ## Upgrading an existing installation / 已有安装升级
20
+
21
+ 1. Confirm Node >=24.9.0 and the actual DSH Host version meets the new floor. Prefer an exact-tested Host; do not assume untested 0.2.x releases have equivalent behavior.
22
+ 2. Run the **read-only** `doctor --upgrade-preflight` before upgrading. It rejects known legacy Connection overlays, private readiness bridges, floating GitHub-version references and older Node; a pass does **not** guarantee complete historical data compatibility.
23
+ 3. Back up profile, Settings, image/attachment state and historical Session records; separately read-validate the copied records with the **target** DSH Host before changing a working profile. User-owned custom patches require manual review. Do not edit or normalize the live Session event log.
24
+ 4. Keep the prior known-good DVR 3.1.5 / Host environment available for rollback if real startup, Vision, Desktop reload, or data restoration fails. No automatic profile or Session migration/deletion is performed by this release.
25
+
26
+ ## Known boundaries / 已知边界
27
+
28
+ - Older DSH persistence formats, including released v0 `permission/preset.origin` and older `subagent/descriptor` records, can fail in particular Host readers. This is an upstream Host migration issue, not a DVR-owned session rewrite. Do not promise a universally lossless upgrade.
29
+ - The separate upstream DSH stale-Fiber/HMR defect remains open; the DVR-specific reload/404 trigger is mitigated, not the entire Host lifecycle issue. The original reported Windows raw JS/CSS screenshot and certain user-field failures have not been conclusively attributed to DVR.
30
+ - Non-loopback network, reverse proxy, untested custom profiles and future DSH releases are not universally certified by loopback CI. The default cloud Vision fallback sends image content to remote providers unless strictly local-only is configured.
31
+
32
+ ## 发布说明摘要(中文)
33
+
34
+ - **支持范围**:DSH >=0.2.1-rc.5、Node >=24.9;3.2 不再支持旧 DSH、Node 22,原先正常工作的 3.1.5 可暂不升级。
35
+ - **核心调整**:Connection 权限归还 DSH,保留保障其他插件 RPC 的必要顺序补丁,延续视觉链稳定性、深度工具和跨平台回归保护。
36
+ - **升级原则**:先运行只读升级预检、备份旧配置与会话、针对目标 Host 单独验收、保留回滚;不自动改写历史数据。
37
+ - **上游已知问题**:历史 Session 读取、HMR/Fiber 等不宣称已由本插件全部修复。
38
+ - **发布校验**:直接走修复后的受保护稳定版 Release 工作流,检查 npm `latest`、GitHub Release、包哈希及来源证明的一致性。
package/index.js CHANGED
@@ -90,6 +90,28 @@ async function* streamVisionWithAbort(source, signal) {
90
90
  }
91
91
  }
92
92
 
93
+ /**
94
+ * A third-party provider transport can ignore AbortSignal indefinitely.
95
+ * Bound the caller's wait independently from the transport's cooperation,
96
+ * while still passing the signal downstream so a real HTTP socket can close.
97
+ * The losing promise remains observed by Promise.race if it settles later.
98
+ */
99
+ async function awaitVisionBackendAttempt(signal, operation) {
100
+ if (!signal) return operation()
101
+ if (signal.aborted) throw signal.reason ?? new Error('vision backend attempt aborted')
102
+ let onAbort
103
+ const canceled = new Promise((_, reject) => {
104
+ onAbort = () => reject(signal.reason ?? new Error('vision backend attempt aborted'))
105
+ signal.addEventListener('abort', onAbort, { once: true })
106
+ if (signal.aborted) onAbort()
107
+ })
108
+ try {
109
+ return await Promise.race([Promise.resolve().then(operation), canceled])
110
+ } finally {
111
+ signal.removeEventListener('abort', onAbort)
112
+ }
113
+ }
114
+
93
115
  export * from './lib/vision-resilience.js'
94
116
 
95
117
  import z from '@deepseek-ai/schemastery'
@@ -129,6 +151,7 @@ import {
129
151
  import { currentVisionExecutionOrder } from './lib/vision-execution-order.js'
130
152
  import { applyVisionExecutionOrder } from './lib/vision-execution-order-apply.js'
131
153
  import { currentVisionTurnBudgetSignal } from './lib/turn-budget-context.js'
154
+ import { parseGroundingBoxResponse, assessGroundingBox } from './lib/grounding-box-recovery.js'
132
155
  import { createHash } from 'node:crypto'
133
156
  import {
134
157
  normalizeStructuredBootstrapResult,
@@ -461,6 +484,7 @@ import {
461
484
  DEFAULT_HTTP_PROVIDERS,
462
485
  httpProviderFallbackWeight,
463
486
  weightedFallbackBudget,
487
+ postServerOutageBudgetMs,
464
488
  localOnlyVisionEnabled,
465
489
  isLoopbackVisionBaseURL,
466
490
  localOllamaProvidersOf,
@@ -1134,6 +1158,15 @@ export function apply(ctx, config = {}, runtime = {}) {
1134
1158
  return undefined
1135
1159
  }
1136
1160
  }
1161
+ const officialStream = createWrapperStreamBody(ctx, {
1162
+ imageMemory,
1163
+ delegateProvider: wrapperDelegateRoute,
1164
+ instantLocal: instantLocalProvider,
1165
+ instantLocalStyle,
1166
+ instantLocalTimeoutMs: timeoutMs,
1167
+ instantLocalMaxPixels,
1168
+ providerTransport,
1169
+ }).stream
1137
1170
  wrapperAdapter = {
1138
1171
  providerInfo(provider) {
1139
1172
  return { id: provider, name: 'DeepSeek + 自动识图' }
@@ -1230,15 +1263,25 @@ export function apply(ctx, config = {}, runtime = {}) {
1230
1263
  inputModalities: ['text', 'image'],
1231
1264
  }
1232
1265
  },
1233
- ...createWrapperStreamBody(ctx, {
1234
- imageMemory,
1235
- delegateProvider: wrapperDelegateRoute,
1236
- instantLocal: instantLocalProvider,
1237
- instantLocalStyle,
1238
- instantLocalTimeoutMs: timeoutMs,
1239
- instantLocalMaxPixels,
1240
- providerTransport,
1241
- }),
1266
+ // The DeepSeek wrapper also advertises composite vision-chain entries
1267
+ // while whole-turn routing is enabled. Those entries are NOT DeepSeek
1268
+ // model ids: dispatching them through the normal wrapper stream sends
1269
+ // e.g. "remote-vlm/qwen-vl" to deepseek-official and always fails.
1270
+ // Delegate only exact live routing pairs to the registered vision
1271
+ // chain. The regular DeepSeek mirror keeps its normal text/image bridge.
1272
+ async *stream(options) {
1273
+ const isRoutingPair = routingEnabled() && routingPairs().some(
1274
+ (pair) => `${pair.provider}/${pair.model}` === options?.model
1275
+ && adapterAvailable(ctx.llm, pair.provider),
1276
+ )
1277
+ if (isRoutingPair) {
1278
+ // Keep the image blocks intact; the Host must route this
1279
+ // image-capable model through the actual visual chain.
1280
+ yield* ctx.llm.stream({ ...options, provider: chainRoute() })
1281
+ return
1282
+ }
1283
+ yield* officialStream(options)
1284
+ },
1242
1285
  }
1243
1286
  }
1244
1287
 
@@ -2098,10 +2141,12 @@ export function apply(ctx, config = {}, runtime = {}) {
2098
2141
  let failMessage = 'unknown error'
2099
2142
  let failCode
2100
2143
  try {
2101
- // Local backends get an independent anti-hang budget: a hung local
2102
- // service must not consume the whole deadline and starve the
2103
- // existing chain. Regular providers keep main's per-call timeout.
2104
- const attemptBudgetMs = isLocalBackendPair(pair)
2144
+ // In an image-bearing whole-turn chain, every candidate (remote
2145
+ // included) must leave a real share of the deadline for fallbacks.
2146
+ // Keep the existing local-backend guard and preserve text-only
2147
+ // remote routes' original per-call timeout semantics.
2148
+ const fairShare = imageIds.length > 0 || isLocalBackendPair(pair)
2149
+ const attemptBudgetMs = fairShare
2105
2150
  ? weightedFallbackBudget(
2106
2151
  deadline.remaining(),
2107
2152
  timeoutMs(),
@@ -2998,6 +3043,7 @@ export function apply(ctx, config = {}, runtime = {}) {
2998
3043
  const errors = [...rejectedPairs]
2999
3044
  const attempted = []
3000
3045
  const primaryWeight = DEFAULT_HTTP_PROVIDERS.length
3046
+ let consecutiveServerFailures = 0
3001
3047
  let remainingWeight =
3002
3048
  usablePairs.length * primaryWeight +
3003
3049
  httpFallbacks.reduce(
@@ -3122,7 +3168,13 @@ ctx.logger?.info(
3122
3168
  empty.code = 'EMPTY_RESPONSE'
3123
3169
  throw empty
3124
3170
  } catch (error) {
3171
+ // A user/Host cancel is not a backend outage. Otherwise the
3172
+ // canceled attempt poisons this turn's breaker/failure memory and
3173
+ // a healthy retry returns BACKEND_UNAVAILABLE_THIS_TURN.
3174
+ throwIfVisionTaskAborted(currentVisionTurnBudgetSignal(), error)
3125
3175
  const classification = classifyVisionFailure(error)
3176
+ consecutiveServerFailures = classification.kind === VISION_FAILURE_KINDS.SERVER
3177
+ ? consecutiveServerFailures + 1 : 0
3126
3178
  visionBreaker.record(backendKey, fingerprint, classification, scope)
3127
3179
  visionTurnMemory.record(scope, backendKey, classification.kind)
3128
3180
  attempted.push({
@@ -3186,13 +3238,22 @@ ctx.logger?.info(
3186
3238
  [{ role: 'user', content: openAIBlocks }],
3187
3239
  promptText,
3188
3240
  ).messages
3241
+ // A stalled HTTP fallback must leave a real share of the shared
3242
+ // turn deadline for later configured providers. The weighting
3243
+ // preserves a full single-provider budget and prioritizes
3244
+ // user-configured providers over built-in anonymous fallbacks.
3245
+ const attemptBudgetMs = postServerOutageBudgetMs(
3246
+ weightedFallbackBudget(deadline.remaining(), timeoutMs(), candidateWeight, weightAtStart),
3247
+ visionTaskTimeoutMs(),
3248
+ consecutiveServerFailures,
3249
+ )
3189
3250
  const attemptSignal = combineSignals(
3190
3251
  currentVisionTurnBudgetSignal(),
3191
3252
  deadline.signal(),
3192
- AbortSignal.timeout(timeoutMs()),
3253
+ AbortSignal.timeout(attemptBudgetMs),
3193
3254
  )
3194
3255
  const askHttp = async (correction) => {
3195
- const answer = await callOpenAIWithProviderTransport(
3256
+ const answer = await awaitVisionBackendAttempt(attemptSignal, () => callOpenAIWithProviderTransport(
3196
3257
  provider,
3197
3258
  correction === undefined
3198
3259
  ? openAIBaseMessages
@@ -3206,7 +3267,7 @@ ctx.logger?.info(
3206
3267
  sessionId,
3207
3268
  resolveCredential,
3208
3269
  },
3209
- )
3270
+ ))
3210
3271
  return answer
3211
3272
  }
3212
3273
  let text = await askHttp(undefined)
@@ -3255,7 +3316,13 @@ ctx.logger?.info(
3255
3316
  empty.code = 'EMPTY_RESPONSE'
3256
3317
  throw empty
3257
3318
  } catch (error) {
3319
+ // A user/Host cancel is not a backend outage. Otherwise the
3320
+ // canceled attempt poisons this turn's breaker/failure memory and
3321
+ // a healthy retry returns BACKEND_UNAVAILABLE_THIS_TURN.
3322
+ throwIfVisionTaskAborted(currentVisionTurnBudgetSignal(), error)
3258
3323
  const classification = classifyVisionFailure(error)
3324
+ consecutiveServerFailures = classification.kind === VISION_FAILURE_KINDS.SERVER
3325
+ ? consecutiveServerFailures + 1 : 0
3259
3326
  visionBreaker.record(backendKey, fingerprint, classification, scope)
3260
3327
  visionTurnMemory.record(scope, backendKey, classification.kind)
3261
3328
  attempted.push({
@@ -3644,6 +3711,7 @@ ctx.logger?.info(
3644
3711
  (sum, provider) => sum + httpProviderFallbackWeight(provider),
3645
3712
  0,
3646
3713
  )
3714
+ let consecutiveServerFailures = 0
3647
3715
  const pairCapabilities = new Map()
3648
3716
  for (const pair of pairs()) {
3649
3717
  if (!pair || pair.provider === HTTP_ROUTE) continue
@@ -3729,6 +3797,8 @@ ctx.logger?.info(
3729
3797
  } catch (error) {
3730
3798
  throwIfVisionTaskAborted(taskSignal, error)
3731
3799
  const classification = classifyVisionFailure(error)
3800
+ consecutiveServerFailures = classification.kind === VISION_FAILURE_KINDS.SERVER
3801
+ ? consecutiveServerFailures + 1 : 0
3732
3802
  visionBreaker.record(pairKey, fingerprint, classification, scope)
3733
3803
  recordFailure(pairKey, classification, error && error.message ? error.message : String(error))
3734
3804
  }
@@ -3756,25 +3826,43 @@ ctx.logger?.info(
3756
3826
  continue
3757
3827
  }
3758
3828
  try {
3759
- const text = await callOpenAIWithProviderTransport(
3829
+ // Shared across OCR, grounding and visual evidence helpers: a
3830
+ // hanging HTTP model must leave time for the next candidate. A
3831
+ // transport that ignores AbortSignal must not outlive its share
3832
+ // either, and after two consecutive server failures the recovery
3833
+ // tail is tightened like the vision_describe walk.
3834
+ const attemptBudgetMs = postServerOutageBudgetMs(
3835
+ weightedFallbackBudget(
3836
+ deadline.remaining(),
3837
+ timeoutMs(),
3838
+ candidateWeight,
3839
+ weightAtStart,
3840
+ ),
3841
+ visionTaskTimeoutMs(),
3842
+ consecutiveServerFailures,
3843
+ )
3844
+ const attemptSignal = combineSignals(
3845
+ taskSignal,
3846
+ deadline.signal(),
3847
+ AbortSignal.timeout(attemptBudgetMs),
3848
+ )
3849
+ const text = await awaitVisionBackendAttempt(attemptSignal, () => callOpenAIWithProviderTransport(
3760
3850
  provider,
3761
3851
  [{ role: 'user', content: [...httpContent, { type: 'text', text: instruction }] }],
3762
3852
  {
3763
3853
  maxTokens: provider.maxTokens ?? 4096,
3764
- signal: combineSignals(
3765
- taskSignal,
3766
- deadline.signal(),
3767
- AbortSignal.timeout(timeoutMs()),
3768
- ),
3854
+ signal: attemptSignal,
3769
3855
  sessionId: options.sessionId,
3770
3856
  resolveCredential,
3771
3857
  },
3772
- )
3858
+ ))
3773
3859
  throwIfVisionTaskAborted(taskSignal)
3774
3860
  if (text && text.trim() !== '') return { ok: true, text: text.trim() }
3775
3861
  } catch (error) {
3776
3862
  throwIfVisionTaskAborted(taskSignal, error)
3777
3863
  const classification = classifyVisionFailure(error)
3864
+ consecutiveServerFailures = classification.kind === VISION_FAILURE_KINDS.SERVER
3865
+ ? consecutiveServerFailures + 1 : 0
3778
3866
  visionBreaker.record(backendKey, fingerprint, classification, scope)
3779
3867
  recordFailure(backendKey, classification, error && error.message ? error.message : String(error))
3780
3868
  }
@@ -3819,60 +3907,52 @@ ctx.logger?.info(
3819
3907
  const { bytes, mediaType } = await readImageBytes(exec, args.image)
3820
3908
  const { width, height } = await imageDims(bytes)
3821
3909
  if (width <= 0 || height <= 0) throw new Error('vision_ground: could not read image dimensions')
3910
+ const target = String(args.target).slice(0, 500)
3911
+ // Internal-only frame metadata comes from the trusted framing runtime,
3912
+ // not the user's tool schema. The model sees exact content bounds.
3913
+ const content = args.__dvrGroundingContentRect
3914
+ const frameHint = content &&
3915
+ [content.x1, content.y1, content.x2, content.y2].every(Number.isInteger)
3916
+ ? `The supplied image is a letterboxed ${width}x${height} frame with BLACK padding. ` +
3917
+ `Only x=[${content.x1},${content.x2}] and y=[${content.y1},${content.y2}] contain image pixels. ` +
3918
+ 'Never return a box in the source image dimensions or black padding. '
3919
+ : ''
3822
3920
  const instruction =
3823
- `Target to locate: "${String(args.target).slice(0, 500)}". ` +
3824
- `The image is ${width}x${height} pixels. Return ONE JSON object with integer fields ` +
3921
+ `Target to locate: "${target}". ` +
3922
+ `The image is ${width}x${height} pixels. ` + frameHint +
3923
+ `Return ONE JSON object with integer fields ` +
3825
3924
  `{"x1":...,"y1":...,"x2":...,"y2":...} — the tight bounding box of that target in ` +
3826
- `ORIGINAL image pixels (0 <= x1 < x2 <= ${width}, 0 <= y1 < y2 <= ${height}). ` +
3925
+ `the pixels of the image you received (0 <= x1 < x2 <= ${width}, 0 <= y1 < y2 <= ${height}). ` +
3827
3926
  `Output only the JSON object.`
3828
3927
  const vision = await answerVisionForTool(exec, bytes, mediaType, instruction)
3829
3928
  if (vision.ok === false) return JSON.stringify(vision)
3830
- const text = vision.text
3831
- const parsed = extractJson(text)
3832
- const box = parsed !== undefined ? parseBox(parsed) : undefined
3833
- if (box === undefined) {
3834
- throw new Error(`vision_ground: the vision model did not return a valid box. Raw output: ${text.slice(0, 500)}`)
3835
- }
3836
- let clamped = {
3837
- x1: Math.max(0, Math.min(box.x1, width - 1)),
3838
- y1: Math.max(0, Math.min(box.y1, height - 1)),
3839
- x2: Math.max(1, Math.min(box.x2, width)),
3840
- y2: Math.max(1, Math.min(box.y2, height)),
3841
- }
3842
- if (clamped.x2 - clamped.x1 < 2 || clamped.y2 - clamped.y1 < 2) {
3843
- // Some vision models answer with a degenerate sliver (e.g. 1px wide)
3844
- // instead of the target's box. Demand the full box once more before
3845
- // giving up.
3929
+ let assessment = assessGroundingBox(
3930
+ parseGroundingBoxResponse(vision.text), width, height, content,
3931
+ )
3932
+ if (!assessment.ok) {
3933
+ // A single correction only, including near-JSON, degenerate, and
3934
+ // wrong coordinate-space outputs. Both calls share the existing
3935
+ // turn-scoped signal/budget, provider policy, and abort behavior.
3846
3936
  const retry = await answerVisionForTool(
3847
- exec,
3848
- bytes,
3849
- mediaType,
3850
- `Your previous box ${JSON.stringify(clamped)} was a degenerate sliver, not the target. ` +
3851
- `Return ONE JSON object with the FULL tight bounding box of the target in ORIGINAL ` +
3852
- `image pixels (0 <= x1 < x2 <= ${width}, 0 <= y1 < y2 <= ${height}). Output only the JSON object.`,
3937
+ exec, bytes, mediaType,
3938
+ `Your preceding answer was invalid (${assessment.reason}). ` +
3939
+ `Locate the same target: "${target}". ` + frameHint +
3940
+ `Return one strictly valid JSON object with integer x1,y1,x2,y2 ` +
3941
+ `inside the received ${width}x${height} frame, without black padding. ` +
3942
+ 'Do not reuse the previous coordinates unless verified against the image. No prose.',
3853
3943
  )
3854
3944
  if (retry.ok === false) return JSON.stringify(retry)
3855
- const retryParsed = extractJson(retry.text)
3856
- const retryBox = retryParsed !== undefined ? parseBox(retryParsed) : undefined
3857
- if (retryBox === undefined) {
3858
- throw new Error(
3859
- `vision_ground: the vision model returned a degenerate box (${clamped.x1},${clamped.y1},${clamped.x2},${clamped.y2}) ` +
3860
- `and the retry returned no valid box. Raw output: ${retry.text.slice(0, 500)}`,
3861
- )
3862
- }
3863
- clamped = {
3864
- x1: Math.max(0, Math.min(retryBox.x1, width - 1)),
3865
- y1: Math.max(0, Math.min(retryBox.y1, height - 1)),
3866
- x2: Math.max(1, Math.min(retryBox.x2, width)),
3867
- y2: Math.max(1, Math.min(retryBox.y2, height)),
3868
- }
3869
- if (clamped.x2 - clamped.x1 < 2 || clamped.y2 - clamped.y1 < 2) {
3945
+ assessment = assessGroundingBox(
3946
+ parseGroundingBoxResponse(retry.text), width, height, content,
3947
+ )
3948
+ if (!assessment.ok) {
3870
3949
  throw new Error(
3871
- `vision_ground: the vision model returned only degenerate boxes for a ${width}x${height} image. ` +
3872
- `Last raw output: ${retry.text.slice(0, 500)}`,
3950
+ `vision_ground: no valid bounding box after one correction (${assessment.reason}). ` +
3951
+ `Last model output: ${String(retry.text).slice(0, 500)}`,
3873
3952
  )
3874
3953
  }
3875
3954
  }
3955
+ const clamped = assessment.box
3876
3956
  const result = { ...clamped, width, height }
3877
3957
  if (args.annotate !== false) {
3878
3958
  const annotated = await annotateBoxBuffer(bytes, clamped)
@@ -4861,7 +4941,7 @@ ctx.logger?.info(
4861
4941
  let deepActive = false
4862
4942
  const deepDisposers = []
4863
4943
  activateDeepTools = () => {
4864
- if (deepActive) return '视觉深看工具已在挂载状态。'
4944
+ if (deepActive) return '视觉深看工具已在挂载状态。请在下一模型步骤调用深度工具,不要与 vision_activate 同批并行调用。'
4865
4945
  deepActive = true
4866
4946
  try {
4867
4947
  for (const def of deepToolDefs) {
@@ -4910,7 +4990,7 @@ ctx.logger?.info(
4910
4990
  '视觉深看工具已挂载:vision_bootstrap(结构化预识别)、vision_describe(看图问答)、vision_ground(像素定位)、vision_detect(元素清单)、' +
4911
4991
  'vision_materialize(附件落盘)、vision_crop(裁剪放大)、vision_pixel_diff(像素对比验证)、vision_colors(取色)、' +
4912
4992
  'vision_ocr(文字识别)、vision_trace(SVG 矢量化)、vision_extract_foreground(抠图)、' +
4913
- 'vision_html_screenshot(页面截图)。现在可以直接调用已启用的工具。' +
4993
+ 'vision_html_screenshot(页面截图)。本次激活调用结束后,下一模型步骤才可调用深度工具;不要在同一批并行工具调用中同时请求 vision_activate 和 vision_describe 等深度工具。' +
4914
4994
  '注意:vision_ocr 只用于读取图片文字;视觉工具返回 ok:false 后端不可用结果时,不要改问法重复调用,继续文本任务。'
4915
4995
  )
4916
4996
  }
@@ -4923,6 +5003,13 @@ ctx.logger?.info(
4923
5003
  )
4924
5004
 
4925
5005
  if (progressive) {
5006
+ // Delayed Cordis Fiber registrations may run outside the i18n decorator's
5007
+ // AsyncLocalStorage scope. Report the Core-owned mount state directly
5008
+ // rather than inferring success from which proxy observed registration.
5009
+ const activationExecute = async () => activateDeepTools()
5010
+ Object.defineProperty(activationExecute, Symbol.for('dsh-vision-router.deep-tools-mounted'), {
5011
+ value: () => deepActive,
5012
+ })
4926
5013
  ctx.effect(
4927
5014
  () =>
4928
5015
  ctx.tools.register({
@@ -4930,13 +5017,11 @@ ctx.logger?.info(
4930
5017
  description:
4931
5018
  'Mount the deep vision tools (vision_bootstrap / vision_describe / vision_ground / vision_detect / vision_materialize / vision_crop / ' +
4932
5019
  'vision_pixel_diff / vision_colors / vision_ocr / vision_trace / ' +
4933
- 'vision_extract_foreground / vision_present / vision_html_screenshot) for this session. Desktop screenshot remains disabled until the user explicitly opts in through Vision Router settings. They mount ' +
5020
+ 'vision_extract_foreground / vision_present / vision_html_screenshot) for subsequent model steps. Do not call any deep vision tool in the same parallel tool batch as vision_activate: DSH freezes the callable tool set before executing that batch. Desktop screenshot remains disabled until the user explicitly opts in through Vision Router settings. They mount ' +
4934
5021
  'automatically on image turns; call this only when you need them on a text-only turn.',
4935
5022
  parameters: { type: 'object', properties: {}, additionalProperties: false },
4936
5023
  output: stringOutput,
4937
- async execute() {
4938
- return activateDeepTools()
4939
- },
5024
+ execute: activationExecute,
4940
5025
  }),
4941
5026
  'vision-router: progressive bootstrap tool',
4942
5027
  )
@@ -4960,8 +5045,8 @@ ctx.logger?.info(
4960
5045
  '# 视觉深看工具(vision-tools)\n\n' +
4961
5046
  '当任务需要像素级视觉操作——照着图写 UI、定位元素、裁剪放大细看、像素对比验证还原结果、' +
4962
5047
  '提取配色、识别图中文字、矢量化图标、抠图、把生成图片安全展示给用户或给页面截图——时使用本套工具。' +
4963
- '图片消息会自动挂载它们;纯文字任务需要时可调用 `vision_activate`(只需一次)。\n' +
4964
- 'Use these tools for pixel-level vision work. They auto-mount on image turns; on text-only turns call `vision_activate` once if needed. When structured bootstrap is enabled, call `vision_bootstrap` first, then MUST call at least 1 evidence/deepening vision tool before answering; after that use more tools as needed.\n\n' +
5048
+ '图片消息会自动挂载它们;纯文字任务需要时先单独调用 `vision_activate`,等待这一批调用结束,下一模型步骤再调用深看工具;不可同批并行调用。\n' +
5049
+ 'Use these tools for pixel-level vision work. They auto-mount on image turns. On text-only turns, call `vision_activate` alone, wait for its result, then use deep tools in a subsequent model step; never batch activation and deep-tool calls together. When structured bootstrap is enabled, call `vision_bootstrap` first, then MUST call at least 1 evidence/deepening vision tool before answering; after that use more tools as needed.\n\n' +
4965
5050
  '1. 定位与细看:`vision_ground` 定位 → `vision_crop` 裁剪放大 → `vision_describe` 细看;盘点页面元素用 `vision_detect`(编号清单+框,可引用“元素 #n”);\n' +
4966
5051
  '2. 还原验证循环(本插件招牌流程):参考图 → 实现 → `vision_html_screenshot` 截图 → `vision_pixel_diff` 度量差异 → 修复 → 再截图,迭代到差异收敛(0% 是常见终点);长页面用 `fullPage: true` 一次截整页并拿到 `pageHeight`;\n' +
4967
5052
  '3. 其余按需取用:配色用 `vision_colors`,文字用 `vision_ocr`,图标矢量化用 `vision_trace`,纯色背景抠图用 `vision_extract_foreground`,本地 HTML 截图用 `vision_html_screenshot`(长页面加 `fullPage: true` 截整页);\n' +