dsh-vision-router 3.2.0 → 3.3.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.
Files changed (56) hide show
  1. package/README.md +6 -6
  2. package/README.zh.md +21 -6
  3. package/THIRD_PARTY_NOTICES.md +167 -0
  4. package/assets/licenses/apache-2.0.txt +202 -0
  5. package/assets/licenses/llvm-mingw-LICENSE.txt +279 -0
  6. package/assets/licenses/mingw-w64-runtime-COPYING.txt +265 -0
  7. package/assets/licenses/moxcms-BSD-3-Clause.txt +26 -0
  8. package/assets/licenses/ncnn-LICENSE.txt +86 -0
  9. package/assets/licenses/roots-BSD-2-Clause.txt +24 -0
  10. package/assets/licenses/unicode-ident-Unicode-3.0.txt +39 -0
  11. package/assets/licenses/vtracer-MIT.txt +25 -0
  12. package/assets/licenses/zlib-rs-Zlib.txt +19 -0
  13. package/docs/architecture/dsh-support-window.md +25 -6
  14. package/docs/compatibility/dsh-0.2.2-rc2-audit.md +40 -0
  15. package/docs/compatibility/dsh-0.2.2-rc3-audit.md +131 -0
  16. package/docs/compliance/vtracer-alpha4-provenance.md +47 -0
  17. package/docs/compliance/vtracer-alpha4-reconstructed-Cargo.lock +567 -0
  18. package/docs/compliance/vtracer-alpha4-rust-inventory.json +421 -0
  19. package/docs/compliance/vtracer-alpha4-rust-license-texts.md +13018 -0
  20. package/docs/releases/v3.2.1.md +21 -0
  21. package/docs/releases/v3.2.2.md +25 -0
  22. package/docs/releases/v3.3.0.md +34 -0
  23. package/docs/remote-settings.md +83 -8
  24. package/index.js +280 -169
  25. package/lib/client.js +17 -17
  26. package/lib/core-primitives.js +155 -214
  27. package/lib/dsh-support-window.js +6 -3
  28. package/lib/native-ocr-annotation-risk.js +33 -0
  29. package/lib/native-ocr-canary.js +156 -0
  30. package/lib/native-ocr-chemistry-review.js +37 -0
  31. package/lib/native-ocr-document.js +243 -0
  32. package/lib/native-ocr-installation.js +17 -0
  33. package/lib/native-ocr-integrity.js +93 -0
  34. package/lib/native-ocr-question-labels.js +167 -0
  35. package/lib/native-ocr-supervisor.js +268 -0
  36. package/lib/remote-settings-bridge.js +93 -57
  37. package/lib/remote-settings-risk-client-boundary.js +2 -2
  38. package/lib/runtime-reliability.js +7 -0
  39. package/lib/session-query-readers.js +8 -2
  40. package/lib/session-vision-attachment-index.js +61 -14
  41. package/lib/settings-client-017-compat.js +4 -2
  42. package/lib/settings-ia-client-prelude.js +26 -10
  43. package/lib/tesseract-image-preprocess.js +35 -0
  44. package/lib/trace-vtracer-process-runtime.js +133 -0
  45. package/lib/trace-vtracer-process.js +43 -0
  46. package/lib/trace-vtracer-worker.js +163 -0
  47. package/lib/vision-attachment-handle-runtime.js +11 -2
  48. package/lib/vision-backend-runtime-policy.js +5 -3
  49. package/lib/vision-image-input-reader.js +67 -0
  50. package/lib/vision-image-input-verdict.js +24 -3
  51. package/lib/vision-tool-runtime-boundary.js +7 -10
  52. package/lib/vision-tool-stage.js +58 -0
  53. package/lib/web/dsh-settings-017-root-transport.js +52 -6
  54. package/lib/web-capability-boundary.js +6 -0
  55. package/package.json +10 -6
  56. package/scripts/install-native-ocr.mjs +144 -0
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ // Installs owner-provided, already license-reviewed PP-OCRv6/ncnn artifacts.
3
+ // It does not download, build, or publish any native executable/model.
4
+ import { copyFile, chmod, mkdir, rename, rm, lstat, writeFile, mkdtemp, readFile } from 'node:fs/promises'
5
+ import { randomUUID } from 'node:crypto'
6
+ import { spawnSync } from 'node:child_process'
7
+ import { tmpdir } from 'node:os'
8
+ import { join, dirname, resolve } from 'node:path'
9
+ import { fileURLToPath } from 'node:url'
10
+ import { localNativeOcrInstallPaths } from '../lib/native-ocr-installation.js'
11
+ import { verifyExperimentalNativeOcrBinary } from '../lib/native-ocr-canary.js'
12
+ import { EXPERIMENTAL_OCR_MODEL_FILES, verifyNativeOcrAssets } from '../lib/native-ocr-integrity.js'
13
+
14
+ const args = process.argv.slice(2)
15
+ const target = process.platform + '-' + process.arch
16
+ const onWindows = target === 'win32-x64'
17
+ const workerName = onWindows ? 'worker.exe' : 'worker'
18
+ const additionalNotices = onWindows
19
+ ? ['LLVM-LICENSE.txt', 'MINGW-RUNTIME-COPYING.txt']
20
+ : []
21
+ if (args.includes('--help')) {
22
+ console.log('Usage: node scripts/install-native-ocr.mjs --bundle ABSOLUTE_ARCHIVE.tar.gz\n node scripts/install-native-ocr.mjs --binary ABSOLUTE_WORKER --models ABSOLUTE_MODEL_DIR')
23
+ process.exit(0)
24
+ }
25
+ const readOption = key => {
26
+ const i = args.indexOf(key)
27
+ if (i < 0 || i + 1 >= args.length) throw Error('missing ' + key)
28
+ return resolve(args[i + 1])
29
+ }
30
+ async function installFromSources(binary, sourceModels) {
31
+ const dest = localNativeOcrInstallPaths()
32
+ if (!dest) throw Error('Only darwin-arm64 and win32-x64 are approved for this local installer')
33
+ await verifyExperimentalNativeOcrBinary(binary)
34
+ await verifyNativeOcrAssets(sourceModels)
35
+
36
+ const base = dirname(dest.root)
37
+ await mkdir(base, { recursive: true, mode: 0o700 })
38
+ const staged = join(base, '.ppocrv6-stage-' + randomUUID())
39
+ const previous = join(base, '.ppocrv6-old-' + randomUUID())
40
+ let movedPrevious = false
41
+ let promoted = false
42
+ try {
43
+ await mkdir(join(staged, 'models'), { recursive: true, mode: 0o700 })
44
+ await copyFile(binary, join(staged, workerName))
45
+ await chmod(join(staged, workerName), 0o700)
46
+ for (const name of Object.keys(EXPERIMENTAL_OCR_MODEL_FILES)) {
47
+ await copyFile(join(sourceModels, name), join(staged, 'models', name))
48
+ await chmod(join(staged, 'models', name), 0o600)
49
+ }
50
+ const assetBase = fileURLToPath(new URL('../assets/licenses/', import.meta.url))
51
+ await copyFile(join(assetBase, 'ncnn-LICENSE.txt'), join(staged, 'NCNN-LICENSE.txt'))
52
+ await copyFile(join(assetBase, 'apache-2.0.txt'), join(staged, 'APACHE-2.0.txt'))
53
+ for (const [name, destName] of [
54
+ ['llvm-mingw-LICENSE.txt', 'LLVM-LICENSE.txt'],
55
+ ['mingw-w64-runtime-COPYING.txt', 'MINGW-RUNTIME-COPYING.txt'],
56
+ ].filter(() => onWindows)) {
57
+ await copyFile(join(assetBase, name), join(staged, destName))
58
+ }
59
+ await writeFile(join(staged, 'SOURCE-NOTICE.md'), [
60
+ '# Locally installed native OCR assets',
61
+ '',
62
+ 'Detector: PaddlePaddle/PP-OCRv6_small_det_onnx, Apache-2.0.',
63
+ 'Recognizer: PaddlePaddle/PP-OCRv6_small_rec_onnx, Apache-2.0.',
64
+ 'Dictionary: PaddlePaddle/PaddleOCR ppocrv6_dict.txt, Apache-2.0.',
65
+ 'Runtime: Tencent/ncnn @ d1f6ac67e9fc91390cc70f7168573fd2626f1d66, BSD-3-Clause',
66
+ 'with its stated BSD-2-Clause and zlib components.',
67
+ 'Models are owner-provided and checksum-gated, never bundled in the npm package.',
68
+ onWindows
69
+ ? 'This Windows build statically links LLVM libc++/unwind, with Apache-2.0 WITH LLVM exceptions and MinGW-w64 runtime notices.'
70
+ : 'This Mac build links only OS-supplied libc++ and libSystem; no platform CRT is redistributed.',
71
+ '',
72
+ ].join('\n'), { mode: 0o600 })
73
+ await verifyExperimentalNativeOcrBinary(join(staged, workerName))
74
+ await verifyNativeOcrAssets(join(staged, 'models'))
75
+ try {
76
+ const existing = await lstat(dest.root)
77
+ if (!existing.isDirectory() || existing.isSymbolicLink()) throw Error('unsafe existing OCR install directory')
78
+ await rename(dest.root, previous)
79
+ movedPrevious = true
80
+ } catch (err) {
81
+ if (err?.code !== 'ENOENT') throw err
82
+ }
83
+ await rename(staged, dest.root)
84
+ promoted = true
85
+ if (movedPrevious) await rm(previous, { recursive: true, force: true })
86
+ console.log('PP_OCRV6_LOCAL_INSTALL_OK (verified '+target+' assets; auto mode now prefers ncnn)')
87
+ } catch (err) {
88
+ if (!promoted && movedPrevious) await rename(previous, dest.root)
89
+ throw err
90
+ } finally {
91
+ if (!promoted) await rm(staged, { recursive: true, force: true })
92
+ }
93
+ }
94
+ async function install() {
95
+ if (args.length === 4 && args.includes('--binary') && args.includes('--models')) {
96
+ return installFromSources(readOption('--binary'), readOption('--models'))
97
+ }
98
+ if (args.length !== 2 || args[0] !== '--bundle') {
99
+ throw Error('required: --bundle ARCHIVE or --binary WORKER --models DIR')
100
+ }
101
+ if (!localNativeOcrInstallPaths()) throw Error('Only darwin-arm64 and win32-x64 are approved')
102
+ const archive = resolve(args[1])
103
+ const info = await lstat(archive)
104
+ if (!info.isFile() || info.isSymbolicLink() || info.size > 64 * 1024 * 1024) {
105
+ throw Error('unsafe native OCR bundle')
106
+ }
107
+ const prefix = 'ppocrv6-small/'
108
+ const members = [
109
+ workerName, 'MANIFEST.json', 'NCNN-LICENSE.txt', 'APACHE-2.0.txt',
110
+ ...additionalNotices,
111
+ ...Object.keys(EXPERIMENTAL_OCR_MODEL_FILES).map(x => 'models/' + x),
112
+ ].map(x => prefix + x).sort()
113
+ const listed = spawnSync('tar', ['-tzf', archive], { encoding:'utf8', timeout:30_000, maxBuffer: 64 * 1024 })
114
+ if (listed.status !== 0 || JSON.stringify(listed.stdout.trim().split(/\r?\n/).sort()) !== JSON.stringify(members)) {
115
+ throw Error('native OCR bundle has unknown/missing entries')
116
+ }
117
+ // Read ONLY individually named entries into memory. Never call 'tar -x':
118
+ // traversal, links and metadata from an external archive cannot write files.
119
+ const tmp = await mkdtemp(join(tmpdir(), 'dvr-ocr-unpack-'))
120
+ try {
121
+ for (const entry of members) {
122
+ const suffix = entry.slice(prefix.length)
123
+ const destPath = join(tmp, suffix)
124
+ await mkdir(dirname(destPath), { recursive: true, mode: 0o700 })
125
+ const data = spawnSync('tar', ['-xOzf', archive, entry], {
126
+ timeout: 45_000, maxBuffer: 32 * 1024 * 1024,
127
+ })
128
+ if (data.status !== 0 || !Buffer.isBuffer(data.stdout)) {
129
+ throw Error('native OCR archive member unreadable: ' + suffix)
130
+ }
131
+ await writeFile(destPath, data.stdout, { mode: 0o600 })
132
+ }
133
+ const manifest = JSON.parse(await readFile(join(tmp,'MANIFEST.json'),'utf8'))
134
+ if (manifest.schemaVersion !== 1 ||
135
+ manifest.platform !== process.platform || manifest.arch !== process.arch) {
136
+ throw Error('unsupported native OCR bundle manifest')
137
+ }
138
+ return await installFromSources(join(tmp,workerName), join(tmp,'models'))
139
+ } finally { await rm(tmp, { recursive:true, force:true }) }
140
+ }
141
+ install().catch(err => {
142
+ console.error('PP_OCRV6_LOCAL_INSTALL_FAILED:', String(err?.code ?? err?.message ?? err))
143
+ process.exitCode = 1
144
+ })