import { readFile, writeFile } from "node:fs/promises"; import { DocxEditor } from "@docx-editor.dev/editor-api"; const input = await readFile("contract.docx"); const runtime = await DocxEditor.createServer(input, { author: "Contract review agent", }); try { await runtime.run(async (context) => { const matches = context.document.body.search("within 7 days", { matchCase: true, }); matches.load("items"); await context.sync(); if (matches.items.length !== 1) { throw new Error("Expected exactly one deadline clause."); } context.document.changeTrackingMode = "TrackMineOnly"; matches.items[0].insertText("within 30 days", "Replace"); await context.sync(); }); await writeFile("contract.redlined.docx", await runtime.save()); } finally { runtime.dispose(); }