lmteavm application authoring skill
Use the lmteavm example to embed annotation-dispatched LMCode entries in a TeaVM browser application.
Purpose
Build browser behavior in Java, expose typed host callbacks to LMCode, and dispatch LMCode interface entries by annotation. The quick reference contains copyable schema, LMCode, Java, and JSON examples.
When to use it
Use this pattern when a browser application needs LMCode behavior with explicit host capabilities, or when Java browser infrastructure and LMCode handlers should share a typed contract. Start with the working demo and its public source.
Install
Install Java 21, Maven, Node 24.15 or newer, lmcode-java 0.1.1 in the local Maven repository, and @lmctl-ai/lmctl 0.2.482 or newer. Set LMCODE_COMPILER_MODULE to the compiler package's dist/dsl.js.
Commands
mvn clean package npm ci npx playwright install --with-deps chromium npm test
Inputs and outputs
- Input: Java browser code, an LMCode schema, annotated LMCode entries, and optional static JSON.
- Build output: demo.html, demo.css, teavm.js, boot.js, favicon, and JSON assets under target/demo/.
- Runtime output: host-defined DOM, SVG, canvas, WebGL, animation, hydration, and drawing effects.
Safety rules
- Register only required host functions and preserve exact schema bytes.
- Match every function and interface signature on both sides.
- Use innerText for external text; do not inject untrusted HTML.
- Cancel animation and guard asynchronous mode changes before replacing output.
- Normalize optional JSON null and undefined values before calling LMCode.
Worked examples
- Read the demo's DemoHandler, DrawCommand, and TodoHandler interfaces.
- Add an annotation and function implementing DemoHandler.
- Register any required host callback with Registry.function.
- Resolve the annotation through program.entries() and invoke Program.call.
- For data-driven drawing, add a JSON document using the shared @data and @draw entries rather than duplicating the renderer.
Errors and exit codes
Compiler diagnostics and Maven failures produce a nonzero build exit. Program.load reports schema mismatches and unbound imports. Browser integration assertions produce a nonzero test exit; inspect the reported status, console errors, and page errors.
How to verify
- Run a clean Maven build.
- Run npm test with Chromium installed.
- Exercise each changed mode through real browser events.
- Check JSON requests and visible output, not only compilation.
- For canvas and WebGL, verify rendered pixels and the absence of browser or GL errors.