Co-authored-by: Hanzo Dev <[email protected]>
@zap-proto/web
Browser-frontend RPC over ZAP. Native ZAP envelopes over WebTransport
(HTTP/3): one bidirectional stream per session, no WebSocket. Layered on
@zap-proto/zap, the ZAP wire runtime.
Wire
- One WebTransport session, one bidirectional stream.
- Each message is a
u32little-endian length, then one ZAP router envelope (buildRequest/buildResponse). - The IAM bearer is the
capof the first envelope. The server holds it for the session; later envelopes carry none.
The server end is a Go listener: zip's webtransport://host:port/path scheme,
built on zap-proto.io/go/transport/quic.
Use
import { connect } from "@zap-proto/web";
const { bootstrap, close } = await connect("https://zap.hanzo.ai/v1/dev/zap/cell", {
bearer: accessToken,
});
const resp = await bootstrap.call(0, { payload });
close();
The stream is full duplex. Every envelope the server sends is a response keyed
by promise id: call is answered once; subscribe receives the answer and
every push the server writes under that id.
const sub = bootstrap.subscribe(method, { payload }, (event) => render(event.body));
sub.close(); // stop delivering; ending the server's side is the app's method
connect takes any WebTransport option (serverCertificateHashes, …).
Callers that frame their own calls use the pipe underneath:
import { openWebTransport } from "@zap-proto/web";
const t = await openWebTransport(url);
await t.send(envelope); // adds the length prefix
const reply = await t.receive(); // the next whole envelope; rejects when the stream ends
Schema → code
zapgen --target=ts -single hello.zap # → hello_zap.ts (views + builders)
Method ordinals are the integers you pass to bootstrap.call(method, …).
Entry points
| Export | Entry | Purpose |
|---|---|---|
connect(url, opts?) |
root, /client |
Open a session; returns { bootstrap, close }. |
openWebTransport(url, opts?), lengthPrefixed, splitMessages |
root, /transport |
The envelope pipe and its framing. |
Conn, WebRpcError |
root | The RPC connection (call, subscribe); transport-level failure. |
httpServe(httpServer, opts) |
/server |
Node only. JSON-over-HTTP face of a service, for the OpenAPI 3.1 surface zapgen --emit=openapi describes. |
MintCap<Ctx> |
/server, /auth |
Node only. The bearer→ctx slot httpServe mints through. |
The root entry is browser-safe: it imports no Node built-ins.
License
MIT © Lux Industries Inc.