@superdoc/mcp 1.4.0-next.2 → 1.4.0-next.4

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 +58 -2
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31330,7 +31330,7 @@ var init_host = __esm(() => {
31330
31330
  });
31331
31331
 
31332
31332
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31333
- var SDK_VERSION = "2.17.0-next.2";
31333
+ var SDK_VERSION = "2.17.0-next.4";
31334
31334
 
31335
31335
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31336
31336
  import { chmodSync, existsSync } from "node:fs";
@@ -272984,6 +272984,13 @@ var init_source = __esm(() => {
272984
272984
  };
272985
272985
  }));
272986
272986
  V2_ONLY_ADAPTER_METHODS = Object.freeze([
272987
+ {
272988
+ method: "createDocumentApi(host.adapter).fields.contextAtPosition",
272989
+ stability: "internal",
272990
+ workerWired: true,
272991
+ relatedV1Operation: null,
272992
+ rationale: "Resolve a clicked field result to its canonical address and rebuild availability for the context menu."
272993
+ },
272987
272994
  {
272988
272995
  method: "createDocumentApi(host.adapter).format.readEffectiveInlineUniformity",
272989
272996
  stability: "internal",
@@ -287507,6 +287514,17 @@ function readDescriptorXml(context, entry) {
287507
287514
  return null;
287508
287515
  return TD81.decode(bytes.subarray(entry.descriptor.byteStart, entry.descriptor.byteEnd));
287509
287516
  }
287517
+ function buildFieldTextResultXml(context, entry, text) {
287518
+ if (!entry.descriptor.complete)
287519
+ return null;
287520
+ const bytes = readPartBytes2(context, entry.partUri);
287521
+ if (!bytes)
287522
+ return null;
287523
+ const { byteStart, byteEnd, resultByteStart, resultByteEnd } = entry.descriptor;
287524
+ if (resultByteStart < byteStart || resultByteEnd > byteEnd || resultByteStart > resultByteEnd)
287525
+ return null;
287526
+ return TD81.decode(bytes.subarray(byteStart, resultByteStart)) + buildTextRunXml(text) + TD81.decode(bytes.subarray(resultByteEnd, byteEnd));
287527
+ }
287510
287528
  function buildSimpleFieldXml(instruction, resultText) {
287511
287529
  return `<w:fldSimple w:instr="${xmlEscapeAttr(instruction)}">` + buildTextRunXml(resultText) + "</w:fldSimple>";
287512
287530
  }
@@ -342647,6 +342665,43 @@ class V2FieldsAdapter {
342647
342665
  this.context = context;
342648
342666
  this.scalarSnapshot = scalarSnapshot;
342649
342667
  }
342668
+ contextAtPosition(input) {
342669
+ throwProjectionReadFailure(this.context, "fields.contextAtPosition");
342670
+ if (!input || !input.story || !Number.isInteger(input.offset) || input.offset < 0 || !input.blockId)
342671
+ return null;
342672
+ const story = this.context.resolveFullStoryLocator(input.story);
342673
+ if ("error" in story)
342674
+ return null;
342675
+ const entries = listCanonicalFieldEntries(this.context).filter((entry2) => {
342676
+ const bounds = story.storyByteRange;
342677
+ return entry2.storyId === story.storyId && entry2.blockId === input.blockId && (!bounds || entry2.descriptor.byteStart >= bounds[0] && entry2.descriptor.byteEnd <= bounds[1]);
342678
+ });
342679
+ const reference = input.reference;
342680
+ if (reference && (typeof reference.instruction !== "string" || typeof reference.empty !== "boolean"))
342681
+ return null;
342682
+ const candidates = entries.flatMap((entry2) => {
342683
+ if (reference && (entry2.descriptor.instructionText.trim() !== reference.instruction.trim() || !["REF", "NOTEREF", "STYLEREF"].includes(instructionKeyword(entry2.descriptor.instructionText))))
342684
+ return [];
342685
+ const anchor = resolveCanonicalFieldResultAnchor(this.context, entry2);
342686
+ if (!anchor)
342687
+ return [];
342688
+ const contains = reference?.empty ? anchor.start === anchor.end && input.offset === anchor.start : input.offset >= anchor.start && input.offset < anchor.end;
342689
+ return contains ? [{ entry: entry2, width: anchor.end - anchor.start }] : [];
342690
+ });
342691
+ candidates.sort((a, b) => a.width - b.width);
342692
+ if (reference?.empty && candidates.length !== 1)
342693
+ return null;
342694
+ const entry = candidates[0]?.entry;
342695
+ if (!entry)
342696
+ return null;
342697
+ const keyword = instructionKeyword(entry.descriptor.instructionText);
342698
+ if (keyword === "TOC")
342699
+ return null;
342700
+ return {
342701
+ target: projectFieldAddress(entry),
342702
+ canRebuild: entry.descriptor.complete && !entry.descriptor.locked && (isScalarField(keyword) || SIMPLE_RESULT_COMPLEX_FIELD_KEYWORDS.has(keyword) || entry.descriptor.kind === "simple" && ["INDEX", "TOA", "CITATION", "BIBLIOGRAPHY", "TC", "XE", "TA"].includes(keyword))
342703
+ };
342704
+ }
342650
342705
  list(query3) {
342651
342706
  throwProjectionReadFailure(this.context, "fields.list");
342652
342707
  const publicEntries = filterFields(listCanonicalFieldEntries(this.context), query3);
@@ -342883,7 +342938,7 @@ class V2FieldsAdapter {
342883
342938
  }
342884
342939
  if (options?.dryRun)
342885
342940
  return { success: true, field: input.target };
342886
- const committed = keyword === "TOC" ? replaceTocXml(this.context, entry, entry.descriptor.instructionText, "fields-rebuild") : replaceFieldXml(this.context, entry, scalarXml ?? buildComplexFieldTextXml(entry.descriptor.instructionText, nextResult, {
342941
+ const committed = keyword === "TOC" ? replaceTocXml(this.context, entry, entry.descriptor.instructionText, "fields-rebuild") : replaceFieldXml(this.context, entry, scalarXml ?? (["REF", "NOTEREF", "STYLEREF"].includes(keyword) ? buildFieldTextResultXml(this.context, entry, nextResult) : null) ?? buildComplexFieldTextXml(entry.descriptor.instructionText, nextResult, {
342887
342942
  preserveSpace: PAGE_NUMBER_FIELD_KEYWORDS.has(keyword) || entry.descriptor.kind === "simple" && /\\r\b/i.test(entry.descriptor.instructionText) && !/\s/.test(nextResult)
342888
342943
  }), "fields-rebuild");
342889
342944
  if (!committed.ok)
@@ -432726,6 +432781,7 @@ var init_freshness = __esm(() => {
432726
432781
  "hyperlinks.get",
432727
432782
  "fields.list",
432728
432783
  "fields.get",
432784
+ "fields.contextAtPosition",
432729
432785
  "images.list",
432730
432786
  "comments.list",
432731
432787
  "comments.get",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.4.0-next.2",
3
+ "version": "1.4.0-next.4",
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.17.0-next.2",
27
+ "@superdoc/sdk": "2.17.0-next.4",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.20.0-next.3",
33
- "@superdoc/docx-engine": "0.19.0-next.3",
32
+ "superdoc": "2.20.0-next.5",
33
+ "@superdoc/docx-engine": "0.19.0-next.5",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",