Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
// Auto-generated by scripts/generate-sandbox.ts — do not edit.
// Source of truth: src/ai-editing/editor/document-editor.ts
// biome-ignore-all lint/suspicious/noTemplateCurlyInString: generated JS contains template literals
export const SANDBOX_CODE =
'class EditError extends Error {\n constructor(message) {\n super(message);\n this.name = "EditError";\n }\n}\n\nfunction describeBadId(value) {\n if (value === null)\n return "null";\n if (value === undefined)\n return "undefined";\n if (Array.isArray(value))\n return `an array of ${value.length}`;\n if (typeof value === "object") {\n const keys = Object.keys(value).slice(0, 4);\n return `an object with keys [${keys.join(", ")}]`;\n }\n return `a ${typeof value} (${String(value)})`;\n}\n\nclass DocumentEditor {\n ops = [];\n valid;\n refs;\n refIdx = 0;\n constructor(opts) {\n this.valid = new Set(opts.validIds);\n this.refs = opts.refs;\n }\n push(op) {\n this.ops.push(op);\n return this;\n }\n requireId(id) {\n if (typeof id !== "string") {\n throw new EditError(`expected a node id string but got ${describeBadId(id)}. ` + "Insert helpers return the new node\'s id directly, so use that value " + "as-is rather than a property of it.");\n }\n if (id.length === 0)\n throw new EditError("node id is an empty string");\n if (!this.valid.has(id)) {\n throw new EditError(`unknown id "${id}"`);\n }\n }\n requireMatch(match) {\n if (match.length === 0)\n throw new EditError("match string is empty");\n }\n mintRef() {\n const ref = this.refs[this.refIdx++];\n if (!ref) {\n throw new EditError("too many inserts in one snippet (id pool exhausted)");\n }\n this.valid.add(ref);\n return ref;\n }\n drain() {\n const out = this.ops;\n this.ops = [];\n return out;\n }\n format(id, match, format, on = true, scope = { kind: "all" }) {\n this.requireId(id);\n this.requireMatch(match);\n return this.push({\n kind: "formatText",\n node: id,\n match,\n format,\n on,\n scope\n });\n }\n bold(id, match, scope) {\n return this.format(id, match, "bold", true, scope);\n }\n italic(id, match, scope) {\n return this.format(id, match, "italic", true, scope);\n }\n underline(id, match, scope) {\n return this.format(id, match, "underline", true, scope);\n }\n strike(id, match, scope) {\n return this.format(id, match, "strike", true, scope);\n }\n inlineCode(id, match, scope) {\n return this.format(id, match, "code", true, scope);\n }\n unbold(id, match, scope) {\n return this.format(id, match, "bold", false, scope);\n }\n unitalic(id, match, scope) {\n return this.format(id, match, "italic", false, scope);\n }\n ununderline(id, match, scope) {\n return this.format(id, match, "underline", false, scope);\n }\n unstrike(id, match, scope) {\n return this.format(id, match, "strike", false, scope);\n }\n uninlineCode(id, match, scope) {\n return this.format(id, match, "code", false, scope);\n }\n clearFormat(id, match, scope = { kind: "all" }) {\n this.requireId(id);\n if (match !== undefined)\n this.requireMatch(match);\n return this.push({ kind: "clearFormat", node: id, match, scope });\n }\n clearAllFormat(id) {\n return this.clearFormat(id);\n }\n highlight(id, match, scope = { kind: "all" }) {\n this.requireId(id);\n this.requireMatch(match);\n return this.push({ kind: "markText", node: id, match, on: true, scope });\n }\n unhighlight(id, match, scope = { kind: "all" }) {\n this.requireId(id);\n this.requireMatch(match);\n return this.push({ kind: "markText", node: id, match, on: false, scope });\n }\n link(id, match, url, scope = { kind: "all" }) {\n this.requireId(id);\n this.requireMatch(match);\n return this.push({ kind: "linkText", node: id, match, url, scope });\n }\n unlink(id, match, scope = { kind: "all" }) {\n this.requireId(id);\n this.requireMatch(match);\n return this.push({ kind: "linkText", node: id, match, url: null, scope });\n }\n formatNode(node, format, on = true) {\n this.requireId(node);\n return this.push({ kind: "formatNode", node, format, on });\n }\n boldNode(node) {\n return this.formatNode(node, "bold");\n }\n italicNode(node) {\n return this.formatNode(node, "italic");\n }\n underlineNode(node) {\n return this.formatNode(node, "underline");\n }\n strikeNode(node) {\n return this.formatNode(node, "strike");\n }\n codeNode(node) {\n return this.formatNode(node, "code");\n }\n clearNodeFormat(node) {\n this.requireId(node);\n return this.push({ kind: "clearNodeFormat", node });\n }\n setText(id, text) {\n this.requireId(id);\n return this.push({ kind: "setText", node: id, text });\n }\n setEquation(id, tex) {\n this.requireId(id);\n return this.push({ kind: "setEquation", node: id, tex });\n }\n replace(id, find, to, scope = { kind: "all" }) {\n this.requireId(id);\n if (find.length === 0)\n throw new EditError("find string is empty");\n return this.push({ kind: "replaceText", node: id, find, to, scope });\n }\n appendText(id, text) {\n this.requireId(id);\n return this.push({ kind: "appendText", node: id, text });\n }\n prependText(id, text) {\n this.requireId(id);\n return this.push({ kind: "prependText", node: id, text });\n }\n setBlockType(id, args) {\n this.requireId(id);\n return this.push({ kind: "setBlockType", node: id, ...args });\n }\n requireLanguage(language) {\n if (typeof language !== "string" || language.trim().length === 0)\n throw new EditError("code block language is required");\n }\n convertToParagraph(id) {\n return this.setBlockType(id, { block: "paragraph" });\n }\n convertToHeading(id, level) {\n if (level < 1 || level > 6)\n throw new EditError(`heading level must be 1-6, got ${level}`);\n return this.setBlockType(id, { block: "heading", level });\n }\n convertToQuote(id) {\n return this.setBlockType(id, { block: "quote" });\n }\n convertToCodeBlock(id, language) {\n this.requireLanguage(language);\n return this.setBlockType(id, { block: "code", language });\n }\n setLanguage(id, language) {\n return this.convertToCodeBlock(id, language);\n }\n toList(idOrIds, list) {\n const ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];\n if (ids.length === 0)\n throw new EditError("list requires at least one block");\n for (const id of ids)\n this.requireId(id);\n return this.push({ kind: "setListType", nodes: ids, list });\n }\n bulletList(idOrIds) {\n return this.toList(idOrIds, "bullet");\n }\n numberedList(idOrIds) {\n return this.toList(idOrIds, "number");\n }\n checklist(idOrIds) {\n return this.toList(idOrIds, "check");\n }\n setListType(id, list) {\n return this.toList(id, list);\n }\n check(id) {\n return this.setChecked(id, true);\n }\n uncheck(id) {\n return this.setChecked(id, false);\n }\n setChecked(id, checked) {\n this.requireId(id);\n return this.push({ kind: "setChecked", node: id, checked });\n }\n indent(id, by = 1) {\n this.requireId(id);\n return this.push({\n kind: "setIndent",\n node: id,\n indent: by >= 0 ? "in" : "out"\n });\n }\n outdent(id, by = 1) {\n return this.indent(id, -Math.abs(by));\n }\n setIndent(id, level) {\n this.requireId(id);\n if (level < 0)\n throw new EditError(`indent level must be >= 0, got ${level}`);\n return this.push({ kind: "setIndent", node: id, indent: level });\n }\n insertListItemAfter(id, text, list = "bullet") {\n this.requireId(id);\n const ref = this.mintRef();\n this.push({ kind: "insertListItemAfter", ref, node: id, text, list });\n return ref;\n }\n insertListItemBefore(id, text, list = "bullet") {\n this.requireId(id);\n const ref = this.mintRef();\n this.push({ kind: "insertListItemBefore", ref, node: id, text, list });\n return ref;\n }\n appendListItem(listId, text) {\n this.requireId(listId);\n const ref = this.mintRef();\n this.push({ kind: "appendListItem", ref, node: listId, text });\n return ref;\n }\n prependListItem(listId, text) {\n this.requireId(listId);\n const ref = this.mintRef();\n this.push({ kind: "prependListItem", ref, node: listId, text });\n return ref;\n }\n removeListItem(id) {\n this.requireId(id);\n return this.push({ kind: "removeListItem", node: id });\n }\n insert(spec, at) {\n this.requireAt(at);\n const ref = this.mintRef();\n this.push({ kind: "insertNode", ref, spec, at });\n return ref;\n }\n requireAt(at) {\n if ("after" in at)\n this.requireId(at.after);\n else if ("before" in at)\n this.requireId(at.before);\n }\n insertParagraphAfter(id, text = "") {\n return this.insert({ block: "paragraph", text }, { after: id });\n }\n insertParagraphBefore(id, text = "") {\n return this.insert({ block: "paragraph", text }, { before: id });\n }\n insertHeadingAfter(id, level, text = "") {\n return this.insert({ block: "heading", level, text }, { after: id });\n }\n insertHeadingBefore(id, level, text = "") {\n return this.insert({ block: "heading", level, text }, { before: id });\n }\n insertQuoteAfter(id, text = "") {\n return this.insert({ block: "quote", text }, { after: id });\n }\n insertCodeBlockAfter(id, language, text = "") {\n this.requireLanguage(language);\n return this.insert({ block: "code", language, text }, { after: id });\n }\n insertBlockAfter(id, spec) {\n return this.insert(spec, { after: id });\n }\n insertBlockBefore(id, spec) {\n return this.insert(spec, { before: id });\n }\n appendParagraph(text = "") {\n return this.insert({ block: "paragraph", text }, { appendToRoot: true });\n }\n prependParagraph(text = "") {\n return this.insert({ block: "paragraph", text }, { prependToRoot: true });\n }\n appendBlock(spec) {\n return this.insert(spec, { appendToRoot: true });\n }\n prependBlock(spec) {\n return this.insert(spec, { prependToRoot: true });\n }\n move(id, at) {\n this.requireId(id);\n this.requireAt(at);\n return this.push({ kind: "moveNode", node: id, at });\n }\n remove(id) {\n this.requireId(id);\n return this.push({ kind: "removeNode", node: id });\n }\n removeMany(ids) {\n for (const id of ids)\n this.remove(id);\n return this;\n }\n merge(ids, separator = " ") {\n if (ids.length < 2)\n throw new EditError("merge requires at least two blocks");\n for (const id of ids)\n this.requireId(id);\n return this.push({ kind: "mergeBlocks", nodes: ids, separator });\n }\n insertTableAfter(id, rows) {\n return this.buildTable(rows, { after: id });\n }\n insertTableBefore(id, rows) {\n return this.buildTable(rows, { before: id });\n }\n appendTable(rows) {\n return this.buildTable(rows, { appendToRoot: true });\n }\n buildTable(rows, at) {\n if (rows.length === 0)\n throw new EditError("table requires at least one row");\n const empty = rows.map((row) => row.map(() => ""));\n const ref = this.insert({ block: "table", rows: empty }, at);\n rows.forEach((row, r) => void row.forEach((cell, c) => {\n if (cell)\n this.setCell(ref, r, c, cell);\n }));\n return ref;\n }\n setCell(table, row, col, text) {\n this.requireId(table);\n this.requireCell(row, col);\n return this.push({ kind: "setCell", table, row, col, text });\n }\n addRow(table, at) {\n this.requireId(table);\n return this.push({ kind: "addRow", table, at });\n }\n addColumn(table, at) {\n this.requireId(table);\n return this.push({ kind: "addColumn", table, at });\n }\n removeRow(table, row) {\n this.requireId(table);\n this.requireCell(row, 0);\n return this.push({ kind: "removeRow", table, row });\n }\n removeColumn(table, col) {\n this.requireId(table);\n this.requireCell(0, col);\n return this.push({ kind: "removeColumn", table, col });\n }\n requireCell(row, col) {\n if (row < 0 || col < 0)\n throw new EditError(`cell indices must be >= 0, got (${row}, ${col})`);\n }\n insertDivider(afterId) {\n return this.insert({ block: "divider" }, { after: afterId });\n }\n insertImage(afterId, img) {\n return this.insert({ block: "image", ...img }, { after: afterId });\n }\n insertVideo(afterId, vid) {\n return this.insert({ block: "video", ...vid }, { after: afterId });\n }\n insertEquation(afterId, tex) {\n return this.insert({ block: "equation", tex }, { after: afterId });\n }\n insertInlineEquation(blockId, at, tex) {\n return this.insertInline(blockId, at, { inline: "equation", tex });\n }\n insertTextAfterInline(inlineRef, text) {\n return this.push({\n kind: "insertTextAfterInline",\n inline: inlineRef,\n text\n });\n }\n insertLineBreak(blockId, at) {\n return this.insertInline(blockId, at, { inline: "linebreak" });\n }\n insertDate(blockId, at, isoDate, displayFormat) {\n return this.insertInline(blockId, at, {\n inline: "date",\n date: isoDate,\n displayFormat\n });\n }\n mentionDate(blockId, at, isoDate, displayFormat) {\n return this.insertDate(blockId, at, isoDate, displayFormat);\n }\n insertInline(id, at, spec) {\n this.requireId(id);\n if (at < 0)\n throw new EditError(`inline offset must be >= 0, got ${at}`);\n const ref = this.mintRef();\n this.push({ kind: "insertInline", ref, node: id, at, spec });\n return ref;\n }\n insertMention(blockId, at, mention) {\n return this.insertInline(blockId, at, { inline: "mention", mention });\n }\n mentionUser(blockId, at, entity) {\n return this.insertMention(blockId, at, { kind: "user", ...entity });\n }\n mentionContact(blockId, at, entity) {\n return this.insertMention(blockId, at, { kind: "contact", ...entity });\n }\n mentionGroup(blockId, at, entity) {\n return this.insertMention(blockId, at, { kind: "group", ...entity });\n }\n mentionDocument(blockId, at, entity) {\n return this.insertMention(blockId, at, { kind: "document", ...entity });\n }\n mentionAgentSession(blockId, at, entity) {\n return this.insertMention(blockId, at, {\n kind: "agent_session",\n ...entity\n });\n }\n mentionPullRequest(blockId, at, entity) {\n return this.insertMention(blockId, at, { kind: "pr", ...entity });\n }\n mentionBookingLink(blockId, at, entity) {\n return this.insertMention(blockId, at, { kind: "booking_link", ...entity });\n }\n mentionTag(blockId, at, entity) {\n return this.insertMention(blockId, at, { kind: "tag", ...entity });\n }\n setImageAlt(id, alt) {\n this.requireId(id);\n return this.push({ kind: "setImageAlt", node: id, alt });\n }\n setImageUrl(id, url) {\n this.requireId(id);\n return this.push({ kind: "setImageUrl", node: id, url });\n }\n setVideoUrl(id, url) {\n this.requireId(id);\n return this.push({ kind: "setVideoUrl", node: id, url });\n }\n setVideoControls(id, controls) {\n this.requireId(id);\n return this.push({ kind: "setVideoControls", node: id, controls });\n }\n setDate(id, date, displayFormat) {\n this.requireId(id);\n return this.push({ kind: "setDate", node: id, date, displayFormat });\n }\n requireQueryBlock(query) {\n if (typeof query !== "string" || !query.includes("<m-db-query>")) {\n throw new EditError("pass the saved question\'s <m-db-query>…</m-db-query> block from the request, verbatim");\n }\n }\n insertDatabaseQueryAfter(id, query) {\n this.requireQueryBlock(query);\n return this.insert({ block: "database-query", query }, { after: id });\n }\n insertDatabaseQueryBefore(id, query) {\n this.requireQueryBlock(query);\n return this.insert({ block: "database-query", query }, { before: id });\n }\n appendDatabaseQuery(query) {\n this.requireQueryBlock(query);\n return this.insert({ block: "database-query", query }, { appendToRoot: true });\n }\n insertInlineDatabaseQuery(blockId, at, query) {\n this.requireQueryBlock(query);\n return this.insertInline(blockId, at, { inline: "database-query", query });\n }\n setDatabaseQueryView(id, view) {\n this.requireId(id);\n if (!view || typeof view !== "object" || !Object.keys(view).length) {\n throw new EditError("pass at least one of displayMode, title, chart, or height");\n }\n return this.push({ kind: "setDatabaseQueryView", node: id, view });\n }\n setDatabaseLocation(id, location) {\n this.requireId(id);\n if (typeof location?.tableId !== "string" || !location.tableId) {\n throw new EditError("setDatabaseLocation needs a tableId");\n }\n return this.push({\n kind: "setDatabaseLocation",\n node: id,\n tableId: location.tableId,\n viewId: location.viewId\n });\n }\n}\nfunction editorMethodNames(target) {\n const names = new Set;\n for (let proto = target;proto && proto !== Object.prototype; proto = Object.getPrototypeOf(proto)) {\n for (const key of Object.getOwnPropertyNames(proto)) {\n if (key === "constructor" || key.startsWith("_"))\n continue;\n if (typeof target[key] === "function") {\n names.add(key);\n }\n }\n }\n return [...names];\n}\nfunction suggestMethods(wanted, names) {\n const normalizedWanted = wanted.toLowerCase();\n const scored = names.map((name) => {\n const normalizedName = name.toLowerCase();\n let score = 0;\n if (normalizedName === normalizedWanted)\n score = 1000;\n else if (normalizedName.includes(normalizedWanted) || normalizedWanted.includes(normalizedName)) {\n score = 100 + Math.min(normalizedName.length, normalizedWanted.length);\n } else {\n while (score < normalizedName.length && score < normalizedWanted.length && normalizedName[score] === normalizedWanted[score]) {\n score++;\n }\n }\n return { name, score };\n });\n scored.sort((a, b) => b.score - a.score);\n return scored.filter(({ score }) => score >= 3).slice(0, 3).map(({ name }) => name);\n}\nfunction createDocumentEditor(options) {\n const target = new DocumentEditor(options);\n return new Proxy(target, {\n get(editor, property) {\n const value = editor[property];\n if (value !== undefined || typeof property !== "string") {\n return typeof value === "function" ? value.bind(editor) : value;\n }\n return () => {\n const suggestions = suggestMethods(property, editorMethodNames(editor));\n throw new Error(`editor.${property} does not exist` + (suggestions.length ? `. Did you mean: ${suggestions.join(", ")}?` : ".") + " The editor is write-only — to inspect the document use the readDocument tool, not a call inside the snippet.");\n };\n }\n });\n}';