mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-21 01:59:49 +00:00
The whole module builds on zip. This is the rest of it — routers/, the relay, and
the 2,823-line in-house router underneath.
ONE ROUTE TABLE. Every address was registered on a hand-written router held in a
package variable built at import time, and the zip app in front of it was a single
app.All("/v1/*", relay) forwarding through a net/http adaptor into that router. A
short "promoted" list re-registered three addresses specifically so the fleet
document could NAME them, because a glob tells a host a prefix and nothing under
it: three operations authenticated, reachable and answering in production with no
generated SDK, no MCP tool, no CLI command, and nothing saying who served them.
Every address is its own route now, so every one is described, and the boundary
the relay crossed — with the OTel context it had to stow and restore over it — is
gone with the relay.
Registration is one entry point, called with the app instead of writing onto a
global at import. The filters go on FIRST, and that is not cosmetic: the router
walks its stack in registration order, so a filter added after a route never runs
before it.
ONE IDENTITY. The filters read a per-pod in-memory session store; the handlers read
the request's verified IAM token. The store's own comment recorded the cost — it is
filled by a hook that does not run when the embedded binary serves these routes, so
it answered nil on every request and the filters billed and rate-limited by the raw
key instead. Filters now ask the same function the handlers ask.
Two filters went entirely, both doing somebody else's job:
- Auto-signin accepted an MD5 of clientId:clientSecret, or HTTP Basic against the
configured pair, and minted an IsAdmin identity into that store. IAM mints
credentials. It was reachable only for /storage, which is why it survived.
- Static served a landing folder, the admin bundle, and /storage from a path
taken off the URL — with no cleaning, beside a sibling branch that checks for
"/.." — then rewrote main.<hash>.js on the way out. Static content is ingress
and the static plugin. Every route here is /v1.
A REFUSAL IS THE END OF THE REQUEST, and now says so. A filter used to write a
response and return, and the router inferred a refusal from something having been
written. Two places got that wrong: the demo-mode gate denied and then ran the
permission filter anyway, and the error envelope defaulted to 200 with a second
function beside it for callers who wanted a real status. One envelope, status
required.
Recording was two filters passing a username through a request parameter, because
a before-filter and an after-filter had no other way to share; it is one
middleware holding a local across the handler. The cookie rewriter went with the
store it patched. The prometheus filter counted /api throughput — a prefix this
service has never served — so its counter has always been zero.
The standalone binary serves the app on zip's own listener rather than a net/http
server wrapping it, and the ZAP transports take the same app as an http.Handler,
resolved per request: App.Fiber() hands out the current generation's router, and a
generation is a projection.
web/ keeps its React source and loses its Go.