npm i @malleable/ui
import { Project } from '@malleable/ui' const project = new Project({ apiKey, id: 'u123' }) await project.init() const session = await project.openSession({ author: { kind: 'agent', id: 'ses_1' } }) await session.apply({ ops: [{ op: 'write', path: 'App.tsx', content: code }] }) const draft = await session.build() // draft: { ok, url } of the new module await session.commit({ message: 'Add chart' }) // one commit, sources + dist, returns its url await project.undo() // new commit with the previous sources
draft.url to the user in its own chat stream, next to the tokens. The client returns absolute urls, so the browser only runs import(url). See docs/projects.md.project.watch({ onMessage: async (msg) => { if (msg.type !== 'update') return const mod = await import(msg.url) // draft or commit module setComponent(() => mod.default) }, })
https://malleableui.dev by default. If you self-host the worker, pass its origin:const project = new Project({ endpoint: 'https://ui.example.com', apiKey, id: 'u123' })
const { authenticatedUrl } = await project.createGitToken({ label: 'laptop' }) // revocable, no expiry
git clone "$AUTHENTICATED_URL" app git commit -am 'Tweak' && git push origin main # the worker builds dist/ on top
write or edit tool builds and returns a url; the browser imports it at once.const edit = tool({ inputSchema: z.object({ path: z.string(), oldString: z.string(), newString: z.string() }), async execute(input) { await session.apply({ ops: [{ op: 'replace', ...input }] }) return session.build() // { ok: true, url } or { ok: false, errorText } for the model }, })
// browser: latest tool output url, React shared through an import map const { default: View } = use(import(url)) return <View api={dashboardApi} />
dashboard-demo/.write / replace / delete opscommit three-way merges, overlapping edits come back as conflict markers plus a prompt for the agentbuild() publishes a module to viewers without touching gitdist/; undo, restore, branches, fast-forward mergeReact.lazy@applymalleable.json at the repo root. Missing keys use the defaults:{ "entry": "App.tsx", "externalPackages": ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime"] }
externalPackages stays external as an esm.sh url with an exact version, for example https://esm.sh/date-fns@4.4.0?external=react,.... The first build that imports a package locks its latest version; project.updateDependencies({ names }) unlocks it.--primary, --secondary, --destructive, --muted, --accent--background, --foreground, --card, --popover--border, --input, --ring, --radius:root (as h s% l%) to theme every view. The generated CSS is scoped to the component: it sits in @scope ([data-malleable-root]), and the entry wraps the component in a display: contents element with that attribute. Utilities and the reset never touch host elements.:root { --primary: 0 0% 9%; --border: 0 0% 92%; } /* host page */
/view/<projectId>:MALLEABLE_API_KEY=... pnpm tsx examples/agent.ts demo1 MALLEABLE_API_KEY=... pnpm tsx examples/dashboard-agent.ts dash1 MALLEABLE_API_KEY=... pnpm tsx examples/parallel-agents.ts par1 # two agents, one conflict
website/: one Spiceflow app on Cloudflare Workers that serves the REST API, the module and git routes, and this docs site (Holocron).website/src/app.tsx ──► /api/projects/* REST, Bearer MALLEABLE_API_KEY ──► /p/:id/* built modules, live socket ──► /git/:id.git/* git remote ──► /view/:id live viewer ──► /, /docs/* Holocron docs (website/src/pages)
pnpm install pnpm dev # vite dev in website/; put MALLEABLE_API_KEY in website/.dev.vars pnpm deployment # typecheck, vite build, wrangler deploy pnpm test # runs against the deployed worker, deploy first
| Test | Covers |
src/bundle.test.ts | Tailwind output, CSS imports, relative and npm imports, code splitting, build errors |
src/project.test.ts | sessions, drafts, commit, undo, branches, parallel sessions and conflicts, live messages, git clone and push |
website/src/generate-tailwind.test.ts | Tailwind class scanner, local, no network (pnpm -C website test) |
MALLEABLE_API_KEY (env or website/.dev.vars) and deno on the PATH.@malleable/ui from dist/:pnpm build # root: emits dist/client.js cd dashboard-demo && pnpm run deploy:prod # D1 migrations, tsc, vite build, wrangler deploy