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.
- package/README.md +3 -3
- package/README.zh.md +3 -3
- package/cordis.patch.yml +8 -15
- package/docs/architecture/dsh-support-window-3.1-historical.md +98 -0
- package/docs/architecture/dsh-support-window.md +30 -83
- package/docs/architecture/dvr32-host-retirement.md +194 -0
- package/docs/ci-archive/README.md +3 -0
- package/docs/ci-archive/minimum-host-settings-persistence.legacy.js +118 -0
- package/docs/progressive-tools-cache.md +4 -0
- package/docs/releases/v3.1.5.md +27 -0
- package/docs/releases/v3.2.0-rc.0.md +16 -0
- package/docs/releases/v3.2.0.md +38 -0
- package/index.js +158 -73
- package/lib/core-primitives.js +18 -0
- package/lib/doctor-cli-p0.js +14 -1
- package/lib/doctor-cli.js +71 -2
- package/lib/doctor-runtime.js +12 -3
- package/lib/doctor.js +141 -2
- package/lib/dsh-support-window.js +80 -31
- package/lib/grounding-box-recovery.js +76 -0
- package/lib/grounding-coordinate-runtime.js +10 -0
- package/lib/runtime-i18n-boundary.js +17 -4
- package/lib/runtime-i18n.js +4 -4
- package/lib/vision-resilience.js +71 -11
- package/lib/vision-tool-runtime-boundary.js +46 -6
- package/package.json +16 -24
- package/presets/README.md +0 -9
- package/presets/web-connection-ready/index.mjs +0 -48
- package/presets/web-connection-ready/package.json +0 -6
package/lib/core-primitives.js
CHANGED
|
@@ -1819,6 +1819,24 @@ export function weightedFallbackBudget(
|
|
|
1819
1819
|
return Math.max(1, Math.min(remaining, callLimit, share))
|
|
1820
1820
|
}
|
|
1821
1821
|
|
|
1822
|
+
/**
|
|
1823
|
+
* After two consecutive server-side 5xx failures, a later HTTP backend that
|
|
1824
|
+
* never responds must not consume the full default 120-second task. Keep a
|
|
1825
|
+
* full budget for normal single/first-provider calls and for recoverable
|
|
1826
|
+
* one-off failures; only tighten the post-outage recovery tail.
|
|
1827
|
+
*
|
|
1828
|
+
* With the default task timeout, this limits a silent third HTTP backend to
|
|
1829
|
+
* 20 seconds. Explicit smaller timeouts remain authoritative.
|
|
1830
|
+
*/
|
|
1831
|
+
export function postServerOutageBudgetMs(attemptBudgetMs, taskTimeoutMs, consecutiveServerFailures) {
|
|
1832
|
+
if (!Number.isInteger(consecutiveServerFailures) || consecutiveServerFailures < 2) return attemptBudgetMs
|
|
1833
|
+
const taskBudget = Math.max(1, Math.floor(Number(taskTimeoutMs) || 1))
|
|
1834
|
+
// A deliberately extended task allowance takes precedence over this
|
|
1835
|
+
// default-only outage recovery policy (the regular per-call limit remains).
|
|
1836
|
+
if (taskBudget > 120_000) return attemptBudgetMs
|
|
1837
|
+
return Math.max(1, Math.min(attemptBudgetMs, 20_000, Math.floor(taskBudget / 4)))
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1822
1840
|
/**
|
|
1823
1841
|
* dsh-vision 并入:本地 Ollama 视觉后端条目。
|
|
1824
1842
|
* 启用时返回单个 local-ollama provider(OpenAI 兼容、无 Key)。
|
package/lib/doctor-cli-p0.js
CHANGED
|
@@ -179,7 +179,20 @@ export async function run(argv = process.argv.slice(2), io = console, env = proc
|
|
|
179
179
|
report.hostCapabilitiesSource = probe.source
|
|
180
180
|
report.hostSupportWindow = DSH_SUPPORT_WINDOW
|
|
181
181
|
report.hostVerificationEvidence = DSH_VERIFICATION_EVIDENCE
|
|
182
|
-
|
|
182
|
+
// An old feature-rich Host must not be admitted based on attachments alone.
|
|
183
|
+
// Multiple profiles with mismatched or absent Host versions stay unknown.
|
|
184
|
+
const rows = report.platform?.hostPackages ?? []
|
|
185
|
+
const detected = rows.map((row) => row.packages?.['@deepseek-ai/dsh'])
|
|
186
|
+
const hostVersion = detected.length > 0 && detected.every((value) =>
|
|
187
|
+
typeof value === 'string' && value === detected[0])
|
|
188
|
+
? detected[0] : undefined
|
|
189
|
+
report.hostSupportVersionEvidence = {
|
|
190
|
+
source: hostVersion ? 'installed-profile-package' : 'unverified',
|
|
191
|
+
version: hostVersion ?? null,
|
|
192
|
+
}
|
|
193
|
+
report.hostSupportAdvice = supportWindowUpgradeAdvice(probe.capabilities, {
|
|
194
|
+
nodeVersion: process.versions.node, hostVersion,
|
|
195
|
+
})
|
|
183
196
|
io.log(JSON.stringify(report, null, 2))
|
|
184
197
|
return code
|
|
185
198
|
} catch {
|
package/lib/doctor-cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import { inspectDoctorVisionLimits, formatDoctorVisionLimits } from './doctor-vi
|
|
|
8
8
|
import { repairLegacySessionLogs } from './legacy-session-repair.js'
|
|
9
9
|
|
|
10
10
|
function usage() {
|
|
11
|
-
return `dsh-vision-router doctor [--profile <name>] [--json | --issue-template] [--sessions] [--runtime-url <url>] [--no-runtime] [--fix]\ndsh-vision-router repair [--profile <name>]\ndsh-vision-router repair-sessions\n\nChecks installation, profile composition, runtime routes, recent settings-save failures and local vision capabilities.\n\nCommands:\n doctor Read-only health report by default. --fix is kept for compatibility but prefer the explicit repair command.\n repair Safely remove a leading UTF-8 BOM and rewrite stale version-pinned minimumReleaseAgeExclude entries.\n repair-sessions Offline repair for exact known Vision Router session corruptions, including the legacy missing-id reminder and duplicate structured guard-stop messages. Stop DSH first.\n\nOptions:\n --profile <name> Check only one profile (for example: web).\n --json Emit a shareable, secret-minimized JSON diagnostic report.\n --issue-template Print a safe, Markdown issue template with diagnostics and fill-in reproduction fields. Read-only.\n --sessions Also scan session logs for exact known Vision Router corruption signatures (read-only; may take longer).\n --runtime-url <url> Probe a running DSH web instance (default: DSH_WEB_URL or http://127.0.0.1:3080).\n --no-runtime Skip the read-only runtime route probe.\n --fix Backward-compatible doctor repair mode; prefer \`repair\`.\n --help Show this help.\n`
|
|
11
|
+
return `dsh-vision-router doctor [--profile <name>] [--json | --issue-template] [--sessions] [--runtime-url <url>] [--no-runtime] [--upgrade-preflight] [--fix]\ndsh-vision-router repair [--profile <name>]\ndsh-vision-router repair-sessions\n\nChecks installation, profile composition, runtime routes, recent settings-save failures and local vision capabilities.\n\nCommands:\n doctor Read-only health report by default. --fix is kept for compatibility but prefer the explicit repair command.\n repair Safely remove a leading UTF-8 BOM and rewrite stale version-pinned minimumReleaseAgeExclude entries.\n repair-sessions Offline repair for exact known Vision Router session corruptions, including the legacy missing-id reminder and duplicate structured guard-stop messages. Stop DSH first.\n\nOptions:\n --profile <name> Check only one profile (for example: web).\n --json Emit a shareable, secret-minimized JSON diagnostic report.\n --issue-template Print a safe, Markdown issue template with diagnostics and fill-in reproduction fields. Read-only.\n --sessions Also scan session logs for exact known Vision Router corruption signatures (read-only; may take longer).\n --runtime-url <url> Probe a running DSH web instance (default: DSH_WEB_URL or http://127.0.0.1:3080).\n --no-runtime Skip the read-only runtime route probe.\n --upgrade-preflight Read-only gate for known 3.2 profile migration hazards; not a full release approval.\n --fix Backward-compatible doctor repair mode; prefer \`repair\`.\n --help Show this help.\n`
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function parseArgs(argv) {
|
|
@@ -20,6 +20,7 @@ function parseArgs(argv) {
|
|
|
20
20
|
let json = false
|
|
21
21
|
let issueTemplate = false
|
|
22
22
|
let sessions = false
|
|
23
|
+
let upgradePreflight = false
|
|
23
24
|
let runtime = command === 'doctor'
|
|
24
25
|
let runtimeUrl
|
|
25
26
|
|
|
@@ -41,6 +42,11 @@ function parseArgs(argv) {
|
|
|
41
42
|
issueTemplate = true
|
|
42
43
|
continue
|
|
43
44
|
}
|
|
45
|
+
if (value === '--upgrade-preflight') {
|
|
46
|
+
if (command !== 'doctor') throw new Error('--upgrade-preflight is only used with doctor')
|
|
47
|
+
upgradePreflight = true
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
44
50
|
if (value === '--sessions') {
|
|
45
51
|
if (command !== 'doctor') throw new Error('--sessions is only used with doctor')
|
|
46
52
|
sessions = true
|
|
@@ -83,6 +89,8 @@ function parseArgs(argv) {
|
|
|
83
89
|
if (!['doctor', 'repair', 'repair-sessions'].includes(command)) throw new Error(`unknown command: ${command}`)
|
|
84
90
|
if (issueTemplate && json) throw new Error('--issue-template and --json cannot be combined')
|
|
85
91
|
if (issueTemplate && fix) throw new Error('--issue-template is read-only and cannot be combined with --fix')
|
|
92
|
+
if (upgradePreflight && fix) throw new Error('--upgrade-preflight is read-only and cannot be combined with --fix')
|
|
93
|
+
if (upgradePreflight && issueTemplate) throw new Error('--upgrade-preflight is not an issue template; use --json instead')
|
|
86
94
|
if (profile && (!/^[A-Za-z0-9._-]+$/.test(profile) || profile === '.' || profile === '..')) {
|
|
87
95
|
throw new Error(`invalid profile name: ${profile}`)
|
|
88
96
|
}
|
|
@@ -91,7 +99,7 @@ function parseArgs(argv) {
|
|
|
91
99
|
try { parsed = new URL(runtimeUrl) } catch { throw new Error(`invalid runtime URL: ${runtimeUrl}`) }
|
|
92
100
|
if (!['http:', 'https:'].includes(parsed.protocol)) throw new Error(`invalid runtime URL protocol: ${parsed.protocol}`)
|
|
93
101
|
}
|
|
94
|
-
return { command, profile, fix, json, issueTemplate, sessions, runtime, runtimeUrl }
|
|
102
|
+
return { command, profile, fix, json, issueTemplate, sessions, upgradePreflight, runtime, runtimeUrl }
|
|
95
103
|
}
|
|
96
104
|
|
|
97
105
|
/**
|
|
@@ -129,6 +137,9 @@ function formatIssueTemplate(report) {
|
|
|
129
137
|
`- Node: ${version(platform.node)} (${platform.nodeSupported ? 'supported' : 'outside or unverified support window'})`,
|
|
130
138
|
`- Vision Router profiles: ${applicable.length} applicable; ${failed.length} installation/problem profile(s)`,
|
|
131
139
|
`- Install modes: ${modes}`,
|
|
140
|
+
`- Offline Host core advisories: ${applicable.filter((profile) => (profile.hostCore?.advisoryCount ?? 0) > 0).length} profile(s), unverified (no Host resolution test)`,
|
|
141
|
+
`- Profile-owned Connection overrides: ${applicable.filter((profile) => (profile.patch?.connectionOverrideRows ?? 0) > 0).length} profile(s), manual review required`,
|
|
142
|
+
`- Retired private Connection-bridge references: ${applicable.filter((profile) => (profile.patch?.retiredReadyBridgeRows ?? 0) + (profile.patch?.retiredReadyInjectionRows ?? 0) > 0).length} profile(s)`,
|
|
132
143
|
`- Runtime: ${runtimeState}`,
|
|
133
144
|
`- Settings save failures: ${number(report.log?.currentSettingsFailureCount)} current / ${number(report.log?.historicalSettingsFailureCount)} historical`,
|
|
134
145
|
`- Known session issues: ${sessionState}`,
|
|
@@ -189,6 +200,52 @@ function printProfileDetails(profile, io) {
|
|
|
189
200
|
for (const warning of profile.installation?.warnings ?? []) io.log(` ! ${warning}`)
|
|
190
201
|
}
|
|
191
202
|
|
|
203
|
+
/** Source refs are classified without dereferencing credentials or Git.
|
|
204
|
+
* A lockfile contains a resolved commit today, but lockfile regeneration can
|
|
205
|
+
* still follow the mutable manifest source.
|
|
206
|
+
*/
|
|
207
|
+
export function isFloatingDvrGitSource(spec) {
|
|
208
|
+
if (typeof spec !== 'string') return false
|
|
209
|
+
const source = spec.trim()
|
|
210
|
+
if (!/^(?:github:|git\+|git@|https?:\/\/(?:www\.)?github\.com\/)/i.test(source)) return false
|
|
211
|
+
const anchor = source.indexOf('#')
|
|
212
|
+
if (anchor < 0 || anchor === source.length - 1) return true
|
|
213
|
+
const ref = source.slice(anchor + 1)
|
|
214
|
+
if (/^[0-9a-f]{40}$/i.test(ref)) return false
|
|
215
|
+
if (/^v?\d+\.\d+\.\d+(?:-[0-9a-z.-]+)?$/i.test(ref)) return false
|
|
216
|
+
// Branch names, semver ranges, HEAD and unconventional tags need
|
|
217
|
+
// review before the 3.2 Host floor becomes user-facing.
|
|
218
|
+
return true
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Read-only, intentionally narrow upgrade fence. This reports only known
|
|
222
|
+
* profile-owned composition blockers. It does not establish the running
|
|
223
|
+
* Desktop Host version or prove image/transport/session functionality.
|
|
224
|
+
* Counts only: no user paths, hostnames, credentials or patch bodies.
|
|
225
|
+
*/
|
|
226
|
+
export function assessUpgradeProfileRisk(profileReport, platform) {
|
|
227
|
+
const applicable = (profileReport?.profiles ?? []).filter((item) => item.installation?.applicable)
|
|
228
|
+
const count = (predicate) => applicable.filter(predicate).length
|
|
229
|
+
const blockers = []
|
|
230
|
+
const add = (code, n) => { if (n > 0) blockers.push({ code, affectedProfiles: n }) }
|
|
231
|
+
add('PROFILE_CONNECTION_OVERRIDE', count((p) => (p.patch?.connectionOverrideRows ?? 0) > 0))
|
|
232
|
+
add('RETIRED_READY_BRIDGE_REFERENCE', count((p) =>
|
|
233
|
+
(p.patch?.retiredReadyBridgeRows ?? 0) + (p.patch?.retiredReadyInjectionRows ?? 0) > 0))
|
|
234
|
+
add('STALE_WORKSPACE_RELEASE_AGE_PIN', count((p) =>
|
|
235
|
+
(p.workspace?.pinned?.length ?? 0) > 0 && p.workspace?.rewritten !== true))
|
|
236
|
+
add('FLOATING_GITHUB_DVR_SOURCE', count((p) => isFloatingDvrGitSource(p.pluginDependency)))
|
|
237
|
+
if (platform?.nodeSupported === false) add('NODE_BELOW_3_2_MINIMUM', 1)
|
|
238
|
+
return Object.freeze({
|
|
239
|
+
scope: 'known-profile-risks-only',
|
|
240
|
+
profileCount: applicable.length,
|
|
241
|
+
pass: Boolean(profileReport?.ok) && blockers.length === 0,
|
|
242
|
+
blockers,
|
|
243
|
+
actualDesktopHostVersionVerified: false,
|
|
244
|
+
runtimeAndHistoricalDataVerified: false,
|
|
245
|
+
fullReleaseApproval: false,
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
192
249
|
function runSessionRepair(dshHome, io) {
|
|
193
250
|
let report
|
|
194
251
|
try {
|
|
@@ -273,13 +330,17 @@ export async function run(argv = process.argv.slice(2), io = console, env = proc
|
|
|
273
330
|
let sessions
|
|
274
331
|
if (options.sessions) sessions = repairLegacySessionLogs({ dshHome, fix: false })
|
|
275
332
|
|
|
333
|
+
const upgradePreflight = options.upgradePreflight
|
|
334
|
+
? assessUpgradeProfileRisk(profileReport, platform) : undefined
|
|
276
335
|
const overallOk = profileReport.ok
|
|
277
336
|
&& (runtime?.ok ?? true)
|
|
278
337
|
&& (!sessions || (sessions.affected === 0 && sessions.errors.length === 0))
|
|
338
|
+
&& (!upgradePreflight || upgradePreflight.pass)
|
|
279
339
|
|
|
280
340
|
if (options.json || options.issueTemplate) {
|
|
281
341
|
const report = supportReport({ profileReport, runtime, platform, sessions })
|
|
282
342
|
report.visionLimits = visionLimits
|
|
343
|
+
if (upgradePreflight) report.upgradePreflight = upgradePreflight
|
|
283
344
|
report.ok = overallOk
|
|
284
345
|
io.log(options.issueTemplate ? formatIssueTemplate(report) : JSON.stringify(report, null, 2))
|
|
285
346
|
return overallOk ? 0 : 1
|
|
@@ -287,6 +348,14 @@ export async function run(argv = process.argv.slice(2), io = console, env = proc
|
|
|
287
348
|
|
|
288
349
|
io.log(`DSH home: ${profileReport.dshHome}`)
|
|
289
350
|
for (const profile of profileReport.profiles) printProfileDetails(profile, io)
|
|
351
|
+
if (upgradePreflight) {
|
|
352
|
+
if (upgradePreflight.pass) io.log('✓ Upgrade profile preflight: known overlay/workspace hazards not detected. Not full release approval.')
|
|
353
|
+
else {
|
|
354
|
+
io.error('✗ Upgrade profile preflight: blocked; do not upgrade this profile without resolving the following.')
|
|
355
|
+
for (const item of upgradePreflight.blockers) io.error(` ✗ ${item.code}: ${item.affectedProfiles} affected profile(s)`)
|
|
356
|
+
}
|
|
357
|
+
io.log('! Upgrade preflight does not verify the running Desktop Host, runtime routes, or historical data.')
|
|
358
|
+
}
|
|
290
359
|
if (profileReport.applicableProfiles === 0) io.error('✗ Vision Router is not installed or mounted in any discovered profile.')
|
|
291
360
|
|
|
292
361
|
if (profileReport.log?.settingsSaveFailures?.length > 0) {
|
package/lib/doctor-runtime.js
CHANGED
|
@@ -227,11 +227,13 @@ const HOST_PACKAGES = [
|
|
|
227
227
|
'@deepseek-ai/dsh-client-ui-settings-plugins',
|
|
228
228
|
'@deepseek-ai/dsh-attachment-local',
|
|
229
229
|
'@deepseek-ai/dsh-llm-deepseek',
|
|
230
|
+
'@deepseek-ai/dsh',
|
|
230
231
|
]
|
|
231
232
|
|
|
232
233
|
function supportedNodeVersion(version = process.versions.node) {
|
|
233
|
-
const [major, minor] = String(version).split('.').map(Number)
|
|
234
|
-
return (major
|
|
234
|
+
const [major, minor, patch] = String(version).replace(/^v/, '').split('.').map(Number)
|
|
235
|
+
return Number.isInteger(major) && Number.isInteger(minor) && Number.isInteger(patch)
|
|
236
|
+
&& (major > 24 || (major === 24 && minor >= 9))
|
|
235
237
|
}
|
|
236
238
|
|
|
237
239
|
export function inspectPlatform({ profileDirs = [], env = process.env } = {}) {
|
|
@@ -247,7 +249,7 @@ export function inspectPlatform({ profileDirs = [], env = process.env } = {}) {
|
|
|
247
249
|
arch: process.arch,
|
|
248
250
|
node: process.version,
|
|
249
251
|
nodeSupported: supportedNodeVersion(),
|
|
250
|
-
nodeRequirement: '
|
|
252
|
+
nodeRequirement: '>=24.9.0',
|
|
251
253
|
release: os.release(),
|
|
252
254
|
tesseract: tesseract ?? { available: false },
|
|
253
255
|
chromium: chromium ?? { available: false },
|
|
@@ -341,9 +343,16 @@ export function supportReport({ profileReport, runtime, platform, sessions }) {
|
|
|
341
343
|
pluginBundle: item.pluginBundle,
|
|
342
344
|
installedVersion: item.installedPlugin?.version,
|
|
343
345
|
installation: safeInstallation(item.installation),
|
|
346
|
+
hostCore: {
|
|
347
|
+
advisoryCount: item.hostCore?.advisories?.length ?? 0,
|
|
348
|
+
scanLimited: item.hostCore?.scanLimited === true,
|
|
349
|
+
},
|
|
344
350
|
workspacePinnedCount: item.workspace?.pinned?.length ?? 0,
|
|
345
351
|
patch: item.patch ? {
|
|
346
352
|
visionRouterRows: item.patch.visionRouterRows,
|
|
353
|
+
connectionOverrideRows: item.patch.connectionOverrideRows ?? 0,
|
|
354
|
+
retiredReadyBridgeRows: item.patch.retiredReadyBridgeRows ?? 0,
|
|
355
|
+
retiredReadyInjectionRows: item.patch.retiredReadyInjectionRows ?? 0,
|
|
347
356
|
manualVisionRouter: item.patch.manualVisionRouter,
|
|
348
357
|
disablesOfficialDeepSeek: item.patch.disablesOfficialDeepSeek,
|
|
349
358
|
} : undefined,
|
package/lib/doctor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { closeSync, existsSync, fstatSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs'
|
|
1
|
+
import { closeSync, existsSync, fstatSync, openSync, opendirSync, readFileSync, readSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { homedir } from 'node:os'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { inspectCoexistingVisionPlugins } from './profile-pnpm-diagnostics.js'
|
|
@@ -60,6 +60,74 @@ function readJsonIfPresent(filePath, maxBytes = INSTALLED_MANIFEST_MAX_BYTES) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
|
|
64
|
+
const HOST_CORE_PACKAGE = /^@deepseek-ai\/dsh-[a-z0-9][a-z0-9._-]*$/
|
|
65
|
+
const PROFILE_PACKAGE = /^(?:@[a-z0-9._-]+\/)?[a-z0-9][a-z0-9._-]*$/
|
|
66
|
+
const HOST_CORE_SCAN_MAX = 64
|
|
67
|
+
|
|
68
|
+
function readBoundedProfilePackage(profileDir, packageName) {
|
|
69
|
+
if (!PROFILE_PACKAGE.test(packageName) || packageName.length > 100) return undefined
|
|
70
|
+
try {
|
|
71
|
+
const root = realpathSync(profileDir)
|
|
72
|
+
const file = path.join(profileDir, 'node_modules', packageName, 'package.json')
|
|
73
|
+
// Keep the offline probe inside the requested profile, even for pnpm links.
|
|
74
|
+
if (!realpathSync(file).startsWith(root + path.sep)) return undefined
|
|
75
|
+
if (!statSync(file).isFile()) return undefined
|
|
76
|
+
const manifest = readJsonIfPresent(file, 64 * 1024)
|
|
77
|
+
return manifest?.name === packageName ? manifest : undefined
|
|
78
|
+
} catch {
|
|
79
|
+
return undefined
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Advisory only: local package presence is not proof of Host module resolution. */
|
|
84
|
+
export function inspectProfileHostCore(profileDir, manifest) {
|
|
85
|
+
const advisories = []
|
|
86
|
+
let scanLimited = false
|
|
87
|
+
const add = (item) => {
|
|
88
|
+
if (advisories.length >= 16) { scanLimited = true; return }
|
|
89
|
+
advisories.push({ ...item, verification: 'unverified' })
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const scope = path.join(profileDir, 'node_modules', '@deepseek-ai')
|
|
93
|
+
if (!realpathSync(scope).startsWith(realpathSync(profileDir) + path.sep)) {
|
|
94
|
+
throw new Error('outside profile scope')
|
|
95
|
+
}
|
|
96
|
+
const dir = opendirSync(scope)
|
|
97
|
+
try {
|
|
98
|
+
let count = 0
|
|
99
|
+
let entry
|
|
100
|
+
while (count < HOST_CORE_SCAN_MAX && (entry = dir.readSync()) !== null) {
|
|
101
|
+
count += 1
|
|
102
|
+
const packageName = '@deepseek-ai/' + entry.name
|
|
103
|
+
if (!HOST_CORE_PACKAGE.test(packageName) || packageName.length > 100) continue
|
|
104
|
+
const pkg = readBoundedProfilePackage(profileDir, packageName)
|
|
105
|
+
if (pkg) {
|
|
106
|
+
const version = typeof pkg.version === 'string' && pkg.version.length <= 64
|
|
107
|
+
&& /^v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(pkg.version) ? pkg.version : undefined
|
|
108
|
+
add({ kind: 'profile-local-host-core', packageName, version })
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (count === HOST_CORE_SCAN_MAX && dir.readSync() !== null) scanLimited = true
|
|
112
|
+
} finally { dir.closeSync() }
|
|
113
|
+
} catch {
|
|
114
|
+
// Missing or unreadable scope directory is not positive evidence.
|
|
115
|
+
}
|
|
116
|
+
const dependencies = manifest?.dependencies
|
|
117
|
+
const names = dependencies && typeof dependencies === 'object' && !Array.isArray(dependencies)
|
|
118
|
+
? Object.keys(dependencies).filter((name) => PROFILE_PACKAGE.test(name) && name.length <= 100
|
|
119
|
+
&& name !== PLUGIN_NAME && !name.startsWith('@deepseek-ai/')) : []
|
|
120
|
+
if (names.length > HOST_CORE_SCAN_MAX) scanLimited = true
|
|
121
|
+
for (const pluginName of names.slice(0, HOST_CORE_SCAN_MAX)) {
|
|
122
|
+
const pkg = readBoundedProfilePackage(profileDir, pluginName)
|
|
123
|
+
const runtimeDeps = pkg?.dependencies
|
|
124
|
+
if (!runtimeDeps || typeof runtimeDeps !== 'object' || Array.isArray(runtimeDeps)) continue
|
|
125
|
+
const hostPackages = Object.keys(runtimeDeps).filter((name) => HOST_CORE_PACKAGE.test(name)).slice(0, 8)
|
|
126
|
+
if (hostPackages.length > 0) add({ kind: 'third-party-runtime-host-core', pluginName, hostPackages })
|
|
127
|
+
}
|
|
128
|
+
return { advisories, scanLimited }
|
|
129
|
+
}
|
|
130
|
+
|
|
63
131
|
function dependencySpecKind(value) {
|
|
64
132
|
if (typeof value !== 'string' || value.trim() === '') return undefined
|
|
65
133
|
const spec = value.trim()
|
|
@@ -346,6 +414,51 @@ function inspectVisionRouterPatchRows(lines) {
|
|
|
346
414
|
return { mountRows, overrideRows }
|
|
347
415
|
}
|
|
348
416
|
|
|
417
|
+
/**
|
|
418
|
+
* Read-only advisory for profile-owned DSH Connection overrides.
|
|
419
|
+
* The supported DSH 0.2.1+ Web Host owns this row; a user patch is applied
|
|
420
|
+
* after bundle patches and can silently resurrect the retired dependency.
|
|
421
|
+
* This deliberately reads only structure, not trust values or secrets.
|
|
422
|
+
*/
|
|
423
|
+
function inspectRetiredConnectionPatchRows(lines) {
|
|
424
|
+
let connectionOverrideRows = 0
|
|
425
|
+
let retiredReadyBridgeRows = 0
|
|
426
|
+
let retiredReadyInjectionRows = 0
|
|
427
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
428
|
+
const line = lines[index]
|
|
429
|
+
const id = /^\s*-\s+id\s*:\s*['"]?([^'"\s]+)['"]?\s*$/.exec(line)?.[1]
|
|
430
|
+
if (id === 'connection') connectionOverrideRows += 1
|
|
431
|
+
if (id === 'vision-router-web-connection-ready') retiredReadyBridgeRows += 1
|
|
432
|
+
const name = /^\s*name\s*:\s*['"]?([^'"\s]+)['"]?\s*$/.exec(line)?.[1]
|
|
433
|
+
if (name === './presets/web-connection-ready/index.mjs'
|
|
434
|
+
|| name === 'vision-router-web-connection-ready') {
|
|
435
|
+
// Count named bridge rows even if an alias id is used, but not twice.
|
|
436
|
+
const previous = lines.slice(Math.max(0, index - 5), index)
|
|
437
|
+
if (!previous.some((item) => /^\s*-\s+id:\s*['"]?vision-router-web-connection-ready['"]?\s*$/.test(item))) {
|
|
438
|
+
retiredReadyBridgeRows += 1
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const inject = /^(\s*)inject\s*:\s*(.*)$/.exec(line)
|
|
442
|
+
if (!inject) continue
|
|
443
|
+
const matchService = (value) => /(?:^|[^A-Za-z0-9_])visionRouterWebConnectionReady(?:$|[^A-Za-z0-9_])/.test(value)
|
|
444
|
+
if (matchService(inject[2])) {
|
|
445
|
+
retiredReadyInjectionRows += 1
|
|
446
|
+
} else if (inject[2].trim() === '') {
|
|
447
|
+
const indent = inject[1].length
|
|
448
|
+
for (let cursor = index + 1; cursor < lines.length; cursor += 1) {
|
|
449
|
+
const row = lines[cursor]
|
|
450
|
+
if (!row.trim()) continue
|
|
451
|
+
if (yamlIndent(row) <= indent) break
|
|
452
|
+
if (/^\s*-\s+visionRouterWebConnectionReady\s*$/.test(row)) {
|
|
453
|
+
retiredReadyInjectionRows += 1
|
|
454
|
+
break
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return { connectionOverrideRows, retiredReadyBridgeRows, retiredReadyInjectionRows }
|
|
460
|
+
}
|
|
461
|
+
|
|
349
462
|
export function inspectProfilePatch(patchPath) {
|
|
350
463
|
if (!existsSync(patchPath)) {
|
|
351
464
|
return {
|
|
@@ -353,6 +466,9 @@ export function inspectProfilePatch(patchPath) {
|
|
|
353
466
|
exists: false,
|
|
354
467
|
visionRouterRows: 0,
|
|
355
468
|
visionRouterOverrideRows: 0,
|
|
469
|
+
connectionOverrideRows: 0,
|
|
470
|
+
retiredReadyBridgeRows: 0,
|
|
471
|
+
retiredReadyInjectionRows: 0,
|
|
356
472
|
manualVisionRouter: false,
|
|
357
473
|
disablesOfficialDeepSeek: false,
|
|
358
474
|
}
|
|
@@ -361,10 +477,11 @@ export function inspectProfilePatch(patchPath) {
|
|
|
361
477
|
try {
|
|
362
478
|
text = readFileBounded(patchPath).toString('utf8')
|
|
363
479
|
} catch (error) {
|
|
364
|
-
return { path: patchPath, exists: true, visionRouterRows: 0, visionRouterOverrideRows: 0, manualVisionRouter: false, disablesOfficialDeepSeek: false, error: error instanceof Error ? error.message : String(error), oversized: error?.code === 'DOCTOR_INPUT_TOO_LARGE' }
|
|
480
|
+
return { path: patchPath, exists: true, visionRouterRows: 0, visionRouterOverrideRows: 0, connectionOverrideRows: 0, retiredReadyBridgeRows: 0, retiredReadyInjectionRows: 0, manualVisionRouter: false, disablesOfficialDeepSeek: false, error: error instanceof Error ? error.message : String(error), oversized: error?.code === 'DOCTOR_INPUT_TOO_LARGE' }
|
|
365
481
|
}
|
|
366
482
|
const lines = text.split(/\r?\n/).map(stripYamlComment)
|
|
367
483
|
const { mountRows: visionRouterRows, overrideRows: visionRouterOverrideRows } = inspectVisionRouterPatchRows(lines)
|
|
484
|
+
const retiredConnection = inspectRetiredConnectionPatchRows(lines)
|
|
368
485
|
let disablesOfficialDeepSeek = false
|
|
369
486
|
for (let index = 0; index < lines.length; index += 1) {
|
|
370
487
|
const line = lines[index]
|
|
@@ -382,6 +499,7 @@ export function inspectProfilePatch(patchPath) {
|
|
|
382
499
|
exists: true,
|
|
383
500
|
visionRouterRows,
|
|
384
501
|
visionRouterOverrideRows,
|
|
502
|
+
...retiredConnection,
|
|
385
503
|
manualVisionRouter: visionRouterRows > 0,
|
|
386
504
|
disablesOfficialDeepSeek,
|
|
387
505
|
}
|
|
@@ -457,6 +575,25 @@ export function classifyProfileInstallation(profile, { requested = false } = {})
|
|
|
457
575
|
if (profile?.patch?.disablesOfficialDeepSeek) {
|
|
458
576
|
warnings.push('cordis.patch.yml statically disables llm-deepseek; legacy stealth patches can make the official model disappear when Vision Router is disabled')
|
|
459
577
|
}
|
|
578
|
+
if (profile?.patch?.connectionOverrideRows > 0) {
|
|
579
|
+
warnings.push('Profile-owned Connection override detected: DSH 0.2.1+ owns this Host row. Review/remove the obsolete override manually after backing up your profile; Doctor does not modify authentication or trustedHosts.')
|
|
580
|
+
}
|
|
581
|
+
if (profile?.patch?.retiredReadyBridgeRows > 0 || profile?.patch?.retiredReadyInjectionRows > 0) {
|
|
582
|
+
warnings.push('Profile still references retired visionRouterWebConnectionReady bridge: verify and migrate this custom overlay manually. DVR 3.2 no longer provides that service; Doctor changes no profile data.')
|
|
583
|
+
}
|
|
584
|
+
for (const item of profile?.hostCore?.advisories ?? []) {
|
|
585
|
+
if (item.kind === 'profile-local-host-core') {
|
|
586
|
+
warnings.push('Possible Host core shadowing (unverified): profile-local '
|
|
587
|
+
+ item.packageName + (item.version ? '@' + item.version : '')
|
|
588
|
+
+ '; check actual Host module resolution before changing dependencies')
|
|
589
|
+
} else if (item.kind === 'third-party-runtime-host-core') {
|
|
590
|
+
warnings.push('Third-party plugin ' + item.pluginName + ' declares DSH Host core runtime dependencies ('
|
|
591
|
+
+ item.hostPackages.join(', ') + '); possible profile hoisting conflict, unverified')
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (profile?.hostCore?.scanLimited) {
|
|
595
|
+
warnings.push('Host core advisory scan reached its bounded inspection limit; results may be incomplete')
|
|
596
|
+
}
|
|
460
597
|
return {
|
|
461
598
|
applicable,
|
|
462
599
|
mode,
|
|
@@ -583,6 +720,7 @@ export function doctorProfiles({ dshHome = resolveDshHome(), profile, fix = fals
|
|
|
583
720
|
patch,
|
|
584
721
|
installedPlugin,
|
|
585
722
|
workspace,
|
|
723
|
+
hostCore: inspectProfileHostCore(profileDir),
|
|
586
724
|
pluginBundleCount: 0,
|
|
587
725
|
pluginBundle: false,
|
|
588
726
|
}
|
|
@@ -597,6 +735,7 @@ export function doctorProfiles({ dshHome = resolveDshHome(), profile, fix = fals
|
|
|
597
735
|
exists: true,
|
|
598
736
|
...manifestReport,
|
|
599
737
|
coexistingVisionPlugins: manifestReport.validJson ? inspectCoexistingVisionPlugins(profileDir) : [],
|
|
738
|
+
hostCore: inspectProfileHostCore(profileDir, manifestReport.manifest),
|
|
600
739
|
workspace,
|
|
601
740
|
patch,
|
|
602
741
|
installedPlugin,
|
|
@@ -1,59 +1,108 @@
|
|
|
1
|
+
import semver from 'semver'
|
|
2
|
+
|
|
1
3
|
export const DSH_SUPPORT_WINDOW = Object.freeze({
|
|
2
|
-
dvrTrain: '2.
|
|
3
|
-
minimum: '0.1.5',
|
|
4
|
-
|
|
4
|
+
dvrTrain: '3.2.x',
|
|
5
|
+
minimum: '0.2.1-rc.5',
|
|
6
|
+
currentRecommended: '0.2.2-rc.1',
|
|
7
|
+
nodeMinimum: '24.9.0',
|
|
5
8
|
})
|
|
6
9
|
|
|
7
10
|
export const DSH_VERIFICATION_EVIDENCE = Object.freeze({
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
exactFloor: '0.2.1-rc.5',
|
|
12
|
+
exactRecommended: '0.2.2-rc.1',
|
|
10
13
|
stableCanaryDistTag: 'latest',
|
|
11
14
|
nextCanaryDistTag: 'next',
|
|
12
15
|
previewCanaryDistTag: 'alpha',
|
|
13
16
|
})
|
|
14
17
|
|
|
15
|
-
export
|
|
16
|
-
const batchAttachments = capabilities?.batchAttachments
|
|
17
|
-
const maxImageDimension = capabilities?.maxImageDimension
|
|
18
|
+
export const DSH_SUPPORTED_RANGE = '>=0.2.1-rc.5 <0.3.0-0'
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
/** Version evidence does not replace a required-capability check. */
|
|
21
|
+
export function supportWindowUpgradeAdvice(capabilities = {}, {
|
|
22
|
+
nodeVersion = process.versions.node,
|
|
23
|
+
hostVersion,
|
|
24
|
+
} = {}) {
|
|
25
|
+
const node = semver.valid(String(nodeVersion).replace(/^v/, ''))
|
|
26
|
+
if (!node) {
|
|
20
27
|
return Object.freeze({
|
|
21
|
-
level: '
|
|
22
|
-
|
|
23
|
-
message: `Host lacks attachment capabilities expected by DVR ${DSH_SUPPORT_WINDOW.dvrTrain}; the minimum supported Host is DSH ${DSH_SUPPORT_WINDOW.minimum}`,
|
|
28
|
+
level: 'unknown', code: 'NODE_VERSION_UNVERIFIED',
|
|
29
|
+
message: 'Node runtime version was not established',
|
|
24
30
|
})
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
// Capability evidence is tri-state (`true` / `false` / `'unknown'`). Only an
|
|
28
|
-
// explicit `true` proves the support floor, so a missing field, a wrong-typed
|
|
29
|
-
// value and `'unknown'` all mean "not proven" rather than "capable".
|
|
30
|
-
if (batchAttachments !== true || maxImageDimension !== true) {
|
|
32
|
+
if (!semver.satisfies(node, '>=24.9.0')) {
|
|
31
33
|
return Object.freeze({
|
|
32
|
-
level: '
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
level: 'required', code: 'NODE_BELOW_CURRENT_FLOOR',
|
|
35
|
+
message: `DVR ${DSH_SUPPORT_WINDOW.dvrTrain} requires Node.js >=${DSH_SUPPORT_WINDOW.nodeMinimum}; current Node is ${node}`,
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
if (hostVersion !== undefined && hostVersion !== null) {
|
|
39
|
+
const host = semver.valid(String(hostVersion).replace(/^v/, ''))
|
|
40
|
+
if (!host) {
|
|
41
|
+
return Object.freeze({
|
|
42
|
+
level: 'unknown', code: 'HOST_VERSION_UNVERIFIED',
|
|
43
|
+
message: 'DSH Host version could not be validated against the new support window',
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
if (!semver.satisfies(host, DSH_SUPPORTED_RANGE, { includePrerelease: true })) {
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
level: 'required', code: 'HOST_BELOW_CURRENT_FLOOR_VERSION',
|
|
49
|
+
message: `DVR ${DSH_SUPPORT_WINDOW.dvrTrain} supports DSH ${DSH_SUPPORTED_RANGE}; detected ${host}`,
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (capabilities?.batchAttachments === false || capabilities?.maxImageDimension === false) {
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
level: 'required', code: 'HOST_BELOW_CURRENT_FLOOR_CAPABILITIES',
|
|
56
|
+
message: 'Host lacks the attachment capabilities required for DVR 3.2',
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
if (!hostVersion) {
|
|
60
|
+
return Object.freeze({
|
|
61
|
+
level: 'unknown', code: 'HOST_VERSION_UNVERIFIED',
|
|
62
|
+
message: `DSH Host version is unverified. DVR ${DSH_SUPPORT_WINDOW.dvrTrain} requires ${DSH_SUPPORTED_RANGE}; attachment capabilities alone cannot prove the version`,
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
if (capabilities?.batchAttachments !== true || capabilities?.maxImageDimension !== true) {
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
level: 'unknown', code: 'HOST_CURRENT_FLOOR_UNKNOWN',
|
|
68
|
+
message: 'DSH version is supported, but required runtime attachment capabilities are not proven',
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
// Admission is an open 0.2.x train on purpose, not blanket evidence.
|
|
72
|
+
// A later Host or Node major is not automatically verified by the exact
|
|
73
|
+
// rc5/rc1, Node 24.9/24.21 matrix; Doctor reports unknown, not green.
|
|
74
|
+
if (semver.major(node) !== 24) {
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
level: 'unknown', code: 'NODE_FORWARD_MAJOR_UNVERIFIED',
|
|
77
|
+
message: `Node ${node} meets the declared >=24.9 floor, but is outside the verified Node 24 test train`,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
const exactHost = semver.valid(String(hostVersion).replace(/^v/, ''))
|
|
81
|
+
if (![DSH_VERIFICATION_EVIDENCE.exactFloor, DSH_VERIFICATION_EVIDENCE.exactRecommended].includes(exactHost)) {
|
|
82
|
+
return Object.freeze({
|
|
83
|
+
level: 'unknown', code: 'HOST_FORWARD_RELEASE_UNVERIFIED',
|
|
84
|
+
message: `DSH ${hostVersion} meets the 0.2.x admission range but lacks the two pinned exact-release acceptance gates`,
|
|
35
85
|
})
|
|
36
86
|
}
|
|
37
|
-
|
|
38
87
|
return Object.freeze({
|
|
39
|
-
level: 'ok',
|
|
40
|
-
|
|
41
|
-
message: `Host exposes the attachment capabilities expected by the DVR ${DSH_SUPPORT_WINDOW.dvrTrain} support floor`,
|
|
88
|
+
level: 'ok', code: 'HOST_CURRENT_FLOOR_CAPABLE',
|
|
89
|
+
message: `DSH ${hostVersion} and required attachment capabilities satisfy the DVR 3.2 floor`,
|
|
42
90
|
})
|
|
43
91
|
}
|
|
44
92
|
|
|
45
|
-
export function formatDshSupportWindowLines(capabilities = {}) {
|
|
46
|
-
const advice = supportWindowUpgradeAdvice(capabilities)
|
|
93
|
+
export function formatDshSupportWindowLines(capabilities = {}, options = {}) {
|
|
94
|
+
const advice = supportWindowUpgradeAdvice(capabilities, options)
|
|
47
95
|
return Object.freeze([
|
|
48
96
|
'DSH Host support window:',
|
|
49
97
|
` DVR train: ${DSH_SUPPORT_WINDOW.dvrTrain}`,
|
|
50
98
|
` minimum supported Host: ${DSH_SUPPORT_WINDOW.minimum}`,
|
|
51
|
-
` current
|
|
52
|
-
`
|
|
99
|
+
` current recommended Host: ${DSH_SUPPORT_WINDOW.currentRecommended}`,
|
|
100
|
+
` minimum supported Node.js: ${DSH_SUPPORT_WINDOW.nodeMinimum}`,
|
|
101
|
+
` support floor: DSH ${DSH_SUPPORTED_RANGE}`,
|
|
53
102
|
'DSH compatibility verification evidence:',
|
|
54
|
-
` exact
|
|
55
|
-
` exact
|
|
56
|
-
` scheduled
|
|
103
|
+
` exact supported Host floor: ${DSH_VERIFICATION_EVIDENCE.exactFloor}`,
|
|
104
|
+
` exact recommended Host: ${DSH_VERIFICATION_EVIDENCE.exactRecommended}`,
|
|
105
|
+
` scheduled published canary: npm dist-tag ${DSH_VERIFICATION_EVIDENCE.stableCanaryDistTag}`,
|
|
57
106
|
` scheduled next/rc canary: npm dist-tag ${DSH_VERIFICATION_EVIDENCE.nextCanaryDistTag}`,
|
|
58
107
|
` scheduled alpha/pre-release canary: npm dist-tag ${DSH_VERIFICATION_EVIDENCE.previewCanaryDistTag}`,
|
|
59
108
|
` upgrade advice: ${advice.level} (${advice.code}) — ${advice.message}`,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { extractJson, parseBox } from './core-primitives.js'
|
|
2
|
+
|
|
3
|
+
// Model output is untrusted: never eval, repair arbitrary JSON, or treat bare
|
|
4
|
+
// numbers as coordinates. Recover only four uniquely named integer fields.
|
|
5
|
+
const MAX_LOOSE_BOX_CHARS = 8192
|
|
6
|
+
const KEYED_PIXEL = /(?:^|[^A-Za-z0-9_])["']?(x1|y1|x2|y2)["']?\s*[:=]\s*["'[(\s]{0,4}(\d{1,6})(?![\d.eE])(?=[\s,}\])"'\]]|$)/g
|
|
7
|
+
|
|
8
|
+
export function looseGroundingBoxFromText(text) {
|
|
9
|
+
if (typeof text !== 'string' || text.length > MAX_LOOSE_BOX_CHARS) return undefined
|
|
10
|
+
const fields = Object.create(null)
|
|
11
|
+
for (const match of text.matchAll(KEYED_PIXEL)) {
|
|
12
|
+
const key = match[1]
|
|
13
|
+
if (Object.hasOwn(fields, key)) return undefined
|
|
14
|
+
fields[key] = Number(match[2])
|
|
15
|
+
}
|
|
16
|
+
if (Object.keys(fields).length !== 4) return undefined
|
|
17
|
+
return parseBox(fields)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function parseGroundingBoxResponse(text) {
|
|
21
|
+
const parsed = extractJson(text)
|
|
22
|
+
const strict = parsed !== undefined ? parseBox(parsed) : undefined
|
|
23
|
+
if (strict) {
|
|
24
|
+
// JSON.parse silently selects the last duplicated object key; a conflicting
|
|
25
|
+
// x1/y1/x2/y2 is not an unambiguous grounding result.
|
|
26
|
+
if (typeof text === 'string' && text.length <= MAX_LOOSE_BOX_CHARS) {
|
|
27
|
+
const seen = new Set()
|
|
28
|
+
for (const match of text.matchAll(KEYED_PIXEL)) {
|
|
29
|
+
if (seen.has(match[1])) return undefined
|
|
30
|
+
seen.add(match[1])
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return strict
|
|
34
|
+
}
|
|
35
|
+
return looseGroundingBoxFromText(text)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function usableContentRect(rect, width, height) {
|
|
39
|
+
if (!rect || !['x1', 'y1', 'x2', 'y2'].every((key) => Number.isInteger(rect[key]))) return undefined
|
|
40
|
+
if (rect.x1 < 0 || rect.y1 < 0 || rect.x2 > width || rect.y2 > height) return undefined
|
|
41
|
+
if (rect.x2 <= rect.x1 || rect.y2 <= rect.y1) return undefined
|
|
42
|
+
return rect
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* No silent coordinate-frame reinterpretation: a model supplying a source-space
|
|
47
|
+
* box to a 1000px letterbox must retry, never become a plausible clamped box.
|
|
48
|
+
* 2px covers the usual integer rounding error near content boundaries.
|
|
49
|
+
*/
|
|
50
|
+
export function assessGroundingBox(box, width, height, rect) {
|
|
51
|
+
if (!box) return { ok: false, reason: 'missing or ambiguous coordinate fields' }
|
|
52
|
+
if (![width, height].every((n) => Number.isInteger(n) && n > 0)) {
|
|
53
|
+
return { ok: false, reason: 'invalid raster dimensions' }
|
|
54
|
+
}
|
|
55
|
+
if (box.x1 < 0 || box.y1 < 0 || box.x2 > width || box.y2 > height) {
|
|
56
|
+
return { ok: false, reason: 'coordinates outside the supplied image frame' }
|
|
57
|
+
}
|
|
58
|
+
if (box.x2 - box.x1 < 2 || box.y2 - box.y1 < 2) {
|
|
59
|
+
return { ok: false, reason: 'degenerate target sliver' }
|
|
60
|
+
}
|
|
61
|
+
const content = usableContentRect(rect, width, height)
|
|
62
|
+
if (content && (
|
|
63
|
+
box.x1 < content.x1 - 2 || box.y1 < content.y1 - 2 ||
|
|
64
|
+
box.x2 > content.x2 + 2 || box.y2 > content.y2 + 2
|
|
65
|
+
)) {
|
|
66
|
+
return { ok: false, reason: 'coordinates extend into the letterbox padding' }
|
|
67
|
+
}
|
|
68
|
+
const normalized = content ? {
|
|
69
|
+
x1: Math.max(box.x1, content.x1), y1: Math.max(box.y1, content.y1),
|
|
70
|
+
x2: Math.min(box.x2, content.x2), y2: Math.min(box.y2, content.y2),
|
|
71
|
+
} : box
|
|
72
|
+
if (normalized.x2 - normalized.x1 < 2 || normalized.y2 - normalized.y1 < 2) {
|
|
73
|
+
return { ok: false, reason: 'no usable target after removing letterbox padding' }
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, box: normalized }
|
|
76
|
+
}
|