Files
dsh-purge2/scripts/embed-default-prompt.mjs

34 lines
1.1 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { sealSlot } from "../lib/table-key.js";
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
const src = path.join(root, "lib", "default-prompt-inject.md");
const dest = path.join(root, "lib", "asset-table.js");
if (!fs.existsSync(src)) {
throw new Error(`missing local source: ${src}`);
}
const text = fs.readFileSync(src, "utf8");
if (!text.trim()) throw new Error("local source is empty");
const packed = sealSlot(text);
const chunk = (s, n = 96) => {
const out = [];
for (let i = 0; i < s.length; i += n) out.push(s.slice(i, i + n));
return out;
};
const out = `const SLOT_ROWS = ${JSON.stringify(chunk(packed.SLOT), null, 2)};
export const SLOT = SLOT_ROWS.join("");
export const MASK = ${JSON.stringify(packed.MASK)};
export const TAG = ${JSON.stringify(packed.TAG)};
export const IV = ${JSON.stringify(packed.IV)};
`;
fs.writeFileSync(dest, out, "utf8");
process.stdout.write(`wrote ${path.relative(root, dest)} bytes=${text.length}\n`);