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, or bun >= 1.1.0
  • Current Release: leveonas@0.6.0 (SemVer — backward compatible across 0.6.x; see CHANGELOG.md)
Production Version Pinning: Pin the exact minor release in 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

bash
# 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.0

If you are only calling the OpenAI-compatible proxy (https://leveonas.ainot.site/api/v1), installing the standard openai SDK alone is sufficient:

bash
npm install openai

Global CLI Installation

bash
npm install -g leveonas@0.6.0

Zero-Install Execution via npx or bunx

bash
npx leveonas@0.6.0 --version
bunx leveonas@0.6.0 --version

2. Post-Install Verification

Verify the CLI binary and compile a minimal LM file locally:

bash
# 1. Confirm installed version & available commands
npx leveonas --version
npx leveonas --help

Create a minimal test file named app.lm:

html
<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:

bash
# 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=code

Expected Windows PowerShell equivalent:

powershell
$env:LEVEONAS_API_KEY = "lv_live_your_key"
npx leveonas compile app.lm --framework=react --target=code
Parameter Note: Always distinguish source block tags (<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).

StackEnv FileHow It Loads
Next.js (App Router).env.localLoaded automatically on the server by Next.js
Node.js (>= 20.6) / Express.envPass node --env-file=.env server.js or import "dotenv/config" on line 1
Bun.envLoaded automatically by Bun
Vite + React.env (backend only)Vite client code must call your backend (/api/*) proxy — never expose keys in VITE_*
Windows PowerShellSession / System Env$env:LEVEONAS_API_KEY = "lv_live_..."

4. Framework-Specific Setup

Next.js (App Router)

bash
npm install openai leveonas@0.6.0

Create .env.local at your project root:

dotenv
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):

typescript
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

bash
npm install express openai dotenv leveonas@0.6.0
typescript
// 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:

typescript
// 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

bash
bun add openai leveonas@0.6.0

Bun 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:

DistributionIntended UsageGlobal / Export
leveonas/runtime (npm subpath)Bundlers (Next.js, Vite, Webpack)DOMPatchApplier, CSSPatchApplier, JSPatchApplier, validatePatches
/leveonas-runtime.js (CDN IIFE)Standalone <iframe sandbox="allow-scripts"> templatewindow.LeveonasRuntime
/leveonas.js (CDN Engine IIFE)Zero-build SSE client + automatic sandbox iframe managerwindow.Leveonas.Engine + window.LeveonasRuntime

Example mounting /leveonas-runtime.js inside a sandboxed preview iframe (sandbox="allow-scripts", omitting allow-same-origin):

html
<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

  1. Content Security Policy (CSP): If your host or sandbox serves CSP headers, permit script-src 'self' https://leveonas.ainot.site and frame-src 'self' blob: data:. Never add allow-same-origin alongside allow-scripts on untrusted preview iframes.
  2. Lifecycle & Cleanup: Call session.abort() / session.destroy() (or engine.abort()) when navigating away or cancelling a request, and post { type: 'leveonas:reset' } (or invoke applier.cleanupJS()) to clear registered timers and listeners between generations.
  3. Self-Hosted Runtime Bundles: Running npm run build:bundles builds deterministic leveonas-runtime.js and leveonas.js assets from the installed 0.6.0 release so you can pin and serve them directly from your own CDN or /public directory with Subresource Integrity (integrity="sha384-...").

Next Steps