The local Rust policy-gate demonstration · Chapter 9 of 9

Wasmer

The app kind is wasmer.io/App.v0. The published package name is soltrinox/policy-gate-example. app.yaml carries the kind, sets owner to soltrinox, and sets package to .. Deploy reads the local wasmer.toml for that package name. A package value that repeats the wasmer.toml name is rejected as deprecated deploy behaviour. wasmer.toml carries the package, the wasm32-wasmer-wasi module, the WASI runner, and the /public mount of web/out. The serve process binds 127.0.0.1 and reads PORT. On wasm the unset default is 80. Wasmer Edge proxies HTTP to that socket. The handler reads the request from the TCP stream. It does not read REQUEST_METHOD. The package owner is the active registry user from wasmer whoami. This branch does not use the eni6ma namespace.

Build the static UI, then the Wasm package, from this directory:

cd web
npm install
npm run build
cd ..
RUSTC="$(rustup which --toolchain wasix rustc)" cargo build --release --bin serve --target wasm32-wasmer-wasi

That command writes target/wasm32-wasmer-wasi/release/serve.wasm. cargo wasix build rewrites .cargo/config.toml so crates.io resolves through the WASIX registry, then fails: the active wasix toolchain has rustc and no cargo, and the fallback host cargo cannot select locked libc 0.2.191 from that registry. Point RUSTC at the wasix toolchain and keep crates.io.

POST /submit uses one HTTPS client on the native target and on wasm32-wasmer-wasi. The client is rustls 0.23.22 with the rustls-rustcrypto provider. That provider is pure Rust and does not link ring 0.17. The module does not depend on ureq. When XAI_API_KEY is set, the client sends POST https://api.x.ai/v1/chat/completions with that bearer credential. When the key is absent, Submit appends grok_unavailable and does not open a socket. A transport failure also appends grok_unavailable. An HTTP status outside 200-299 appends grok_http_<status>:<code>. The client error text does not include the key.

The Grok key is the Wasmer app secret XAI_API_KEY. It is not a file in the package. After the app exists, set it with:

wasmer app secret create --app soltrinox/policy-gate-example --non-interactive XAI_API_KEY

Pass the secret value as the next argument, or omit the value and use the prompt. Do not commit the value.

Deploy publishes the package and creates the Edge app:

wasmer deploy --non-interactive --publish-package

wasmer whoami prints the active registry user. app.yaml owner and the wasmer.toml package owner must be that user. On this branch the user is soltrinox. A deploy whose owner is a namespace the active user cannot access stops before publish and does not return a URL.

A local GET / runs the Wasm module as an HTTP server. Map web/out to /public and set PORT:

wasmer run --volume "$PWD/web/out:/public" --env PORT=8787 ./target/wasm32-wasmer-wasi/release/serve.wasm

GET http://127.0.0.1:8787/ returns HTTP 200. The body contains Policy gate.