@superdoc/mcp 1.0.0-next.4 → 1.0.0-next.6

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 +168 -7
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -349641,7 +349641,7 @@ var init_host = __esm(() => {
349641
349641
  });
349642
349642
 
349643
349643
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
349644
- var SDK_VERSION = "2.13.0-next.6";
349644
+ var SDK_VERSION = "2.13.0-next.8";
349645
349645
 
349646
349646
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
349647
349647
  import { chmodSync, existsSync } from "node:fs";
@@ -499901,6 +499901,46 @@ var init_decide_engine = __esm(() => {
499901
499901
  init_xml_sax();
499902
499902
  });
499903
499903
 
499904
+ // ../../../v2/editor-core/dist/document/transactions/tracked-changes/structural-inline-decision.js
499905
+ function hasSessionSyncStructuralInlineDeletion(xml, fragments, namespaceBindings = new Map) {
499906
+ const selectedRanges = fragments.filter((fragment2) => fragment2.kind === "del").map((fragment2) => ({ start: fragment2.byteStart, end: fragment2.byteEnd })).sort((left, right) => left.start - right.start || right.end - left.end);
499907
+ if (selectedRanges.length === 0)
499908
+ return false;
499909
+ const prefixMaxEnds = [];
499910
+ for (const range of selectedRanges) {
499911
+ prefixMaxEnds.push(Math.max(prefixMaxEnds.at(-1) ?? -1, range.end));
499912
+ }
499913
+ const isInsideSelectedDeletion = (start, end) => {
499914
+ let low = 0;
499915
+ let high = selectedRanges.length;
499916
+ while (low < high) {
499917
+ const middle = low + high >>> 1;
499918
+ if (selectedRanges[middle].start < start)
499919
+ low = middle + 1;
499920
+ else
499921
+ high = middle;
499922
+ }
499923
+ return low > 0 && prefixMaxEnds[low - 1] > end;
499924
+ };
499925
+ let matched = false;
499926
+ walkXmlElements(xml, {
499927
+ additionalNamespaces: xmlFragmentAdditionalNamespaces(xml, namespaceBindings, {
499928
+ w: NS_W,
499929
+ m: OFFICE_MATH_NAMESPACE
499930
+ }),
499931
+ onOpenTag({ tag, start, end }) {
499932
+ if (matched || !isInsideSelectedDeletion(start, end))
499933
+ return;
499934
+ matched = tag.namespaceUri === NS_W ? tag.localName === "smartTag" || tag.localName === "dir" || tag.localName === "bdo" : tag.namespaceUri === OFFICE_MATH_NAMESPACE && tag.localName === "oMath";
499935
+ }
499936
+ });
499937
+ return matched;
499938
+ }
499939
+ var OFFICE_MATH_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/math";
499940
+ var init_structural_inline_decision = __esm(() => {
499941
+ init_xml_sax();
499942
+ });
499943
+
499904
499944
  // ../../../v2/editor-core/dist/document/transactions/compile-tracked-change-decide-local.js
499905
499945
  function tryRunLocalTrackedChangeDecideCommit(input) {
499906
499946
  const { state, txId, op } = input;
@@ -500075,6 +500115,7 @@ function tryRunLocalTrackedChangeDecideCommit(input) {
500075
500115
  };
500076
500116
  })
500077
500117
  };
500118
+ const sessionSyncedTextDecision = hasSessionSyncStructuralInlineDeletion(beforeXml, decisions.map(({ localFragment }) => localFragment), new Map(Object.entries(state.mainStorySourceOverlay?.rootNamespaceBindings ?? {})));
500078
500119
  const prepared = {
500079
500120
  txId,
500080
500121
  source: op,
@@ -500107,7 +500148,8 @@ function tryRunLocalTrackedChangeDecideCommit(input) {
500107
500148
  storyLocal: true,
500108
500149
  targetBlockIds: [paragraph.blockId],
500109
500150
  atomCarrierContract: SD_DEFAULT_ATOM_CARRIER_CONTRACT,
500110
- trackedTextDecide
500151
+ trackedTextDecide,
500152
+ ...sessionSyncedTextDecision ? { sessionSync: { reason: "structural-inline-edit" } } : {}
500111
500153
  }
500112
500154
  }
500113
500155
  };
@@ -500372,6 +500414,7 @@ var init_compile_tracked_change_decide_local = __esm(() => {
500372
500414
  init_logical_catalog();
500373
500415
  init_decide_engine();
500374
500416
  init_block_deletion_text();
500417
+ init_structural_inline_decision();
500375
500418
  TD41 = new TextDecoder;
500376
500419
  TE19 = new TextEncoder;
500377
500420
  });
