@superdoc/mcp 1.2.0-next.13 → 1.2.0-next.14

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 +88 -31
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31314,7 +31314,7 @@ var init_host = __esm(() => {
31314
31314
  });
31315
31315
 
31316
31316
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31317
- var SDK_VERSION = "2.15.0-next.13";
31317
+ var SDK_VERSION = "2.15.0-next.14";
31318
31318
 
31319
31319
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31320
31320
  import { chmodSync, existsSync } from "node:fs";
@@ -134832,26 +134832,68 @@ function canonicalName(namespace, localName2) {
134832
134832
  return `xml:${localName2}`;
134833
134833
  return namespace ? `{${namespace}}${localName2}` : localName2;
134834
134834
  }
134835
- function computeRunSignature(runXml) {
134836
- const canonicalXml = canonicalizeXmlForSignature(runXml);
134837
- const normalized = normalizeRunXmlForSignature(canonicalXml.replace(REVISION_ATTR_RE, (attribute, offset, xml) => {
134838
- const precedingTag = xml.slice(xml.lastIndexOf("<", offset), offset);
134839
- return /^<w:proofErr(?:\s|$)/.test(precedingTag) ? attribute : "";
134840
- }).replace(REVISION_ELEMENT_RE, (markup) => markup.replace(REVISION_ID_ATTR_RE, "")).replace(COMMENT_MARKUP_RE, (markup, name, attributes) => isWordprocessingElement3(name, attributes, canonicalXml) ? "" : markup).replace(NOTE_REFERENCE_MARKUP_RE, (markup, runName, runAttributes, _rPrName, nestedName, nestedAttributes, standaloneName, standaloneAttributes) => {
134841
- const name = nestedName ?? standaloneName;
134842
- const attributes = nestedAttributes ?? standaloneAttributes;
134843
- if (!isWordprocessingElement3(name, attributes, canonicalXml))
134844
- return markup;
134845
- if (runName && !isWordprocessingElement3(runName, runAttributes, canonicalXml))
134846
- return markup;
134847
- return "";
134848
- }));
134849
- let hash2 = 2166136261;
134850
- for (let i = 0;i < normalized.length; i += 1) {
134851
- hash2 ^= normalized.charCodeAt(i);
134852
- hash2 = Math.imul(hash2, 16777619) >>> 0;
134835
+ function normalizeBalancedBookmarkIds(canonicalXmls) {
134836
+ const starts = new Map;
134837
+ const ends = new Set;
134838
+ const names = new Set;
134839
+ for (const xml of canonicalXmls) {
134840
+ const tags = [...xml.matchAll(BOOKMARK_TAG_RE)];
134841
+ if (tags.length !== [...xml.matchAll(BOOKMARK_OPENING_RE)].length)
134842
+ return canonicalXmls;
134843
+ for (const tag of tags) {
134844
+ if (tag[1] || !tag[0].endsWith("/>"))
134845
+ return canonicalXmls;
134846
+ const attributes = [...tag[3].matchAll(ATTRIBUTE_RE)];
134847
+ const ids = attributes.filter((attribute) => attribute[1] === "w:id");
134848
+ const bookmarkNames = attributes.filter((attribute) => attribute[1] === "w:name");
134849
+ const id = ids[0]?.[2] ?? ids[0]?.[3];
134850
+ if (ids.length !== 1 || !id || !/^\d+$/u.test(id))
134851
+ return canonicalXmls;
134852
+ if (tag[2] === "Start") {
134853
+ const name = bookmarkNames[0]?.[2] ?? bookmarkNames[0]?.[3];
134854
+ if (bookmarkNames.length !== 1 || !name || starts.has(id) || names.has(name))
134855
+ return canonicalXmls;
134856
+ starts.set(id, name);
134857
+ names.add(name);
134858
+ } else {
134859
+ if (bookmarkNames.length > 0 || !starts.has(id) || ends.has(id))
134860
+ return canonicalXmls;
134861
+ ends.add(id);
134862
+ }
134863
+ }
134853
134864
  }
134854
- return `v2-run-${hash2.toString(16).padStart(8, "0")}`;
134865
+ if (starts.size !== ends.size)
134866
+ return canonicalXmls;
134867
+ return canonicalXmls.map((xml) => xml.replace(BOOKMARK_TAG_RE, (tag, _closing, _kind, attributes) => {
134868
+ const id = /\bw:id="([^"]*)"/u.exec(attributes)[1];
134869
+ return tag.replace(/\bw:id="[^"]*"/u, `w:id=${JSON.stringify(`bookmark:${starts.get(id)}`)}`);
134870
+ }));
134871
+ }
134872
+ function computeRunSignatures(runXmls) {
134873
+ const canonicalXmls = normalizeBalancedBookmarkIds(runXmls.map(canonicalizeXmlForSignature));
134874
+ return canonicalXmls.map((canonicalXml) => {
134875
+ const normalized = normalizeRunXmlForSignature(canonicalXml.replace(REVISION_ATTR_RE, (attribute, offset, xml) => {
134876
+ const precedingTag = xml.slice(xml.lastIndexOf("<", offset), offset);
134877
+ return /^<w:proofErr(?:\s|$)/.test(precedingTag) ? attribute : "";
134878
+ }).replace(REVISION_ELEMENT_RE, (markup) => markup.replace(REVISION_ID_ATTR_RE, "")).replace(COMMENT_MARKUP_RE, (markup, name, attributes) => isWordprocessingElement3(name, attributes, canonicalXml) ? "" : markup).replace(NOTE_REFERENCE_MARKUP_RE, (markup, runName, runAttributes, _rPrName, nestedName, nestedAttributes, standaloneName, standaloneAttributes) => {
134879
+ const name = nestedName ?? standaloneName;
134880
+ const attributes = nestedAttributes ?? standaloneAttributes;
134881
+ if (!isWordprocessingElement3(name, attributes, canonicalXml))
134882
+ return markup;
134883
+ if (runName && !isWordprocessingElement3(runName, runAttributes, canonicalXml))
134884
+ return markup;
134885
+ return "";
134886
+ }));
134887
+ let hash2 = 2166136261;
134888
+ for (let i = 0;i < normalized.length; i += 1) {
134889
+ hash2 ^= normalized.charCodeAt(i);
134890
+ hash2 = Math.imul(hash2, 16777619) >>> 0;
134891
+ }
134892
+ return `v2-run-${hash2.toString(16).padStart(8, "0")}`;
134893
+ });
134894
+ }
134895
+ function computeRunSignature(runXml) {
134896
+ return computeRunSignatures([runXml])[0];
134855
134897
  }
