@prototyperco/bridge-client
v0.5.6
Published
Zero-dependency HTTP client SDK for the Prototyper Live Canvas server
Downloads
419
Maintainers
Readme
@prototyperco/bridge-client
Zero-dependency HTTP client SDK for the Prototyper Live Canvas server. Works in Node.js, Bun, Deno, and any environment with a global fetch.
Install
npm install @prototyperco/bridge-clientUsage
import { createBridgeClient } from "@prototyperco/bridge-client";
const client = createBridgeClient({ baseUrl: "http://localhost:4321" });
// Create a session
const session = await client.createSession({
name: "My Design",
spec: {
root: "card",
elements: {
card: { type: "Card", props: { className: "p-6" }, children: ["title"] },
title: { type: "Heading", props: { level: 2, children: "Hello" } },
},
},
});
console.log(session.previewUrl);
// Apply operations
await client.applyOps(session.id, {
ops: [{ op: "set_prop", key: "title", prop: "children", value: "Updated!" }],
});
// Read state back
const state = await client.getSession(session.id);
console.log(state.spec);
// Clean up
await client.closeSession(session.id);API Reference
createBridgeClient(options)
Creates a client instance. Options:
baseUrl(string, required) -- Base URL of the Bridge servertoken(string, optional) -- Auth token for future use
Client Methods
| Method | Description |
| ---------------------------------------- | ------------------------------------- |
| createSession(input) | Create a new design session |
| listSessions() | List all active sessions |
| getSession(id) | Get full session state (spec + theme) |
| getSessionMeta(id) | Get full session metadata |
| applyOps(sessionId, { ops, agentId? }) | Apply spec operations |
| setPresence(sessionId, input) | Update agent presence/status |
| closeSession(sessionId) | Delete a session |
| health() | Server health check |
Types
All types are exported from the package: Spec, UIElement, ThemeParams, SpecOp, BridgeClient, BridgeClientOptions, and all input/result interfaces.
License
MIT
