@beyondwork/docx-react-component 1.0.135 → 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 (62) hide show
  1. package/dist/api/public-types.d.cts +2 -2
  2. package/dist/api/public-types.d.ts +2 -2
  3. package/dist/api/v3.cjs +827 -59
  4. package/dist/api/v3.d.cts +3 -3
  5. package/dist/api/v3.d.ts +3 -3
  6. package/dist/api/v3.js +2 -2
  7. package/dist/{canonical-document-CfZIc-fC.d.cts → canonical-document-COmM7v11.d.cts} +1 -1
  8. package/dist/{canonical-document-CfZIc-fC.d.ts → canonical-document-COmM7v11.d.ts} +1 -1
  9. package/dist/{chunk-EPFVMUKF.js → chunk-M3AEVSKU.js} +793 -56
  10. package/dist/{chunk-5CCYF333.js → chunk-NYIMPM3Z.js} +143 -1
  11. package/dist/{chunk-GIFXKIM5.js → chunk-SMBDQV73.js} +688 -57
  12. package/dist/compare.d.cts +1 -1
  13. package/dist/compare.d.ts +1 -1
  14. package/dist/core/commands/formatting-commands.d.cts +2 -2
  15. package/dist/core/commands/formatting-commands.d.ts +2 -2
  16. package/dist/core/commands/image-commands.d.cts +2 -2
  17. package/dist/core/commands/image-commands.d.ts +2 -2
  18. package/dist/core/commands/section-layout-commands.d.cts +2 -2
  19. package/dist/core/commands/section-layout-commands.d.ts +2 -2
  20. package/dist/core/commands/style-commands.d.cts +2 -2
  21. package/dist/core/commands/style-commands.d.ts +2 -2
  22. package/dist/core/commands/table-structure-commands.d.cts +2 -2
  23. package/dist/core/commands/table-structure-commands.d.ts +2 -2
  24. package/dist/core/commands/text-commands.d.cts +2 -2
  25. package/dist/core/commands/text-commands.d.ts +2 -2
  26. package/dist/core/selection/mapping.d.cts +2 -2
  27. package/dist/core/selection/mapping.d.ts +2 -2
  28. package/dist/core/state/editor-state.d.cts +2 -2
  29. package/dist/core/state/editor-state.d.ts +2 -2
  30. package/dist/index.cjs +1808 -190
  31. package/dist/index.d.cts +5 -5
  32. package/dist/index.d.ts +5 -5
  33. package/dist/index.js +144 -32
  34. package/dist/io/docx-session.d.cts +4 -4
  35. package/dist/io/docx-session.d.ts +4 -4
  36. package/dist/legal.d.cts +1 -1
  37. package/dist/legal.d.ts +1 -1
  38. package/dist/{loader-BQ7AB-0v.d.cts → loader-BB7tRkY2.d.cts} +3 -3
  39. package/dist/{loader-Cy6OYBfn.d.ts → loader-DGPbaboy.d.ts} +3 -3
  40. package/dist/{public-types-D31xKNGc.d.cts → public-types-CIvw1GQa.d.cts} +142 -9
  41. package/dist/{public-types-DqYt8GdP.d.ts → public-types-COCDrgVX.d.ts} +142 -9
  42. package/dist/public-types.d.cts +2 -2
  43. package/dist/public-types.d.ts +2 -2
  44. package/dist/runtime/collab.d.cts +3 -3
  45. package/dist/runtime/collab.d.ts +3 -3
  46. package/dist/runtime/document-runtime.cjs +825 -54
  47. package/dist/runtime/document-runtime.d.cts +2 -2
  48. package/dist/runtime/document-runtime.d.ts +2 -2
  49. package/dist/runtime/document-runtime.js +2 -2
  50. package/dist/{session-DA-F2fCw.d.cts → session-CVU-rtCd.d.cts} +3 -3
  51. package/dist/{session-DqL8H0oZ.d.ts → session-DOqy1-Lf.d.ts} +3 -3
  52. package/dist/session.d.cts +5 -5
  53. package/dist/session.d.ts +5 -5
  54. package/dist/tailwind.d.cts +2 -2
  55. package/dist/tailwind.d.ts +2 -2
  56. package/dist/{types-SllbCtGs.d.ts → types-CB_tOnVp.d.ts} +2 -2
  57. package/dist/{types-B2y94n5t.d.cts → types-CZAll7OS.d.cts} +2 -2
  58. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +3 -3
  59. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +3 -3
  60. package/dist/ui-tailwind.d.cts +3 -3
  61. package/dist/ui-tailwind.d.ts +3 -3
  62. 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;
@@ -45104,6 +45123,20 @@ function normalizeHeaderFooterTarget(document2, target, preferredSectionIndex) {
45104
45123
  }
