@superdoc/mcp 1.6.0-next.1 → 1.6.0-next.2

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 +115 -5
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31443,7 +31443,7 @@ var init_host = __esm(() => {
31443
31443
  });
31444
31444
 
31445
31445
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31446
- var SDK_VERSION = "2.19.0-next.1";
31446
+ var SDK_VERSION = "2.19.0-next.2";
31447
31447
 
31448
31448
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31449
31449
  import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
@@ -194717,6 +194717,9 @@ function isBreakRunToken(token) {
194717
194717
  }
194718
194718
  function compileOverlapEdit(input) {
194719
194719
  const paragraphInlineMap = input.paragraphInlineMap ?? parseParagraphInlineMap(input.paragraphXml, input.namespaceBindings);
194720
+ const consecutiveBreakInsertion = tryConsecutiveManualBreakInsertion(input, paragraphInlineMap);
194721
+ if (consecutiveBreakInsertion)
194722
+ return consecutiveBreakInsertion;
194720
194723
  const readsComplexDeletionForCollapsedInsert = input.newText.length > 0 && input.rangeStart === input.rangeEnd && ((input.coordinateSpace ?? "visible") === "visible" || input.changeMode === "tracked");
194721
194724
  const readsStructuralDeletionForReplacement = input.changeMode === "tracked" && input.newText.length > 0 && input.rangeStart < input.rangeEnd && paragraphInlineMap.pieces.some((piece) => piece.kind === "tracked" && piece.trackedKind === "del" && piece.visibleStart === piece.visibleEnd && input.rangeStart < piece.visibleStart && input.rangeEnd > piece.visibleEnd && piece.children.some(isSupportedStructuralDeletionChild));
194722
194725
  const readsComplexDeletions = (input.changeMode === "direct" || input.newText.length === 0) && input.rangeStart < input.rangeEnd || readsComplexDeletionForCollapsedInsert || readsStructuralDeletionForReplacement;
@@ -194734,6 +194737,52 @@ function compileOverlapEdit(input) {
194734
194737
  const directInsertAtTrackedEnd = input.changeMode === "direct" && input.rangeStart === input.rangeEnd && input.newText.length > 0 && parsed.tokens.some((token) => token.kind === "ins" && token.visibleEnd === input.rangeStart);
194735
194738
  return result.ok && (directInsertAtTrackedEnd || parsed.descendedEditableContainers.some(({ kind, xml }) => kind === "sdt" && result.xml.split(xml).length < input.paragraphXml.split(xml).length)) ? { ...result, requiresCollaborationSessionSync: true } : result;
194736
194739
  }
194740
+ function tryConsecutiveManualBreakInsertion(input, model) {
194741
+ if (input.changeMode !== "tracked" || input.rangeStart !== input.rangeEnd || input.newText.length === 0)
194742
+ return null;
194743
+ const paragraph = findRawXmlElementRangeAt(input.paragraphXml, 0, NS_W3, "p", { w: NS_W3, ...input.namespaceBindings });
194744
+ if (!paragraph || input.paragraphXml.slice(paragraph.end).trim().length > 0)
194745
+ return null;
194746
+ const bindings = new Map(Object.entries(paragraph.namespaceBindings));
194747
+ if (model.pieces.some((piece) => piece.containerStack.length > 0 || !(piece.kind === "text" && piece.textRole === "visible" || piece.kind === "control" && !piece.deleted && isManualBreak(piece, bindings))))
194748
+ return null;
194749
+ const spanStart = (piece) => input.coordinateSpace === "tracked" ? piece.trackedStart : piece.visibleStart;
194750
+ const spanEnd = (piece) => input.coordinateSpace === "tracked" ? piece.trackedEnd : piece.visibleEnd;
194751
+ for (let index = 1;index < model.pieces.length; index++) {
194752
+ const before = model.pieces[index - 1];
194753
+ const after = model.pieces[index];
194754
+ if (before.kind !== "control" || after.kind !== "control" || spanEnd(before) !== input.rangeStart || spanStart(after) !== input.rangeStart)
194755
+ continue;
194756
+ const sharedRun = before.runCharStart === after.runCharStart;
194757
+ const gap = sharedRun ? input.paragraphXml.slice(before.charEnd, after.charStart) : input.paragraphXml.slice(before.runCharEnd, after.runCharStart);
194758
+ if (gap.trim().length > 0)
194759
+ return null;
194760
+ const parsed = collectXmlElementRanges(input.paragraphXml, { fragment: true, additionalNamespaces: paragraph.namespaceBindings });
194761
+ if (parsed.errors.length > 0)
194762
+ return null;
194763
+ const elements2 = new Map(parsed.ranges.map((element) => [element.start, element]));
194764
+ for (const piece of model.pieces) {
194765
+ if (piece.kind !== "text" && piece.kind !== "control")
194766
+ return null;
194767
+ const run = elements2.get(piece.runCharStart);
194768
+ const payload = elements2.get(piece.charStart);
194769
+ if (run?.tag.namespaceUri !== NS_W3 || run.tag.localName !== "r" || run.end !== piece.runCharEnd || payload?.tag.namespaceUri !== NS_W3 || payload.tag.localName !== piece.localName)
194770
+ return null;
194771
+ }
194772
+ const insertion = buildInsWrapperXml({
194773
+ nsPrefix: nsPrefixOfRun(before.runOpenTag),
194774
+ wId: String(resolveNextWId(input)),
194775
+ author: { name: input.currentAuthor.name, initials: input.currentAuthor.initials ?? null, email: input.currentAuthor.email ?? null },
194776
+ date: input.txTimestamp,
194777
+ rsidR: input.insRsid,
194778
+ inner: { runOpen: before.runOpenTag, runClose: before.runCloseTag, rPr: before.runProperties ?? "", text: input.newText }
194779
+ });
194780
+ const at = sharedRun ? after.charStart : before.runCharEnd;
194781
+ const xml = input.paragraphXml.slice(0, at) + (sharedRun ? before.runCloseTag : "") + insertion + (sharedRun ? after.runOpenTag + (after.runProperties ?? "") : "") + input.paragraphXml.slice(at);
194782
+ return { ok: true, xml, emittedRsids: [input.insRsid], requiresCollaborationSessionSync: true };
194783
+ }
194784
+ return null;
194785
+ }
194737
194786
  function compileParsedOverlapEdit(input, tokens, descendedEditableContainers) {
194738
194787
  const touched = [];
194739
194788
  const touchedBreaks = [];
@@ -200130,7 +200179,8 @@ function commitTracked(input, view) {
200130
200179
  entityId: revision.rsid,
200131
200180
  storyId: op.on.storyId
200132
200181
  }));
