@superdoc/mcp 1.11.0-next.7 → 1.11.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 +106 -16
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31630,7 +31630,7 @@ var init_host = __esm(() => {
31630
31630
  });
31631
31631
 
31632
31632
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31633
- var SDK_VERSION = "2.24.0-next.7";
31633
+ var SDK_VERSION = "2.24.0-next.9";
31634
31634
 
31635
31635
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31636
31636
  import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
@@ -283322,6 +283322,68 @@ async function serializeSDDocumentSessionInternalPackageToSinkAsync(session, sin
283322
283322
  }
283323
283323
  return saveSourceBackedStreamingToSink(internal, reader.partUri, sink, options);
283324
283324
  }
283325
+ function readRemoteParagraphBytes(state, storyId) {
283326
+ const index = getStoryParagraphIndexFromState(state, storyId);
283327
+ if (!index)
283328
+ return null;
283329
+ const first = index.entries[0];
283330
+ const head = first ? readPartRangeFromStateSync(state, first.partUri, 0, first.byteStart) : null;
283331
+ if (first && !head)
283332
+ return null;
283333
+ const declarations = head ? new TextDecoder().decode(head).matchAll(/xmlns(?::([A-Za-z_][\w.-]*))?="([^"]*)"/g) : [];
283334
+ const namespaceBindings = createCanonicalXmlNamespaceBindings([...declarations].map((match) => [match[1] ?? "", match[2]]));
283335
+ const paragraphs2 = new Map;
283336
+ for (const entry of index.entries) {
283337
+ const bytes = readPartRangeFromStateSync(state, entry.partUri, entry.byteStart, entry.byteEnd);
283338
+ if (!bytes)
283339
+ return null;
283340
+ const ambiguous = paragraphs2.has(entry.blockId) || index.duplicateParaIds.has(entry.blockId);
283341
+ paragraphs2.set(entry.blockId, ambiguous ? null : bytes);
283342
+ }
283343
+ return { paragraphs: paragraphs2, namespaceBindings };
283344
+ }
283345
+ function sameRemoteParagraphText(before, beforeBindings, after, afterBindings) {
283346
+ try {
283347
+ const decoder7 = new TextDecoder;
283348
+ const previous = parseParagraphInlineMap(decoder7.decode(before), beforeBindings);
283349
+ const next = parseParagraphInlineMap(decoder7.decode(after), afterBindings);
283350
+ return previous.visibleText() === next.visibleText() && previous.trackedText() === next.trackedText();
283351
+ } catch {
283352
+ return false;
283353
+ }
283354
+ }
283355
+ function listParagraphIdsInWholeBlocks(blockWindows) {
283356
+ const decoder7 = new TextDecoder;
283357
+ const blockIds = new Set;
283358
+ for (const blockWindow of blockWindows) {
283359
+ const xml = decoder7.decode(blockWindow).trim();
283360
+ const wholeBlocks = /^<w:(p|tbl|sdt)[\s>/]/.test(xml) && /(<\/w:(p|tbl|sdt)>|\/>)$/.test(xml);
283361
+ if (xml && !wholeBlocks)
283362
+ return null;
283363
+ for (const open2 of xml.matchAll(/<w:p(?=[\s>/])[^>]*>/g)) {
283364
+ const paraId = open2[0].match(/w14:paraId="([^"]+)"/)?.[1];
283365
+ if (!paraId)
283366
+ return null;
283367
+ blockIds.add(paraId);
283368
+ }
283369
+ }
283370
+ return [...blockIds];
283371
+ }
283372
+ function listChangedRemoteParagraphs(before, after) {
283373
+ const sameBytes2 = (left, right) => left.byteLength === right.byteLength && left.every((value, index) => value === right[index]);
283374
+ const changed = new Set;
283375
+ for (const [blockId, previous] of before.paragraphs) {
283376
+ const next = after.paragraphs.get(blockId);
283377
+ if (!previous || !next)
283378
+ changed.add(blockId);
283379
+ else if (!sameBytes2(previous, next) && !sameRemoteParagraphText(previous, before.namespaceBindings, next, after.namespaceBindings))
283380
+ changed.add(blockId);
283381
+ }
283382
+ for (const [blockId, next] of after.paragraphs)
283383
+ if (!next || !before.paragraphs.has(blockId))
283384
+ changed.add(blockId);
283385
+ return [...changed];
283386
+ }
283325
283387
  function applySDDocumentSessionInternalProjection(session, input) {
283326
283388
  const internal = INTERNALS.get(session);
283327
283389
  if (!internal)
@@ -283369,6 +283431,10 @@ function applySDDocumentSessionInternalProjection(session, input) {
283369
283431
  });
