Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.4 KB
Raw Blame
// Hermes does not retain function source. Generate its inline viewer from the
// same static module that Electron imports, without runtime eval or new CSP rights.
import fs from 'node:fs/promises';
const root = new URL('../packages/maker-shared/src/remote-desktop/', import.meta.url);
const source = (await fs.readFile(new URL('viewerRuntime.js', root), 'utf8')).replace(/\r\n/g, '\n');
const result = '// Generated by scripts/sync-remote-desktop-viewer.mjs. Do not edit.\n' +
  `export const DESKTOP_VIEWER_SOURCE = ${JSON.stringify(source.replace('export function', 'function'))};\n`;
const target = new URL('viewerSource.ts', root);
let scripts = '// Generated by scripts/sync-remote-desktop-viewer.mjs. Do not edit.\n';
for (const name of ['RTC', 'TRANSFORM', 'NETWORK_STATS']) {
  const match = source.match(new RegExp(`/\\* BEGIN ${name} \\*/([\\s\\S]*?)/\\* END ${name} \\*/`));
  if (!match) throw new Error(`Missing shared viewer ${name} source`);
  const body = name === 'RTC' ? match[1].trim() : match[1].trim().replace(/;$/, '');
  scripts += `export const DESKTOP_${name}_SCRIPT = ${JSON.stringify(body)};\n`;
}
for (const [url, content] of [[target,result],[new URL('viewerScripts.ts',root),scripts]]) {
  if (process.argv.includes('--check')) {
    if ((await fs.readFile(url, 'utf8')).replace(/\r\n/g, '\n') !== content) throw new Error('Run node scripts/sync-remote-desktop-viewer.mjs');
  } else await fs.writeFile(url, content);
}