Files
openworker/docs-site/scripts/code-tabs.mjs
Rohit PrasadandDevika Verma d53e058eda Introduce OpenWorker Harness SDK (in beta), agent service cluster and relevant developer documentation (#844)
Allow developers to easily build AI apps without worrying about the harness part.
Bundles the Rust agent runtime as a SDK (Rust and TypeScript) for building desktop and web applications. Applications can manage a local harness or connect to an authenticated harness service on k8s with separately scaled workers and sandbox execution.

The implementation is primarily contained in harness/, with deployment tooling in deploy/, Markdown guides in docs/harness/guides/, and the static documentation site in docs-site/. It does not replace the existing Python harness or migrate OpenWorker Desktop.

Co-authored-by: Devika Verma <devikaverma11@gmail.com>
2026-11-06 09:45:20 -08:00

27 lines
2.1 KiB
JavaScript

// HTML comments are invisible on GitHub; the headings/fences remain normal Markdown.
const LABELS = new Map([
['TypeScript', 'typescript'], ['Rust', 'rust'],
['TypeScript / Electron', 'typescript'], ['Rust / Tauri', 'rust'],
]);
const INSTALL_LABELS = new Map([['Codex', 'codex'], ['Claude Code', 'claude']]);
export function renderCodeTabs(markdown, page) {
let group = 0;
const output = markdown.replace(/^<!-- sdk-(tabs|install-tabs) -->\s*\n([\s\S]*?)^<!-- \/sdk-\1 -->/gm, (_, kind, body) => {
const install = kind === 'install-tabs';
const labels = install ? INSTALL_LABELS : LABELS;
const parts = [...body.matchAll(/^### (.+)\n([\s\S]*?)(?=^### |$(?![\s\S]))/gm)];
if (parts.length !== 2 || parts.some(p => !labels.has(p[1].trim())))
throw Error(`Expected ${install ? 'Codex and Claude Code' : 'TypeScript and Rust'} in SDK tabs: ${page}`);
const keys = parts.map(p => labels.get(p[1].trim()));
if (new Set(keys).size !== 2 || !body.trimStart().startsWith('### '))
throw Error(`Duplicate or malformed SDK tabs: ${page}`);
const id = `${page}-code-${++group}`;
const buttons = parts.map((p, i) => `<button type="button" role="tab" id="${id}-${keys[i]}-tab" aria-controls="${id}-${keys[i]}-panel" aria-selected="${i === 0}" tabindex="${i === 0 ? 0 : -1}" data-language="${keys[i]}">${p[1].trim()}</button>`).join('\n');
const panels = parts.map((p, i) => `<div role="tabpanel" id="${id}-${keys[i]}-panel" aria-labelledby="${id}-${keys[i]}-tab" data-language-panel="${keys[i]}" tabindex="0">\n\n<h4 class="sdk-tab-fallback">${p[1].trim()}</h4>\n\n${p[2].trim()}\n\n</div>`).join('\n\n');
// Without JavaScript, both labelled examples remain readable.
return `<div class="sdk-code-tabs${install ? ' sdk-install-tabs' : ''}" data-sdk-tabs data-tab-kind="${install ? 'installer' : 'language'}">\n<div role="tablist" aria-label="${install ? 'Coding agent' : 'Example language'}" hidden>\n${buttons}\n</div>\n\n${panels}\n\n</div>`;
});
if (/^<!-- \/?sdk-(?:tabs|install-tabs) -->/m.test(output)) throw Error(`Unclosed SDK tabs: ${page}`);
return output.replace(/^```rust,(?:ignore|no_run)\s*$/gm, '```rust');
}