import { projectRef } from "@/lib/projects"; import { refuseCaller } from "@/lib/report/caller"; import { sayCommand, voicesCommand } from "@/lib/report/postSay.mjs"; import { postsCommand } from "@/lib/report/postsCli.mjs"; import { readManifest } from "@/lib/projects/report.mjs"; import { addStep } from "@/lib/queue/store.mjs"; import { kickQueue, queueDir } from "@/lib/queue/runner"; export const dynamic = "force-dynamic"; // A POST PROJECT's PRONUNCIATION LEXICON and VOICE MAP in the app (lane/ui-simplify, 5 Nov; terminal-only // before: `umtool posts say` / `umtool posts voices`). The CLI's own commands (lib/report/postSay.mjs), run // here with --json -- the files' one writer each (narration/lexicon.json, narration/voices.json). // // GET ?project -> { lexicon: say ls, voices: voices ls, stale: say stale, redact: posts redact ls, // slurs: posts slurs ls } (the redaction and the slur filter: their own commands) // POST { project, op: "say-add", word, say, case?, item?, note? } posts say
add remove try " set remove --cut add " remove --all
// --draft-scripts | --all --take -- long, so a step of
// the queue, never a request held open; the argv is built
// here, never taken from the page
type Flags = Map …` in this process (postsCli.mjs postsCommand), --json.
const posts = async (args: string[]) => {
const said: string[] = [];
const r: { exit: number; json: Record --cut k=v): one knob a press; the CLI's own words refuse a wrong one.
else if (b.op === "mix-cut") r = await posts(["narrate", project.id, "--cut", `${s("key")}=${s("value")}`]);
else if (b.op === "redact-add") r = await posts(["redact", project.id, "add", s("term"), ...(b.substring === true ? ["--substring"] : []), ...(s("note") ? ["--note", s("note")] : [])]);
else if (b.op === "redact-remove") r = await posts(["redact", project.id, "remove", String(Number(b.n))]);
else if (b.op === "slurs") {
const verb = s("verb");
if (!["on", "off", "level", "visual", "voice", "add", "except", "remove", "edges"].includes(verb)) return Response.json({ error: "slurs: on, off, level, visual, voice, add, except, remove or edges" }, { status: 400 });
r = await posts(["slurs", project.id, verb, ...(verb === "on" || verb === "off" ? [] : [s("value")]), ...(verb === "edges" && b.off === true ? ["--off"] : [])]);
} else if (b.op === "queue-narrate") {
// Also the cut-wide post passes that are terminal-only otherwise: fill each item's context from its capture
// (posts context), gather each conversation together (timeline threads --write).
const what = b.what === "takes" ? "takes" : b.what === "context" ? "context" : b.what === "threads" ? "threads" : "scripts";
const argv =
what === "context" ? ["posts", "context", project.id] : what === "threads" ? ["timeline", project.id, "threads", "--write"] : ["posts", "narrate", project.id, "--all", what === "takes" ? "--take" : "--draft-scripts"];
const words = { scripts: "draft every post script", takes: "read every missing post take", context: "fill every post's context from its capture", threads: "gather each conversation" }[what];
try {
const step = (await addStep(queueDir(), {
argv,
label: `${words} of ${project.id}`,
target: { project: project.id, take: null },
by: "the umtool app (Reads and voices)",
})) as { qid: string };
kickQueue();
return Response.json({ exit: 0, json: { queued: step.qid } }, { headers: { "cache-control": "no-store" } });
} catch (e) {
return Response.json({ exit: 1, json: null, error: e instanceof Error ? e.message : String(e) }, { status: 400 });
}
} else return Response.json({ error: "op must be say-add, say-remove, say-try, voices-set, voices-remove or queue-narrate" }, { status: 400 });
return Response.json(r, { status: r.exit === 0 ? 200 : 400, headers: { "cache-control": "no-store" } });
}