@superdoc/mcp 1.9.0-next.10 → 1.9.0-next.11

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 +79 -18
  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.10";
31623
+ var SDK_VERSION = "2.22.0-next.11";
31624
31624
 
31625
31625
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31626
31626
  import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
@@ -186198,7 +186198,7 @@ function captureCooperativeTrackedCatalogRead(state, mode, assertActive) {
186198
186198
  numberingCatalog: listContext.numberingCatalog,
186199
186199
  styleNumberingIndex: listContext.styleIndex,
186200
186200
  stylesStatus: listContext.stylesStatus,
186201
- textboxRegistryRecords: state.textboxRegistry.records
186201
+ textboxRegistryRecords: Array.from(state.textboxRegistry.records)
186202
186202
  });
186203
186203
  let released = false, building = false;
186204
186204
  const check2 = () => {
@@ -314315,6 +314315,7 @@ function computeFieldResult(context, instruction, options = {}) {
314315
314315
  }
314316
314316
  switch (keyword) {
314317
314317
  case "PAGE":
314318
+ return resolvePageFieldText(context, options.currentField ?? options.pageLocation, instruction);
314318
314319
  case "PAGEREF":
314319
314320
  return resolvePageFieldText(context, options.currentField);
314320
314321
  case "NUMPAGES":
@@ -315934,32 +315935,60 @@ function readPreservedTocPageByText(preserved, text) {
315934
315935
  function normalizeGeneratedTocHeadingText(text) {
315935
315936
  return text.replace(/[\r\n\t]+/g, " ").replace(/\s+/g, " ").trim();
315936
315937
  }
315937
- function resolvePageFieldText(context, currentField) {
315938
+ function resolvePageFieldText(context, currentField, instruction) {
315939
+ const format = (page, sectionFormat) => instruction == null ? String(page) : formatPageFieldNumber(page, instruction, sectionFormat);
315938
315940
  if (!currentField)
315939
- return "1";
315941
+ return format(1);
315940
315942
  const pages = estimateDocumentPages(context);
315941
315943
  if (!currentField.storyId.startsWith("header:") && !currentField.storyId.startsWith("footer:")) {
315942
- return String(pages.displayPageByBlockId.get(currentField.blockId) ?? 1);
315944
+ return format(pages.displayPageByBlockId.get(currentField.blockId) ?? 1, pages.numberFormatByBlockId.get(currentField.blockId));
315943
315945
  }
315944
315946
  const snapshot2 = getSDDocumentSessionInternalSourceSignalsSnapshot(context.session);
315945
315947
  const main = snapshot2?.stories.find((story) => story.storyKind === "main");
315946
315948
  if (!main)
315947
- return "1";
315949
+ return format(1);
315948
315950
  const kind = currentField.storyId.startsWith("header:") ? "header" : "footer";
315949
315951
  const liveSections = readLiveSectionSignals(context);
315950
315952
  const rel = listSDDocumentSessionInternalHeaderFooterRels(context.session).find((candidate2) => candidate2.partUri === currentField.partUri);
315951
315953
  if (!rel)
315952
- return "1";
315954
+ return format(1);
315953
315955
  for (const section of liveSections) {
315954
315956
  const ref5 = section.headerFooterRefs.find((candidate2) => candidate2.kind === kind && candidate2.relationshipId === rel.refId);
315955
315957
  if (!ref5)
315956
315958
  continue;
315957
315959
  const sectionPages = pages.sectionById.get(section.sectionId);
315958
315960
  if (!sectionPages)
315959
- return "1";
315960
- return String(sectionPages.startDisplayPage + headerFooterPageOffset(ref5.variant, sectionPages.startDisplayPage, sectionPages.pageCount, sectionPages.titlePage, sectionPages.pageNumberingMode));
315961
+ return format(1);
315962
+ return format(sectionPages.startDisplayPage + headerFooterPageOffset(ref5.variant, sectionPages.startDisplayPage, sectionPages.pageCount, sectionPages.titlePage, sectionPages.pageNumberingMode), section.pageNumbering.format);
315963
+ }
315964
+ return format(1);
315965
+ }
315966
+ function formatPageFieldNumber(page, instruction, sectionFormat) {
315967
+ let format = sectionFormat ?? "decimal";
315968
+ for (const match of instruction.matchAll(/(?:^|\s)\\\*\s*(?:"([^"]*)"|([^\s"]+))/g)) {
315969
+ const value2 = match[1] ?? match[2];
315970
+ switch (value2.toLowerCase()) {
315971
+ case "roman":
315972
+ format = value2[0] === "r" ? "lowerRoman" : "upperRoman";
315973
+ break;
315974
+ case "alphabetic":
315975
+ format = value2[0] === "a" ? "lowerLetter" : "upperLetter";
315976
+ break;
315977
+ case "arabic":
315978
+ format = "decimal";
315979
+ break;
315980
+ case "arabicdash":
315981
+ format = "numberInDash";
315982
+ break;
315983
+ }
315961
315984
  }
315962
- return "1";
315985
+ if (format === "numberInDash")
315986
+ return `- ${page} -`;
315987
+ if ((format === "upperLetter" || format === "lowerLetter") && page > 0) {
315988
+ const letter = String.fromCharCode(65 + (page - 1) % 26).repeat(Math.floor((page - 1) / 26) + 1);
315989
+ return format === "lowerLetter" ? letter.toLowerCase() : letter;
315990
+ }
315991
+ return formatNumberingOrdinal(page, format);
315963
315992
  }
