parseModel / detectFormat
parseModel
import { parseModel } from "@wetron/core";
async function parseModel(bytes: Uint8Array, filename?: string): Promise<ModelGraph>;Inspects the buffer’s magic bytes (with filename extension as a tiebreaker) to identify the format, then dynamically imports and calls the matching parser package.
Throws ParseError if the format cannot be detected or parsing fails.
Direct parser imports
Call parsers directly to avoid the auto-detection overhead, or if you want to exclude specific parsers from your bundle:
import { parseOnnx } from "@wetron/onnx";
import { parseTflite } from "@wetron/tflite";
import { parseKeras } from "@wetron/keras";
import { parseTorchscript } from "@wetron/torchscript";
import { parseExecutorch } from "@wetron/executorch";
import { parseSavedModel } from "@wetron/savedmodel";
const graph = parseOnnx(bytes);
const graph = parseTflite(bytes);
const graph = parseKeras(bytes);
const graph = parseTorchscript(bytes);
const graph = parseExecutorch(bytes);
const graph = parseSavedModel(bytes);detectFormat
import { detectFormat } from "@wetron/core";
type Format = "onnx" | "tflite" | "keras" | "torchscript" | "executorch" | "savedmodel" | "unknown";
function detectFormat(bytes: Uint8Array, filename?: string): Format;Returns a format string - never throws. Useful for showing format badges in a UI before parsing.
| Format | Detection |
|---|---|
savedmodel | .pb filename extension (checked before ONNX) |
onnx | protobuf field 1 varint tag 0x08 |
tflite | TFL3 or ODLF at offset 4 |
keras | ZIP magic PK\x03\x04 + .keras extension (default for ZIP) |
torchscript | ZIP magic PK\x03\x04 + .pt/.ptl extension, or PTMF at 4 |
executorch | ET12 at offset 4 |
unknown | no match |
modelGraphToFlow
import { modelGraphToFlow } from "@wetron/core";
function modelGraphToFlow(graph: ModelGraph): { nodes: FlowNode[]; edges: FlowEdge[] };Converts a ModelGraph to layout-positioned FlowNode[] and FlowEdge[] ready for ReactFlow or SvelteFlow. Dagre is applied top-to-bottom. Call directly only when building a custom renderer; the renderer packages call it automatically.
opCategory
import { opCategory } from "@wetron/core";
type OpCategory =
| "input"
| "output"
| "conv"
| "activation"
| "normalization"
| "pooling"
| "reshape"
| "math"
| "reduction"
| "merge"
| "attention"
| "recurrent"
| "quantization"
| "constant"
| "logic"
| "unknown";
function opCategory(opType: string): OpCategory;Maps an op type string to a semantic category. Used by the renderer to assign node colours.
opInputLabels
import { opInputLabels } from "@wetron/core";
function opInputLabels(opType: string): readonly string[];Returns named input slot labels for known ops (e.g. Conv -> ["X", "W", "B"]). Returns an empty array for unrecognised ops.
filterGraph
import { filterGraph } from "@wetron/core";
function filterGraph(graph: ModelGraph, query: string): ReadonlySet<string>;Returns the set of node names whose opType or name contains query (case-insensitive). Empty query returns an empty set. Used by the renderer’s search box to dim non-matching nodes.