npu-forge / bin /register.js
LJTSG's picture
NPU-Forge v0.1: permanent custom-model registry for FastFlowLM on Ryzen AI NPUs
7d5a851 verified
Raw
History Blame Contribute Delete
2 kB
#!/usr/bin/env node
// register.js — merge npu-forge's own registry into FLM's model_list.json.
// Forge entries live in npu-forge\registry.json (user-space, permanent);
// FLM's list lives in Program Files and gets RESET by flm updates — so this
// merge is idempotent and re-runnable any time a custom model "disappears."
// Needs elevation (run via register-admin.bat). Always backs up first.
'use strict';
const fs = require('fs');
const path = require('path');
const FORGE = path.join(__dirname, '..');
const FLM_LIST = 'C:\\Program Files\\flm\\model_list.json';
const REGISTRY = path.join(FORGE, 'registry.json');
function main() {
if (!fs.existsSync(REGISTRY)) { console.log('No registry.json — nothing to register.'); return; }
const reg = JSON.parse(fs.readFileSync(REGISTRY, 'utf8').replace(/^/, ''));
const ml = JSON.parse(fs.readFileSync(FLM_LIST, 'utf8').replace(/^/, ''));
// timestamped backup beside the forge registry (user-space, survives anything)
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
fs.copyFileSync(FLM_LIST, path.join(FORGE, `model_list.backup-${stamp}.json`));
let added = 0, kept = 0;
for (const [key, sizes] of Object.entries(reg.models || {})) {
for (const [size, entry] of Object.entries(sizes)) {
ml.models[key] = ml.models[key] || {};
if (ml.models[key][size] && JSON.stringify(ml.models[key][size]) === JSON.stringify(entry)) { kept++; continue; }
ml.models[key][size] = entry;
added++;
console.log(`registered: ${key}:${size} -> ${entry.name}`);
}
}
try {
fs.writeFileSync(FLM_LIST, JSON.stringify(ml, null, 2));
} catch (e) {
console.error('\n[!] Could not write ' + FLM_LIST);
console.error(' This needs administrator rights — double-click register-admin.bat instead.');
process.exit(1);
}
console.log(`\nDone: ${added} entries written, ${kept} already current.`);
console.log('Verify with: flm list (your models end in -forge)');
}
main();