45105
45124
 
45106
45125
  // src/runtime/story-targeting.ts
45126
+ function storyTargetKey(target) {
45127
+ switch (target.kind) {
45128
+ case "main":
45129
+ return "main";
45130
+ case "header":
45131
+ return `header:${target.relationshipId}:${target.variant}:${target.sectionIndex ?? "*"}`;
45132
+ case "footer":
45133
+ return `footer:${target.relationshipId}:${target.variant}:${target.sectionIndex ?? "*"}`;
45134
+ case "footnote":
45135
+ return `footnote:${target.noteId}`;
45136
+ case "endnote":
45137
+ return `endnote:${target.noteId}`;
45138
+ }
45139
+ }
45107
45140
  function getStoryBlocks(document2, target) {
45108
45141
  if (target.kind === "main") {
45109
45142
  return document2.content.children;
@@ -47344,9 +47377,23 @@ function findSurfaceBlockById(blocks, blockId) {
47344
47377
  }
47345
47378
  function createScopeFromAnchor(runtime, input) {
47346
47379
  const doc = runtime.getCanonicalDocument();
47347
- const storyTarget = input.anchor.storyTarget ?? { kind: "main" };
47380
+ const normalizedInputAnchor = normalizeCreateScopeAnchor(input.anchor);
47381
+ const storyTarget = normalizedInputAnchor.storyTarget ?? { kind: "main" };
47348
47382
  const storyLength = storyTarget.kind === "main" ? computeMainStoryLength(doc) : Number.MAX_SAFE_INTEGER;
47349
- const { from, to } = input.anchor;
47383
+ const { from, to } = normalizedInputAnchor;
47384
+ if (!Number.isFinite(from) || !Number.isFinite(to)) {
47385
+ const diagnosticFrom = Number.isFinite(from) ? from : 0;
47386
+ const diagnosticTo = Number.isFinite(to) ? to : diagnosticFrom;
47387
+ return {
47388
+ status: "range-invalid",
47389
+ reason: "non-finite-range",
47390
+ from: diagnosticFrom,
47391
+ to: diagnosticTo,
47392
+ storyLength,
47393
+ message: `createScopeFromAnchor requires finite numeric from/to offsets. Pass selection.activeRange or an object shaped as {from, to}; do not pass a malformed range.`,
47394
+ nextStep: "pass-selection-activeRange-or-finite-from-to"
47395
+ };
47396
+ }
47350
47397
  if (from < 0) {
47351
47398
  return {
47352
47399
  status: "range-invalid",
@@ -47444,6 +47491,29 @@ function createScopeFromAnchor(runtime, input) {
47444
47491
  }
47445
47492
  return { status: "created", scopeId: result.scopeId, anchor: result.anchor };
47446
47493
  }
47494
+ function normalizeCreateScopeAnchor(anchor) {
47495
+ const candidate = anchor;
47496
+ const activeRange = candidate.activeRange;
47497
+ if (activeRange?.kind === "range") {
47498
+ return {
47499
+ from: activeRange.from,
47500
+ to: activeRange.to,
47501
+ storyTarget: candidate.storyTarget
47502
+ };
47503
+ }
47504
+ if (candidate.kind === "range") {
47505
+ return {
47506
+ from: candidate.from ?? Number.NaN,
47507
+ to: candidate.to ?? Number.NaN,
47508
+ storyTarget: candidate.storyTarget
47509
+ };
47510
+ }
47511
+ return {
47512
+ from: candidate.from ?? Number.NaN,
47513
+ to: candidate.to ?? Number.NaN,
47514
+ storyTarget: candidate.storyTarget
47515
+ };
47516
+ }
47447
47517
 
47448
47518
  // src/runtime/workflow/scope-tag-registry.ts
47449
47519
  var DEFAULT_UNKNOWN_BEHAVIOR = {
@@ -47559,6 +47629,29 @@ var createScopeFromAnchorMetadata = {
47559
47629
  broadcastsVia: "crdt",
47560
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)."
47561
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
+ };
47562
47655
  var setScopeGuardPolicyMetadata = {
47563
47656
  name: "runtime.workflow.setScopeGuardPolicy",
47564
47657
  status: "live",
@@ -47654,6 +47747,228 @@ var setMarkupModePolicyMetadata = {
47654
47747
  broadcastsVia: "crdt",
47655
47748
  rwdReference: "\xA7Runtime API \xA7 runtime.workflow.setMarkupModePolicy"
47656
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
+ }
47657
47972
  function createWorkflowFamily(runtime) {
47658
47973
  return {
47659
47974
  queryScopes(filter) {
@@ -47668,7 +47983,10 @@ function createWorkflowFamily(runtime) {
47668
47983
  createScope(input) {
47669
47984
  const adapterResult = createScopeFromBlockId(runtime, {
47670
47985
  blockId: input.blockId,
47986
+ scopeId: input.scopeId,
47671
47987
  mode: input.mode,
47988
+ persistence: input.persistence,
47989
+ metadata: input.metadata,
47672
47990
  label: input.label,
47673
47991
  ...input.visibility ? { visibility: input.visibility } : {},
47674
47992
  ...input.guardPolicy ? { guardPolicy: input.guardPolicy } : {},
@@ -47702,6 +48020,25 @@ function createWorkflowFamily(runtime) {
47702
48020
  }
47703
48021
  return { scopeId: adapterResult.scopeId, status: "created" };
47704
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
+ },
47705
48042
  getScopeGuardPolicy(scopeId) {
47706
48043
  return runtime.getScopeGuardPolicy(scopeId);
47707
48044
  },
@@ -47737,7 +48074,10 @@ function createWorkflowFamily(runtime) {
47737
48074
  createScopeFromAnchor(input) {
47738
48075
  const adapterResult = createScopeFromAnchor(runtime, {
47739
48076
  anchor: input.anchor,
48077
+ scopeId: input.scopeId,
47740
48078
  mode: input.mode,
48079
+ persistence: input.persistence,
48080
+ metadata: input.metadata,
47741
48081
  label: input.label,
47742
48082
  ...input.visibility ? { visibility: input.visibility } : {},
47743
48083
  ...input.guardPolicy ? { guardPolicy: input.guardPolicy } : {},
@@ -57091,7 +57431,8 @@ var SUPPORTED_COMMANDS = [
57091
57431
  "indent",
57092
57432
  "outdent",
57093
57433
  "restart-numbering",
57094
- "continue-numbering"
57434
+ "continue-numbering",
57435
+ "set-value"
57095
57436
  ];
57096
57437
  var UNSUPPORTED_COMMANDS = [
57097
57438
  "create",
@@ -57100,7 +57441,6 @@ var UNSUPPORTED_COMMANDS = [
57100
57441
  "join",
57101
57442
  "separate",
57102
57443
  "split",
57103
- "set-value",
57104
57444
  "apply-template",
57105
57445
  "capture-template",
57106
57446
  "apply-preset",
@@ -57148,11 +57488,17 @@ function createListsFamily(runtime) {
57148
57488
  const resolved = resolveCurrentListTarget(runtime.getCanonicalDocument(), input);
57149
57489
  return resolved.kind === "resolved" ? toReadback(runtime.getCanonicalDocument(), resolved.target, resolved.paragraph) : null;
57150
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
+ },
57151
57497
  previewCommand(input) {
57152
- return previewListCommand(runtime.getCanonicalDocument(), input);
57498
+ return previewListCommand(runtime.getCanonicalDocument(), input, activeStoryKey(runtime));
57153
57499
  },
57154
57500
  applyCommand(input) {
57155
- const preview = previewListCommand(runtime.getCanonicalDocument(), input);
57501
+ const preview = previewListCommand(runtime.getCanonicalDocument(), input, activeStoryKey(runtime));
57156
57502
  if (!preview.supported || !preview.target) {
57157
57503
  return {
57158
57504
  applied: false,
@@ -57212,7 +57558,38 @@ function createListsFamily(runtime) {
57212
57558
  }
57213
57559
  };
57214
57560
  }
57215
- function previewListCommand(document2, input) {
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
+ }
57592
+ function previewListCommand(document2, input, activeStoryKey2) {
57216
57593
  const resolved = resolveCurrentListTarget(document2, input);
57217
57594
  if (resolved.kind !== "resolved") {
57218
57595
  return {
@@ -57224,6 +57601,20 @@ function previewListCommand(document2, input) {
57224
57601
  }
57225
57602
  const target = toReadback(document2, resolved.target, resolved.paragraph);
57226
57603
  const targetRef = { targetKey: target.targetKey, addressKey: target.addressKey };
57604
+ if (activeStoryKey2 !== void 0 && target.storyKey !== activeStoryKey2) {
57605
+ return {
57606
+ command: input.command,
57607
+ supported: false,
57608
+ target,
57609
+ affectedTargets: [target],
57610
+ blockers: [{
57611
+ code: "list-target-wrong-story",
57612
+ ownerLayer: "L07",
57613
+ message: "List target does not belong to the runtime active story.",
57614
+ ...targetRef
57615
+ }]
57616
+ };
57617
+ }
57227
57618
  if (!SUPPORTED_COMMANDS.includes(input.command)) {
57228
57619
  return {
57229
57620
  command: input.command,
@@ -57236,6 +57627,17 @@ function previewListCommand(document2, input) {
57236
57627
  const canContinuePrevious = canContinuePreviousSequence(document2, resolved.paragraphIndex);
57237
57628
  const canJoin = canJoinPreviousSequence(document2, resolved.paragraphIndex);
57238
57629
  const blockers = [];
57630
+ if (input.command === "set-value") {
57631
+ const value = input.startAt;
57632
+ if (!Number.isInteger(value) || value === void 0 || value < 1) {
57633
+ blockers.push({
57634
+ code: "list-command-preflight-blocked",
57635
+ ownerLayer: "L07",
57636
+ message: "runtime.lists.set-value requires a positive integer startAt value.",
57637
+ ...targetRef
57638
+ });
57639
+ }
57640
+ }
57239
57641
  if (input.command === "continue-numbering" && !canContinuePrevious) {
57240
57642
  blockers.push({
57241
57643
  code: "list-continue-target-missing",
@@ -57266,6 +57668,7 @@ function editorCommandForListCommand(command, editableTarget, timestamp, startAt
57266
57668
  case "outdent":
57267
57669
  return { type: "list.outdent", editableTargets: [editableTarget], origin };
57268
57670
  case "restart-numbering":
57671
+ case "set-value":
57269
57672
  return {
57270
57673
  type: "list.restart-numbering",
57271
57674
  editableTarget,
@@ -57349,33 +57752,35 @@ function resolveCurrentListTarget(document2, input) {
57349
57752
  return { kind: "resolved", ...resolved };
57350
57753
  }
57351
57754
  function currentListTargets(document2) {
57352
- const paragraphs = collectParagraphEntries(document2.content.children, "main");
57755
+ const paragraphs = collectParagraphEntries(document2);
57353
57756
  const targets = collectEditableTargetRefs(document2).filter(isListTextTarget);
57354
- const byBlockPath = /* @__PURE__ */ new Map();
57355
- for (const target of targets) byBlockPath.set(target.blockPath, target);
57757
+ const byStoryBlockPath = /* @__PURE__ */ new Map();
57758
+ for (const target of targets) byStoryBlockPath.set(storyBlockPathKey(target.storyKey, target.blockPath), target);
57356
57759
  const out = [];
57357
57760
  for (let paragraphIndex = 0; paragraphIndex < paragraphs.length; paragraphIndex += 1) {
57358
57761
  const entry = paragraphs[paragraphIndex];
57359
57762
  if (!entry?.paragraph.numbering) continue;
57360
- const target = byBlockPath.get(entry.blockPath);
57763
+ const target = byStoryBlockPath.get(storyBlockPathKey(entry.storyKey, entry.blockPath));
57361
57764
  if (!target) continue;
57362
- out.push({ target, paragraph: entry.paragraph, paragraphIndex });
57765
+ out.push({ target, paragraph: entry.paragraph, paragraphIndex, storyKey: entry.storyKey });
57363
57766
  }
57364
57767
  return out;
57365
57768
  }
57366
- function collectParagraphEntries(blocks, basePath) {
57769
+ function collectParagraphEntries(document2) {
57367
57770
  const out = [];
57368
- collectParagraphEntriesInto(blocks, basePath, out);
57771
+ for (const context of collectStoryBlockContexts(document2)) {
57772
+ collectParagraphEntriesInto(context.blocks, context.storyKey, context.basePath, out);
57773
+ }
57369
57774
  return out;
57370
57775
  }
57371
- function collectParagraphEntriesInto(blocks, basePath, out) {
57776
+ function collectParagraphEntriesInto(blocks, storyKey, basePath, out) {
57372
57777
  for (let blockIndex = 0; blockIndex < blocks.length; blockIndex += 1) {
57373
57778
  const block = blocks[blockIndex];
57374
57779
  if (!block) continue;
57375
57780
  const blockPath = `${basePath}/block[${blockIndex}]`;
57376
57781
  switch (block.type) {
57377
57782
  case "paragraph":
57378
- out.push({ paragraph: block, blockPath });
57783
+ out.push({ paragraph: block, storyKey, blockPath, containerPath: basePath });
57379
57784
  break;
57380
57785
  case "table":
57381
57786
  for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex += 1) {
@@ -57386,6 +57791,7 @@ function collectParagraphEntriesInto(blocks, basePath, out) {
57386
57791
  if (!cell) continue;
57387
57792
  collectParagraphEntriesInto(
57388
57793
  cell.children,
57794
+ storyKey,
57389
57795
  `${blockPath}/row[${rowIndex}]/cell[${cellIndex}]`,
57390
57796
  out
57391
57797
  );
@@ -57393,7 +57799,7 @@ function collectParagraphEntriesInto(blocks, basePath, out) {
57393
57799
  }
57394
57800
  break;
57395
57801
  case "sdt":
57396
- collectParagraphEntriesInto(block.children, blockPath, out);
57802
+ collectParagraphEntriesInto(block.children, storyKey, blockPath, out);
57397
57803
  break;
57398
57804
  case "custom_xml":
57399
57805
  break;
@@ -57437,13 +57843,17 @@ function toReadback(document2, target, paragraph) {
57437
57843
  };
57438
57844
  }
57439
57845
  function canContinuePreviousSequence(document2, paragraphIndex) {
57440
- const paragraphs = collectParagraphEntries(document2.content.children, "main");
57441
- const current = paragraphs[paragraphIndex]?.paragraph;
57846
+ const paragraphs = collectParagraphEntries(document2);
57847
+ const currentEntry = paragraphs[paragraphIndex];
57848
+ const current = currentEntry?.paragraph;
57442
57849
  if (!current?.numbering) return false;
57443
57850
  const currentKind = getListKind(document2.numbering, current.numbering.numberingInstanceId);
57444
57851
  if (!currentKind) return false;
57445
57852
  for (let index = paragraphIndex - 1; index >= 0; index -= 1) {
57446
- const previous = paragraphs[index]?.paragraph;
57853
+ const previousEntry = paragraphs[index];
57854
+ if (previousEntry?.storyKey !== currentEntry.storyKey) break;
57855
+ if (previousEntry.containerPath !== currentEntry.containerPath) break;
57856
+ const previous = previousEntry.paragraph;
57447
57857
  if (!previous?.numbering) continue;
57448
57858
  const previousKind = getListKind(document2.numbering, previous.numbering.numberingInstanceId);
57449
57859
  return previousKind === currentKind && previous.numbering.numberingInstanceId !== current.numbering.numberingInstanceId;
@@ -57451,14 +57861,26 @@ function canContinuePreviousSequence(document2, paragraphIndex) {
57451
57861
  return false;
57452
57862
  }
57453
57863
  function canJoinPreviousSequence(document2, paragraphIndex) {
57454
- const paragraphs = collectParagraphEntries(document2.content.children, "main");
57455
- const current = paragraphs[paragraphIndex]?.paragraph;
57456
- const previous = paragraphs[paragraphIndex - 1]?.paragraph;
57864
+ const paragraphs = collectParagraphEntries(document2);
57865
+ const currentEntry = paragraphs[paragraphIndex];
57866
+ const previousEntry = paragraphs[paragraphIndex - 1];
57867
+ if (previousEntry?.storyKey !== currentEntry?.storyKey) return false;
57868
+ if (previousEntry?.containerPath !== currentEntry?.containerPath) return false;
57869
+ const current = currentEntry?.paragraph;
57870
+ const previous = previousEntry?.paragraph;
57457
57871
  if (!current?.numbering || !previous?.numbering) return false;
57458
57872
  const currentKind = getListKind(document2.numbering, current.numbering.numberingInstanceId);
57459
57873
  const previousKind = getListKind(document2.numbering, previous.numbering.numberingInstanceId);
57460
57874
  return Boolean(currentKind) && currentKind === previousKind && current.numbering.numberingInstanceId !== previous.numbering.numberingInstanceId;
57461
57875
  }
57876
+ function storyBlockPathKey(storyKey, blockPath) {
57877
+ return `${storyKey}
57878
+ ${blockPath}`;
57879
+ }
57880
+ function activeStoryKey(runtime) {
57881
+ const activeStory = runtime.getRenderSnapshot()?.activeStory;
57882
+ return activeStory ? storyTargetKey(activeStory) : void 0;
57883
+ }
57462
57884
  function unsupportedCommandBlocker(command, target) {
57463
57885
  return {
57464
57886
  code: "list-command-unsupported",
@@ -57712,8 +58134,8 @@ function resolveEditableTextTarget(input) {
57712
58134
  `Editable target ref is malformed: ${shapeIssues[0]?.path ?? "$"}.`
57713
58135
  );
57714
58136
  }
57715
- const activeStoryKey = input.activeStoryKey ?? "main";
57716
- if (input.target.storyKey !== activeStoryKey) {
58137
+ const activeStoryKey2 = input.activeStoryKey ?? "main";
58138
+ if (input.target.storyKey !== activeStoryKey2) {
57717
58139
  return reject(
57718
58140
  "editable_target_wrong_story",
57719
58141
  "Editable target ref does not belong to the active story."
@@ -58142,8 +58564,8 @@ function resolveEditableTableStructureTarget(input) {
58142
58564
  `Editable target ref is malformed: ${shapeIssues[0]?.path ?? "$"}.`
58143
58565
  );
58144
58566
  }
58145
- const activeStoryKey = input.activeStoryKey ?? input.target.storyKey;
58146
- if (input.target.storyKey !== activeStoryKey) {
58567
+ const activeStoryKey2 = input.activeStoryKey ?? input.target.storyKey;
58568
+ if (input.target.storyKey !== activeStoryKey2) {
58147
58569
  return reject2(
58148
58570
  "editable_target_wrong_story",
58149
58571
  "Editable target ref does not belong to the active story."
@@ -62379,33 +62801,51 @@ function createPlaceholderScopes(runtime, input) {
62379
62801
  blockerDetails: Object.freeze([detail])
62380
62802
  };
62381
62803
  }
62382
- const compiler = createScopeCompilerService(runtime);
62383
62804
  const byOriginalIndex = /* @__PURE__ */ new Map();
62384
- for (const item of orderedHits) {
62805
+ const createdScopeIds = [];
62806
+ const scopeRequests = orderedHits.map((item) => {
62385
62807
  const text = item.text || query;
62386
62808
  const label = input.labelPrefix === void 0 ? text : `${input.labelPrefix} ${item.originalIndex + 1}`;
62387
- const result = createScopeFromAnchor(runtime, {
62388
- anchor: { from: item.hit.from, to: item.hit.to },
62809
+ return {
62810
+ anchor: {
62811
+ kind: "range",
62812
+ from: item.hit.from,
62813
+ to: item.hit.to,
62814
+ assoc: input.assoc ?? { start: 1, end: -1 }
62815
+ },
62389
62816
  mode: input.mode ?? "edit",
62390
62817
  label,
62391
62818
  ...input.visibility ? { visibility: input.visibility } : {},
62392
62819
  ...input.guardPolicy ? { guardPolicy: input.guardPolicy } : {},
62393
62820
  ...input.assoc ? { assoc: input.assoc } : {},
62394
- ...input.stableRefHint ? { stableRefHint: input.stableRefHint } : {}
62395
- });
62396
- if (result.status === "created") {
62397
- const compiled = compiler.compileScopeById(result.scopeId)?.scope;
62821
+ ...input.stableRefHint ? {
62822
+ scopeMetadataFields: [
62823
+ {
62824
+ key: "stableRefHint",
62825
+ valueType: "string",
62826
+ value: input.stableRefHint
62827
+ }
62828
+ ]
62829
+ } : {}
62830
+ };
62831
+ });
62832
+ const scopeResults = runtime.addScopes(scopeRequests);
62833
+ orderedHits.forEach((item, requestIndex) => {
62834
+ const text = item.text || query;
62835
+ const result = scopeResults[requestIndex];
62836
+ if (result && result.scopeId && result.plantStatus?.planted !== false) {
62837
+ createdScopeIds.push(result.scopeId);
62398
62838
  byOriginalIndex.set(item.originalIndex, {
62399
62839
  status: "created",
62400
62840
  text,
62401
62841
  excerpt: excerpt(text),
62402
- scopeId: result.scopeId,
62403
- ...compiled?.handle ? { handle: compiled.handle } : {}
62842
+ scopeId: result.scopeId
62404
62843
  });
62405
- continue;
62844
+ return;
62406
62845
  }
62846
+ const reason = result?.plantStatus?.reason ?? "unknown";
62407
62847
  const detail = blockerWithOwner(
62408
- `actions:placeholder-scopes:create-refused:${result.reason}`,
62848
+ `actions:placeholder-scopes:create-refused:${reason}`,
62409
62849
  "blocked",
62410
62850
  "The placeholder match could not be converted into a workflow scope.",
62411
62851
  "Refresh the document and retry; if it still refuses, route the target to the workflow/scope writer owner.",
@@ -62418,6 +62858,38 @@ function createPlaceholderScopes(runtime, input) {
62418
62858
  blockers: Object.freeze([detail.code]),
62419
62859
  blockerDetails: Object.freeze([detail])
62420
62860
  });
62861
+ });
62862
+ if (createdScopeIds.length > 0) {
62863
+ const createdScopeIdSet = new Set(createdScopeIds);
62864
+ const handlesByScopeId = new Map(
62865
+ createScopeCompilerService(runtime).compileAllScopes().filter((scope) => createdScopeIdSet.has(scope.handle.scopeId)).map((scope) => [scope.handle.scopeId, scope.handle])
62866
+ );
62867
+ for (const [originalIndex, item] of byOriginalIndex) {
62868
+ if (item.status !== "created" || !item.scopeId) continue;
62869
+ const handle = handlesByScopeId.get(item.scopeId);
62870
+ if (!handle) {
62871
+ const detail = blockerWithOwner(
62872
+ `actions:placeholder-scopes:create-unresolved:${item.scopeId}`,
62873
+ "blocked",
62874
+ "The placeholder scope marker was planted but did not enumerate as a current semantic scope handle.",
62875
+ "Treat this target as unresolved, refresh scope enumeration, and route persistent misses to the semantic-scope compiler owner.",
62876
+ "L08"
62877
+ );
62878
+ byOriginalIndex.set(originalIndex, {
62879
+ status: "blocked",
62880
+ text: item.text,
62881
+ excerpt: item.excerpt,
62882
+ scopeId: item.scopeId,
62883
+ blockers: Object.freeze([detail.code]),
62884
+ blockerDetails: Object.freeze([detail])
62885
+ });
62886
+ continue;
62887
+ }
62888
+ byOriginalIndex.set(originalIndex, {
62889
+ ...item,
62890
+ handle
62891
+ });
62892
+ }
62421
62893
  }
62422
62894
  const scopes = orderedHits.map((item) => byOriginalIndex.get(item.originalIndex)).filter((value) => value !== void 0);
62423
62895
  const created = scopes.filter((scope) => scope.status === "created").length;
@@ -62880,6 +63352,9 @@ function applyRewrite(runtime, target, input) {
62880
63352
  if (target.kind === "editable-text") {
62881
63353
  return applyEditableTextRewrite(runtime, target, input);
62882
63354
  }
63355
+ if (target.handle.provenance === "marker-backed" && (target.scope.kind === "paragraph" || target.scope.kind === "list-item")) {
63356
+ return applyMarkerBackedRangeRewrite(runtime, target, input);
63357
+ }
62883
63358
  if (target.scope.kind === "list-item") {
62884
63359
  const listTextTarget = uniqueListTextActionForScope(runtime, target.handle);
62885
63360
  if (!listTextTarget.ok) return blockedApplyFromResolution(listTextTarget);
@@ -63026,13 +63501,97 @@ function applyEditableTextRewrite(runtime, target, input) {
63026
63501
  afterReadback
63027
63502
  };
63028
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
+ }
63029
63585
  function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63030
63586
  const workflowScope = runtime.getScope(target.handle.scopeId);
63587
+ const markerRange = buildScopePositionMap(runtime.getCanonicalDocument()).markerScopes.get(
63588
+ target.handle.scopeId
63589
+ );
63031
63590
  const editableTarget = tableEditableTargetForActionHandle(
63032
63591
  runtime,
63033
63592
  action.actionHandle
63034
63593
  );
63035
- if (!workflowScope || workflowScope.anchor.kind !== "range" || !editableTarget) {
63594
+ if (!workflowScope || !markerRange || !editableTarget) {
63036
63595
  return blockedApply(
63037
63596
  `actions:rewrite:table-marker-target-unresolved:${target.handle.scopeId}`,
63038
63597
  "unresolved-target",
@@ -63040,19 +63599,23 @@ function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63040
63599
  "Refresh placeholder scopes and retry; route persistent failures to L08 table scope target mapping."
63041
63600
  );
63042
63601
  }
63602
+ const beforeReadback = markerScopeReadback(runtime, target.handle.scopeId) ?? {
63603
+ text: target.scope.content.text,
63604
+ isEmpty: target.scope.content.text.length === 0
63605
+ };
63043
63606
  const before = runtime.getCanonicalDocument();
63044
63607
  try {
63045
63608
  runtime.dispatch({
63046
63609
  type: "selection.set",
63047
63610
  selection: {
63048
- anchor: workflowScope.anchor.from,
63049
- head: workflowScope.anchor.to,
63050
- isCollapsed: workflowScope.anchor.from === workflowScope.anchor.to,
63611
+ anchor: markerRange.from,
63612
+ head: markerRange.to,
63613
+ isCollapsed: markerRange.from === markerRange.to,
63051
63614
  activeRange: {
63052
63615
  kind: "range",
63053
- from: workflowScope.anchor.from,
63054
- to: workflowScope.anchor.to,
63055
- assoc: workflowScope.anchor.assoc ?? { start: -1, end: 1 }
63616
+ from: markerRange.from,
63617
+ to: markerRange.to,
63618
+ assoc: { start: -1, end: 1 }
63056
63619
  }
63057
63620
  },
63058
63621
  origin: actionOrigin(runtime, input)
@@ -63087,12 +63650,19 @@ function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63087
63650
  );
63088
63651
  const afterText = paragraph ? collectInlineText3(paragraph.children) : void 0;
63089
63652
  const afterReadback = afterText === void 0 ? void 0 : { text: afterText, isEmpty: afterText.length === 0 };
63090
- 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) {
63091
63659
  return {
63092
63660
  status: "blocked",
63093
63661
  applied: false,
63094
63662
  changed,
63095
- target: summarizeTarget({ kind: "table-text", action }),
63663
+ target: summarizeTarget(
63664
+ compiledAfter ? { ...target, scope: compiledAfter.scope, handle: compiledAfter.scope.handle } : target
63665
+ ),
63096
63666
  posture: "suspect-readback",
63097
63667
  blockers: Object.freeze([
63098
63668
  `actions:rewrite:table-marker-readback-mismatch:${target.handle.scopeId}`
@@ -63105,25 +63675,24 @@ function applyTableScopedMarkerRewrite(runtime, target, action, input) {
63105
63675
  "Treat the mutation as suspect. Re-read the target and export before claiming success."
63106
63676
  )
63107
63677
  ]),
63108
- ...afterReadback ? { afterReadback } : {}
63678
+ ...scopeReadback ? { afterReadback: scopeReadback } : afterReadback ? { afterReadback } : {}
63109
63679
  };
63110
63680
  }
63111
63681
  return {
63112
63682
  status: "applied",
63113
63683
  applied: true,
63114
63684
  changed: true,
63115
- target: summarizeTarget({
63116
- kind: "table-text",
63117
- action: { ...action, readback: afterReadback }
63118
- }),
63685
+ target: summarizeTarget(
63686
+ compiledAfter ? { ...target, scope: compiledAfter.scope, handle: compiledAfter.scope.handle } : { kind: "table-text", action: { ...action, readback: scopeReadback } }
63687
+ ),
63119
63688
  commandReference: {
63120
63689
  command: "text.insert",
63121
63690
  actorId: input.actorId ?? "v3-ai-api",
63122
63691
  origin: input.origin ?? "agent",
63123
63692
  emittedAtUtc: currentAuditTimestamp(runtime)
63124
63693
  },
63125
- ...action.readback ? { beforeReadback: action.readback } : {},
63126
- afterReadback
63694
+ beforeReadback,
63695
+ afterReadback: scopeReadback
63127
63696
  };
63128
63697
  }
63129
63698
  function projectRewriteScopeResult(runtime, result, target, beforeText, proposedText, documentMutated) {
@@ -63217,7 +63786,7 @@ function summarizeTarget(target) {
63217
63786
  if (target.kind === "editable-text") {
63218
63787
  return {
63219
63788
  kind: target.targetKind,
63220
- handle: target.ownerHandle,
63789
+ handle: publicActionScopeHandle(target.ownerHandle),
63221
63790
  actionHandle: target.actionHandle,
63222
63791
  readback: target.readback,
63223
63792
  canRewriteText: true,
@@ -63228,13 +63797,21 @@ function summarizeTarget(target) {
63228
63797
  }
63229
63798
  return {
63230
63799
  kind: target.scope.kind,
63231
- handle: target.handle,
63800
+ handle: publicActionScopeHandle(target.handle),
63232
63801
  canRewriteText: canRewriteScopeText(target.scope),
63233
63802
  canInsertAdjacentText: canInsertAdjacentScopeText(target.scope),
63234
63803
  canFlag: true,
63235
63804
  canMark: canMarkScope(target.scope)
63236
63805
  };
63237
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
+ }
63238
63815
  function tableTextActionsForScope(runtime, handle) {
63239
63816
  const result = createTableActionFamily(runtime).listTableActions({
63240
63817
  handle,
@@ -63287,6 +63864,13 @@ function tableEditableTargetForActionHandle(runtime, actionHandle) {
63287
63864
  }
63288
63865
  return null;
63289
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
+ }
63290
63874
  function editableTextActionsForScope(runtime, handle) {
63291
63875
  const bundle = createScopeCompilerService(runtime).compileBundleById(
63292
63876
  handle.scopeId,
@@ -64639,6 +65223,86 @@ function blockTextLength(block) {
64639
65223
  return 0;
64640
65224
  }
64641
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
+ }
64642
65306
  function inlineTextLength(inline) {
64643
65307
  if (!inline) return 0;
64644
65308
  switch (inline.type) {
@@ -64794,6 +65458,109 @@ function summarizePlanResult(mode, steps) {
64794
65458
  };
64795
65459
  }
64796
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
+
64797
65564
  // src/api/v3/ui/_context.ts
64798
65565
  function createUiApiContext(handle) {
64799
65566
  return {
@@ -67104,7 +67871,8 @@ function createApiV3(handle, opts) {
67104
67871
  ...createOutlineFamily(handle),
67105
67872
  ...createTableActionFamily(handle),
67106
67873
  ...createObjectActionFamily(handle),
67107
- ...createActionsFamily(handle)
67874
+ ...createActionsFamily(handle),
67875
+ ...createAgentFamily(handle, opts?.pe2Evidence)
67108
67876
  };
67109
67877
  const runtime = {
67110
67878
  document: createDocumentFamily(handle),