From a4414cc735cc0dadf0eb354d143492999df2e76c Mon Sep 17 00:00:00 2001 From: Akash Shakdwipeea Date: Tue, 21 Jul 2026 22:58:59 +0530 Subject: [PATCH] Prepare repository for Amp orbs (#18) * Prepare repository for Amp orbs Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Declare Amp preview service and portal Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Allow E2B portal hosts in Vite preview Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Enable WebGPU for agent-browser Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Install virtual display for WebGPU captures Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Revert Amp orb setup pending review Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Prepare repository for Amp orbs Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Declare Amp preview service and portal Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Allow E2B portal hosts in Vite preview Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Enable WebGPU for agent-browser Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Install virtual display for WebGPU captures Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea * Address orb portal review feedback Amp-Thread-ID: https://ampcode.com/threads/T-019f8509-6815-71df-b137-f40075cd06f8 Co-authored-by: Akash Shakdwipeea --------- Co-authored-by: Amp --- .agents/resume | 13 +++++ .agents/setup | 124 +++++++++++++++++++++++++++++++++++++++++++++ .amp/services.yaml | 6 +++ .gitignore | 4 ++ agent-browser.json | 5 ++ vite.config.js | 4 ++ 6 files changed, 156 insertions(+) create mode 100755 .agents/resume create mode 100755 .agents/setup create mode 100644 .amp/services.yaml create mode 100644 agent-browser.json diff --git a/.agents/resume b/.agents/resume new file mode 100755 index 0000000..3ce2ff4 --- /dev/null +++ b/.agents/resume @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH" + +for command in node npm cargo wasm-pack rsw; do + if ! command -v "$command" >/dev/null 2>&1; then + echo "Missing required command after orb resume: $command" >&2 + exit 1 + fi +done + +echo "Orb environment ready." diff --git a/.agents/setup b/.agents/setup new file mode 100755 index 0000000..09436bd --- /dev/null +++ b/.agents/setup @@ -0,0 +1,124 @@ +#!/usr/bin/env bash +set -euo pipefail + +NODE_VERSION="22.23.1" +WASM_PACK_VERSION="0.15.0" +RSW_VERSION="0.8.0" + +export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH" +mkdir -p "$HOME/.local/bin" "$HOME/.cargo/bin" + +missing_packages=() +for package in libvulkan1 mesa-vulkan-drivers xauth xvfb; do + if ! dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -Fq "install ok installed"; then + missing_packages+=("$package") + fi +done +if ((${#missing_packages[@]})); then + echo "Installing WebGPU runtime dependencies..." + sudo apt-get update + sudo apt-get install -y "${missing_packages[@]}" +fi + +install_node() { + local machine node_arch archive install_dir tmp_dir + machine="$(uname -m)" + case "$machine" in + x86_64) node_arch="x64" ;; + aarch64) node_arch="arm64" ;; + *) + echo "Unsupported architecture for Node.js: $machine" >&2 + return 1 + ;; + esac + + archive="node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" + install_dir="$HOME/.local/node-v${NODE_VERSION}-linux-${node_arch}" + if [[ ! -x "$install_dir/bin/node" ]]; then + echo "Installing Node.js v${NODE_VERSION}..." + tmp_dir="$(mktemp -d)" + trap 'rm -rf "$tmp_dir"' RETURN + curl --fail --location --silent --show-error \ + "https://nodejs.org/dist/v${NODE_VERSION}/${archive}" \ + --output "$tmp_dir/$archive" + curl --fail --location --silent --show-error \ + "https://nodejs.org/dist/v${NODE_VERSION}/SHASUMS256.txt" \ + --output "$tmp_dir/SHASUMS256.txt" + ( + cd "$tmp_dir" + grep " ${archive}$" SHASUMS256.txt | sha256sum --check --strict + ) + tar -xJf "$tmp_dir/$archive" -C "$HOME/.local" + rm -rf "$tmp_dir" + trap - RETURN + fi + + for command in node npm npx corepack; do + ln -sfn "$install_dir/bin/$command" "$HOME/.local/bin/$command" + done +} + +install_wasm_pack() { + local machine target archive tmp_dir + machine="$(uname -m)" + case "$machine" in + x86_64) target="x86_64-unknown-linux-musl" ;; + aarch64) target="aarch64-unknown-linux-musl" ;; + *) + echo "Unsupported architecture for wasm-pack: $machine" >&2 + return 1 + ;; + esac + + if ! wasm-pack --version 2>/dev/null | grep -Fq "${WASM_PACK_VERSION}"; then + echo "Installing wasm-pack ${WASM_PACK_VERSION}..." + archive="wasm-pack-v${WASM_PACK_VERSION}-${target}.tar.gz" + tmp_dir="$(mktemp -d)" + trap 'rm -rf "$tmp_dir"' RETURN + curl --fail --location --silent --show-error \ + "https://github.com/wasm-bindgen/wasm-pack/releases/download/v${WASM_PACK_VERSION}/${archive}" \ + --output "$tmp_dir/$archive" + tar -xzf "$tmp_dir/$archive" -C "$tmp_dir" + install -m 0755 \ + "$tmp_dir/wasm-pack-v${WASM_PACK_VERSION}-${target}/wasm-pack" \ + "$HOME/.cargo/bin/wasm-pack" + rm -rf "$tmp_dir" + trap - RETURN + fi +} + +install_node + +if ! command -v rustup >/dev/null 2>&1; then + echo "Installing rustup..." + curl --proto '=https' --tlsv1.2 --fail --silent --show-error \ + https://sh.rustup.rs | sh -s -- -y --profile minimal --no-modify-path \ + --default-toolchain none +fi +source "$HOME/.cargo/env" + +toolchain="$(sed -n 's/^channel = "\([^"]*\)"/\1/p' rust-toolchain.toml)" +echo "Installing Rust toolchain ${toolchain}..." +rustup toolchain install "$toolchain" --profile minimal \ + --component rust-src \ + --target wasm32-unknown-unknown + +install_wasm_pack + +if ! rsw --version 2>/dev/null | grep -Fq "${RSW_VERSION}"; then + echo "Installing rsw ${RSW_VERSION}..." + cargo install rsw --version "$RSW_VERSION" --locked +fi + +# Amp shells include ~/.local/bin, while setup's PATH changes do not persist. +for command in cargo rustc rustdoc rustfmt rustup wasm-pack rsw; do + ln -sfn "$HOME/.cargo/bin/$command" "$HOME/.local/bin/$command" +done + +echo "Installing JavaScript dependencies..." +npm ci + +echo "Building the application..." +npm run build + +echo "Orb setup complete." diff --git a/.amp/services.yaml b/.amp/services.yaml new file mode 100644 index 0000000..05f9a0a --- /dev/null +++ b/.amp/services.yaml @@ -0,0 +1,6 @@ +services: + yawn-preview: + command: npm start -- --host 0.0.0.0 --port "$PORT" + portal: + title: Yawn + description: WebGPU level editor preview. diff --git a/.gitignore b/.gitignore index 9621f52..7328621 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,7 @@ target/ # WASM build artifacts .rsw/ static/level-editor/ + +# Amp runtime artifacts +.amp/in/ +.amp/portals/ diff --git a/agent-browser.json b/agent-browser.json new file mode 100644 index 0000000..bd6a3b0 --- /dev/null +++ b/agent-browser.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://agent-browser.dev/schema.json", + "webgpu": true, + "args": "--enable-unsafe-webgpu,--enable-features=Vulkan,--use-angle=vulkan,--use-vulkan=swiftshader,--use-webgpu-adapter=swiftshader,--disable-vulkan-surface" +} diff --git a/vite.config.js b/vite.config.js index abd25d1..78d3722 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,6 +7,9 @@ import copy from "rollup-plugin-copy"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +const portalHost = process.env.PUBLIC_URL + ? new URL(process.env.PUBLIC_URL).hostname + : undefined; export default defineConfig({ build: { @@ -54,6 +57,7 @@ export default defineConfig({ }, preview: { port: 8080, + allowedHosts: portalHost ? [portalHost, ".e2b.app"] : [], headers: { "Cross-Origin-Embedder-Policy": "require-corp", "Cross-Origin-Opener-Policy": "same-origin",