UI Builder
The builder keeps the design document independent of rendered Svelte components. A BuilderSpec is plain serialisable data; a block registry maps each node type to metadata and an implementation; a reactive store owns mutation history and messages; and a recursive renderer turns the node forest into the preview.
Source boundaries
| Boundary | Repository surface | Contract |
|---|---|---|
| Data model | src/lib/builder/spec.ts | versioned node tree, chat state, block metadata, and mutation vocabulary |
| Block registry | src/lib/builder/blocks.ts | rendered component definitions plus serialisable metadata |
| State | src/lib/builder/store.svelte.ts | apply, select, undo, redo, persistence, messages, and export |
| Renderer | src/lib/builder/Render.svelte | recursive node rendering, editable mouse/keyboard selection, and unknown-type fallback |
| Relay | src/lib/builder/relay.ts | version 1 window.bitsBuilder surface, cloned state boundaries, and lifecycle markers |
| Export | src/lib/builder/export.ts | Svelte source projection with Bits UI namespace collection |
| Persistence | src/routes/api/builder/session/+server.ts | validated GET and bounded POST of { spec, messages } |
| User interface | src/routes/builder and src/routes/relay | canvas/editor surface and relay-oriented workbench |
The model contract is detailed in Spec model. The concrete block shape is in Block registry. Browser-agent integration is in Relay protocol.
State flow
- The UI or relay submits one or more
BuilderOpvalues. BuilderStore.applyvalidates and applies the batch, returning{ ok, errors }.- Valid operations apply in order. An error does not roll back earlier mutations in the batch. If at least one operation changes the spec, one pre-batch spec/selection snapshot enters undo history; a selection-only batch does not.
Render.svelterecursively resolves eachtypethrough the block registry.- The UI and
window.bitsBuildershare the same store rather than mutate parallel documents. save()andload()exchange the spec and messages through the builder session endpoint.exportCode()projects the current spec to Svelte source.
Trust boundary
The relay is an in-browser integration point for an OMP agent operating through the browser relay. The application dependency set contains no server-side LLM SDK, and the relay contract does not accept or store an LLM provider key. This is a transport choice, not a claim that arbitrary browser scripts are trusted: an agent must still inspect applyOps failures before reporting success.
Verification state
- Builder source surfaces: present in the repository.
- Application build: verified with 0
svelte-checkerrors and warnings. - Browser interaction: verified through the live
window.bitsBuilderrelay. - Persistence: live GET/write/read round trip returned
200with equivalent state. - Exported Svelte behavior: sample and all-block exports compiled; the live export reflected the rendered switch.
The exact relay, persistence, validation, history, and canvas receipts are recorded in Operations.
loca.zone · bits.loca.zone · Svelte · Bits UI