@@ -502640,7 +502683,7 @@ function runTrackedChangeDecideCommit(input) {
502640
502683
  fragmentsByPart,
502641
502684
  structuralTargets
502642
502685
  });
502643
- const nestedTextDecision = trackedTextDecide && hasNestedTextDecision(catalog, fragmentsByPart);
502686
+ const sessionSyncedTextDecision = trackedTextDecide && (hasNestedTextDecision(catalog, fragmentsByPart) || hasStructuralInlineDeletionDecision(state, fragmentsByPart));
502644
502687
  const prepared = {
502645
502688
  txId,
502646
502689
  source: op,
@@ -502674,7 +502717,7 @@ function runTrackedChangeDecideCommit(input) {
502674
502717
  targetBlockIds: trackedTextDecide?.targets.map((target) => target.blockId) ?? [],
502675
502718
  atomCarrierContract: SD_DEFAULT_ATOM_CARRIER_CONTRACT,
502676
502719
  ...trackedTextDecide ? { trackedTextDecide } : {},
502677
- ...nestedTextDecision ? { sessionSync: { reason: "structural-inline-edit" } } : {}
502720
+ ...sessionSyncedTextDecision ? { sessionSync: { reason: "structural-inline-edit" } } : {}
502678
502721
  }
502679
502722
  }
502680
502723
  };
@@ -503000,6 +503043,16 @@ function hasNestedTextDecision(catalog, fragmentsByPart) {
503000
503043
  }
503001
503044
  return false;
503002
503045
  }