283370
283432
  const remoteParagraphInput = !input.packageReplaced && inventoryUnchanged && requestedChangedPartUris.size === 1 && requestedChangedStoryIds.size === 1 && textPart?.bytes === null && textPart.patches?.length === 1 && textStory?.storyKind === "main" && textStory.partUri === textPart.partUri ? { storyId: textStory.storyId, partUri: textPart.partUri, patch: textPart.patches[0] } : null;
283371
283433
  const remoteTextInput = remoteParagraphInput ? captureSDRemoteTextRenderInput(state, remoteParagraphInput.storyId, remoteParagraphInput.partUri, remoteParagraphInput.patch) : null;
283434
+ const mainStoryRemoteChange = !input.packageReplaced && inventoryUnchanged && requestedChangedPartUris.size === 1 && requestedChangedStoryIds.size === 1 && textStory?.storyKind === "main" && textStory.storyId === state.mainStoryId && textPart !== undefined && textStory.partUri === textPart.partUri ? textStory.storyId : null;
283435
+ const wholeStoryRemoteChange = mainStoryRemoteChange && textPart?.bytes ? mainStoryRemoteChange : null;
283436
+ const paragraphsBeforeRemoteChange = wholeStoryRemoteChange ? readRemoteParagraphBytes(state, wholeStoryRemoteChange) : null;
283437
+ const patchedRemoteWindows = mainStoryRemoteChange && !textPart?.bytes && textPart?.patches?.length ? textPart.patches.map((patch) => readPartRangeFromStateSync(state, textPart.partUri, patch.startByte, patch.endByte)) : null;
283372
283438
  const publishRemoteParagraph = inventoryUnchanged ? remoteParagraphCandidate : null;
283373
283439
  const publishRemoteResidentParagraph = inventoryUnchanged && remoteParagraphInput ? captureRemoteResidentParagraphPublication(state, remoteParagraphInput.storyId, remoteParagraphInput.partUri, remoteParagraphInput.patch) : null;
283374
283440
  const coverageHints = new Map;
@@ -283586,6 +283652,10 @@ function applySDDocumentSessionInternalProjection(session, input) {
283586
283652
  const remoteGeneration = (REMOTE_PROJECTION_GENERATIONS.get(session) ?? 0) + 1;
283587
283653
  REMOTE_PROJECTION_GENERATIONS.set(session, remoteGeneration);
283588
283654
  const remoteText = remoteTextInput && changedStoryIds.size === 1 && changedPartUris.size === 1 ? sealSDRemoteTextRenderInput(state, remoteTextInput) : null;
283655
+ const paragraphsAfterRemoteChange = wholeStoryRemoteChange && paragraphsBeforeRemoteChange && changedStoryIds.size === 1 && changedStoryIds.has(wholeStoryRemoteChange) && changedPartUris.size === 1 ? readRemoteParagraphBytes(state, wholeStoryRemoteChange) : null;
283656
+ const remoteChangeIsNarrow = remoteText?.classification != null;
283657
+ const remoteChangedParagraphs = wholeStoryRemoteChange && paragraphsBeforeRemoteChange && paragraphsAfterRemoteChange ? { storyId: wholeStoryRemoteChange, blockIds: listChangedRemoteParagraphs(paragraphsBeforeRemoteChange, paragraphsAfterRemoteChange) } : null;
283658
+ const patchedRemoteParagraphs = !remoteChangedParagraphs && mainStoryRemoteChange && patchedRemoteWindows && !remoteChangeIsNarrow && patchedRemoteWindows.every((blockWindow) => blockWindow !== null) && changedStoryIds.size === 1 && changedStoryIds.has(mainStoryRemoteChange) && changedPartUris.size === 1 ? listParagraphIdsInWholeBlocks([...patchedRemoteWindows, ...textPart.patches.map((patch) => patch.bytes)]) : null;
283589
283659
  return snapshotSDRenderCommitEnvelope({
283590
283660
  documentEpoch: state.documentRef.documentId,
283591
283661
  commitSequence: state.renderCommitSequence,
@@ -283610,7 +283680,8 @@ function applySDDocumentSessionInternalProjection(session, input) {
283610
283680
  ...remoteText ? { localizedBodyText: remoteText.localizedBodyText } : {}
283611
283681
  },
283612
283682
  ...remoteText ? { sourceProjectionEffect: remoteText.sourceProjectionEffect } : {},
283613
- remote: { generation: remoteGeneration }
283683
+ remote: { generation: remoteGeneration },
283684
+ ...remoteChangedParagraphs && !input.packageReplaced ? { remoteChangedParagraphs } : patchedRemoteParagraphs && mainStoryRemoteChange && !input.packageReplaced ? { remoteChangedParagraphs: { storyId: mainStoryRemoteChange, blockIds: patchedRemoteParagraphs } } : {}
283614
283685
  });
283615
283686
  }