315964
315993
  function headerFooterPageOffset(variant, startDisplayPage, pageCount, titlePage, pageNumberingMode = "unknown") {
315965
315994
  const firstBodyPageOffset = titlePage && pageCount > 1 && (pageNumberingMode === "restart" || pageNumberingMode === "invalid") ? 1 : 0;
@@ -315977,11 +316006,12 @@ function headerFooterPageOffset(variant, startDisplayPage, pageCount, titlePage,
315977
316006
  function estimateDocumentPages(context) {
315978
316007
  const physicalPageByBlockId = new Map;
315979
316008
  const displayPageByBlockId = new Map;
316009
+ const numberFormatByBlockId = new Map;
315980
316010
  const sectionById = new Map;
315981
316011
  const snapshot2 = getSDDocumentSessionInternalSourceSignalsSnapshot(context.session);
315982
316012
  const main = snapshot2?.stories.find((story) => story.storyKind === "main");
315983
316013
  if (!main)
315984
- return { physicalPageByBlockId, displayPageByBlockId, sectionById };
316014
+ return { physicalPageByBlockId, displayPageByBlockId, numberFormatByBlockId, sectionById };
315985
316015
  const sections = readLiveSectionSignals(context);
315986
316016
  const liveBody = readLiveBodyPageSignals(context);
315987
316017
  const paragraphOrdinals = main.paragraphIndex.map((signal, index) => ({
@@ -316018,9 +316048,10 @@ function estimateDocumentPages(context) {
316018
316048
  const priorBreaks = breaksInSection.filter((entry) => entry.bodyChildOrdinal < paragraph2.ordinal || entry.bodyChildOrdinal === paragraph2.ordinal && entry.source === "paragraph-page-break-before").length;
316019
316049
  physicalPageByBlockId.set(paragraph2.blockId, startPhysicalPage + priorBreaks);
316020
316050
  displayPageByBlockId.set(paragraph2.blockId, startDisplayPage + priorBreaks);
316051
+ numberFormatByBlockId.set(paragraph2.blockId, section.pageNumbering.format);
316021
316052
  }
316022
316053
  }
316023
- return { physicalPageByBlockId, displayPageByBlockId, sectionById };
316054
+ return { physicalPageByBlockId, displayPageByBlockId, numberFormatByBlockId, sectionById };
316024
316055
  }
316025
316056
  function readLiveBodyPageSignals(context) {
316026
316057
  const documentBytes = getSDDocumentSessionInternalPartBytes(context.session, "/word/document.xml");
@@ -379066,8 +379097,17 @@ class V2TrackedChangesAdapter {
379066
379097
  items: [],
379067
379098
  unresolvedTrackedChangeIds: [...new Set(requestedIds)]
379068
379099
  };
379069
- const sourceFilter = source && { ...source, structuralScope: structuralScope ?? undefined };
379070
379100
  const resolveSession = createTrackedChangeFragmentResolveSession();
379101
+ const range = source?.textRange;
379102
+ const validTextRange = range && Number.isSafeInteger(range.start) && Number.isSafeInteger(range.end) && range.start >= 0 && range.end > range.start;
379103
+ const sourceFilter = source && {
379104
+ ...source,
379105
+ structuralScope: structuralScope ?? undefined,
379106
+ matchesTextFragment: validTextRange ? (fragment4) => {
379107
+ const resolved = resolveTrackedChangeFragmentTextTarget(this.context, fragment4, "tracked", story, resolveSession);
379108
+ return resolved.ok && resolved.normalizedTarget.segments.some((segment) => segment.blockId === range.blockId && segment.range.start <= range.start && range.end <= segment.range.end);
379109
+ } : undefined
379110
+ };
379071
379111
  const seenInput = new Set;
379072
379112
  const seenCanonical = new Set;
379073
379113
  const orderedRequestedIds = [];
@@ -382043,6 +382083,11 @@ function resolveReviewSnapshotOwner(logical, entry) {
382043
382083
  function reviewSnapshotEntryMatchesSource(entry, source, requestedId) {
382044
382084
  if (source?.partUri && entry.partUri !== source.partUri)
382045
382085
  return false;
382086
+ if (source?.textRange) {
382087
+ const aliases = requestedId ? reviewSnapshotRequestedIdAliases(requestedId) : [];
382088
+ if (!entry.fragments.some((fragment4) => (requestedId === entry.id || aliases.includes(fragment4.wId) || aliases.includes(fragment4.rsid)) && (source.kind === "insert" ? fragment4.kind === "ins" || fragment4.kind === "moveTo" : source.kind === "delete" ? fragment4.kind === "del" || fragment4.kind === "moveFrom" : false) && source.matchesTextFragment?.(fragment4)))
382089
+ return false;
382090
+ }
382046
382091
  if (source?.structuralScope) {
382047
382092
  const scope = source.structuralScope;
382048
382093
  const aliases = requestedId ? reviewSnapshotRequestedIdAliases(requestedId) : [];
@@ -389529,15 +389574,16 @@ class V2FieldsAdapter {
389529
389574
  const resolved = resolveInsertTarget(this.context, input.at, options);
389530
389575
  if ("failure" in resolved)
389531
389576
  return mutationFailure2(resolved.failure.code, resolved.failure.message);
389577
+ const paragraph4 = findParagraphInStory(this.context, resolved.range.storyId, resolved.range.startBlockId);
389578
+ if (!paragraph4)
389579
+ return mutationFailure2("TARGET_NOT_FOUND", `Paragraph "${resolved.range.startBlockId}" was not found.`);
389532
389580
  const beforeFieldEntries = listCanonicalFieldEntries(this.context);
389533
389581
  const beforeFieldIds = new Set(beforeFieldEntries.map((entry) => entry.stableFieldId));
389534
389582
  const preserveCached = input.updatePolicy === "preserveCached" && typeof input.cachedResultText === "string";
389535
389583
  const resultText = preserveCached ? input.cachedResultText : computeFieldResult(this.context, input.instruction, {
389584
+ pageLocation: paragraph4,
389536
389585
  seqFallbackLabel: parseSeqFallbackLabel(input.instruction)
389537
389586
  });
389538
- const paragraph4 = findParagraphInStory(this.context, resolved.range.storyId, resolved.range.startBlockId);
389539
- if (!paragraph4)
389540
- return mutationFailure2("TARGET_NOT_FOUND", `Paragraph "${resolved.range.startBlockId}" was not found.`);
389541
389587
  const selectedText = paragraph4.text.slice(resolved.range.startOffset, resolved.range.endOffset);
389542
389588
  const replaceSelection = resolved.range.endOffset > resolved.range.startOffset && selectedText === resultText;
389543
389589
  let fieldXml = preserveCached ? buildPreservedCachedFieldXml(input.instruction, resultText) : options?.changeMode === "tracked" ? buildComplexFieldTextXml(input.instruction, resultText) : buildSimpleFieldXml(input.instruction, resultText);
@@ -478713,6 +478759,9 @@ function createHeadlessCollabRoomCoordinator(options) {
478713
478759
  let syncingManifest = false;
478714
478760
  let registryChangedDuringSync = false;
478715
478761
  let packageParts = getPackagePartsMap(options.rootDoc);
478762
+ const numberingPartKey = encodeLogicalOwnerKey(NUMBERING_PART_URI7);
478763
+ const numberingShardId = packageShardId(options.rootId, SHARD_KIND.numbering, NUMBERING_PART_URI7);
478764
+ let numberingDeletionObserved = false;
478716
478765
  const meta3 = getMetaMap(options.rootDoc);
478717
478766
  const packageSelection = options.rootDoc.getMap(ROOT_MAP.package);
478718
478767
  const observedReplacements = new Set;
@@ -478727,9 +478776,19 @@ function createHeadlessCollabRoomCoordinator(options) {
478727
478776
  return changed;
478728
478777
  }
478729
478778
  observeReplacementCommits();
478730
- const manifestObserver = () => {
478779
+ const manifestObserver = (event) => {
478731
478780
  if (disposed)
478732
478781
  return;
478782
+ if (event.target === packageParts) {
478783
+ for (const [partKey2, change] of event.changes.keys) {
478784
+ if (change.action !== "delete")
478785
+ continue;
478786
+ const previous3 = toManifestPartDescriptor(partKey2, change.oldValue);
478787
+ if (previous3?.partKind === "numbering" && previous3.partUri === NUMBERING_PART_URI7 && partKey2 === numberingPartKey) {
478788
+ numberingDeletionObserved = true;
478789
+ }
478790
+ }
478791
+ }
478733
478792
  const replacementCommitted = observeReplacementCommits();
478734
478793
  if (replacementCommitted)
478735
478794
  pruneReplacedRoomOrphans(options.rootDoc);
@@ -479876,7 +479935,8 @@ function createHeadlessCollabRoomCoordinator(options) {
479876
479935
  for (const [shardId, handle] of options.graph.projectionHandles.entries()) {
479877
479936
  if (activeShardIds.has(shardId))
479878
479937
  continue;
479879
- if (!replacingPackage && !isManifestPrunableProjectionHandle(handle))
479938
+ const explicitlyRetiredNumbering = handle.shardKind === SHARD_KIND.numbering && shardId === numberingShardId && numberingDeletionObserved;
479939
+ if (!replacingPackage && !explicitlyRetiredNumbering && !isManifestPrunableProjectionHandle(handle))
479880
479940
  continue;
479881
479941
  options.graph.projectionHandles.delete(shardId);
479882
479942
  options.graph.requiredShardIds.delete(shardId);
@@ -479884,6 +479944,7 @@ function createHeadlessCollabRoomCoordinator(options) {
479884
479944
  options.graph.commentsHandle = null;
479885
479945
  changed = true;
479886
479946
  }
479947
+ numberingDeletionObserved = false;
479887
479948
  if (changed)
479888
479949
  notifyRegistryChangedIfActive();
479889
479950
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.9.0-next.10",
3
+ "version": "1.9.0-next.11",
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.10",
27
+ "@superdoc/sdk": "2.22.0-next.11",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.25.0-next.10",
33
- "@superdoc/docx-engine": "0.24.0-next.10",
32
+ "superdoc": "2.25.0-next.11",
33
+ "@superdoc/docx-engine": "0.24.0-next.11",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",