Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
135 changes: 135 additions & 0 deletions services/sim2real-web/camera-ai-downloads.spec.mjs
Original file line number Diff line number Diff line change
@@ -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), '');
});
118 changes: 118 additions & 0 deletions services/sim2real-web/public/camera-ai-downloads.mjs
Original file line number Diff line number Diff line change
@@ -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();
}
}
10 changes: 10 additions & 0 deletions services/sim2real-web/public/downloads.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 34 additions & 1 deletion services/sim2real-web/public/downloads.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<script src="./theme-boot.js?v=2"></script>
<link rel="stylesheet" href="./tokens.css?v=4" />
<link rel="stylesheet" href="./experiment.css?v=studio-2" />
<link rel="stylesheet" href="./downloads.css?v=2" />
<link rel="stylesheet" href="./downloads.css?v=3" />
<script type="module" src="./downloads-page.mjs?v=4"></script>
<script type="module" src="./camera-ai-downloads.mjs?v=1"></script>
</head>
<body>
<a class="skip-link" href="#downloads-main">跳到插件下载内容</a>
Expand Down Expand Up @@ -72,6 +73,38 @@ <h2 id="downloads-requirements-title">运行要求</h2>
</ul>
</section>

<section class="downloads-plugin" aria-labelledby="downloads-camera-title">
<div class="downloads-plugin-head">
<p class="eyebrow">RDK Studio 插件</p>
<h2 id="downloads-camera-title">RDK Camera AI</h2>
<p class="downloads-lead">相机点亮、采流诊断、ISP 调参与 180 分钟视觉 Pipeline Workshop(X5 + IMX415)。它与 RDK Robot Learning 是两个相互独立的插件,按需分别安装。</p>
</div>

<section class="downloads-card" aria-labelledby="downloads-camera-package-title" data-camera-ai>
<div class="downloads-card-head">
<h3 id="downloads-camera-package-title">Studio 插件包</h3>
</div>
<p>解压后从扩展中心导入。在 Studio 新对话里说「开启视觉 Workshop」即可打开课堂工作台。</p>
<dl class="downloads-meta">
<div><dt>版本</dt><dd data-camera-field="version">读取中</dd></div>
<div><dt>大小</dt><dd data-camera-field="size"></dd></div>
</dl>
<div class="downloads-actions">
<a class="downloads-button" data-camera-field="url" href="https://rdkstudio.d-robotics.cc/ducklab-mcp/plugins/rdk-camera-ai-latest.zip" download>下载 RDK Camera AI</a>
<button class="downloads-copy" type="button" data-camera-copy hidden>复制 SHA-256</button>
</div>
<p class="downloads-sha"><span>SHA-256</span><code data-camera-field="sha256"></code></p>
<ol class="downloads-steps">
<li>解压 ZIP,得到 <code>rdk-camera-workshop</code> 目录。</li>
<li>打开 RDK Studio,在扩展中心选择「添加 → 从目录导入插件」,选中该目录并启用;升级时勾选覆盖安装。</li>
<li>新建对话并发送「开启视觉 Workshop」。选中助手给出的开课选项并提交,在安全确认卡上点确认,再用本机浏览器打开助手返回的课堂链接。开课不需要连接板卡或相机。</li>
</ol>
<p class="downloads-muted">本机需要 Node.js 22 或更高版本。示例图与 ISP 练习免接相机;点亮、实拍和真机调参需要连接 X5 与 d-obs 相机服务,仅训练路径需要 RoboGO 账号。</p>
</section>

<p class="downloads-status" data-camera-status role="status">正在读取版本信息</p>
</section>

<p class="downloads-status" id="downloads-status" role="status">正在读取版本信息</p>
</main>
</body>
Expand Down
37 changes: 37 additions & 0 deletions services/sim2real-web/ui-ia.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -984,3 +984,40 @@ assert.match(
'manifest failures are announced',
);
assert.equal((downloadsPage.match(/<h1/g) || []).length, 1, 'download page has one h1');

// ---- plugin download page: RDK Camera AI is a separate plugin from RDK Robot Learning ----
assert.match(
downloadsPage,
/<script type="module" src="\.\/camera-ai-downloads\.mjs[^"]*"><\/script>/,
'the RDK Camera AI card loads its behaviour from its own external module',
);
const cameraAiCard =
downloadsPage.match(/<section[^>]*data-camera-ai[^>]*>[\s\S]*?<\/section>/)?.[0] ?? '';
assert.ok(cameraAiCard, 'the download page offers RDK Camera AI as its own card');
assert.match(
cameraAiCard,
/href="https:\/\/rdkstudio\.d-robotics\.cc\/ducklab-mcp\/plugins\/rdk-camera-ai-latest\.zip"/,
'RDK Camera AI download works before its manifest loads',
);
assert.match(cameraAiCard, /data-camera-field="version"/);
assert.match(cameraAiCard, /data-camera-field="sha256"/);
assert.match(
cameraAiCard,
/开启视觉 Workshop/,
'RDK Camera AI install steps use its own entry phrase',
);
assert.doesNotMatch(
cameraAiCard,
/OriginMan|rdk-robot-learning-platform|data-package=|data-copy/,
'the RDK Camera AI card never points at RDK Robot Learning or shares its controls',
);
assert.doesNotMatch(
downloadsCard,
/Camera AI|视觉 Workshop|rdk-camera-workshop/,
'the RDK Robot Learning card never points at RDK Camera AI',
);
assert.match(
downloadsPage,
/data-camera-status[^>]*role="status"/,
'RDK Camera AI manifest failures are announced separately',
);
Loading