import { AgentOffice } from "agent-office-sdk";
import { v4 as uuidv4 } from "uuid";
import fs from "fs";
const client = new AgentOffice({
apiKey: process.env.AGENT_OFFICE_API_KEY || "",
});
const fileBuffer = fs.readFileSync("document.docx");
const file = new File([fileBuffer], "document.docx", {
type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
});
// Upload with tracked changes enabled
const { docId, markdown } = await client.documents.create({
file: file,
returnMarkdown: true,
trackedChanges: true,
authorName: "John Doe",
});
// Edit the document
const editResult = await client.edit({
docId: docId,
editUid: uuidv4(),
editInstructions: "Change the title to 'My New Title'",
saveChunksForReview: false,
});
// Download the edited document
const { downloadUrl } = await client.documents.download({
docId: docId,
});