503046
+ function hasStructuralInlineDeletionDecision(state, fragmentsByPart) {
503047
+ for (const [partUri, fragments] of fragmentsByPart) {
503048
+ const bytes = state.packageBytes.get(partUri);
503049
+ if (!bytes)
503050
+ continue;
503051
+ if (hasSessionSyncStructuralInlineDeletion(TD44.decode(bytes), fragments))
503052
+ return true;
503053
+ }
503054
+ return false;
503055
+ }
503003
503056
  function buildPreparedTrackedTextDecide(input) {
503004
503057
  if (input.op.targets.some((target) => target.partial || target.formatting || target.derivedStructural || (target.moveRangeMarkers?.ids.length ?? 0) > 0)) {
503005
503058
  return;
@@ -505495,6 +505548,7 @@ var init_compile_tracked_change_decide = __esm(() => {
505495
505548
  init_package_graph();
505496
505549
  init_decide_engine();
505497
505550
  init_block_deletion_text();
505551
+ init_structural_inline_decision();
505498
505552
  init_structural_groups();
505499
505553
  init_comment_cascade();
505500
505554
  init_exact_part_mutation_proof();
@@ -707726,6 +707780,12 @@ function createStorySurfaceExecutionBackend(options) {
707726
707780
  rejectedReason: "unsupported-context"
707727
707781
  };
707728
707782
  }
707783
+ if (options.strictMirror && !hasStrictMirrorPrerequisites(prepared, options)) {
707784
+ return {
707785
+ status: "rejected",
707786
+ rejectedReason: "internal-error"
707787
+ };
707788
+ }
707729
707789
  const undo2 = prepared.backendExtensions.storySurface?.historyReplay?.direction === "undo";
707730
707790
  const paragraphOnlyReviewStoryIds = undo2 ? null : readParagraphOnlyReviewStoryIds(options.session, prepared);
707731
707791
  const result = delegate.apply(prepared);
@@ -707844,7 +707904,39 @@ function runStorySurfaceMirror(prepared, options, admission, paragraphOnlyReview
707844
707904
  function resolvePackagePartHandoff(prepared, extension2) {
707845
707905
  const ownedStoryParts = new Set(prepared.resolvedTargets.storyPartOwnership.map((entry) => String(entry.partUri)));
707846
707906
  const touchesPackageSidecar = prepared.resolvedTargets.partUris.some((partUri) => !ownedStoryParts.has(String(partUri)));
707847
- return touchesPackageSidecar || extension2?.storyLocal === false;
707907
+ const retiresOwnedStoryPart = prepared.resolvedTargets.storyPartOwnership.some((entry) => prepared.localApplyBundle.perPart?.[String(entry.partUri)]?.kind === "remove");
707908
+ return touchesPackageSidecar || retiresOwnedStoryPart || extension2?.storyLocal === false;
707909
+ }
707910
+ function hasStrictMirrorPrerequisites(prepared, options) {
707911
+ const extension2 = prepared.backendExtensions.storySurface;
707912
+ if (!extension2)
707913
+ return false;
707914
+ if (!touchesOwnedStoryPart(prepared))
707915
+ return true;
707916
+ if (extension2.headerFooterSlotMaterialization)
707917
+ return options.session != null;
707918
+ switch (extension2.family) {
707919
+ case "storyText":
707920
+ return !extension2.historyReplay && !extension2.resyncFromSession && !extension2.sessionSync ? true : options.session != null;
707921
+ case "storyTrackedDecide":
707922
+ return !usesTrackedDecisionSessionSync(prepared, extension2) || options.session != null;
707923
+ case "storyTable":
707924
+ return true;
707925
+ case "storyBlocks":
707926
+ case "storyPaste":
707927
+ case "storyFormat":
707928
+ case "storyList":
707929
+ case "storyHyperlink":
707930
+ case "storyImage":
707931
+ case "storyAnchor":
707932
+ return options.session != null;
707933
+ case "compareApply":
707934
+ return false;
707935
+ default: {
707936
+ const exhaustive = extension2.family;
707937
+ return exhaustive;
707938
+ }
707939
+ }
707848
707940
  }
707849
707941
  function runFamilyMirror(prepared, extension2, options, directStoryText, paragraphOnlyReviewStoryIds) {
707850
707942
  if (!options.resolveStoryShard) {
@@ -707909,6 +708001,7 @@ function runFamilyMirror(prepared, extension2, options, directStoryText, paragra
707909
708001
  session: options.session,
707910
708002
  prepared,
707911
708003
  extension: extension2,
708004
+ storyIds: storyIdsRequiringShards(prepared, extension2),
707912
708005
  paragraphOnlyReviewStoryIds,
707913
708006
  resolveStoryShard: options.resolveStoryShard
707914
708007
  });
@@ -707942,6 +708035,7 @@ function runFamilyMirror(prepared, extension2, options, directStoryText, paragra
707942
708035
  session: options.session,
707943
708036
  prepared,
707944
708037
  extension: extension2,
708038
+ storyIds: storyIdsRequiringShards(prepared, extension2),
707945
708039
  resolveStoryShard: options.resolveStoryShard
707946
708040
  });
707947
708041
  return { ...sessionSync, mirrorPath: "session-sync" };
@@ -708985,7 +709079,10 @@ function storyIdsRequiringShards(prepared, extension2) {
708985
709079
  if (extension2.family === "storyText" && prepared.source.kind === "editText") {
708986
709080
  return [String(prepared.source.on.storyId)];
708987
709081
  }
708988
- return [...new Set(prepared.resolvedTargets.stories.map((storyId) => String(storyId)))];
709082
+ const retiredStoryIds = new Set(prepared.resolvedTargets.storyPartOwnership.filter((entry) => prepared.localApplyBundle.perPart?.[String(entry.partUri)]?.kind === "remove").map((entry) => String(entry.storyId)));
709083
+ return [
709084
+ ...new Set(prepared.resolvedTargets.stories.map((storyId) => String(storyId)).filter((storyId) => !retiredStoryIds.has(storyId)))
709085
+ ];
708989
709086
  }
708990
709087
  function hasSourceStoryOwnership(prepared, sourceStoryId, sourcePartUri) {
708991
709088
  const ownership = prepared.resolvedTargets.storyPartOwnership;
@@ -712131,6 +712228,11 @@ function createHeadlessCollabRoomCoordinator(options) {
712131
712228
  const usesImagePackageSync = isImageSourceKind(prepared.source.kind) || storySurfaceFamily === "storyImage";
712132
712229
  const syncedListSidecarParts = syncPreparedListSidecar(prepared.backendExtensions.packagePart?.listSidecar);
712133
712230
  const storyPartUris = new Set(prepared.resolvedTargets.storyPartOwnership.map((entry) => String(entry.partUri)));
712231
+ for (const partUri of storyPartUris) {
712232
+ if (prepared.localApplyBundle.perPart[partUri]?.kind === "remove") {
712233
+ retireStoryPart(partUri);
712234
+ }
712235
+ }
712134
712236
  const packagePartUris = Array.from(new Set(prepared.resolvedTargets.partUris.filter((partUri) => !storyPartUris.has(String(partUri)))));
712135
712237
  for (const partUri of packagePartUris) {
712136
712238
  if (syncedListSidecarParts.has(partUri))
@@ -712743,8 +712845,11 @@ function createHeadlessCollabRoomCoordinator(options) {
712743
712845
  ensurePartHandlesFromManifest(descriptor);
712744
712846
  }
712745
712847
  ensureStoryHandlesFromManifest();
712746
- if (replacingPackage)
712848
+ if (replacingPackage) {
712747
712849
  reconcileReplacementStories();
712850
+ } else {
712851
+ pruneStoryHandlesMissingFromManifest();
712852
+ }
712748
712853
  pruneProjectionHandlesMissingFromManifest(activeProjectionShardIdsFromManifest(descriptors), replacingPackage);
712749
712854
  } finally {
712750
712855
  syncingManifest = false;
@@ -712835,6 +712940,34 @@ function createHeadlessCollabRoomCoordinator(options) {
712835
712940
  notifyRegistryChangedIfActive();
712836
712941
  }
712837
712942
  }
712943
+ function pruneStoryHandlesMissingFromManifest() {
712944
+ const snapshot3 = readRoomManifest(options.rootDoc).snapshot;
712945
+ if (!snapshot3)
712946
+ return;
712947
+ const active = new Set(snapshot3.shards.filter((descriptor) => descriptor.shardKind === SHARD_KIND.story).map((descriptor) => descriptor.shardId));
712948
+ let changed = false;
712949
+ for (const [storyId, info] of storyInfos) {
712950
+ if (active.has(info.shardId))
712951
+ continue;
712952
+ storyInfos.delete(storyId);
712953
+ changed = true;
712954
+ }
712955
+ for (const [storyId, handle] of options.graph.storyHandlesByStoryId) {
712956
+ if (active.has(handle.shardId))
712957
+ continue;
712958
+ options.graph.storyHandlesByStoryId.delete(storyId);
712959
+ changed = true;
712960
+ }
712961
+ for (const shardId of options.graph.storyHandles.keys()) {
712962
+ if (active.has(shardId))
712963
+ continue;
712964
+ options.graph.storyHandles.delete(shardId);
712965
+ options.graph.requiredShardIds.delete(shardId);
712966
+ changed = true;
712967
+ }
712968
+ if (changed)
712969
+ notifyRegistryChangedIfActive();
712970
+ }
712838
712971
  function syncHeaderFooterMaterialization(prepared) {
712839
712972
  const proof = prepared.backendExtensions.storySurface?.headerFooterSlotMaterialization;
712840
712973
  if (!proof)
@@ -714550,6 +714683,34 @@ function createHeadlessCollabRoomCoordinator(options) {
714550
714683
  options.graph.requiredShardIds.delete(shardId);
714551
714684
  options.onRegistryChanged();
714552
714685
  }
714686
+ function retireStoryPart(partUri) {
714687
+ const partKey = encodeLogicalOwnerKey(partUri);
714688
+ const shardIds = new Set([...storyInfos.values()].filter((info) => info.partUri === partUri).map((info) => info.shardId));
714689
+ const snapshot3 = readRoomManifest(options.rootDoc).snapshot;
714690
+ for (const descriptor of snapshot3?.shards ?? []) {
714691
+ if (descriptor.shardKind === SHARD_KIND.story && descriptor.story?.sourcePartKey === partKey) {
714692
+ shardIds.add(descriptor.shardId);
714693
+ }
714694
+ }
714695
+ options.rootDoc.transact(() => {
714696
+ getPackagePartsMap(options.rootDoc).delete(partKey);
714697
+ for (const shardId of shardIds)
714698
+ deleteShardDescriptor(options.rootDoc, shardId);
714699
+ }, "headless:collab-v2:manifest-retire-story");
714700
+ for (const [storyId, info] of storyInfos) {
714701
+ if (info.partUri === partUri)
714702
+ storyInfos.delete(storyId);
714703
+ }
714704
+ for (const [storyId, handle] of options.graph.storyHandlesByStoryId) {
714705
+ if (shardIds.has(handle.shardId))
714706
+ options.graph.storyHandlesByStoryId.delete(storyId);
714707
+ }
714708
+ for (const shardId of shardIds) {
714709
+ options.graph.storyHandles.delete(shardId);
714710
+ options.graph.requiredShardIds.delete(shardId);
714711
+ }
714712
+ options.onRegistryChanged();
714713
+ }
714553
714714
  function retireCommentsFamilyPart(partUri) {
714554
714715
  if (partUri === COMMENTS_PART_URI4 && options.graph.commentsHandle) {
714555
714716
  resetPackagePartPayload(collabUnitTargetOrDoc(options.graph.commentsHandle));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.0.0-next.4",
3
+ "version": "1.0.0-next.6",
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.13.0-next.6",
27
+ "@superdoc/sdk": "2.13.0-next.8",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.16.0-next.5",
33
- "@superdoc/docx-engine": "0.15.0-next.5",
32
+ "superdoc": "2.16.0-next.6",
33
+ "@superdoc/docx-engine": "0.15.0-next.6",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",