From 723da305042e8b6aebf0160754c183fc577fac6f Mon Sep 17 00:00:00 2001 From: lx-1997 <13500790262@163.com> Date: Fri, 4 Dec 2026 16:14:39 +0800 Subject: [PATCH] feat(sim2real-web): add the RDK Camera AI card to the plugin download page The page only offered RDK Robot Learning. RDK Camera AI is a separate plugin with its own manifest, card, install steps and failure status, so the page gains a second section filled by its own module instead of a second entry in the learning-platform manifest. The new module never imports downloads-page.mjs: the page loads that module under a versioned URL, so a bare import would instantiate it twice and run the learning-platform card logic again. A Camera AI release is shown only when its package sits on the public download host and carries a valid SHA-256. Structure assertions keep the two cards from pointing at each other. --- package.json | 2 +- .../sim2real-web/camera-ai-downloads.spec.mjs | 135 ++++++++++++++++++ .../public/camera-ai-downloads.mjs | 118 +++++++++++++++ services/sim2real-web/public/downloads.css | 10 ++ services/sim2real-web/public/downloads.html | 35 ++++- services/sim2real-web/ui-ia.spec.mjs | 37 +++++ 6 files changed, 335 insertions(+), 2 deletions(-) create mode 100644 services/sim2real-web/camera-ai-downloads.spec.mjs create mode 100644 services/sim2real-web/public/camera-ai-downloads.mjs diff --git a/package.json b/package.json index 90c51be..7fe7a9b 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "lint:fix": "eslint . --fix", "format": "prettier --write .", "format:check": "prettier --check .", - "verify:ui": "node services/sim2real-web/ui-ia.spec.mjs && node --test services/sim2real-web/experiment-view.spec.mjs && node --test services/sim2real-web/workshop-page.spec.mjs && node --test services/sim2real-web/run-detail-view.spec.mjs && node --test services/sim2real-web/originman-creative-lab.spec.mjs && node --test services/sim2real-web/request-mutation-spacing.spec.mjs && node --test services/sim2real-web/downloads-page.spec.mjs", + "verify:ui": "node services/sim2real-web/ui-ia.spec.mjs && node --test services/sim2real-web/experiment-view.spec.mjs && node --test services/sim2real-web/workshop-page.spec.mjs && node --test services/sim2real-web/run-detail-view.spec.mjs && node --test services/sim2real-web/originman-creative-lab.spec.mjs && node --test services/sim2real-web/request-mutation-spacing.spec.mjs && node --test services/sim2real-web/downloads-page.spec.mjs && node --test services/sim2real-web/camera-ai-downloads.spec.mjs", "verify:entry-contract": "node scripts/check-entry-contract.mjs", "verify:ui-path": "node services/sim2real-web/ui-workbench-path.spec.mjs", "verify:escape-audit": "node services/sim2real-web/escape-audit.spec.mjs", diff --git a/services/sim2real-web/camera-ai-downloads.spec.mjs b/services/sim2real-web/camera-ai-downloads.spec.mjs new file mode 100644 index 0000000..3251663 --- /dev/null +++ b/services/sim2real-web/camera-ai-downloads.spec.mjs @@ -0,0 +1,135 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +import { JSDOM } from 'jsdom'; +import { + cameraAiViewModel, + formatBytes, + startCameraAiDownloads, +} from './public/camera-ai-downloads.mjs'; + +const html = await fs.readFile(new URL('./public/downloads.html', import.meta.url), 'utf8'); +const BASE = 'https://rdkstudio.d-robotics.cc/ducklab-mcp/plugins/'; +const LATEST = `${BASE}rdk-camera-ai-latest.zip`; +const sha = (seed) => seed.repeat(64).slice(0, 64); +const studio = (version) => ({ + role: 'studio', + url: `${BASE}rdk-camera-ai-${version}.zip`, + sizeBytes: 1801745, + sha256: sha('d'), +}); +const manifest = { + schemaVersion: 1, + pluginName: 'rdk-camera-workshop', + releases: [ + { version: '1.5.15', publishedAt: '2026-12-04T08:30:00.000Z', files: [studio('1.5.15')] }, + ], +}; +const respond = + (body, status = 200) => + async () => ({ ok: status === 200, status, json: async () => body }); +const plainNavigator = { userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' }; + +function page() { + const dom = new JSDOM(html, { + url: 'https://rdkstudio.d-robotics.cc/robotics-learning/downloads.html', + }); + return dom.window.document; +} +const cameraCard = (document) => document.querySelector('[data-camera-ai]'); +const field = (document, name) => + cameraCard(document).querySelector(`[data-camera-field="${name}"]`); + +test('the RDK Camera AI card fills from its own manifest and leaves the RDK Robot Learning card alone', async () => { + const document = page(); + const model = await startCameraAiDownloads({ + document, + fetch: respond(manifest), + navigator: plainNavigator, + }); + + assert.equal(model.version, '1.5.15'); + assert.equal(field(document, 'version').textContent, 'v1.5.15'); + assert.equal(field(document, 'size').textContent, '1.8 MB'); + assert.equal(field(document, 'sha256').textContent, sha('d')); + assert.equal(field(document, 'url').href, `${BASE}rdk-camera-ai-1.5.15.zip`); + assert.equal(cameraCard(document).querySelector('[data-camera-copy]').hidden, false); + assert.equal(document.querySelector('[data-camera-status]').textContent, ''); + + const universal = document.querySelector('[data-package="universal"]'); + assert.equal(universal.querySelector('[data-field="version"]').textContent, '读取中'); + assert.equal(universal.querySelector('[data-copy]').hidden, true); + assert.equal(document.getElementById('downloads-status').textContent, '正在读取版本信息'); +}); + +test('a failed RDK Camera AI manifest keeps the latest-zip link and says so', async () => { + const document = page(); + const model = await startCameraAiDownloads({ + document, + fetch: async () => { + throw new Error('offline'); + }, + navigator: plainNavigator, + }); + + assert.equal(model, null); + assert.equal(field(document, 'url').href, LATEST); + assert.equal(cameraCard(document).querySelector('[data-camera-copy]').hidden, true); + assert.match( + document.querySelector('[data-camera-status]').textContent, + /RDK Camera AI 的版本信息暂时读取不到,下载按钮仍指向最新发布版/, + ); + assert.equal(document.getElementById('downloads-status').textContent, '正在读取版本信息'); +}); + +test('the RDK Camera AI card only links Studio packages on the public download host', () => { + const hostile = { + releases: [ + { version: '9.9.9', files: [{ ...studio('9.9.9'), url: 'https://example.com/evil.zip' }] }, + { version: '9.9.8', files: [{ ...studio('9.9.8'), url: `${BASE}rdk-camera-ai-9.9.8.exe` }] }, + { version: 'not-a-version', files: [studio('nope')] }, + { + version: '9.9.7', + files: [{ role: 'platform', url: `${BASE}rdk-camera-workshop-9.9.7.zip` }], + }, + { version: '9.9.6', files: [{ ...studio('9.9.6'), sha256: 'MD5:abc' }] }, + ...manifest.releases, + ], + }; + + const model = cameraAiViewModel(hostile); + assert.equal(model.version, '1.5.15'); + assert.equal(model.sha256, sha('d')); + assert.equal( + cameraAiViewModel({ + releases: [{ version: '9.9.6', files: [{ ...studio('9.9.6'), sizeBytes: 0 }] }], + }).sizeBytes, + 0, + ); + assert.equal(cameraAiViewModel({ releases: hostile.releases.slice(0, 5) }), null); + assert.equal(cameraAiViewModel(null), null); +}); + +test('the RDK Camera AI copy button writes its own SHA-256 to the clipboard', async () => { + const document = page(); + const writes = []; + await startCameraAiDownloads({ + document, + fetch: respond(manifest), + navigator: { ...plainNavigator, clipboard: { writeText: async (text) => writes.push(text) } }, + }); + const button = cameraCard(document).querySelector('[data-camera-copy]'); + + button.click(); + await new Promise((resolve) => setTimeout(resolve, 0)); + + assert.deepEqual(writes, [sha('d')]); + assert.equal(button.textContent, '已复制'); +}); + +test('RDK Camera AI sizes use the same unit as the rest of the page', () => { + assert.equal(formatBytes(1801745), '1.8 MB'); + assert.equal(formatBytes(74007543), '74.0 MB'); + assert.equal(formatBytes(512), '512 B'); + assert.equal(formatBytes(0), ''); +}); diff --git a/services/sim2real-web/public/camera-ai-downloads.mjs b/services/sim2real-web/public/camera-ai-downloads.mjs new file mode 100644 index 0000000..bc2068f --- /dev/null +++ b/services/sim2real-web/public/camera-ai-downloads.mjs @@ -0,0 +1,118 @@ +// RDK Camera AI is a separate plugin from RDK Robot Learning: this module only fills its own card +// and stays independent of downloads-page.mjs, which the page loads under a versioned URL. +const PUBLIC_ORIGIN = 'https://rdkstudio.d-robotics.cc'; +const DOWNLOADS_PATH = '/ducklab-mcp/plugins/'; +const MANIFEST_PATH = `${DOWNLOADS_PATH}rdk-camera-ai-downloads.json`; +const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/; + +/** Decimal units, matching the RDK Robot Learning card on the same page. */ +export function formatBytes(bytes) { + if (!Number.isInteger(bytes) || bytes <= 0) return ''; + if (bytes < 1000) return `${bytes} B`; + if (bytes < 1_000_000) return `${Math.round(bytes / 1000)} KB`; + return `${(bytes / 1_000_000).toFixed(1)} MB`; +} + +function normalizeRelease(raw) { + const file = Array.isArray(raw?.files) + ? raw.files.find((entry) => entry?.role === 'studio') + : undefined; + if (typeof raw?.version !== 'string' || !VERSION_PATTERN.test(raw.version)) return null; + let url; + try { + url = new URL(file?.url); + } catch { + return null; + } + if ( + url.origin !== PUBLIC_ORIGIN || + !url.pathname.startsWith(DOWNLOADS_PATH) || + !url.pathname.endsWith('.zip') || + typeof file.sha256 !== 'string' || + !/^[a-f0-9]{64}$/.test(file.sha256) + ) { + return null; + } + return { + version: raw.version, + url: url.href, + sha256: file.sha256, + sizeBytes: Number.isInteger(file.sizeBytes) && file.sizeBytes > 0 ? file.sizeBytes : 0, + }; +} + +/** The newest release that carries a hash-verified Studio package on the public download host. */ +export function cameraAiViewModel(manifest) { + if (!manifest || typeof manifest !== 'object' || !Array.isArray(manifest.releases)) return null; + for (const release of manifest.releases) { + const view = normalizeRelease(release); + if (view) return view; + } + return null; +} + +export async function startCameraAiDownloads({ + document: doc, + fetch: fetchImpl = (input, init) => fetch(input, init), + manifestUrl = MANIFEST_PATH, + navigator: nav = globalThis.navigator, +} = {}) { + const card = doc.querySelector('[data-camera-ai]'); + if (!card) return null; + const field = (name) => card.querySelector(`[data-camera-field="${name}"]`); + const status = doc.querySelector('[data-camera-status]'); + const setStatus = (text) => { + if (status) status.textContent = text; + }; + const copy = card.querySelector('[data-camera-copy]'); + copy?.addEventListener('click', async () => { + const clipboard = nav?.clipboard; + const original = copy.textContent; + try { + if (!clipboard || typeof clipboard.writeText !== 'function') throw new Error('clipboard_unavailable'); + await clipboard.writeText(copy.dataset.sha ?? ''); + copy.textContent = '已复制'; + } catch { + setStatus('当前浏览器不允许自动复制,请手动选中 SHA-256 复制。'); + } + setTimeout(() => { + copy.textContent = original; + }, 1600); + }); + + let model = null; + if (typeof fetchImpl === 'function') { + try { + const response = await fetchImpl(manifestUrl, { + cache: 'no-store', + headers: { accept: 'application/json' }, + }); + model = response.ok ? cameraAiViewModel(await response.json()) : null; + } catch { + model = null; + } + } + if (!model) { + setStatus('RDK Camera AI 的版本信息暂时读取不到,下载按钮仍指向最新发布版。'); + return null; + } + field('version').textContent = `v${model.version}`; + field('size').textContent = formatBytes(model.sizeBytes); + field('sha256').textContent = model.sha256; + field('url').href = model.url; + copy.dataset.sha = model.sha256; + copy.hidden = false; + setStatus(''); + return model; +} + +const start = () => { + void startCameraAiDownloads({ document }); +}; +if (typeof document !== 'undefined') { + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', start, { once: true }); + } else { + start(); + } +} diff --git a/services/sim2real-web/public/downloads.css b/services/sim2real-web/public/downloads.css index 0531687..0e31a1c 100644 --- a/services/sim2real-web/public/downloads.css +++ b/services/sim2real-web/public/downloads.css @@ -9,6 +9,16 @@ .downloads-intro h1 { margin-bottom: 12px; } +.downloads-plugin { + padding-top: 24px; + border-top: 1px solid var(--line); +} +.downloads-plugin-head { + margin-bottom: 16px; +} +.downloads-plugin-head h2 { + margin: 0 0 12px; +} .downloads-lead { margin: 0; color: var(--muted-strong); diff --git a/services/sim2real-web/public/downloads.html b/services/sim2real-web/public/downloads.html index 6e62e36..688aa4d 100644 --- a/services/sim2real-web/public/downloads.html +++ b/services/sim2real-web/public/downloads.html @@ -7,8 +7,9 @@ - + +
跳到插件下载内容 @@ -72,6 +73,38 @@RDK Studio 插件
+相机点亮、采流诊断、ISP 调参与 180 分钟视觉 Pipeline Workshop(X5 + IMX415)。它与 RDK Robot Learning 是两个相互独立的插件,按需分别安装。
+解压后从扩展中心导入。在 Studio 新对话里说「开启视觉 Workshop」即可打开课堂工作台。
+ +SHA-256
rdk-camera-workshop 目录。本机需要 Node.js 22 或更高版本。示例图与 ISP 练习免接相机;点亮、实拍和真机调参需要连接 X5 与 d-obs 相机服务,仅训练路径需要 RoboGO 账号。
+正在读取版本信息
+正在读取版本信息
diff --git a/services/sim2real-web/ui-ia.spec.mjs b/services/sim2real-web/ui-ia.spec.mjs index c8d99e3..de5bdc3 100644 --- a/services/sim2real-web/ui-ia.spec.mjs +++ b/services/sim2real-web/ui-ia.spec.mjs @@ -984,3 +984,40 @@ assert.match( 'manifest failures are announced', ); assert.equal((downloadsPage.match(/