200133
- const resyncFromSession = usedSpanningDelete || usedBookmarkDelete || spansLiveInlineControl || usedTrackedControlRunFallback;
200182
+ const followsDeletedManualBreak = isPureTrackedInsert(op) && op.on.coordinateSpace === "tracked" && parseParagraphInlineMap(paragraphXml).leaves().some((leaf) => leaf.kind === "control" && leaf.control === "br" && leaf.deleted && leaf.trackedEnd === op.on.startOffset);
200183
+ const resyncFromSession = usedSpanningDelete || usedBookmarkDelete || spansLiveInlineControl || usedTrackedControlRunFallback || followsDeletedManualBreak;
200134
200184
  return finalizeCommit({
200135
200185
  input,
200136
200186
  perPart,
@@ -436243,7 +436293,7 @@ function sortedProjectedAtoms(block, extraAtoms) {
436243
436293
  sequence: block.atoms.length + index2
436244
436294
  }))
436245
436295
  ];
436246
- return normalizeLiveTrackedWrapperOverlap(sortProjectedAtoms(baseAtoms));
436296
+ return normalizeLiveTrackedWrapperOverlap(sortLiveTrackedWrapperBoundaries(sortProjectedAtoms(baseAtoms)));
436247
436297
  }
436248
436298
  function sortProjectedAtoms(atoms) {
436249
436299
  return [...atoms].sort((left, right) => {
@@ -436256,6 +436306,32 @@ function sortProjectedAtoms(atoms) {
436256
436306
  return left.sequence - right.sequence;
436257
436307
  });
436258
436308
  }
436309
+ function sortLiveTrackedWrapperBoundaries(atoms) {
436310
+ const spans = collectLiveTrackedWrapperSpans(atoms).filter((span) => span.kind === "ins");
436311
+ const starts = new Map;
436312
+ for (const span of spans) {
436313
+ if (span.endOffset <= span.startOffset)
436314
+ continue;
436315
+ const atOffset = starts.get(span.startOffset) ?? [];
436316
+ atOffset.push(span);
436317
+ starts.set(span.startOffset, atOffset);
436318
+ }
436319
+ const ordered = [...atoms];
436320
+ for (const span of spans) {
436321
+ if (span.endOffset <= span.startOffset)
436322
+ continue;
436323
+ const closeIndex = ordered.indexOf(span.closeAtom);
436324
+ const reversed = (starts.get(span.endOffset) ?? []).some((following) => following.rsid !== span.rsid && ordered.indexOf(following.openAtom) < closeIndex);
436325
+ if (!reversed)
436326
+ continue;
436327
+ const openIndex = ordered.findIndex((atom, index2) => index2 < closeIndex && atom.visibleOffset === span.endOffset && liveTrackedWrapperInfo(atom)?.position === "start");
436328
+ if (openIndex < 0)
436329
+ continue;
436330
+ ordered.splice(closeIndex, 1);
436331
+ ordered.splice(openIndex, 0, span.closeAtom);
436332
+ }
436333
+ return ordered.map((atom, sequence) => ({ ...atom, sequence }));
436334
+ }
436259
436335
  function normalizeLiveTrackedWrapperOverlap(atoms) {
436260
436336
  const spans = collectLiveTrackedWrapperSpans(atoms);
436261
436337
  if (spans.length === 0)
@@ -436279,6 +436355,7 @@ function normalizeLiveTrackedWrapperOverlap(atoms) {
436279
436355
  let nextSequence = atoms.reduce((max5, atom) => Math.max(max5, atom.sequence), -1) + 1;
436280
436356
  const syntheticAtoms = [];
436281
436357
  const coveredParentEdges = new Set;
436358
+ const coveredEndChildren = new Map;
436282
436359
  for (const [parentKey, children2] of foreignChildrenByParent) {
436283
436360
  const parent = spansByKey.get(parentKey);
436284
436361
  if (!parent)
@@ -436309,9 +436386,42 @@ function normalizeLiveTrackedWrapperOverlap(atoms) {
436309
436386
  syntheticAtoms.push(makeSyntheticTrackedWrapperAtom(parent.openAtom, lastChild.endOffset, 110, nextSequence++));
436310
436387
  } else {
436311
436388
  coveredParentEdges.add(parent.closeAtom);
436389
+ coveredEndChildren.set(parent.closeAtom, lastChild.closeAtom);
436312
436390
  }
436313
436391
  }
436314
- return sortProjectedAtoms([...atoms.filter((atom) => !coveredParentEdges.has(atom)), ...syntheticAtoms]);
436392
+ const childClosings = new Set(coveredEndChildren.values());
436393
+ const atomIndexes = new Map(atoms.map((atom, index2) => [atom, index2]));
436394
+ const closingSlotReplacements = new Map;
436395
+ for (const parentClose of coveredEndChildren.keys()) {
436396
+ if (childClosings.has(parentClose))
436397
+ continue;
436398
+ let earliestClose = parentClose;
436399
+ let survivingClose = parentClose;
436400
+ let childClose = coveredEndChildren.get(survivingClose);
436401
+ while (childClose) {
436402
+ if (atomIndexes.get(childClose) < atomIndexes.get(earliestClose))
436403
+ earliestClose = childClose;
436404
+ survivingClose = childClose;
436405
+ childClose = coveredEndChildren.get(survivingClose);
436406
+ }
436407
+ if (earliestClose === survivingClose)
436408
+ continue;
436409
+ closingSlotReplacements.set(earliestClose, {
436410
+ ...survivingClose,
436411
+ sequence: earliestClose.sequence,
436412
+ sortOrder: earliestClose.sortOrder
436413
+ });
436414
+ coveredParentEdges.add(survivingClose);
436415
+ }
436416
+ return sortProjectedAtoms([
436417
+ ...atoms.flatMap((atom) => {
436418
+ const replacement = closingSlotReplacements.get(atom);
436419
+ if (replacement)
436420
+ return [replacement];
436421
+ return coveredParentEdges.has(atom) ? [] : [atom];
436422
+ }),
436423
+ ...syntheticAtoms
436424
+ ]);
436315
436425
  }
436316
436426
  function collectLiveTrackedWrapperSpans(atoms) {
436317
436427
  const spans = [];
@@ -436342,7 +436452,7 @@ function collectLiveTrackedWrapperSpans(atoms) {
436342
436452
  }
436343
436453
  let openIndex = -1;
436344
436454
  for (let index2 = openStack.length - 1;index2 >= 0; index2 -= 1) {
436345
- if (openStack[index2].kind === info.kind) {
436455
+ if (openStack[index2].kind === info.kind && openStack[index2].rsid === info.rsid) {
436346
436456
  openIndex = index2;
436347
436457
  break;
436348
436458
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.6.0-next.1",
3
+ "version": "1.6.0-next.2",
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.19.0-next.1",
27
+ "@superdoc/sdk": "2.19.0-next.2",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.22.0-next.1",
33
- "@superdoc/docx-engine": "0.21.0-next.1",
32
+ "superdoc": "2.22.0-next.2",
33
+ "@superdoc/docx-engine": "0.21.0-next.2",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",