lmcode-js reference

Reference tables for @lmctl-ai/lmcode-js classes and functions, lmcode_std_v3 REST/CLI interfaces, and error codes.

Host SDK API surface

APIType / ReturnDescription
createRegistry()RegistryCreate a Registry with all 226 canonical lmcode_std_v3 signatures installed
new Registry()RegistryCreate an empty Registry without standard library functions
registry.context(name, type)RegistryRegister a host context variable name and schema type
registry.function(signature, fn, options?)RegistryRegister a host function by canonical signature string ('fn foo(int) -> string')
registry.method(signature, fn, options?)RegistryRegister a host method by canonical signature string ('method Owner.bar(int) -> void')
registry.signatures()string[]Return sorted canonical signatures registered in the Registry
Program.load(bytecode, schema, registry)ProgramVerify DSLB v6 bytes against exact schema bytes and bind imports
program.entries()Entry[]Return source-ordered R49 rule entry metadata objects
program.run(context)voidExecute the main program body
program.call(nameOrIndex, context, args?)anyInvoke an R49 rule entry by name or index
program.callIsolated(nameOrIndex, context, args?)anyInvoke an R49 entry without resetting or colliding with an active outer run arena
registerRest(registry, options?)RestControllerRe-bind the 20 standard REST/CLI signatures to a configured RestController
await rest.run(program, context?)Promise<void>Run program body and serve HTTP/1.1 over configured streams if rest_serve() was called
rest.dispatch(request)RestResponseDispatch one HTTP request synchronously in memory
InvocationResults.fromCommand(files)InvocationResultsInitialize per-part ResultSinks and dry mode from LMCODE_INVOCATION_FILE

Standard REST and CLI interfaces (lmcode_std_v3)

The default lmcode_std_v3 catalog provides 226 canonical signatures and 10 standard interfaces on RestExchange for HTTP/1.1 stdio endpoints and stateless CLI commands.

InterfaceCanonical declarationBehavior
RestGetinterface RestGet(exchange: RestExchange) -> voidHTTP GET endpoint bound by path annotation such as @"/users/:id"
RestPostinterface RestPost(exchange: RestExchange) -> voidHTTP POST endpoint bound by path annotation such as @"/users"
RestPutinterface RestPut(exchange: RestExchange) -> voidHTTP PUT endpoint bound by path annotation such as @"/users/:id"
RestDeleteinterface RestDelete(exchange: RestExchange) -> voidHTTP DELETE endpoint bound by path annotation such as @"/users/:id"
RestPatchinterface RestPatch(exchange: RestExchange) -> voidHTTP PATCH endpoint bound by path annotation such as @"/users/:id"
RestHeadinterface RestHead(exchange: RestExchange) -> voidHTTP HEAD endpoint bound by path annotation
RestOptionsinterface RestOptions(exchange: RestExchange) -> voidHTTP OPTIONS endpoint bound by path annotation
RestHandlerinterface RestHandler(exchange: RestExchange) -> voidMethod-prefixed (@"POST /users") or rest_route(method, path, annotation) handler
CliCommandinterface CliCommand(exchange: RestExchange) -> voidStateless CLI subcommand entry dispatched by rest_cli(args)
CliOptioninterface CliOption(exchange: RestExchange) -> voidStateless CLI flag or option entry dispatched before CliCommand by rest_cli(args)

Standard REST and CLI functions and methods

NameCanonical signatureDescription
rest_configfn rest_config(string, string) -> voidSet controller configuration keys such as prefix, max_body_bytes, or session before rest_serve()
rest_routefn rest_route(string, string, string) -> voidBind an HTTP method and path template (:param, :rest..., {param}, {rest...}) to a RestHandler annotation
rest_servefn rest_serve() -> voidValidate registered routes and request HTTP/1.1 stdio serving after the program body finishes
rest_stopfn rest_stop() -> voidStop stdio HTTP/1.1 serving after the active response finishes flushing
rest_clifn rest_cli(StrList) -> stringDispatch a single stateless CLI argv vector across CliOption, CliCommand, or REST routes and return the response body
RestExchange.methodmethod RestExchange.method() -> stringReturn the uppercase HTTP method verb for the active request
RestExchange.pathmethod RestExchange.path() -> stringReturn the percent-decoded request path without the query string
RestExchange.querymethod RestExchange.query(string) -> stringReturn the first value of a query key or empty string when absent
RestExchange.has_querymethod RestExchange.has_query(string) -> boolReturn true when the query key is present in the request target
RestExchange.parammethod RestExchange.param(string) -> stringReturn a matched path parameter from :param or :rest... (or {param} / {rest...})
RestExchange.headermethod RestExchange.header(string) -> stringReturn case-insensitive header value (repeated headers joined by comma-space)
RestExchange.has_headermethod RestExchange.has_header(string) -> boolReturn true when the header is present on the request
RestExchange.bodymethod RestExchange.body() -> stringReturn raw request body bytes
RestExchange.statusmethod RestExchange.status(int) -> voidSet HTTP response status code in range 200..599
RestExchange.set_headermethod RestExchange.set_header(string, string) -> voidSet or replace a response header outside managed framing headers
RestExchange.sendmethod RestExchange.send(string) -> voidReplace response body with raw bytes
RestExchange.jsonmethod RestExchange.json(string) -> voidReplace response body and set Content-Type to application/json
RestExchange.getmethod RestExchange.get(string) -> stringRead server-wide shared string state key or empty string when absent
RestExchange.setmethod RestExchange.set(string, string) -> voidWrite server-wide shared string state key
RestExchange.incrementmethod RestExchange.increment(string) -> intAtomically increment a named integer counter starting at 1

Structured error codes and exit statuses

Error codePhaseExit statusTrigger condition
LOAD_BAD_BYTECODEload3Malformed DSLB v6 header, bad magic or version, truncated section, invalid opcode, or stack depth violation
LOAD_BAD_SCHEMAload3Host schema JSON fails dsl.schema 2 validation or declares an invalid result contract
LOAD_SCHEMA_MISMATCHload332-byte SHA-256 schema hash in DSLB v6 header does not match exact host schema bytes
LOAD_UNBOUNDload3Bytecode imports a context, function, or method signature not registered in the host Registry
RUN_ERRORrun3VM division or remainder by zero, or loop-free operand stack underflow
RUN_HOSTrun3Host callback failure, invalid encoding, expired collection handle, or REST route validation failure
APP_FAILapp4Post-run application domain validation failure or output stream write failure