134856
134898
  function normalizeRunXmlForSignature(runXml) {
134857
134899
  const pieces = [];
@@ -134934,7 +134976,7 @@ function isWordprocessingElement3(name, attributes, namespaceContext) {
134934
134976
  return true;
134935
134977
  return (declaration[2] ?? declaration[3] ?? "") === WORDPROCESSINGML_NAMESPACE2;
134936
134978
  }
134937
- var REVISION_ATTR_RE, REVISION_ELEMENT_RE, REVISION_ID_ATTR_RE, COMMENT_MARKUP_RE, PROOFING_BOUNDARY_MARKUP_RE, NOTE_REFERENCE_MARKUP_RE, RUN_RE, RUN_PROPERTIES_RE, EMPTY_RUN_PROPERTIES_RE, TEXTISH_RE, RUN_CONTROL_RE, ATTRIBUTE_RE, WORDPROCESSINGML_NAMESPACE2 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", WORDPROCESSINGML_2010_NAMESPACE = "http://schemas.microsoft.com/office/word/2010/wordml", MARKUP_COMPATIBILITY_NAMESPACE = "http://schemas.openxmlformats.org/markup-compatibility/2006", XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace", XML_TAG_RE;
134979
+ var REVISION_ATTR_RE, REVISION_ELEMENT_RE, REVISION_ID_ATTR_RE, COMMENT_MARKUP_RE, PROOFING_BOUNDARY_MARKUP_RE, NOTE_REFERENCE_MARKUP_RE, RUN_RE, RUN_PROPERTIES_RE, EMPTY_RUN_PROPERTIES_RE, TEXTISH_RE, RUN_CONTROL_RE, ATTRIBUTE_RE, WORDPROCESSINGML_NAMESPACE2 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", WORDPROCESSINGML_2010_NAMESPACE = "http://schemas.microsoft.com/office/word/2010/wordml", MARKUP_COMPATIBILITY_NAMESPACE = "http://schemas.openxmlformats.org/markup-compatibility/2006", XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace", XML_TAG_RE, BOOKMARK_OPENING_RE, BOOKMARK_TAG_RE;
134938
134980
  var init_run_signature = __esm(() => {
134939
134981
  REVISION_ATTR_RE = /\s+(?:w:rsid\w*|w14:paraId|w14:textId)="[^"]*"/g;
134940
134982
  REVISION_ELEMENT_RE = /<w:(?:ins|del|moveFrom|moveTo)\b[^>]*>/g;
@@ -134949,6 +134991,8 @@ var init_run_signature = __esm(() => {
134949
134991
  RUN_CONTROL_RE = /<((?:[\w.-]+:)?(tab|br|cr))\b([^>]*)\/>/g;
134950
134992
  ATTRIBUTE_RE = /([\w.:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
134951
134993
  XML_TAG_RE = /<(\/?)(([A-Za-z_][\w.-]*)(?::([A-Za-z_][\w.-]*))?)((?:(?:"[^"]*"|'[^']*'|[^>"'])*))>/g;
134994
+ BOOKMARK_OPENING_RE = /<\/?w:bookmark(?:Start|End)\b/g;
134995
+ BOOKMARK_TAG_RE = /<(\/?)w:bookmark(Start|End)\b((?:"[^"]*"|[^">])*)>/g;
134952
134996
  });
134953
134997
 
134954
134998
  // ../../../v2/document-compare/src/note-story-projection.ts
@@ -134960,7 +135004,7 @@ function projectCapturedNoteStoryEntries(value) {
134960
135004
  const ranges = collectWordParagraphRanges(value.notePartXml);
134961
135005
  if (!ranges)
134962
135006
  return null;
134963
- return ranges.flatMap((range, ordinal) => {
135007
+ const entries = ranges.flatMap((range, ordinal) => {
134964
135008
  if (range.start < noteStart || range.end > noteEnd)
134965
135009
  return [];
134966
135010
  const paragraphXml = value.notePartXml.slice(range.start, range.end);
@@ -134974,12 +135018,13 @@ function projectCapturedNoteStoryEntries(value) {
134974
135018
  text: visibleParagraphText(paragraphXml, range.namespaceBindings),
134975
135019
  headingLevel: metadata2.headingLevel,
134976
135020
  styleId: metadata2.styleId,
134977
- runSignature: computeRunSignature(runXml),
134978
135021
  runXml,
134979
135022
  paragraphPropertiesXml,
134980
135023
  paragraphPropertiesSignature: computeParagraphPropertiesSignature(paragraphPropertiesXml)
134981
135024
  }];
134982
135025
  });
135026
+ const runSignatures = computeRunSignatures(entries.map((entry) => entry.runXml ?? ""));
135027
+ return entries.map((entry, index) => ({ ...entry, runSignature: runSignatures[index] }));
134983
135028
  }
134984
135029
  function collectWordParagraphRanges(xml) {
134985
135030
  let valid = true;
@@ -355004,8 +355049,12 @@ function projectStories(context, slots) {
355004
355049
  if (family === "footnotes" || family === "endnotes")
355005
355050
  requiredPartBytes(context, story.partUri);
355006
355051
  const paragraphs = readStoryParagraphs(context, story.storyId).filter(isWordprocessingParagraph);
355052
+ const runXmls = paragraphs.map((p) => extractParagraphRunXml(p.rawXml, p.namespaceBindings ?? {}));
355053
+ const runSignatures = computeRunSignatures(runXmls);
355054
+ const runXmlByOrdinal = new Map(paragraphs.map((p, i2) => [p.ordinal, runXmls[i2]]));
355055
+ const runSignatureByOrdinal = new Map(paragraphs.map((p, i2) => [p.ordinal, runSignatures[i2]]));
355007
355056
  const projectEntry2 = (p) => {
355008
- const runXml = extractParagraphRunXml(p.rawXml, p.namespaceBindings ?? {});
355057
+ const runXml = runXmlByOrdinal.get(p.ordinal);
355009
355058
  const paragraphPropertiesXml = extractParagraphPropertiesXml(p.rawXml, p.namespaceBindings ?? {});
355010
355059
  const blockId = family === "header-footer-parts" && isStructurallyBlankStoryParagraph({ text: p.text, runXml }) ? `${slotKey}::blank:${p.ordinal}` : p.blockId;
355011
355060
  return {
@@ -355014,7 +355063,7 @@ function projectStories(context, slots) {
355014
355063
  text: p.text,
355015
355064
  headingLevel: p.headingLevel,
355016
355065
  styleId: p.styleId,
355017
- runSignature: computeRunSignature(runXml),
355066
+ runSignature: runSignatureByOrdinal.get(p.ordinal),
355018
355067
  runXml,
355019
355068
  trackedChangeAnnotationKeys: trackedChangeAnnotationKeysForParagraph(context, p),
355020
355069
  paragraphPropertiesXml,
@@ -355087,8 +355136,10 @@ function bodyParagraphStructuralScopes(context, paragraphs) {
355087
355136
  function projectBody(context) {
355088
355137
  const paragraphs = readBodyParagraphs(context).filter(isWordprocessingParagraph);
355089
355138
  const scopes = bodyParagraphStructuralScopes(context, paragraphs);
355139
+ const runXmls = paragraphs.map((p) => extractParagraphRunXml(p.rawXml, p.namespaceBindings ?? {}));
355140
+ const runSignatures = computeRunSignatures(runXmls);
355090
355141
  return paragraphs.map((p, ordinal) => {
355091
- const runXml = extractParagraphRunXml(p.rawXml, p.namespaceBindings ?? {});
355142
+ const runXml = runXmls[ordinal];
355092
355143
  const paragraphPropertiesXml = extractParagraphPropertiesXml(p.rawXml, p.namespaceBindings ?? {});
355093
355144
  return {
355094
355145
  blockId: p.blockId,
@@ -355097,7 +355148,7 @@ function projectBody(context) {
355097
355148
  text: p.text,
355098
355149
  headingLevel: p.headingLevel,
355099
355150
  styleId: p.styleId,
355100
- runSignature: computeRunSignature(runXml),
355151
+ runSignature: runSignatures[ordinal],
355101
355152
  runXml,
355102
355153
  trackedChangeAnnotationKeys: trackedChangeAnnotationKeysForParagraph(context, p),
355103
355154
  paragraphPropertiesXml,
@@ -360667,10 +360718,16 @@ function projectMainDocumentBodyEntries(source, options = {}) {
360667
360718
  });
360668
360719
  const scopes = mapBodyParagraphStructuralScopes(tableCatalog, paragraphIndex.entries);
360669
360720
  const namespaceBindingsByByteStart = scanParagraphNamespaceBindingsByByteStart(source.xml);
360670
- return paragraphIndex.entries.map((entry) => {
360671
- const rawXml = TD107.decode(bytes.subarray(entry.byteStart, entry.byteEnd));
360721
+ const rawXmls = paragraphIndex.entries.map((entry) => TD107.decode(bytes.subarray(entry.byteStart, entry.byteEnd)));
360722
+ const runXmls = paragraphIndex.entries.map((entry, index2) => {
360723
+ const namespaceBindings = namespaceBindingsByByteStart.get(entry.byteStart) ?? {};
360724
+ return extractParagraphRunXml(rawXmls[index2], namespaceBindings);
360725
+ });
360726
+ const runSignatures = computeRunSignatures(runXmls);
360727
+ return paragraphIndex.entries.map((entry, index2) => {
360728
+ const rawXml = rawXmls[index2];
360672
360729
  const namespaceBindings = namespaceBindingsByByteStart.get(entry.byteStart) ?? {};
360673
- const runXml = extractParagraphRunXml(rawXml, namespaceBindings);
360730
+ const runXml = runXmls[index2];
360674
360731
  const paragraphPropertiesXml = extractParagraphPropertiesXml(rawXml, namespaceBindings);
360675
360732
  return {
360676
360733
  blockId: entry.blockId,
@@ -360679,7 +360736,7 @@ function projectMainDocumentBodyEntries(source, options = {}) {
360679
360736
  text: readVisibleParagraphText(rawXml),
360680
360737
  headingLevel: paragraphHeadingLevel(rawXml, { paragraphStyleOutlineLevels }),
360681
360738
  styleId: paragraphStyleId(rawXml),
360682
- runSignature: computeRunSignature(runXml),
360739
+ runSignature: runSignatures[index2],
360683
360740
  runXml,
360684
360741
  paragraphPropertiesXml,
360685
360742
  paragraphPropertiesSignature: computeParagraphPropertiesSignature2(paragraphPropertiesXml)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.2.0-next.13",
3
+ "version": "1.2.0-next.14",
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.15.0-next.13",
27
+ "@superdoc/sdk": "2.15.0-next.14",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.18.0-next.13",
33
- "@superdoc/docx-engine": "0.17.0-next.15",
32
+ "superdoc": "2.18.0-next.14",
33
+ "@superdoc/docx-engine": "0.17.0-next.16",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",