@beyondwork/docx-react-component 1.0.136 → 1.0.137

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 (56) hide show
  1. package/dist/api/public-types.d.cts +1 -1
  2. package/dist/api/public-types.d.ts +1 -1
  3. package/dist/api/v3.cjs +645 -21
  4. package/dist/api/v3.d.cts +2 -2
  5. package/dist/api/v3.d.ts +2 -2
  6. package/dist/api/v3.js +2 -2
  7. package/dist/{chunk-NX7W6T7L.js → chunk-M3AEVSKU.js} +626 -21
  8. package/dist/{chunk-HUWZ7AHE.js → chunk-NYIMPM3Z.js} +20 -1
  9. package/dist/{chunk-JZZKTL7K.js → chunk-SMBDQV73.js} +141 -80
  10. package/dist/core/commands/formatting-commands.d.cts +1 -1
  11. package/dist/core/commands/formatting-commands.d.ts +1 -1
  12. package/dist/core/commands/image-commands.d.cts +1 -1
  13. package/dist/core/commands/image-commands.d.ts +1 -1
  14. package/dist/core/commands/section-layout-commands.d.cts +1 -1
  15. package/dist/core/commands/section-layout-commands.d.ts +1 -1
  16. package/dist/core/commands/style-commands.d.cts +1 -1
  17. package/dist/core/commands/style-commands.d.ts +1 -1
  18. package/dist/core/commands/table-structure-commands.d.cts +1 -1
  19. package/dist/core/commands/table-structure-commands.d.ts +1 -1
  20. package/dist/core/commands/text-commands.d.cts +1 -1
  21. package/dist/core/commands/text-commands.d.ts +1 -1
  22. package/dist/core/selection/mapping.d.cts +1 -1
  23. package/dist/core/selection/mapping.d.ts +1 -1
  24. package/dist/core/state/editor-state.d.cts +1 -1
  25. package/dist/core/state/editor-state.d.ts +1 -1
  26. package/dist/index.cjs +808 -111
  27. package/dist/index.d.cts +4 -4
  28. package/dist/index.d.ts +4 -4
  29. package/dist/index.js +26 -14
  30. package/dist/io/docx-session.d.cts +3 -3
  31. package/dist/io/docx-session.d.ts +3 -3
  32. package/dist/{loader-Cr35kVUi.d.cts → loader-BB7tRkY2.d.cts} +2 -2
  33. package/dist/{loader-uGY6nDZP.d.ts → loader-DGPbaboy.d.ts} +2 -2
  34. package/dist/{public-types-CSSH2Whc.d.cts → public-types-CIvw1GQa.d.cts} +126 -1
  35. package/dist/{public-types-8kVIB5HW.d.ts → public-types-COCDrgVX.d.ts} +126 -1
  36. package/dist/public-types.d.cts +1 -1
  37. package/dist/public-types.d.ts +1 -1
  38. package/dist/runtime/collab.d.cts +2 -2
  39. package/dist/runtime/collab.d.ts +2 -2
  40. package/dist/runtime/document-runtime.cjs +160 -80
  41. package/dist/runtime/document-runtime.d.cts +1 -1
  42. package/dist/runtime/document-runtime.d.ts +1 -1
  43. package/dist/runtime/document-runtime.js +2 -2
  44. package/dist/{session-Beg8ihOi.d.cts → session-CVU-rtCd.d.cts} +2 -2
  45. package/dist/{session-Dgp-2uYw.d.ts → session-DOqy1-Lf.d.ts} +2 -2
  46. package/dist/session.d.cts +4 -4
  47. package/dist/session.d.ts +4 -4
  48. package/dist/tailwind.d.cts +1 -1
  49. package/dist/tailwind.d.ts +1 -1
  50. package/dist/{types-Cin_abw3.d.ts → types-CB_tOnVp.d.ts} +1 -1
  51. package/dist/{types-qsS39ZkQ.d.cts → types-CZAll7OS.d.cts} +1 -1
  52. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +2 -2
  53. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +2 -2
  54. package/dist/ui-tailwind.d.cts +2 -2
  55. package/dist/ui-tailwind.d.ts +2 -2
  56. package/package.json +1 -1