283616
283687
  function validateSDDocumentSessionInternalPackageBytes(bytes) {
@@ -509125,6 +509196,12 @@ async function openV2CollaborativeDocumentSession(options) {
509125
509196
  }));
509126
509197
  }
509127
509198
  if (openIntent.mode === "create") {
509199
+ session = await openSourceSession(options, trace);
509200
+ await assertSourceOpenedForSeed(session, options.runtime.rootId);
509201
+ await session.waitForSourceComplete();
509202
+ trace.mark("source-complete");
509203
+ trace.sessionSnapshot("after-source-complete", session);
509204
+ await assertSourceOpenedForSeed(session, options.runtime.rootId);
509128
509205
  stopBootstrapHeartbeat = startBootstrapHeartbeat(rootConn.ydoc, bootstrapClaimerId, () => rootConn.state);
509129
509206
  }
509130
509207
  const bootstrapBytes = resolveBootstrapBytes(openIntent, options.buffer);
@@ -509164,20 +509241,15 @@ async function openV2CollaborativeDocumentSession(options) {
509164
509241
  joinedFromEmbeddedMigrationCarrier = true;
509165
509242
  joinedRoomStillMatchesInitialContent = verifyRoomInitialContentDigest(rootConn.ydoc).ok;
509166
509243
  }
509167
- session = await openSDDocumentSession({
509168
- ...options,
509169
- buffer: options.buffer,
509170
- autoStartSourceLoading: true
509171
- });
509172
- trace.mark("open-session");
509173
- trace.sessionSnapshot("after-open-session", session);
509174
- const mustCompleteSourceBeforeSeed = initialReadiness === "full-projection" || openIntent.mode === "create";
509175
- if (mustCompleteSourceBeforeSeed) {
509176
- await session.waitForSourceComplete();
509177
- trace.mark("source-complete");
509178
- trace.sessionSnapshot("after-source-complete", session);
509179
- } else {
509180
- trace.mark("source-complete-deferred");
509244
+ if (!session) {
509245
+ session = await openSourceSession(options, trace);
509246
+ if (initialReadiness === "full-projection") {
509247
+ await session.waitForSourceComplete();
509248
+ trace.mark("source-complete");
509249
+ trace.sessionSnapshot("after-source-complete", session);
509250
+ } else {
509251
+ trace.mark("source-complete-deferred");
509252
+ }
509181
509253
  }
509182
509254
  if (ownsPreparedBootstrap) {
509183
509255
  const current = readRoomManifest(rootConn.ydoc);
@@ -509435,6 +509507,24 @@ async function openV2CollaborativeDocumentSession(options) {
509435
509507
  throw error50;
509436
509508
  }
509437
509509
  }
509510
+ async function openSourceSession(options, trace) {
509511
+ const session = await openSDDocumentSession({
509512
+ ...options,
509513
+ buffer: options.buffer,
509514
+ autoStartSourceLoading: true
509515
+ });
509516
+ trace.mark("open-session");
509517
+ trace.sessionSnapshot("after-open-session", session);
509518
+ return session;
509519
+ }
509520
+ async function assertSourceOpenedForSeed(session, rootId) {
509521
+ const { readiness } = await session.getReadiness();
509522
+ if (readiness !== "failed" && readiness !== "blocked")
509523
+ return;
509524
+ const diagnostics = await session.getDiagnostics();
509525
+ const reason = diagnostics.find((diagnostic2) => diagnostic2.severity === "error")?.message ?? `readiness=${readiness}`;
509526
+ throw new CollabV2DiagnosticError(COLLAB_V2_DIAGNOSTICS.COLLAB_V2_BOOTSTRAP_SOURCE_INVALID, `document could not be opened, so the collaboration room was not created (${reason}); fix the document and create the room again`, { rootId, readiness, reason });
509527
+ }
509438
509528
  async function prepareRoomReplacement(options, operationId, expectedSourceSha256) {
509439
509529
  const provider = createSDYjsSingleDocProvider({
509440
509530
  capabilities: COLLAB_V2_CAPABILITY_MATRIX["y-websocket"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.11.0-next.7",
3
+ "version": "1.11.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.24.0-next.7",
27
+ "@superdoc/sdk": "2.24.0-next.9",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.27.0-next.7",
33
- "@superdoc/docx-engine": "0.26.0-next.7",
32
+ "superdoc": "2.27.0-next.9",
33
+ "@superdoc/docx-engine": "0.26.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",