@superdoc/mcp 1.9.0-next.7 → 1.9.0-next.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +231 -16
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31620,7 +31620,7 @@ var init_host = __esm(() => {
31620
31620
  });
31621
31621
 
31622
31622
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31623
- var SDK_VERSION = "2.22.0-next.7";
31623
+ var SDK_VERSION = "2.22.0-next.9";
31624
31624
 
31625
31625
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31626
31626
  import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
@@ -253967,7 +253967,7 @@ function parseSimpleRunTokens(xml) {
253967
253967
  const tMatch = /^\s*<([\w.-]+):t\b([^>]*)>([\s\S]*?)<\/\1:t>\s*$/.exec(afterRPr);
253968
253968
  if (!tMatch)
253969
253969
  return null;
253970
- const text = decodeCompareXmlText(tMatch[3] ?? "");
253970
+ const text = decodeXmlTextPreservingInvalidNumericEntities(tMatch[3] ?? "");
253971
253971
  tokens.push({
253972
253972
  rawXml: match[0],
253973
253973
  openTag: `<${prefix}:r${runAttrs}>${rPrXml}`,
@@ -254027,7 +254027,9 @@ function equalWordTokensPreserveFormatting(oldTokens, targetTokens) {
254027
254027
  let targetIndex = 0;
254028
254028
  for (const op of ops) {
254029
254029
  if (op === "equal") {
254030
- if (oldWords[oldIndex]?.openTag !== targetWords[targetIndex]?.openTag)
254030
+ const oldFormat = oldWords[oldIndex].openTag;
254031
+ const targetFormat = targetWords[targetIndex].openTag;
254032
+ if (oldFormat !== targetFormat)
254031
254033
  return false;
254032
254034
  oldIndex += 1;
254033
254035
  targetIndex += 1;
@@ -254041,24 +254043,165 @@ function equalWordTokensPreserveFormatting(oldTokens, targetTokens) {
254041
254043
  }
254042
254044
  return true;
254043
254045
  }
254044
- function renderWordLevelTrackedRunSegment(oldSegment, targetSegment, getStamp, prefix) {
254045
- const oldTokens = parseSimpleRunTokens(oldSegment);
254046
- const targetTokens = parseSimpleRunTokens(targetSegment);
254047
- if (!oldTokens || !targetTokens)
254048
- return null;
254046
+ function unchangedCompareRunRangesPreserveFormatting(oldTokens, targetTokens, ops, prefix) {
254047
+ const formats = (tokens) => tokens.map((token) => ({
254048
+ end: token.startOffset + token.text.length,
254049
+ signature: compareRunCarrierSignature(`${token.openTag}</${token.runPrefix}:r>`, prefix)
254050
+ }));
254051
+ const oldFormats = formats(oldTokens), targetFormats = formats(targetTokens);
254052
+ let oldIndex = 0, targetIndex = 0;
254053
+ const equalRange = (oldFrom, targetFrom, length) => {
254054
+ while (length > 0) {
254055
+ while (oldFormats[oldIndex].end <= oldFrom)
254056
+ oldIndex += 1;
254057
+ while (targetFormats[targetIndex].end <= targetFrom)
254058
+ targetIndex += 1;
254059
+ const old = oldFormats[oldIndex], target = targetFormats[targetIndex];
254060
+ if (old.signature !== target.signature)
254061
+ return false;
254062
+ const matched = Math.min(length, old.end - oldFrom, target.end - targetFrom);
254063
+ oldFrom += matched;
254064
+ targetFrom += matched;
254065
+ length -= matched;
254066
+ }
254067
+ return true;
254068
+ };
254069
+ let oldCursor = 0, targetCursor = 0;
254070
+ for (const op of ops) {
254071
+ const start = op.type === "insert" ? op.insertAt : op.oldFrom;
254072
+ const retained = start - oldCursor;
254073
+ if (!equalRange(oldCursor, targetCursor, retained))
254074
+ return false;
254075
+ oldCursor = op.type === "insert" ? start : op.oldTo;
254076
+ targetCursor += retained + (op.type === "delete" ? 0 : op.newText.length);
254077
+ }
254078
+ const oldLength = oldFormats.at(-1)?.end ?? 0;
254079
+ return equalRange(oldCursor, targetCursor, oldLength - oldCursor);
254080
+ }
254081
+ function prepareCompareWordSegment(oldTokens, targetTokens, checkDensity, prefix) {
254049
254082
  const oldText = oldTokens.map((token) => token.text).join("");
254050
254083
  const targetText = targetTokens.map((token) => token.text).join("");
254051
254084
  if (oldText === targetText)
254052
254085
  return null;
254053
- if (necessarilyExceedsWordDiffRatio(oldText, targetText, WORD_DIFF_FALLBACK_RATIO))
254086
+ if (oldText.includes("\r") || targetText.includes("\r"))
254087
+ return null;
254088
+ if (checkDensity && necessarilyExceedsWordDiffRatio(oldText, targetText, WORD_DIFF_FALLBACK_RATIO))
254054
254089
  return null;
254055
- if (!equalWordTokensPreserveFormatting(oldTokens, targetTokens))
254090
+ if (!prefix && !equalWordTokensPreserveFormatting(oldTokens, targetTokens))
254056
254091
  return null;
254057
254092
  const ops = getWordChanges(oldText, targetText);
254058
- if (ops.length === 0)
254093
+ if (ops.length === 0 || checkDensity && shouldFallBackFromWordDiff(ops, oldText.length, targetText.length))
254094
+ return null;
254095
+ if (prefix && !unchangedCompareRunRangesPreserveFormatting(oldTokens, targetTokens, ops, prefix))
254096
+ return null;
254097
+ return { oldTokens, targetTokens, oldText, ops };
254098
+ }
254099
+ function compareRunCarrierSignature(xml, prefix) {
254100
+ const canonical = canonicalizeXmlForSignature(`<root xmlns:${prefix}="${NS_W}">${xml}</root>`);
254101
+ return canonical.replace(/<w:r\b[^>]*>/g, (run) => run.replace(/\s+w:rsid\w*="[^"]*"/g, ""));
254102
+ }
254103
+ function splitCompareManualBreakSegments(xml, prefix) {
254104
+ const parsed = collectXmlElementRanges(xml, { fragment: true, additionalNamespaces: { [prefix]: NS_W } });
254105
+ if (parsed.errors.length > 0)
254106
+ return null;
254107
+ const ranges = parsed.ranges.sort((left, right) => left.start - right.start);
254108
+ const spans = [""];
254109
+ const breaks = [];
254110
+ let cursor = 0;
254111
+ for (let index = 0;index < ranges.length; ) {
254112
+ const run = ranges[index++];
254113
+ if (xml.slice(cursor, run.start).trim() || run.tag.namespaceUri !== NS_W || run.tag.localName !== "r" || run.tag.prefix !== prefix || run.tag.isSelfClosing)
254114
+ return null;
254115
+ const children = [];
254116
+ let childCursor = run.openEnd;
254117
+ while (index < ranges.length && ranges[index].start < run.closeStart) {
254118
+ const child = ranges[index++];
254119
+ if (child.start < childCursor)
254120
+ continue;
254121
+ if (xml.slice(childCursor, child.start).trim() || child.end > run.closeStart)
254122
+ return null;
254123
+ children.push(child);
254124
+ childCursor = child.end;
254125
+ }
254126
+ if (xml.slice(childCursor, run.closeStart).trim())
254127
+ return null;
254128
+ const rPr = children[0]?.tag.namespaceUri === NS_W && children[0].tag.localName === "rPr" ? children.shift() : undefined;
254129
+ const openTag = xml.slice(run.start, run.openEnd) + (rPr ? xml.slice(rPr.start, rPr.end) : "");
254130
+ if (children.length === 0)
254131
+ return null;
254132
+ for (const child of children) {
254133
+ if (child.tag.namespaceUri !== NS_W || child.tag.prefix !== prefix)
254134
+ return null;
254135
+ const childXml = xml.slice(child.start, child.end);
254136
+ const carrier = children.length === 1 ? xml.slice(run.start, run.end) : `${openTag}${childXml}</${prefix}:r>`;
254137
+ if (child.tag.localName === "t") {
254138
+ if (child.tag.isSelfClosing || xml.slice(child.openEnd, child.closeStart).includes("<") || child.tag.attributes.some((attr3) => !(attr3.namespaceUri === "http://www.w3.org/XML/1998/namespace" && attr3.localName === "space")))
254139
+ return null;
254140
+ spans[spans.length - 1] += carrier;
254141
+ } else if (child.tag.localName === "br") {
254142
+ if (xml.slice(child.openEnd, child.closeStart).trim() || child.tag.attributes.some((attr3) => attr3.namespaceUri !== NS_W || (attr3.localName === "type" ? attr3.value !== "textWrapping" : attr3.localName !== "clear" || !["none", "left", "right", "all"].includes(attr3.value))))
254143
+ return null;
254144
+ breaks.push(carrier);
254145
+ spans.push("");
254146
+ } else
254147
+ return null;
254148
+ }
254149
+ cursor = run.end;
254150
+ }
254151
+ if (xml.slice(cursor).trim() || breaks.length === 0)
254059
254152
  return null;
254060
- if (shouldFallBackFromWordDiff(ops, oldText.length, targetText.length))
254153
+ return { spans, breaks };
254154
+ }
254155
+ function renderWordLevelTrackedRunSegment(oldSegment, targetSegment, getStamp, prefix) {
254156
+ const simpleOld = parseSimpleRunTokens(oldSegment);
254157
+ const simpleTarget = parseSimpleRunTokens(targetSegment);
254158
+ if (simpleOld && simpleTarget && !/<[\w.-]+:br\b/.test(oldSegment + targetSegment)) {
254159
+ const prepared2 = prepareCompareWordSegment(simpleOld, simpleTarget, true);
254160
+ return prepared2 ? { xml: renderPreparedCompareWordSegment(prepared2, getStamp, prefix) } : null;
254161
+ }
254162
+ const old = splitCompareManualBreakSegments(oldSegment, prefix);
254163
+ const target = splitCompareManualBreakSegments(targetSegment, prefix);
254164
+ if (!old || !target || old.breaks.length !== target.breaks.length || old.breaks.some((br, index) => compareRunCarrierSignature(br, prefix) !== compareRunCarrierSignature(target.breaks[index], prefix)))
254061
254165
  return null;
254166
+ const spans = [];
254167
+ for (let index = 0;index < old.spans.length; index += 1) {
254168
+ const oldSpan = old.spans[index];
254169
+ const targetSpan = target.spans[index];
254170
+ const oldTokens = parseSimpleRunTokens(oldSpan);
254171
+ const targetTokens = parseSimpleRunTokens(targetSpan);
254172
+ if (!oldTokens || !targetTokens)
254173
+ return null;
254174
+ if (oldTokens.some((token) => token.text.length === 0) || targetTokens.some((token) => token.text.length === 0))
254175
+ return null;
254176
+ const oldText2 = oldTokens.map((token) => token.text).join("");
254177
+ const targetText2 = targetTokens.map((token) => token.text).join("");
254178
+ spans.push({ oldSpan, oldTokens, targetTokens, oldText: oldText2, targetText: targetText2 });
254179
+ }
254180
+ const oldText = spans.map((span) => span.oldText).join(`
254181
+ `);
254182
+ const targetText = spans.map((span) => span.targetText).join(`
254183
+ `);
254184
+ if (necessarilyExceedsWordDiffRatio(oldText, targetText, WORD_DIFF_FALLBACK_RATIO))
254185
+ return null;
254186
+ const prepared = [];
254187
+ for (const { oldSpan, oldTokens, targetTokens, oldText: oldText2, targetText: targetText2 } of spans) {
254188
+ if (oldText2 === targetText2) {
254189
+ if (!unchangedCompareRunRangesPreserveFormatting(oldTokens, targetTokens, [], prefix))
254190
+ return null;
254191
+ prepared.push(oldSpan);
254192
+ } else {
254193
+ const span = prepareCompareWordSegment(oldTokens, targetTokens, false, prefix);
254194
+ if (!span)
254195
+ return null;
254196
+ prepared.push(span);
254197
+ }
254198
+ }
254199
+ const ops = prepared.flatMap((span) => typeof span === "string" ? [] : span.ops);
254200
+ if (ops.length === 0 || shouldFallBackFromWordDiff(ops, oldText.length, targetText.length))
254201
+ return null;
254202
+ return { xml: prepared.map((span, index) => (typeof span === "string" ? span : renderPreparedCompareWordSegment(span, getStamp, prefix)) + (old.breaks[index] ?? "")).join("") };
254203
+ }
254204
+ function renderPreparedCompareWordSegment({ oldTokens, targetTokens, oldText, ops }, getStamp, prefix) {
254062
254205
  let xml = "";
254063
254206
  let oldCursor = 0;
254064
254207
  let newCursor = 0;
@@ -254087,7 +254230,7 @@ function renderWordLevelTrackedRunSegment(oldSegment, targetSegment, getStamp, p
254087
254230
  if (oldCursor < oldText.length) {
254088
254231
  xml += renderCompareRunRange(oldTokens, oldCursor, oldText.length, "passthrough");
254089
254232
  }
254090
- return { xml };
254233
+ return xml;
254091
254234
  }
254092
254235
  function runCompareBodyFormatEditCommit(input, storyId, step2, changeMode, options, pushHistory, referenceSteps) {
254093
254236
  const { state, txId } = input;
@@ -328116,6 +328259,7 @@ function convertHtmlToFragment(html, options = {}) {
328116
328259
  }
328117
328260
  const context = {
328118
328261
  source: html,
328262
+ tableSpanPolicy: options.tableSpanPolicy ?? "html",
328119
328263
  limits,
328120
328264
  sheet,
328121
328265
  diagnostics,
@@ -328806,6 +328950,8 @@ function usesDefaultWordOrderedLevelShape(descriptor) {
328806
328950
  function convertTable(table, context, inherited, path6) {
328807
328951
  let structurallyRejected = false;
328808
328952
  const rows = collectTableRows(table, path6);
328953
+ if (context.tableSpanPolicy === "strict" && !validateTableSpans(rows, context))
328954
+ return null;
328809
328955
  for (const { row, path: rowPath } of rows) {
328810
328956
  let rowGridColumns = 0;
328811
328957
  for (let cellIndex = 0;cellIndex < row.childNodes.length; cellIndex += 1) {
@@ -329321,6 +329467,72 @@ function orderedListItemValue(item, definition, context, path6) {
329321
329467
  });
329322
329468
  return null;
329323
329469
  }
329470
+ function validateTableSpans(rows, context) {
329471
+ const occupiedUntil = Array.from({ length: MAX_WORD_TABLE_GRID_COLUMNS }, () => 0);
329472
+ let valid = true;
329473
+ const reject2 = (cell, path6, attribute2, message) => {
329474
+ valid = false;
329475
+ addDiagnostic(context, {
329476
+ code: "conversion-malformed-input",
329477
+ severity: "error",
329478
+ message,
329479
+ construct: attribute2 === "rowspan" ? "rowSpan" : "colSpan",
329480
+ disposition: "rejected",
329481
+ lossy: true,
329482
+ path: [...path6, `@${attribute2}`],
329483
+ range: sourceRangeForAttribute(cell, attribute2) ?? sourceRangeForNode(cell)
329484
+ });
329485
+ };
329486
+ const span = (cell, path6, attribute2) => {
329487
+ const raw = attributeValue2(cell, attribute2);
329488
+ if (raw === undefined)
329489
+ return 1;
329490
+ const trimmed = raw.replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, "");
329491
+ const value2 = Number(trimmed);
329492
+ if (/^\d+$/.test(trimmed) && Number.isSafeInteger(value2) && value2 >= (attribute2 === "rowspan" ? 0 : 1))
329493
+ return value2;
329494
+ reject2(cell, path6, attribute2, `Table cell ${attribute2} must be a valid ${attribute2 === "rowspan" ? "non-negative" : "positive"} integer.`);
329495
+ return;
329496
+ };
329497
+ for (let rowIndex = 0;rowIndex < rows.length; rowIndex += 1) {
329498
+ const { row, path: path6, remainingGroupRows } = rows[rowIndex];
329499
+ let column = 0;
329500
+ for (let cellIndex = 0;cellIndex < row.childNodes.length; cellIndex += 1) {
329501
+ const cell = row.childNodes[cellIndex];
329502
+ if (!isElement(cell) || cell.tagName !== "td" && cell.tagName !== "th")
329503
+ continue;
329504
+ const cellPath = [...path6, cellIndex];
329505
+ const authoredRowSpan = span(cell, cellPath, "rowspan");
329506
+ const rowSpan = authoredRowSpan === 0 ? remainingGroupRows : authoredRowSpan;
329507
+ const colSpan = span(cell, cellPath, "colspan");
329508
+ if (rowSpan === undefined || colSpan === undefined)
329509
+ continue;
329510
+ if (rowSpan > remainingGroupRows) {
329511
+ reject2(cell, cellPath, "rowspan", "Table cell rowspan extends beyond its HTML row group.");
329512
+ continue;
329513
+ }
329514
+ while (column < MAX_WORD_TABLE_GRID_COLUMNS && occupiedUntil[column] > rowIndex)
329515
+ column += 1;
329516
+ if (column + colSpan > MAX_WORD_TABLE_GRID_COLUMNS) {
329517
+ reject2(cell, cellPath, "colspan", `Table rows cannot exceed ${MAX_WORD_TABLE_GRID_COLUMNS} grid columns, including vertical continuations.`);
329518
+ break;
329519
+ }
329520
+ let overlaps2 = false;
329521
+ for (let slot = column;slot < column + colSpan; slot += 1) {
329522
+ if (occupiedUntil[slot] > rowIndex)
329523
+ overlaps2 = true;
329524
+ }
329525
+ if (overlaps2) {
329526
+ reject2(cell, cellPath, "colspan", "Table cell colspan overlaps an active rowspan.");
329527
+ } else {
329528
+ for (let slot = column;slot < column + colSpan; slot += 1)
329529
+ occupiedUntil[slot] = rowIndex + rowSpan;
329530
+ }
329531
+ column += colSpan;
329532
+ }
329533
+ }
329534
+ return valid;
329535
+ }
329324
329536
  function positiveIntegerAttribute(element, attribute2, context, path6, construct) {
329325
329537
  const raw = attributeValue2(element, attribute2);
329326
329538
  if (raw === undefined)
@@ -341082,7 +341294,7 @@ var init_markdown = __esm(() => {
341082
341294
 
341083
341295
  // ../../../v2/document-api-v2-adapter/dist/conversion/convert-to-fragment.js
341084
341296
  function convertContentToFragment(request) {
341085
- return request.format === "html" ? convertHtmlToFragment(request.source, request.options) : convertMarkdownToFragment(request.source, request.options);
341297
+ return request.format === "html" ? convertHtmlToFragment(request.source, { tableSpanPolicy: "strict", ...request.options }) : convertMarkdownToFragment(request.source, request.options);
341086
341298
  }
341087
341299
  var init_convert_to_fragment = __esm(() => {
341088
341300
  init_html2();
@@ -341631,6 +341843,9 @@ function lowerTable(node4, path7, images) {
341631
341843
  if (col + gridSpan > MAX_WORD_TABLE_GRID_COLUMNS3) {
341632
341844
  invalid3([...rowPath, "cells"], `Table rows cannot exceed ${MAX_WORD_TABLE_GRID_COLUMNS3} grid columns.`);
341633
341845
  }
341846
+ if (activeSpans.some((span) => span.remaining > 0 && span.col > col && span.col < col + gridSpan)) {
341847
+ invalid3([...cellPath, "colSpan"], "Table cell colspan overlaps an active rowspan.");
341848
+ }
341634
341849
  if (cell.content.length === 0)
341635
341850
  invalid3([...cellPath, "content"], "Table cells must contain a paragraph.");
341636
341851
  const blocks = cell.content.flatMap((content3, contentIndex) => {
@@ -344335,7 +344550,7 @@ function planFromHtml(payload, html, options, rejectUnsafeContent = false) {
344335
344550
  const converted = convertContentToFragment({
344336
344551
  format: "html",
344337
344552
  source: rewritten,
344338
- options: { limits: {
344553
+ options: { tableSpanPolicy: "html", limits: {
344339
344554
  maxSourceCodeUnits: DEFAULT_HTML_CONVERSION_LIMITS.maxSourceCodeUnits + allowance,
344340
344555
  maxOutputCodeUnits: DEFAULT_HTML_CONVERSION_LIMITS.maxOutputCodeUnits + allowance,
344341
344556
  ...allowance > 0 ? { maxNestingDepth: MAX_WORD_VML_RECOVERY_NESTING_DEPTH } : {}
@@ -469219,7 +469434,7 @@ function mirrorStorySurfaceFromSession(input) {
469219
469434
  const actorType = readActorAttributionFromPrepared(input.prepared);
469220
469435
  tx.meta.set(ACTOR_ATTRIBUTION_META_KEY, actorType);
469221
469436
  scope.meta.set(STORY_META_KEY.lastEditActorType, actorType);
469222
- const groups = extension2.contentControlRewrite || hasContentControlGroups(scope) ? prepareStoryContentControlGroups(input.session, storyId, doc2) : null;
469437
+ const groups = extension2.contentControlRewrite || extension2.family === "storyPaste" || hasContentControlGroups(scope) ? prepareStoryContentControlGroups(input.session, storyId, doc2) : null;
469223
469438
  mirrorFamilyIntoStory({
469224
469439
  session: input.session,
469225
469440
  prepared: input.prepared,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.9.0-next.7",
3
+ "version": "1.9.0-next.9",
4
4
  "description": "Model Context Protocol server for SuperDoc, giving an AI agent tools to read and edit .docx files.",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0",
@@ -24,13 +24,13 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@modelcontextprotocol/sdk": "^1.26.0",
27
- "@superdoc/sdk": "2.22.0-next.7",
27
+ "@superdoc/sdk": "2.22.0-next.9",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.25.0-next.7",
33
- "@superdoc/docx-engine": "0.24.0-next.7",
32
+ "superdoc": "2.25.0-next.9",
33
+ "@superdoc/docx-engine": "0.24.0-next.9",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",