Title here
Summary here
packages/<format>/
src/
index.ts # re-exports the parse function
parse.ts # parser implementation
test/
parse.test.ts
package.json
tsconfig.json
tsup.config.ts// packages/<format>/src/parse.ts
import type { ModelGraph, GraphNode, GraphValue, ParseWarning } from '@wetron/common/ir';
import { ParseError } from '@wetron/common/ir';
export function parse<Format>(bytes: Uint8Array): ModelGraph {
// ...
throw new ParseError('<format>', 'human-readable reason');
}Rules:
@wetron/common/ir - never redefine them.@wetron/common/dtypes - never inline shims.DataView, TextDecoder, DecompressionStream.protobufjs for protobuf formats, flatbuffers for FlatBuffers formats.ModelGraph.fileSizeBytes to bytes.byteLength. For inline initializer bytes, set ModelGraph.weights to { kind: "available", source }, where source has totalBytes and get(name). For required sidecar files, use { kind: "external", format }. Return raw little-endian byte slices; decoding lives in @wetron/core/weight-decoder.warnings on the returned ModelGraph rather than throwing.Add magic byte detection to packages/core/src/detect.ts:
// Example: detect "ET12" at offset 4
if (bytes[4] === 0x45 && bytes[5] === 0x54 && bytes[6] === 0x31 && bytes[7] === 0x32) {
return 'myformat';
}detectFormat must always return a Format string - never throw.
Add a dynamic import branch to packages/core/src/index.ts:
case "myformat": {
const { parseMyFormat } = await import("@wetron/myformat");
return parseMyFormat(bytes);
}// packages/<format>/test/parse.test.ts
import { test, expect } from 'vitest';
import { readFileSync } from 'fs';
import { parseMyFormat } from '../src/index.ts';
test('parses test model', () => {
const bytes = new Uint8Array(readFileSync('../../test-models/model.ext'));
const graph = parseMyFormat(bytes);
expect(graph.nodes.length).toBe(42); // must match Netron's node count
expect(graph.inputs.length).toBeGreaterThan(0);
expect(graph.nodes.every((n) => n.opType)).toBe(true);
});Add a real model file to test-models/. Node count must match what Netron shows for the same file - use netron-main/ as a reference for schema field layouts.
{
"name": "@wetron/<format>",
"version": "0.0.1",
"type": "module",
"exports": {
".": {
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"dependencies": {
"@wetron/core": "workspace:*"
}
}WeightSource and let consumers call decodeWeight / decodeFirstN from @wetron/core on demand.parseMyFormat(bytes) is the entire public API.@wetron/common/dtypes.DataView.prototype or BigInt.prototype.detectFormat - return "unknown".