Working notes for AI agents operating in this library. End-user docs: README.md,
docs/USAGE.md. An in-flight change, if any, is described in docs/PLAN.md.
Server-Sent Events for the webtyp ecosystem: a Go server (hub, channels, replay history) that
mounts on any webtyp.com/router implementation, and a TinyGo/WASM browser client over
EventSource. Plus the two adapters to the ecosystem's pub/sub contract: Publisher
(server side, events.Publisher) and Subscriber (browser side, events.Subscriber).
| Files | Build tag | Runs on | stdlib |
|---|---|---|---|
server.go, hub.go, events_publisher.go |
//go:build !wasm |
backend | Allowed where already used (bytes, sync). This is backend code: do not "clean up" those imports. |
client.go, client_config.go, subscriber.go |
//go:build wasm |
browser (TinyGo) | Forbidden — use the replacements below |
config.go, server_config.go, interfaces_server.go, models.go |
none | both | Forbidden — they compile into the browser too |
Replacements in browser/shared code:
| Never | Use |
|---|---|
fmt, errors, strings, strconv |
webtyp.com/fmt |
encoding/json |
webtyp.com/json (and only where a payload really is encoded; encoding/json alone costs ~1 MB of wasm under TinyGo) |
net/http |
webtyp.com/router (the server mounts on a router.Router; this library never names net/http) |
context for transport |
webtyp.com/context |
time |
webtyp.com/time |
map[K]V |
a slice of structs scanned linearly, or []fmt.KeyValue — no exceptions, not "just a small cache" |
reflect |
nothing — models are generated by definitionc |
gotest runs both lanes (native + browser) in one command, and both must pass. A change that
only passes go test, or that "compiles with GOOS=js GOARCH=wasm go build", is not done:
that command uses the full Go stdlib and is not TinyGo, so it accepts net/http, maps and
encoding/json that TinyGo would ship or reject. gotest -tinygo is the TinyGo check.
The contracts this library meets already exist upstream — implement them, never declare a local copy:
- mounting:
router.APIModule(ModelName()+MountAPI(r router.Router)); - streaming:
router.StreamFunc/router.Streamer; - access:
model.Access(AccessGuardedzero value,AccessAuthenticated,AccessPublic) +model.Resource; - pub/sub:
events.Publisher/events.Subscriber/events.Event.
If one of those lacks something this library needs, that is a defect upstream: stop and report it,
never patch it here. webtyp.com/mcp has its own SSEPublisher interface; it is not this
package's and is not touched from here.
All tests live in tests/ (package sse_test, black-box). Server tests use
webtyp.com/router/mock (a real gate: Invoke rejects what the route's access forbids). Browser
tests (//go:build wasm) replace the global EventSource with a JS object that records calls.
go install webtyp.com/devflow/cmd/gotest@latest
gotest # vet + race + cover + wasm lane
gotest -tinygo # also the TinyGo compilerPublishing is done by the maintainer (gopush / codejob); an agent never runs either.