docs/INSTALLATION.md
Installation Guide
Install Leveonas v0.6.0 across npm, pnpm, yarn, or Bun, verify CLI and env configuration, and wire Next.js, Express, Vite, Plain HTML, or browser runtimes.
Install Leveonas as a Node.js/TypeScript SDK (leveonas@0.6.0), run the CLI via npx or global install, or mount the sandboxed browser runtime.
Prerequisites & Version Pinning
- Runtime: Node.js
>= 18.0.0(or Bun>= 1.1.0) - Package Managers:
npm >= 9.0.0,pnpm >= 8.0.0,yarn >= 1.22.0, orbun >= 1.1.0 - Current Release:
leveonas@0.6.0(SemVer — backward compatible across0.6.x; seeCHANGELOG.md)
package.json (leveonas@0.6.0) so compiler diagnostics, AST types, and runtime patch schemas remain synchronized across your backend and preview host.1. Install the Package
Local Project Dependency (Recommended)
# npm
npm install leveonas@0.6.0
# pnpm
pnpm add leveonas@0.6.0
# yarn
yarn add leveonas@0.6.0
# bun
bun add leveonas@0.6.0If you are only calling the OpenAI-compatible proxy (https://leveonas.ainot.site/api/v1), installing the standard openai SDK alone is sufficient:
npm install openaiGlobal CLI Installation
npm install -g leveonas@0.6.0Zero-Install Execution via npx or bunx
npx leveonas@0.6.0 --version
bunx leveonas@0.6.0 --version2. Post-Install Verification
Verify the CLI binary and compile a minimal LM file locally:
# 1. Confirm installed version & available commands
npx leveonas --version
npx leveonas --helpCreate a minimal test file named app.lm:
<REACT>
component(Counter)(
state(count, 0)
di(cs(p-6 rounded-xl border)
h2(cs(text-lg font-semibold) Counter)
bo(tp(button) oc(count++) Count: {count})
)
)
</REACT>Check syntax offline and compile it via your Leveonas API key:
# Offline syntax check (no API key required)
npx leveonas check app.lm
# Set your Leveonas API key (Bash / macOS / Linux)
export LEVEONAS_API_KEY="lv_live_your_key"
# Compile to React TSX code (--framework picks the dialect, --target picks output format)
npx leveonas compile app.lm --framework=react --target=codeExpected Windows PowerShell equivalent:
$env:LEVEONAS_API_KEY = "lv_live_your_key"
npx leveonas compile app.lm --framework=react --target=code<REACT>, <HTML>), --framework (language dialect override such as react, vue, html), and --target (CLI artifact format: code, document, ui-ir, ast, runtime-ir, or patch).3. Environment Variables by Stack
Never place LEVEONAS_API_KEY or upstream provider keys in client-side environment prefixes (NEXT_PUBLIC_*, VITE_*, or browser bundles).
| Stack | Env File | How It Loads |
|---|---|---|
| Next.js (App Router) | .env.local | Loaded automatically on the server by Next.js |
| Node.js (>= 20.6) / Express | .env | Pass node --env-file=.env server.js or import "dotenv/config" on line 1 |
| Bun | .env | Loaded automatically by Bun |
| Vite + React | .env (backend only) | Vite client code must call your backend (/api/*) proxy — never expose keys in VITE_* |
| Windows PowerShell | Session / System Env | $env:LEVEONAS_API_KEY = "lv_live_..." |
4. Framework-Specific Setup
Next.js (App Router)
npm install openai leveonas@0.6.0Create .env.local at your project root:
LEVEONAS_API_KEY="lv_live_your_leveonas_api_key"
GEMINI_API_KEY="AIzaSy_your_gemini_key"Create a server-only route (app/api/ai/route.ts):
import OpenAI from 'openai';
import { NextRequest, NextResponse } from 'next/server';
const leveonas = new OpenAI({
baseURL: 'https://leveonas.ainot.site/api/v1',
apiKey: process.env.LEVEONAS_API_KEY!,
defaultHeaders: {
'x-gemini-key': process.env.GEMINI_API_KEY!,
},
});
export async function POST(req: NextRequest) {
const { prompt } = await req.json();
const completion = await leveonas.chat.completions.create(
{
model: 'gemini-4-carbon',
messages: [{ role: 'user', content: prompt }],
},
{ headers: { 'x-leveonas-provider': 'gemini' } }
);
return NextResponse.json({ code: completion.choices[0]?.message?.content ?? '' });
}Node.js & Express
npm install express openai dotenv leveonas@0.6.0// src/server.ts — Load .env on line 1
import 'dotenv/config';
import express from 'express';
import OpenAI from 'openai';
const app = express();
app.use(express.json());
const leveonas = new OpenAI({
baseURL: 'https://leveonas.ainot.site/api/v1',
apiKey: process.env.LEVEONAS_API_KEY!,
});
app.post('/api/ai', async (req, res) => {
const completion = await leveonas.chat.completions.create(
{
model: 'gpt-6.2-sol',
messages: [{ role: 'user', content: String(req.body.prompt || '') }],
},
{
headers: {
'x-leveonas-provider': 'openai',
'x-user-llm-key': process.env.OPENAI_API_KEY!,
},
}
);
res.json({ code: completion.choices[0]?.message?.content ?? '' });
});
app.listen(4000);Vite + React (Frontend + Dev Proxy)
Keep all API keys inside an Express/Hono backend on port 4000 and configure vite.config.ts to proxy /api from the React dev server:
// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
server: {
proxy: {
'/api': 'http://127.0.0.1:4000',
},
},
});Bun
bun add openai leveonas@0.6.0Bun loads .env automatically and runs compile(), createSession(), and the CLI (bunx leveonas) natively with standard Web fetch and ReadableStream.
Plain HTML / Browser Runtime
For standalone HTML previews or progressive DOM patch rendering inside a sandboxed <iframe>, choose the distribution matching your environment:
| Distribution | Intended Usage | Global / Export |
|---|---|---|
leveonas/runtime (npm subpath) | Bundlers (Next.js, Vite, Webpack) | DOMPatchApplier, CSSPatchApplier, JSPatchApplier, validatePatches |
/leveonas-runtime.js (CDN IIFE) | Standalone <iframe sandbox="allow-scripts"> template | window.LeveonasRuntime |
/leveonas.js (CDN Engine IIFE) | Zero-build SSE client + automatic sandbox iframe manager | window.Leveonas.Engine + window.LeveonasRuntime |
Example mounting /leveonas-runtime.js inside a sandboxed preview iframe (sandbox="allow-scripts", omitting allow-same-origin):
<iframe id="preview" sandbox="allow-scripts" style="width:100%;min-height:420px;border:0"></iframe>
<script>
const iframe = document.getElementById('preview');
iframe.srcdoc = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://leveonas.ainot.site/leveonas-runtime.js"><\/script>
</head>
<body>
<div id="leveonas-root"></div>
<script>
var root = document.getElementById('leveonas-root');
var applier = null;
window.addEventListener('message', function (event) {
if (event.source !== window.parent) return;
if (!event.data || event.data.type !== 'leveonas:patch') return;
var rt = window.LeveonasRuntime;
if (!applier) {
applier = new rt.DOMPatchApplier(root, document);
applier.registerNode('leveonas-root', root);
}
applier.apply(rt.validatePatches(event.data.patches));
});
<\/script>
</body>
</html>`;
</script>5. Production Browser Runtime Checklist
- Content Security Policy (CSP): If your host or sandbox serves CSP headers, permit
script-src 'self' https://leveonas.ainot.siteandframe-src 'self' blob: data:. Never addallow-same-originalongsideallow-scriptson untrusted preview iframes. - Lifecycle & Cleanup: Call
session.abort()/session.destroy()(orengine.abort()) when navigating away or cancelling a request, and post{ type: 'leveonas:reset' }(or invokeapplier.cleanupJS()) to clear registered timers and listeners between generations. - Self-Hosted Runtime Bundles: Running
npm run build:bundlesbuilds deterministicleveonas-runtime.jsandleveonas.jsassets from the installed0.6.0release so you can pin and serve them directly from your own CDN or/publicdirectory with Subresource Integrity (integrity="sha384-...").
Next Steps
- HTTP Endpoints & Schemas: Public API Reference
- TypeScript SDK & Browser Runtime Bridge: SDK Reference
- CLI Commands & Flags: CLI Reference