package/dist/api/v3.cjs CHANGED
@@ -40307,13 +40307,32 @@ function storyKeyFromHandle(handle) {
40307
40307
  function textLeafEditableTargetHint(entry, semanticBlockRange) {
40308
40308
  const storyKey = storyKeyFromHandle(entry.handle);
40309
40309
  if (!storyKey) return void 0;
40310
+ const semanticBlockPath = textLeafBlockPathFromSemanticPath(entry.handle.semanticPath, storyKey);
40310
40311
  return {
40311
40312
  kind: "text-leaf",
40312
40313
  storyKey,
40313
- blockPath: `${storyKey}/block[${entry.blockIndex}]`,
40314
+ blockPath: semanticBlockPath ?? `${storyKey}/block[${entry.blockIndex}]`,
40314
40315
  semanticBlockRange
40315
40316
  };
40316
40317
  }
40318
+ function textLeafBlockPathFromSemanticPath(semanticPath, storyKey) {
40319
+ if (!semanticPath) return null;
40320
+ const tableIndex = semanticPath.indexOf("table");
40321
+ const rowIndex = semanticPath.indexOf("row", tableIndex + 1);
40322
+ const cellIndex = semanticPath.indexOf("cell", rowIndex + 1);
40323
+ const paragraphIndex = semanticPath.indexOf("paragraph", cellIndex + 1);
40324
+ if (tableIndex < 0 || rowIndex < 0 || cellIndex < 0 || paragraphIndex < 0) {
40325
+ return null;
40326
+ }
40327
+ const table = Number(semanticPath[tableIndex + 1]);
40328
+ const row = Number(semanticPath[rowIndex + 1]);
40329
+ const cell = Number(semanticPath[cellIndex + 1]);
40330
+ const paragraph = Number(semanticPath[paragraphIndex + 1]);
40331
+ if (!Number.isInteger(table) || !Number.isInteger(row) || !Number.isInteger(cell) || !Number.isInteger(paragraph)) {
40332
+ return null;
40333
+ }
40334
+ return `${storyKey}/block[${table}]/row[${row}]/cell[${cell}]/block[${paragraph}]`;
40335
+ }
40317
40336
  function compileParagraphReplacement(entry, proposed, options) {
40318
40337
  if (proposed.operation !== "replace" && proposed.operation !== "insert-before" && proposed.operation !== "insert-after") {
40319
40338
  return null;
@@ -47610,6 +47629,29 @@ var createScopeFromAnchorMetadata = {
47610
47629
  broadcastsVia: "crdt",
47611
47630
  rwdReference: "\xA7Runtime API \xA7 runtime.workflow.createScopeFromAnchor. Companion to createScope({blockId}) for sub-block ranges. Consumes from/to once to plant inline scope_marker_start/end; the returned scopeId is the durable reference (KI-P9)."
47612
47631
  };
47632
+ var createScopesMetadata = {
47633
+ name: "runtime.workflow.createScopes",
47634
+ status: "live-with-adapter",
47635
+ sourceLayer: "workflow-review",
47636
+ liveEvidence: {
47637
+ runnerTest: "test/api/v3/workflow-create-scope-live.test.ts",
47638
+ commit: "pending"
47639
+ },
47640
+ uxIntent: {
47641
+ uiVisible: true,
47642
+ expectsUxResponse: "scope-created",
47643
+ expectedDelta: "rail shows new scope chips; editor surface refreshes once after the bulk scope batch"
47644
+ },
47645
+ agentMetadata: {
47646
+ readOrMutate: "mutate",
47647
+ boundedScope: "selection",
47648
+ auditCategory: "scope-creation"
47649
+ },
47650
+ stateClass: "A-canonical",
47651
+ persistsTo: "customXml",
47652
+ broadcastsVia: "crdt",
47653
+ rwdReference: "\xA7Runtime API \xA7 runtime.workflow.createScopes. Bulk companion to createScope/createScopeFromAnchor; resolves blockId/range inputs, plants marker-backed scopes via one runtime addScopes batch, and returns per-item results."
47654
+ };
47613
47655
  var setScopeGuardPolicyMetadata = {
47614
47656
  name: "runtime.workflow.setScopeGuardPolicy",
47615
47657
  status: "live",
@@ -47705,6 +47747,228 @@ var setMarkupModePolicyMetadata = {
47705
47747
  broadcastsVia: "crdt",
47706
47748
  rwdReference: "\xA7Runtime API \xA7 runtime.workflow.setMarkupModePolicy"
47707
47749
  };
47750
+ function isAnchorScopeInput(input) {
47751
+ return "anchor" in input;
47752
+ }
47753
+ function normalizeCreateScopesAnchor(anchor) {
47754
+ const candidate = anchor;
47755
+ const activeRange = candidate.activeRange;
47756
+ if (activeRange?.kind === "range") {
47757
+ return {
47758
+ from: activeRange.from,
47759
+ to: activeRange.to,
47760
+ storyTarget: candidate.storyTarget
47761
+ };
47762
+ }
47763
+ if (candidate.kind === "range") {
47764
+ return {
47765
+ from: candidate.from ?? Number.NaN,
47766
+ to: candidate.to ?? Number.NaN,
47767
+ storyTarget: candidate.storyTarget
47768
+ };
47769
+ }
47770
+ return {
47771
+ from: candidate.from ?? Number.NaN,
47772
+ to: candidate.to ?? Number.NaN,
47773
+ storyTarget: candidate.storyTarget
47774
+ };
47775
+ }
47776
+ function stableRefMetadataFields(stableRefHint) {
47777
+ if (stableRefHint === void 0) return void 0;
47778
+ return [{
47779
+ key: "stableRefHint",
47780
+ valueType: "string",
47781
+ value: stableRefHint
47782
+ }];
47783
+ }
47784
+ function createRangeInvalidResult(inputIndex, reason, from, to, storyLength, detail) {
47785
+ const base = {
47786
+ inputIndex,
47787
+ scopeId: "",
47788
+ status: "range-invalid",
47789
+ reason,
47790
+ from,
47791
+ to,
47792
+ storyLength,
47793
+ ...detail?.blockIndex !== void 0 ? { blockIndex: detail.blockIndex } : {},
47794
+ ...detail?.blockKind !== void 0 ? { blockKind: detail.blockKind } : {}
47795
+ };
47796
+ switch (reason) {
47797
+ case "non-finite-range":
47798
+ return {
47799
+ ...base,
47800
+ message: `createScopes requires finite numeric from/to values (received from=${from}, to=${to}). Pass selection.activeRange or an object shaped as {from, to}.`,
47801
+ nextStep: "pass-selection-activeRange-or-finite-from-to"
47802
+ };
47803
+ case "from-negative":
47804
+ return {
47805
+ ...base,
47806
+ message: `createScopes requires from >= 0 (received from=${from}). Clamp negative values to 0 before calling.`,
47807
+ nextStep: "clamp-from-to-zero"
47808
+ };
47809
+ case "to-less-than-from":
47810
+ return {
47811
+ ...base,
47812
+ message: `createScopes requires to >= from (received from=${from}, to=${to}). Swap the two values before calling.`,
47813
+ nextStep: "swap-from-and-to"
47814
+ };
47815
+ case "range-exceeds-story-length":
47816
+ return {
47817
+ ...base,
47818
+ message: `createScopes requires to <= storyLength (received to=${to}, storyLength=${storyLength}). Re-derive positions from the current document and retry.`,
47819
+ nextStep: "clamp-to-to-storyLength-or-pick-a-different-range"
47820
+ };
47821
+ case "non-paragraph-target":
47822
+ return {
47823
+ ...base,
47824
+ message: `createScopes refused range [${from}, ${to}]: it targets a ${detail?.blockKind ?? "non-paragraph"} block. Pick a paragraph target or use a structural workflow scope.`,
47825
+ nextStep: "pick-a-paragraph-target"
47826
+ };
47827
+ case "empty-document":
47828
+ return {
47829
+ ...base,
47830
+ message: "createScopes refused: the target document has no blocks; initialize a document before creating scopes.",
47831
+ nextStep: "initialize-document-before-creating-scopes"
47832
+ };
47833
+ }
47834
+ }
47835
+ function plantFailureToCreateScopesResult(pending, result) {
47836
+ const status = result.plantStatus;
47837
+ if (!status || status.planted !== false) {
47838
+ return {
47839
+ inputIndex: pending.inputIndex,
47840
+ status: "created",
47841
+ scopeId: result.scopeId
47842
+ };
47843
+ }
47844
+ if (status.reason === "non-paragraph-target") {
47845
+ return createRangeInvalidResult(
47846
+ pending.inputIndex,
47847
+ "non-paragraph-target",
47848
+ pending.from,
47849
+ pending.to,
47850
+ status.storyLength ?? pending.storyLength,
47851
+ {
47852
+ blockIndex: status.blockIndex ?? -1,
47853
+ blockKind: status.blockKind ?? "unknown"
47854
+ }
47855
+ );
47856
+ }
47857
+ if (status.reason === "range-out-of-bounds") {
47858
+ return createRangeInvalidResult(
47859
+ pending.inputIndex,
47860
+ "range-exceeds-story-length",
47861
+ pending.from,
47862
+ pending.to,
47863
+ status.storyLength ?? pending.storyLength
47864
+ );
47865
+ }
47866
+ return createRangeInvalidResult(
47867
+ pending.inputIndex,
47868
+ "empty-document",
47869
+ pending.from,
47870
+ pending.to,
47871
+ status.storyLength ?? pending.storyLength
47872
+ );
47873
+ }
47874
+ function createScopesBulk(runtime, input) {
47875
+ const doc = runtime.getCanonicalDocument();
47876
+ const storyLength = runtime.getRenderSnapshot().surface?.storySize ?? 0;
47877
+ const results = [];
47878
+ const pending = [];
47879
+ input.scopes.forEach((item, inputIndex) => {
47880
+ const assoc = item.assoc ?? { start: 1, end: -1 };
47881
+ const scopeMetadataFields = stableRefMetadataFields(item.stableRefHint);
47882
+ if (isAnchorScopeInput(item)) {
47883
+ const normalizedAnchor = normalizeCreateScopesAnchor(item.anchor);
47884
+ const { from, to } = normalizedAnchor;
47885
+ const itemStoryLength = normalizedAnchor.storyTarget?.kind === void 0 || normalizedAnchor.storyTarget.kind === "main" ? storyLength : Number.MAX_SAFE_INTEGER;
47886
+ if (!Number.isFinite(from) || !Number.isFinite(to)) {
47887
+ results.push(createRangeInvalidResult(inputIndex, "non-finite-range", from, to, itemStoryLength));
47888
+ return;
47889
+ }
47890
+ if (from < 0) {
47891
+ results.push(createRangeInvalidResult(inputIndex, "from-negative", from, to, itemStoryLength));
47892
+ return;
47893
+ }
47894
+ if (to < from) {
47895
+ results.push(createRangeInvalidResult(inputIndex, "to-less-than-from", from, to, itemStoryLength));
47896
+ return;
47897
+ }
47898
+ if (to > itemStoryLength) {
47899
+ results.push(createRangeInvalidResult(inputIndex, "range-exceeds-story-length", from, to, itemStoryLength));
47900
+ return;
47901
+ }
47902
+ const anchor2 = {
47903
+ kind: "range",
47904
+ from,
47905
+ to,
47906
+ assoc
47907
+ };
47908
+ pending.push({
47909
+ inputIndex,
47910
+ request: {
47911
+ anchor: anchor2,
47912
+ scopeId: item.scopeId,
47913
+ mode: item.mode,
47914
+ persistence: item.persistence,
47915
+ metadata: item.metadata,
47916
+ label: item.label,
47917
+ storyTarget: normalizedAnchor.storyTarget ?? { kind: "main" },
47918
+ ...item.visibility ? { visibility: item.visibility } : {},
47919
+ ...item.guardPolicy ? { guardPolicy: item.guardPolicy } : {},
47920
+ ...scopeMetadataFields ? { scopeMetadataFields } : {}
47921
+ },
47922
+ from,
47923
+ to,
47924
+ storyLength: itemStoryLength
47925
+ });
47926
+ return;
47927
+ }
47928
+ const anchor = resolveBlockAnchorFromCanonical(doc, item.blockId, assoc);
47929
+ if (!anchor || anchor.kind !== "range") {
47930
+ results.push({
47931
+ inputIndex,
47932
+ scopeId: "",
47933
+ status: "block-not-found"
47934
+ });
47935
+ return;
47936
+ }
47937
+ pending.push({
47938
+ inputIndex,
47939
+ request: {
47940
+ anchor,
47941
+ scopeId: item.scopeId,
47942
+ mode: item.mode,
47943
+ persistence: item.persistence,
47944
+ metadata: item.metadata,
47945
+ label: item.label,
47946
+ ...item.visibility ? { visibility: item.visibility } : {},
47947
+ ...item.guardPolicy ? { guardPolicy: item.guardPolicy } : {},
47948
+ ...scopeMetadataFields ? { scopeMetadataFields } : {}
47949
+ },
47950
+ from: anchor.from,
47951
+ to: anchor.to,
47952
+ storyLength
47953
+ });
47954
+ });
47955
+ const created = runtime.addScopes(pending.map((item) => item.request));
47956
+ created.forEach((result, index) => {
47957
+ const item = pending[index];
47958
+ if (!item) return;
47959
+ results.push(plantFailureToCreateScopesResult(item, result));
47960
+ });
47961
+ const sorted = results.sort((a, b) => a.inputIndex - b.inputIndex);
47962
+ const createdCount = sorted.filter((item) => item.status === "created").length;
47963
+ const blocked2 = sorted.length - createdCount;
47964
+ return {
47965
+ status: blocked2 === 0 ? "created" : createdCount > 0 ? "partial" : "blocked",
47966
+ total: input.scopes.length,
47967
+ created: createdCount,
47968
+ blocked: blocked2,
47969
+ scopes: Object.freeze(sorted)
47970
+ };
47971
+ }
47708
47972
  function createWorkflowFamily(runtime) {
47709
47973
  return {
47710
47974
  queryScopes(filter) {
@@ -47719,7 +47983,10 @@ function createWorkflowFamily(runtime) {
47719
47983
  createScope(input) {
47720
47984
  const adapterResult = createScopeFromBlockId(runtime, {
47721
47985
  blockId: input.blockId,
47986
+ scopeId: input.scopeId,
47722
47987
  mode: input.mode,
47988
+ persistence: input.persistence,
47989
+ metadata: input.metadata,
47723
47990
  label: input.label,
47724
47991
  ...input.visibility ? { visibility: input.visibility } : {},
47725
47992
  ...input.guardPolicy ? { guardPolicy: input.guardPolicy } : {},
@@ -47753,6 +48020,25 @@ function createWorkflowFamily(runtime) {
47753
48020
  }
47754
48021
  return { scopeId: adapterResult.scopeId, status: "created" };
47755
48022
  },
48023
+ createScopes(input) {
48024
+ const result = createScopesBulk(runtime, input);
48025
+ emitUxResponse(runtime, {
48026
+ apiFn: createScopesMetadata.name,
48027
+ intent: createScopesMetadata.uxIntent.expectedDelta ?? "",
48028
+ mockOrLive: "live",
48029
+ uiVisible: true,
48030
+ expectedDelta: createScopesMetadata.uxIntent.expectedDelta,
48031
+ actualDelta: result.created > 0 ? {
48032
+ kind: "inline-change",
48033
+ payload: {
48034
+ created: result.created,
48035
+ blocked: result.blocked,
48036
+ scopeIds: result.scopes.filter((scope) => scope.status === "created").map((scope) => scope.scopeId)
48037
+ }
48038
+ } : void 0
48039
+ });
48040
+ return result;
48041
+ },
47756
48042
  getScopeGuardPolicy(scopeId) {
47757
48043
  return runtime.getScopeGuardPolicy(scopeId);
47758
48044
  },
@@ -47788,7 +48074,10 @@ function createWorkflowFamily(runtime) {
47788
48074
  createScopeFromAnchor(input) {
47789
48075
  const adapterResult = createScopeFromAnchor(runtime, {
47790
48076
  anchor: input.anchor,
48077
+ scopeId: input.scopeId,
47791
48078
  mode: input.mode,
48079
+ persistence: input.persistence,
48080
+ metadata: input.metadata,
47792
48081
  label: input.label,
47793
48082
  ...input.visibility ? { visibility: input.visibility } : {},
47794
48083
  ...input.guardPolicy ? { guardPolicy: input.guardPolicy } : {},
@@ -57199,6 +57488,12 @@ function createListsFamily(runtime) {
57199
57488
  const resolved = resolveCurrentListTarget(runtime.getCanonicalDocument(), input);
57200
57489
  return resolved.kind === "resolved" ? toReadback(runtime.getCanonicalDocument(), resolved.target, resolved.paragraph) : null;
57201
57490
  },
57491
+ canJoin(input) {
57492
+ return sequencePreflight(runtime.getCanonicalDocument(), input, activeStoryKey(runtime));
57493
+ },
57494
+ canContinuePrevious(input) {
57495
+ return sequencePreflight(runtime.getCanonicalDocument(), input, activeStoryKey(runtime));
57496
+ },
57202
57497
  previewCommand(input) {
57203
57498
  return previewListCommand(runtime.getCanonicalDocument(), input, activeStoryKey(runtime));
57204
57499
  },
@@ -57263,6 +57558,37 @@ function createListsFamily(runtime) {
57263
57558
  }
57264
57559
  };
57265
57560
  }
57561
+ function sequencePreflight(document2, input, activeStoryKey2) {
57562
+ const resolved = resolveCurrentListTarget(document2, input);
57563
+ if (resolved.kind !== "resolved") {
57564
+ return {
57565
+ canJoin: false,
57566
+ canContinuePrevious: false,
57567
+ blockers: [resolved.blocker]
57568
+ };
57569
+ }
57570
+ const target = toReadback(document2, resolved.target, resolved.paragraph);
57571
+ const targetRef = { targetKey: target.targetKey, addressKey: target.addressKey };
57572
+ if (activeStoryKey2 !== void 0 && target.storyKey !== activeStoryKey2) {
57573
+ return {
57574
+ target,
57575
+ canJoin: false,
57576
+ canContinuePrevious: false,
57577
+ blockers: [{
57578
+ code: "list-target-wrong-story",
57579
+ ownerLayer: "L07",
57580
+ message: "List target does not belong to the runtime active story.",
57581
+ ...targetRef
57582
+ }]
57583
+ };
57584
+ }
57585
+ return {
57586
+ target,
57587
+ canJoin: canJoinPreviousSequence(document2, resolved.paragraphIndex),
57588
+ canContinuePrevious: canContinuePreviousSequence(document2, resolved.paragraphIndex),
57589
+ blockers: []
57590
+ };
57591
+ }
57266
57592
  function previewListCommand(document2, input, activeStoryKey2) {
57267
57593
  const resolved = resolveCurrentListTarget(document2, input);
57268
57594
  if (resolved.kind !== "resolved") {
@@ -57454,7 +57780,7 @@ function collectParagraphEntriesInto(blocks, storyKey, basePath, out) {
57454
57780
  const blockPath = `${basePath}/block[${blockIndex}]`;
57455
57781
  switch (block.type) {
57456
57782
  case "paragraph":
57457
- out.push({ paragraph: block, storyKey, blockPath });
57783
+ out.push({ paragraph: block, storyKey, blockPath, containerPath: basePath });
57458
57784
  break;
57459
57785
  case "table":
57460
57786
  for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
@@ -57526,6 +57852,7 @@ function canContinuePreviousSequence(document2, paragraphIndex) {
57526
57852
  for (let index = paragraphIndex - 1; index >= 0; index -= 1) {
57527
57853
  const previousEntry = paragraphs[index];
57528
57854
  if (previousEntry?.storyKey !== currentEntry.storyKey) break;
57855
+ if (previousEntry.containerPath !== currentEntry.containerPath) break;
57529
57856
  const previous = previousEntry.paragraph;
57530
57857
  if (!previous?.numbering) continue;
57531
57858
  const previousKind = getListKind(document2.numbering, previous.numbering.numberingInstanceId);
@@ -57538,6 +57865,7 @@ function canJoinPreviousSequence(document2, paragraphIndex) {
57538
57865
  const currentEntry = paragraphs[paragraphIndex];
57539
57866
  const previousEntry = paragraphs[paragraphIndex - 1];
57540
57867
  if (previousEntry?.storyKey !== currentEntry?.storyKey) return false;
57868
+ if (previousEntry?.containerPath !== currentEntry?.containerPath) return false;
57541
57869
  const current = currentEntry?.paragraph;
57542
57870
  const previous = previousEntry?.paragraph;
57543
57871
  if (!current?.numbering || !previous?.numbering) return false;
@@ -63024,6 +63352,9 @@ function applyRewrite(runtime, target, input) {
63024
63352
  if (target.kind === "editable-text") {
63025
63353
  return applyEditableTextRewrite(runtime, target, input);
63026
63354
  }
63355
+ if (target.handle.provenance === "marker-backed" && (target.scope.kind === "paragraph" || target.scope.kind === "list-item")) {
63356
+ return applyMarkerBackedRangeRewrite(runtime, target, input);
63357
+ }
63027
63358
  if (target.scope.kind === "list-item") {
63028
63359
  const listTextTarget = uniqueListTextActionForScope(runtime, target.handle);
63029
63360
  if (!listTextTarget.ok) return blockedApplyFromResolution(listTextTarget);
@@ -63170,13 +63501,97 @@ function applyEditableTextRewrite(runtime, target, input) {
63170
63501
  afterReadback
63171
63502
  };
63172
63503
  }
63504
+ function applyMarkerBackedRangeRewrite(runtime, target, input) {
63505
+ const range = buildScopePositionMap(runtime.getCanonicalDocument()).markerScopes.get(
63506
+ target.handle.scopeId
63507
+ );
63508
+ if (!range) {
63509
+ return blockedApply(
63510
+ `actions:rewrite:marker-range-unresolved:${target.handle.scopeId}`,
63511
+ "unresolved-target",
63512
+ "The marker-backed scope could not be joined to its current marker range.",
63513
+ "Refresh placeholder scopes and retry; route persistent failures to L06 marker scope tracking."
63514
+ );
63515
+ }
63516
+ const beforeReadback = markerScopeReadback(runtime, target.handle.scopeId) ?? {
63517
+ text: target.scope.content.text,
63518
+ isEmpty: target.scope.content.text.length === 0
63519
+ };
63520
+ const before = runtime.getCanonicalDocument();
63521
+ const origin = actionOrigin(runtime, input);
63522
+ runtime.dispatch({
63523
+ type: "selection.set",
63524
+ selection: {
63525
+ anchor: range.from,
63526
+ head: range.to,
63527
+ isCollapsed: range.from === range.to,
63528
+ activeRange: {
63529
+ kind: "range",
63530
+ from: range.from,
63531
+ to: range.to,
63532
+ assoc: { start: -1, end: 1 }
63533
+ }
63534
+ },
63535
+ origin
63536
+ });
63537
+ const ack = runtime.applyActiveStoryTextCommand({
63538
+ type: "text.insert",
63539
+ text: input.text,
63540
+ origin
63541
+ });
63542
+ const changed = runtime.getCanonicalDocument() !== before;
63543
+ const afterReadback = markerScopeReadback(runtime, target.handle.scopeId);
63544
+ const compiledAfter = createScopeCompilerService(runtime).compileScopeById(target.handle.scopeId);
63545
+ if (!changed || afterReadback?.text !== input.text) {
63546
+ return {
63547
+ status: "blocked",
63548
+ applied: false,
63549
+ changed,
63550
+ target: summarizeTarget(
63551
+ compiledAfter ? { ...target, scope: compiledAfter.scope, handle: compiledAfter.scope.handle } : target
63552
+ ),
63553
+ posture: "suspect-readback",
63554
+ blockers: Object.freeze([
63555
+ `actions:rewrite:marker-range-readback-mismatch:${target.handle.scopeId}`
63556
+ ]),
63557
+ blockerDetails: Object.freeze([
63558
+ blocker(
63559
+ `actions:rewrite:marker-range-readback-mismatch:${target.handle.scopeId}`,
63560
+ "blocked",
63561
+ ack.kind === "rejected" ? "The marker-backed rewrite command was rejected or did not produce the requested marker readback." : "The marker-backed rewrite command did not produce the requested marker readback.",
63562
+ "Treat the mutation as suspect. Re-read the target and export before claiming success."
63563
+ )
63564
+ ]),
63565
+ ...afterReadback ? { afterReadback } : {}
63566
+ };
63567
+ }
63568
+ return {
63569
+ status: "applied",
63570
+ applied: true,
63571
+ changed: true,
63572
+ target: summarizeTarget(
63573
+ compiledAfter ? { ...target, scope: compiledAfter.scope, handle: compiledAfter.scope.handle } : target
63574
+ ),
63575
+ commandReference: {
63576
+ command: "text.insert",
63577
+ actorId: input.actorId ?? "v3-ai-api",
63578
+ origin: input.origin ?? "agent",
63579
+ emittedAtUtc: currentAuditTimestamp(runtime)
63580
+ },
63581
+ beforeReadback,
63582
+ afterReadback
63583
+ };
63584
+ }
63173
63585
  function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63174
63586
  const workflowScope = runtime.getScope(target.handle.scopeId);
63587
+ const markerRange = buildScopePositionMap(runtime.getCanonicalDocument()).markerScopes.get(
63588
+ target.handle.scopeId
63589
+ );
63175
63590
  const editableTarget = tableEditableTargetForActionHandle(
63176
63591
  runtime,
63177
63592
  action.actionHandle
63178
63593
  );
63179
- if (!workflowScope || workflowScope.anchor.kind !== "range" || !editableTarget) {
63594
+ if (!workflowScope || !markerRange || !editableTarget) {
63180
63595
  return blockedApply(
63181
63596
  `actions:rewrite:table-marker-target-unresolved:${target.handle.scopeId}`,
63182
63597
  "unresolved-target",
@@ -63184,19 +63599,23 @@ function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63184
63599
  "Refresh placeholder scopes and retry; route persistent failures to L08 table scope target mapping."
63185
63600
  );
63186
63601
  }
63602
+ const beforeReadback = markerScopeReadback(runtime, target.handle.scopeId) ?? {
63603
+ text: target.scope.content.text,
63604
+ isEmpty: target.scope.content.text.length === 0
63605
+ };
63187
63606
  const before = runtime.getCanonicalDocument();
63188
63607
  try {
63189
63608
  runtime.dispatch({
63190
63609
  type: "selection.set",
63191
63610
  selection: {
63192
- anchor: workflowScope.anchor.from,
63193
- head: workflowScope.anchor.to,
63194
- isCollapsed: workflowScope.anchor.from === workflowScope.anchor.to,
63611
+ anchor: markerRange.from,
63612
+ head: markerRange.to,
63613
+ isCollapsed: markerRange.from === markerRange.to,
63195
63614
  activeRange: {
63196
63615
  kind: "range",
63197
- from: workflowScope.anchor.from,
63198
- to: workflowScope.anchor.to,
63199
- assoc: workflowScope.anchor.assoc ?? { start: -1, end: 1 }
63616
+ from: markerRange.from,
63617
+ to: markerRange.to,
63618
+ assoc: { start: -1, end: 1 }
63200
63619
  }
63201
63620
  },
63202
63621
  origin: actionOrigin(runtime, input)
@@ -63231,12 +63650,19 @@ function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63231
63650
  );
63232
63651
  const afterText = paragraph ? collectInlineText3(paragraph.children) : void 0;
63233
63652
  const afterReadback = afterText === void 0 ? void 0 : { text: afterText, isEmpty: afterText.length === 0 };
63234
- if (!changed || afterReadback?.text !== input.text) {
63653
+ const compiledAfter = createScopeCompilerService(runtime).compileScopeById(target.handle.scopeId);
63654
+ const scopeReadback = markerScopeReadback(runtime, target.handle.scopeId) ?? (compiledAfter ? {
63655
+ text: compiledAfter.scope.content.text,
63656
+ isEmpty: compiledAfter.scope.content.text.length === 0
63657
+ } : void 0);
63658
+ if (!changed || scopeReadback?.text !== input.text) {
63235
63659
  return {
63236
63660
  status: "blocked",
63237
63661
  applied: false,
63238
63662
  changed,
63239
- target: summarizeTarget({ kind: "table-text", action }),
63663
+ target: summarizeTarget(
63664
+ compiledAfter ? { ...target, scope: compiledAfter.scope, handle: compiledAfter.scope.handle } : target
63665
+ ),
63240
63666
  posture: "suspect-readback",
63241
63667
  blockers: Object.freeze([
63242
63668
  `actions:rewrite:table-marker-readback-mismatch:${target.handle.scopeId}`
@@ -63249,25 +63675,24 @@ function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63249
63675
  "Treat the mutation as suspect. Re-read the target and export before claiming success."
63250
63676
  )
63251
63677
  ]),
63252
- ...afterReadback ? { afterReadback } : {}
63678
+ ...scopeReadback ? { afterReadback: scopeReadback } : afterReadback ? { afterReadback } : {}
63253
63679
  };
63254
63680
  }
63255
63681
  return {
63256
63682
  status: "applied",
63257
63683
  applied: true,
63258
63684
  changed: true,
63259
- target: summarizeTarget({
63260
- kind: "table-text",
63261
- action: { ...action, readback: afterReadback }
63262
- }),
63685
+ target: summarizeTarget(
63686
+ compiledAfter ? { ...target, scope: compiledAfter.scope, handle: compiledAfter.scope.handle } : { kind: "table-text", action: { ...action, readback: scopeReadback } }
63687
+ ),
63263
63688
  commandReference: {
63264
63689
  command: "text.insert",
63265
63690
  actorId: input.actorId ?? "v3-ai-api",
63266
63691
  origin: input.origin ?? "agent",
63267
63692
  emittedAtUtc: currentAuditTimestamp(runtime)
63268
63693
  },
63269
- ...action.readback ? { beforeReadback: action.readback } : {},
63270
- afterReadback
63694
+ beforeReadback,
63695
+ afterReadback: scopeReadback
63271
63696
  };
63272
63697
  }
63273
63698
  function projectRewriteScopeResult(runtime, result, target, beforeText, proposedText, documentMutated) {
@@ -63361,7 +63786,7 @@ function summarizeTarget(target) {
63361
63786
  if (target.kind === "editable-text") {
63362
63787
  return {
63363
63788
  kind: target.targetKind,
63364
- handle: target.ownerHandle,
63789
+ handle: publicActionScopeHandle(target.ownerHandle),
63365
63790
  actionHandle: target.actionHandle,
63366
63791
  readback: target.readback,
63367
63792
  canRewriteText: true,
@@ -63372,13 +63797,21 @@ function summarizeTarget(target) {
63372
63797
  }
63373
63798
  return {
63374
63799
  kind: target.scope.kind,
63375
- handle: target.handle,
63800
+ handle: publicActionScopeHandle(target.handle),
63376
63801
  canRewriteText: canRewriteScopeText(target.scope),
63377
63802
  canInsertAdjacentText: canInsertAdjacentScopeText(target.scope),
63378
63803
  canFlag: true,
63379
63804
  canMark: canMarkScope(target.scope)
63380
63805
  };
63381
63806
  }
63807
+ function publicActionScopeHandle(handle) {
63808
+ const parentScopeId = handle.parentScopeId;
63809
+ if (!parentScopeId || !/^(cell|table|row|column|span):/u.test(parentScopeId)) {
63810
+ return handle;
63811
+ }
63812
+ const { parentScopeId: _parentScopeId, ...rest } = handle;
63813
+ return rest;
63814
+ }
63382
63815
  function tableTextActionsForScope(runtime, handle) {
63383
63816
  const result = createTableActionFamily(runtime).listTableActions({
63384
63817
  handle,
@@ -63431,6 +63864,13 @@ function tableEditableTargetForActionHandle(runtime, actionHandle) {
63431
63864
  }
63432
63865
  return null;
63433
63866
  }
63867
+ function markerScopeReadback(runtime, scopeId) {
63868
+ const document2 = runtime.getCanonicalDocument();
63869
+ const range = buildScopePositionMap(document2).markerScopes.get(scopeId);
63870
+ if (!range) return null;
63871
+ const text = textForCanonicalRange(document2, range.from, range.to);
63872
+ return { text, isEmpty: text.length === 0 };
63873
+ }
63434
63874
  function editableTextActionsForScope(runtime, handle) {
63435
63875
  const bundle = createScopeCompilerService(runtime).compileBundleById(
63436
63876
  handle.scopeId,
@@ -64783,6 +65223,86 @@ function blockTextLength(block) {
64783
65223
  return 0;
64784
65224
  }
64785
65225
  }
65226
+ function textForCanonicalRange(document2, from, to) {
65227
+ let cursor = 0;
65228
+ let text = "";
65229
+ const append = (value, start, end) => {
65230
+ const clippedFrom = Math.max(from, start);
65231
+ const clippedTo = Math.min(to, end);
65232
+ if (clippedTo <= clippedFrom) return;
65233
+ const localFrom = clippedFrom - start;
65234
+ const localTo = clippedTo - start;
65235
+ text += Array.from(value).slice(localFrom, localTo).join("");
65236
+ };
65237
+ const walkInline = (inline) => {
65238
+ const start = cursor;
65239
+ switch (inline.type) {
65240
+ case "text": {
65241
+ const length = Array.from(inline.text).length;
65242
+ cursor += length;
65243
+ append(inline.text, start, cursor);
65244
+ return length;
65245
+ }
65246
+ case "tab":
65247
+ cursor += 1;
65248
+ append(" ", start, cursor);
65249
+ return 1;
65250
+ case "hard_break":
65251
+ cursor += 1;
65252
+ append("\n", start, cursor);
65253
+ return 1;
65254
+ case "hyperlink":
65255
+ case "field": {
65256
+ const before = cursor;
65257
+ for (const child of inline.children) {
65258
+ walkInline(child);
65259
+ }
65260
+ return cursor - before;
65261
+ }
65262
+ case "bookmark_start":
65263
+ case "bookmark_end":
65264
+ case "scope_marker_start":
65265
+ case "scope_marker_end":
65266
+ return 0;
65267
+ default:
65268
+ cursor += 1;
65269
+ return 1;
65270
+ }
65271
+ };
65272
+ const walkBlock = (block) => {
65273
+ if (!block) return 0;
65274
+ const before = cursor;
65275
+ switch (block.type) {
65276
+ case "paragraph":
65277
+ for (const child of block.children) walkInline(child);
65278
+ break;
65279
+ case "table":
65280
+ for (const row of block.rows) {
65281
+ for (const cell of row.cells) {
65282
+ for (const child of cell.children) walkBlock(child);
65283
+ }
65284
+ }
65285
+ break;
65286
+ case "sdt":
65287
+ case "custom_xml":
65288
+ for (const child of block.children) walkBlock(child);
65289
+ break;
65290
+ default:
65291
+ cursor += 1;
65292
+ break;
65293
+ }
65294
+ return cursor - before;
65295
+ };
65296
+ const blocks = document2.content.children;
65297
+ for (let index = 0; index < blocks.length; index += 1) {
65298
+ walkBlock(blocks[index]);
65299
+ if (index < blocks.length - 1 && blocks[index + 1]?.type === "paragraph") {
65300
+ cursor += 1;
65301
+ append("\n", cursor - 1, cursor);
65302
+ }
65303
+ }
65304
+ return text;
65305
+ }
64786
65306
  function inlineTextLength(inline) {
64787
65307
  if (!inline) return 0;
64788
65308
  switch (inline.type) {
@@ -64938,6 +65458,109 @@ function summarizePlanResult(mode, steps) {
64938
65458
  };
64939
65459
  }
64940
65460
 
65461
+ // src/api/v3/ai/agent.ts
65462
+ function createAgentFamily(runtime, pe2Evidence) {
65463
+ const inspect = createInspectFamily(runtime, pe2Evidence);
65464
+ const resolve = createResolveFamily(runtime);
65465
+ const bundle = createBundleFamily(runtime, pe2Evidence);
65466
+ const actions2 = createActionsFamily(runtime).actions;
65467
+ const table = createTableActionFamily(runtime);
65468
+ const object = createObjectActionFamily(runtime);
65469
+ const policy = createPolicyFamily(runtime);
65470
+ const evaluate = createEvaluateFamily(runtime);
65471
+ const outline = createOutlineFamily(runtime);
65472
+ const stats = createStatsFamily(runtime);
65473
+ const explain = createExplainFamily(runtime);
65474
+ const review = createReviewFamily2(runtime);
65475
+ const exportFamily = createExportFamily(runtime);
65476
+ const read = Object.freeze({
65477
+ inspectDocument: inspect.inspectDocument,
65478
+ listScopes: inspect.listScopes,
65479
+ getScope: bundle.getScope,
65480
+ getScopeBundle: bundle.getScopeBundle,
65481
+ resolveReference: resolve.resolveReference,
65482
+ queryScopeAtPosition: resolve.queryScopeAtPosition,
65483
+ queryScopeInRange: resolve.queryScopeInRange,
65484
+ brief: actions2.brief,
65485
+ getDocumentOutline: outline.getDocumentOutline,
65486
+ getDocumentStatistics: stats.getDocumentStatistics,
65487
+ explainFormatting: explain.explainFormatting
65488
+ });
65489
+ const target = Object.freeze({
65490
+ discover: actions2.discover,
65491
+ locate: actions2.locate,
65492
+ locateAll: actions2.locateAll,
65493
+ createPlaceholderScopes: actions2.createPlaceholderScopes
65494
+ });
65495
+ const edit = Object.freeze({
65496
+ rewrite: actions2.rewrite,
65497
+ runPlan: actions2.runPlan,
65498
+ insertText: actions2.insertText,
65499
+ mark: actions2.mark,
65500
+ flag: actions2.flag,
65501
+ flagMany: actions2.flagMany,
65502
+ fieldRefresh: actions2.fieldRefresh,
65503
+ tocRefresh: actions2.tocRefresh,
65504
+ bookmarkEdit: actions2.bookmarkEdit,
65505
+ hyperlinkDestinationEdit: actions2.hyperlinkDestinationEdit,
65506
+ hyperlinkTextEdit: actions2.hyperlinkTextEdit
65507
+ });
65508
+ const template = Object.freeze({
65509
+ validateTargets: actions2.validateTemplateTargets,
65510
+ readTarget: actions2.templateTargetRead,
65511
+ fillField: actions2.templateFieldFill
65512
+ });
65513
+ const tableGroup = Object.freeze({
65514
+ replaceContent: actions2.tableContent,
65515
+ applyFragment: actions2.tableFragment,
65516
+ applySelection: actions2.tableSelection,
65517
+ listActions: table.listTableActions,
65518
+ applyAction: table.applyTableAction
65519
+ });
65520
+ const list = Object.freeze({
65521
+ applyOperation: actions2.listOperation
65522
+ });
65523
+ const objectGroup = Object.freeze({
65524
+ listActions: object.listObjectActions,
65525
+ applyAction: object.applyObjectAction
65526
+ });
65527
+ const reviewGroup = Object.freeze({
65528
+ acceptRevision: review.acceptRevision,
65529
+ rejectRevision: review.rejectRevision,
65530
+ resolveCommentThread: review.resolveCommentThread,
65531
+ resolveIssue: review.resolveIssue,
65532
+ reopenIssue: review.reopenIssue
65533
+ });
65534
+ const policyGroup = Object.freeze({
65535
+ getPolicy: policy.getPolicy,
65536
+ listActions: policy.listAIActions,
65537
+ evaluateAction: evaluate.evaluateAction
65538
+ });
65539
+ const exportGroup = Object.freeze({
65540
+ reviewedDocument: exportFamily.exportReviewedDocument
65541
+ });
65542
+ const category = Object.freeze({
65543
+ read,
65544
+ target,
65545
+ edit,
65546
+ template,
65547
+ table: tableGroup,
65548
+ list,
65549
+ object: objectGroup,
65550
+ review: reviewGroup,
65551
+ policy: policyGroup,
65552
+ export: exportGroup
65553
+ });
65554
+ const family = {
65555
+ agent() {
65556
+ return category;
65557
+ }
65558
+ };
65559
+ return {
65560
+ agent: family.agent()
65561
+ };
65562
+ }
65563
+
64941
65564
  // src/api/v3/ui/_context.ts
64942
65565
  function createUiApiContext(handle) {
64943
65566
  return {
@@ -67248,7 +67871,8 @@ function createApiV3(handle, opts) {
67248
67871
  ...createOutlineFamily(handle),
67249
67872
  ...createTableActionFamily(handle),
67250
67873
  ...createObjectActionFamily(handle),
67251
- ...createActionsFamily(handle)
67874
+ ...createActionsFamily(handle),
67875
+ ...createAgentFamily(handle, opts?.pe2Evidence)
67252
67876
  };
67253
67877
  const runtime = {
67254
67878
  document: createDocumentFamily(handle),