Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
chore(workers): add agent-gateway build files and update the Hunyuan3D README and GCP credits plan
nirholas6048014912bc
diff --git a/docs/ops/gcp-credits-plan.md b/docs/ops/gcp-credits-plan.mdindex e2f735e11..140c7a39b 100644--- a/docs/ops/gcp-credits-plan.md+++ b/docs/ops/gcp-credits-plan.md@@ -93,7 +93,7 @@ Six GPU services share those 3 GPUs:| ~~avatar-reconstruction~~ | photo-to-avatar: **moved to CPU-only 2026-07-25, holds no GPU** (see below); sized for the 10k avatars/day launch target 2026-08-12 (min 1, max 12, 4 jobs per instance: docs/ops/avatar-reconstruction-capacity.md) | 1 | 12 || model-hunyuan3d-21 | PBR realism lane, L4 build (min 0 since 2026-07-17; a pinned min 1 here starved every other rollout). KNOWN-BROKEN for actual jobs: 18 GiB tmpfs weight staging + 14 GiB model OOMs the 32 Gi L4 ceiling (signal 9 mid-load); see workers/model-hunyuan3d/README.md | 0 | 1 |-`model-hunyuan3d-21-rtx` (same 2.1 PBR lane, warm min 1 / max 4) does NOT draw+`model-hunyuan3d-21-rtx` (same 2.1 PBR lane, warm min 1 / max 1) does NOT drawfrom this pool; it runs on the RTX PRO 6000 quota below.**Resolved 2026-07-25 by returning a GPU nobody was using.** `avatar-reconstruction` held one of the three L4s solely for background removal (rembg / onnxruntime-gpu); every other stage (MediaPipe, TPS, GLB ops) is CPU-bound. Measured: rembg took **~2.2 s per job with the L4 attached versus ~1.9 s on a plain CPU box** — the CUDA provider was never engaging and the GPU was buying nothing. It now runs `--gpu=0 --cpu=8`, which is *faster* (end-to-end 4.2-4.7 s, was 4.8-5.8 s) at identical output quality (mean ISE 0.1595 both ways).diff --git a/workers/agent-gateway/Dockerfile b/workers/agent-gateway/Dockerfilenew file mode 100644index 000000000..b6059930d--- /dev/null+++ b/workers/agent-gateway/Dockerfile@@ -0,0 +1,63 @@+# syntax=docker/dockerfile:1.7-labs+# agent-gateway: the chat gateway worker (Cloud Run service).+#+# Build from the REPO ROOT. The worker runs the shared gateway core in+# api/_lib/gateway, which reaches the copilot engine, the agent wallet and the+# trade engine, so the image carries the same install the API image does (root+# workspaces, built SDKs) plus the worker's own two dependencies (grammy,+# discord.js) and the distro ffmpeg the voice path transcodes with+# (api/_lib/gateway/audio.js reads FFMPEG_PATH).+#+# docker build -f workers/agent-gateway/Dockerfile -t agent-gateway .+# docker run --env-file .env.local -e TELEGRAM_BOT_TOKEN=... -p 8080:8080 agent-gateway+#+# Deploy: workers/agent-gateway/cloudbuild.yaml (README.md has the command).++FROM node:24-slim++WORKDIR /app++# node-gyp toolchain for the root install's native deps (no Node 24 prebuilts),+# and ffmpeg for voice notes in and spoken replies out.+RUN apt-get update \+ && apt-get install -y --no-install-recommends python3 make g++ ffmpeg ca-certificates \+ && rm -rf /var/lib/apt/lists/*++ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \+ PUPPETEER_SKIP_DOWNLOAD=1++# The npm that produced package-lock.json; see the root Dockerfile for why a+# floating npm breaks `npm ci` on an untouched lockfile.+ARG NPM_VERSION=11.9.0+RUN npm install -g npm@${NPM_VERSION}++# 1. Root manifests only, so the large `npm ci` layer survives source changes.+COPY --parents package.json package-lock.json .npmrc* **/package.json /app/+RUN npm ci --ignore-scripts --no-audit --no-fund++# 2. The worker's own dependencies, from its own lockfile. Node resolves them+# from workers/agent-gateway/node_modules for the worker's files and falls+# back to /app/node_modules for everything under api/.+COPY workers/agent-gateway/package.json workers/agent-gateway/package-lock.json ./workers/agent-gateway/+RUN npm --prefix workers/agent-gateway ci --omit=dev --no-audit --no-fund++# 3. Full source, then the deferred lifecycle scripts the API image runs too+# (native rebuilds, the root postinstall that builds the workspace SDKs).+COPY . .+RUN npm rebuild && npm run postinstall++# 4. Drop the root devDependencies; the worker's tree was installed without them.+RUN npm prune --omit=dev --ignore-scripts --no-audit --no-fund++ENV NODE_ENV=production \+ NODE_OPTIONS=--no-deprecation \+ FFMPEG_PATH=/usr/bin/ffmpeg \+ PORT=8080++# Same permission normalisation as the root image (it explains the find), then+# drop root: the worker never writes under /app.+RUN find /app \( \( -type d ! -perm -555 \) -o \( -type f \( ! -perm -444 -o \( -perm /111 ! -perm -111 \) \) \) \) -exec chmod a+rX {} ++USER node++EXPOSE 8080+CMD ["node", "workers/agent-gateway/src/index.js"]diff --git a/workers/agent-gateway/cloudbuild.yaml b/workers/agent-gateway/cloudbuild.yamlnew file mode 100644index 000000000..d7c1f7fc0--- /dev/null+++ b/workers/agent-gateway/cloudbuild.yaml@@ -0,0 +1,120 @@+# Cloud Build -> Cloud Run for the chat gateway worker (workers/agent-gateway).+#+# Submit from the REPO ROOT (the Dockerfile builds the root install and copies+# api/, which the gateway core lives in):+#+# gcloud builds submit --config workers/agent-gateway/cloudbuild.yaml . \+# --region us-central1 --project aerial-vehicle-466722-p5 \+# --substitutions=SHORT_SHA=manual$(date +%s)+#+# SHORT_SHA is only set for trigger-driven builds; a manual submit must pass it+# or the image tag is empty and the push fails.+#+# The service's environment is derived from the live three-ws-api service on+# every deploy (scripts/deploy-env.mjs): literals by value, credentials by+# Secret Manager reference, platform treasury and payer signers left out. A+# variable the gateway needs (DISCORD_BOT_TOKEN, DISCORD_APP_ID,+# DISCORD_PUBLIC_KEY, TELEGRAM_BOT_TOKEN) therefore belongs on three-ws-api,+# which needs it too for the receivers and the settings page, and reaches the+# worker on its next deploy. Gateway tuning knobs ride in as substitutions.+#+# Always on: --no-cpu-throttling keeps the drain loop and the Discord gateway+# connection running between requests, and min-instances 1 keeps one worker up.+# The VPC connector matches three-ws-api: the rate limiter's Redis endpoint is a+# private address. Ingress is closed (no unauthenticated invokes); nothing calls+# this service over HTTP except Cloud Run's own probes.+#+# Builds run as the pinned three-ws-build service account (the project's+# default compute service account was deleted) and the service runs as three-ws.++serviceAccount: projects/aerial-vehicle-466722-p5/serviceAccounts/[email protected]++substitutions:+ _REGION: us-central1+ _SERVICE: agent-gateway+ _REPO: workers+ _SOURCE_SERVICE: three-ws-api+ _MIN_INSTANCES: "1"+ _MAX_INSTANCES: "1"+ _CONCURRENCY: "8"+ _MAX_ATTEMPTS: "5"++steps:+ - id: pull-cache+ name: gcr.io/cloud-builders/docker+ entrypoint: bash+ args: ['-c', 'docker pull ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}:latest || exit 0']++ - id: build+ name: gcr.io/cloud-builders/docker+ env: ['DOCKER_BUILDKIT=1']+ args:+ - build+ - --file+ - workers/agent-gateway/Dockerfile+ - --tag+ - ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}:$SHORT_SHA+ - --tag+ - ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}:latest+ - --cache-from+ - ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}:latest+ - --build-arg+ - BUILDKIT_INLINE_CACHE=1+ - .+ timeout: 1800s++ - id: push+ name: gcr.io/cloud-builders/docker+ args: ['push', '--all-tags', '${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}']++ - id: read-api-env+ name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim+ entrypoint: bash+ args: ['-c', 'gcloud run services describe ${_SOURCE_SERVICE} --region=${_REGION} --project=$PROJECT_ID --format=json > /workspace/api-service.json']++ - id: derive-env+ name: node:24-slim+ entrypoint: node+ args:+ - workers/agent-gateway/scripts/deploy-env.mjs+ - /workspace/api-service.json+ - /workspace/gateway-env.yaml+ - /workspace/gateway-secrets.txt+ - --set+ - GATEWAY_CONCURRENCY=${_CONCURRENCY}+ - --set+ - GATEWAY_MAX_ATTEMPTS=${_MAX_ATTEMPTS}++ - id: deploy+ name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim+ entrypoint: bash+ args:+ - -c+ - >-+ gcloud run deploy ${_SERVICE}+ --image=${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}:$SHORT_SHA+ --region=${_REGION}+ --project=$PROJECT_ID+ --platform=managed+ --service-account=three-ws@$PROJECT_ID.iam.gserviceaccount.com+ --no-allow-unauthenticated+ --no-cpu-throttling+ --cpu=1+ --memory=2Gi+ --min-instances=${_MIN_INSTANCES}+ --max-instances=${_MAX_INSTANCES}+ --vpc-connector=three-ws-vpc+ --vpc-egress=private-ranges-only+ --env-vars-file=/workspace/gateway-env.yaml+ --set-secrets="$$(cat /workspace/gateway-secrets.txt)"+ && rm -f /workspace/api-service.json /workspace/gateway-env.yaml /workspace/gateway-secrets.txt++images:+ - ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}:$SHORT_SHA+ - ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/${_SERVICE}:latest++options:+ machineType: E2_HIGHCPU_8+ logging: CLOUD_LOGGING_ONLY++timeout: 2700sdiff --git a/workers/model-hunyuan3d/README.md b/workers/model-hunyuan3d/README.mdindex 03d70fc4c..e8fb986a3 100644--- a/workers/model-hunyuan3d/README.md+++ b/workers/model-hunyuan3d/README.md@@ -254,6 +254,27 @@ gcloud builds submit --config workers/model-hunyuan3d/cloudbuild.yaml \Every submit deploys as well as builds, so all three are owner-gated productiondeploys, not build checks.+**The RTX deploy takes the lane down for one model load.** Cloud Run enforces+the RTX PRO 6000 quota at one GPU, and the serving revision holds it, so a+normal rolling update can never start the new revision's instance (it waits for+a GPU until the 4 minute startup probe gives up, and the revision is left not+Ready while traffic stays on the old one). `cloudbuild.hunyuan21rtx.yaml`+therefore releases the GPU first with service-level manual scaling at 0,+deploys, and restores autoscaling (`--scaling=auto --max=1`) whether or not the+deploy succeeded. Expect about ten minutes without this lane while the new+instance loads its weights; forge fails over to the other image lanes+meanwhile. A config-only change (an env var, a probe) needs the same three+steps by hand:++```bash+gcloud run services update model-hunyuan3d-21-rtx --region us-central1 --scaling=0+gcloud run services update model-hunyuan3d-21-rtx --region us-central1 --update-env-vars KEY=VALUE+gcloud run services update model-hunyuan3d-21-rtx --region us-central1 --scaling=auto --max=1+```++The full incident is in+[docs/ops/production-log-triage.md](../../docs/ops/production-log-triage.md).+What each config asks Cloud Run for, all in `us-central1`, all with no GPU zonalredundancy, a 900 s request timeout, and the `three-ws-build@` /`avatar-reconstruction-sa@` service accounts pinned (the project's default