Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

1.2 KB
Raw Blame
export function releaseAssetBase(release) {
  return `/harness-web/releases/${release.version}-${release.sha256.slice(0, 12)}/`;
}

// Keep the public URL and base href stable, but never reuse a runtime asset URL
// between archives. Edge/browser cache lifetimes can override origin headers.
export function configureReleaseAssets(html, release) {
  const startup = /_flutter\.loader\.load\(\{[\s\S]*?\}\);\s*(?=<\/script>)/g;
  if ([...html.matchAll(startup)].length !== 1) {
    throw new Error('Unexpected Flutter bootstrap; refusing to publish unversioned assets');
  }
  const assetBase = releaseAssetBase(release);
  const config = {
    entrypointBaseUrl: assetBase,
    assetBase,
    canvasKitBaseUrl: `${assetBase}canvaskit/`,
  };
  // The host serves online workspaces. Do not start the deprecated generated
  // service worker, which can independently retain an older application.
  return html
    .replace(startup, `_flutter.loader.load(${JSON.stringify({ config })});\n`)
    // The release script preloads the fonts Flutter asks for (build-web-release.sh); it asks
    // for them under assetBase, so a preload of the unversioned copy would only fetch them twice.
    .replace(/(<link rel="preload" href=")(?![/a-z]+:|\/)/g, `$1${assetBase}`);
}