Proprietary Sufficiency Engine

Loading and configuring a proprietary engine.

The Sufficiency Engine interface is Apache-2.0 and lives in @meted/engine-interface, alongside baseline-heuristic, an Apache-2.0 implementation that runs when nothing else is configured. A separate proprietary implementation of the same interface is distributed as a private npm package or a WASM module.

Where it runs

The proprietary engine loads as a local module and is called as a function, in the same place as baseline-heuristic. It makes no network call, so the only outbound request in the request path remains the one to your configured provider.

Using it

// meted.config.json
{
  "engine": {
    "wasm": "./engine.wasm",
  },
}
{
  "engine": {
    "module": "@meted/engine",
  },
}

The loader resolves, in order:

  1. An explicit wasm path or module
  2. An explicit module
  3. @meted/engine, if it happens to be installed
  4. The Apache-2.0 baseline

If a configured engine fails to load, Meted falls back to the baseline and prints the reason at start-up:

  Engine      baseline-heuristic 0.1.0 (open source, baseline)
              ! WASM engine failed to load: no such file

In a Worker

Workers cannot import by dynamic path, so it is wired in statically:

import engineWasm from './engine.wasm'
import { createWasmEngine } from '@meted/engine-interface'

const engine = await createWasmEngine({ module: engineWasm })

The same contract

interface SufficiencyEngine {
  readonly name: string
  readonly version: string
  readonly proprietary?: boolean
  evaluate(request: SufficiencyRequest, options?): Promise<EngineDecision>
}

Both engines are held to the same rules:

  • A 250ms budget, after which the engine counts as failed
  • Decisions validated before use; an invalid one is a failure
  • Failure forwards the original request unchanged
  • Nothing the engine sees is retained

The WASM ABI

memory                : WebAssembly.Memory
meted_abi_version()   -> i32   must equal 1
meted_alloc(len)      -> i32
meted_free(ptr, len)  -> void
meted_evaluate(p, n)  -> i64   packed (ptr << 32) | len, UTF-8 JSON decision
meted_engine_info()   -> i64   optional, packed JSON {name, version}

Input is a UTF-8 JSON SufficiencyRequest; output is a UTF-8 JSON SufficiencyDecision. The ABI version is checked before the module is used.

The ABI is public so that a third-party engine can be written against it.

Checking which engine is running

curl localhost:8787/_meted/health | jq .engine
{
  "name": "baseline-heuristic",
  "version": "0.1.0",
  "proprietary": false,
  "source": "baseline",
  "timeoutMs": 250
}

The engine name and version are reported on every request, so a change in decision quality can be attributed to a change in engine.

Was this page helpful?