@stll/folio-agents 0.11.3 → 0.12.0

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.
package/dist/compare.js CHANGED
@@ -18,14 +18,19 @@ const renderSegment = (segment) => {
18
18
  default: return "";
19
19
  }
20
20
  };
21
+ const renderChangedProperties = (properties) => properties && properties.length > 0 ? ` (${properties.join(", ")})` : "";
21
22
  const formatChangeLine = (change) => {
22
23
  switch (change.type) {
23
24
  case "added": return `+ [${change.blockId}] added: ${change.text}`;
24
25
  case "deleted": return `- [${change.blockId}] deleted: ${change.text}`;
25
- case "modified": return `~ [${change.blockId}] modified: ${change.segments.map(renderSegment).join("")}`;
26
+ case "modified": return `~ [${change.blockId}] modified${renderChangedProperties(change.changedProperties)}: ${change.segments.map(renderSegment).join("")}`;
26
27
  case "formatChanged": return `~ [${change.blockId}] format changed (${change.changedProperties.join(", ")}): ${truncateUnchangedRun(change.text)}`;
27
28
  case "movedFrom": return `< [${change.blockId}] moved away (move ${change.moveGroupId}): ${truncateUnchangedRun(change.text)}`;
28
- case "movedTo": return `> [${change.blockId}] moved here (move ${change.moveGroupId}): ${truncateUnchangedRun(change.text)}`;
29
+ case "movedTo": {
30
+ const changedProperties = change.changedProperties?.length ? `; changed: ${change.changedProperties.join(", ")}` : "";
31
+ const content = change.segments ? change.segments.map(renderSegment).join("") : truncateUnchangedRun(change.text);
32
+ return `> [${change.blockId}] moved here (move ${change.moveGroupId}${changedProperties}): ${content}`;
33
+ }
29
34
  default: return "";
30
35
  }
31
36
  };
package/dist/execute.js CHANGED
@@ -282,6 +282,7 @@ const explainSkipReason = (reason) => {
282
282
  if (reason === "preconditionFailed") return "the target block changed after the operation was prepared; re-read the document and retry with a fresh operation.";
283
283
  if (reason === "staleRange") return "the selected range changed or shifted; run find_text again and retry with the fresh range.";
284
284
  if (reason === "emptyOperation") return "this operation has no effect; nothing to apply.";
285
+ if (reason === "pendingParagraphPropertyChange") return "this paragraph already has an unresolved tracked formatting change; accept or reject that change before retrying.";
285
286
  if (reason === "noopOperation") return "this operation would not change the document (the text already matches what you asked for).";
286
287
  if (reason === "documentVersionMismatch") return "the document changed after these edits were proposed; re-read it and regenerate the edits against the current version.";
287
288
  if (reason === "documentNotEditable") return "the document is not open for editing right now; nothing was applied or queued. Ask the user to open it for editing, then retry.";
@@ -6,6 +6,7 @@ type FolioJsonSchema = {
6
6
  readonly description?: string;
7
7
  readonly enum?: readonly unknown[];
8
8
  readonly minimum?: number;
9
+ readonly maximum?: number;
9
10
  readonly minLength?: number;
10
11
  readonly minProperties?: number;
11
12
  readonly pattern?: string;
@@ -44,11 +45,56 @@ declare const FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA: {
44
45
  readonly oneOf: readonly [{
45
46
  readonly type: "integer";
46
47
  readonly minimum: 0;
48
+ readonly maximum: number;
47
49
  }, {
48
50
  readonly type: "null";
49
51
  }];
50
52
  readonly description: "`w:numPr/w:ilvl`, zero-based; a number retains the paragraph or anchor's numbering instance (`numId`), while null removes paragraph numbering.";
51
53
  };
54
+ /** Complete direct `w:spacing` attributes, or null to restore style inheritance. */
55
+ declare const FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA: {
56
+ readonly oneOf: readonly [{
57
+ readonly type: "object";
58
+ readonly properties: {
59
+ readonly spaceBefore: {
60
+ readonly type: "integer";
61
+ readonly minimum: 0;
62
+ readonly maximum: number;
63
+ readonly description: "Non-negative space before, in twips.";
64
+ };
65
+ readonly spaceAfter: {
66
+ readonly type: "integer";
67
+ readonly minimum: 0;
68
+ readonly maximum: number;
69
+ readonly description: "Non-negative space after, in twips.";
70
+ };
71
+ readonly lineSpacing: {
72
+ readonly type: "integer";
73
+ readonly minimum: number;
74
+ readonly maximum: number;
75
+ readonly description: "Signed line spacing: 240ths of a line with the auto rule, otherwise twips.";
76
+ };
77
+ readonly lineSpacingRule: {
78
+ readonly type: "string";
79
+ readonly enum: readonly ("auto" | "exact" | "atLeast")[];
80
+ readonly description: "How `lineSpacing` is interpreted.";
81
+ };
82
+ readonly beforeAutospacing: {
83
+ readonly type: "boolean";
84
+ readonly description: "Whether the application determines spacing before automatically.";
85
+ };
86
+ readonly afterAutospacing: {
87
+ readonly type: "boolean";
88
+ readonly description: "Whether the application determines spacing after automatically.";
89
+ };
90
+ };
91
+ readonly minProperties: 1;
92
+ readonly additionalProperties: false;
93
+ }, {
94
+ readonly type: "null";
95
+ }];
96
+ readonly description: "Complete direct paragraph spacing (`w:spacing`); omitted attributes stay absent, while zero and false remain explicit. Null removes the direct spacing child and restores style inheritance.";
97
+ };
52
98
  /**
53
99
  * JSON Schema (draft-07 compatible) for ONE document operation: the full
54
100
  * union accepted by `parseFolioDocumentOperationBatch` in
@@ -117,4 +163,4 @@ type FolioDocumentOperationBatchSchema = StandardSchemaV1<unknown, FolioDocument
117
163
  */
118
164
  declare const folioDocumentOperationBatchSchema: FolioDocumentOperationBatchSchema;
119
165
  //#endregion
120
- export { FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_STYLE_ID_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, FOLIO_PRECONDITION_JSON_SCHEMA, FOLIO_TEXT_RANGE_JSON_SCHEMA, FolioJsonSchema, folioDocumentOperationBatchSchema };
166
+ export { FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_STYLE_ID_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, FOLIO_PRECONDITION_JSON_SCHEMA, FOLIO_TEXT_RANGE_JSON_SCHEMA, FolioJsonSchema, folioDocumentOperationBatchSchema };
@@ -1,4 +1,4 @@
1
- import { FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, parseFolioDocumentOperationBatch } from "@stll/folio-core/server";
1
+ import { FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, parseFolioDocumentOperationBatch } from "@stll/folio-core/server";
2
2
  //#region src/operation-schema.ts
3
3
  /**
4
4
  * Reusable projections of folio's versioned document-operation contract for
@@ -46,11 +46,13 @@ const FOLIO_TEXT_RANGE_JSON_SCHEMA = {
46
46
  },
47
47
  startOffset: {
48
48
  type: "integer",
49
- minimum: 0
49
+ minimum: 0,
50
+ maximum: Number.MAX_SAFE_INTEGER
50
51
  },
51
52
  endOffset: {
52
53
  type: "integer",
53
54
  minimum: 1,
55
+ maximum: Number.MAX_SAFE_INTEGER,
54
56
  description: "Exclusive end offset; must be greater than `startOffset`."
55
57
  },
56
58
  selectedTextHash: {
@@ -138,10 +140,53 @@ const FOLIO_CLEARABLE_PARAGRAPH_STYLE_ID_JSON_SCHEMA = {
138
140
  const FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA = {
139
141
  oneOf: [{
140
142
  type: "integer",
141
- minimum: 0
143
+ minimum: 0,
144
+ maximum: Number.MAX_SAFE_INTEGER
142
145
  }, { type: "null" }],
143
146
  description: "`w:numPr/w:ilvl`, zero-based; a number retains the paragraph or anchor's numbering instance (`numId`), while null removes paragraph numbering."
144
147
  };
148
+ /** Complete direct `w:spacing` attributes, or null to restore style inheritance. */
149
+ const FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA = {
150
+ oneOf: [{
151
+ type: "object",
152
+ properties: {
153
+ spaceBefore: {
154
+ type: "integer",
155
+ minimum: 0,
156
+ maximum: Number.MAX_SAFE_INTEGER,
157
+ description: "Non-negative space before, in twips."
158
+ },
159
+ spaceAfter: {
160
+ type: "integer",
161
+ minimum: 0,
162
+ maximum: Number.MAX_SAFE_INTEGER,
163
+ description: "Non-negative space after, in twips."
164
+ },
165
+ lineSpacing: {
166
+ type: "integer",
167
+ minimum: Number.MIN_SAFE_INTEGER,
168
+ maximum: Number.MAX_SAFE_INTEGER,
169
+ description: "Signed line spacing: 240ths of a line with the auto rule, otherwise twips."
170
+ },
171
+ lineSpacingRule: {
172
+ type: "string",
173
+ enum: FOLIO_LINE_SPACING_RULE_VALUES,
174
+ description: "How `lineSpacing` is interpreted."
175
+ },
176
+ beforeAutospacing: {
177
+ type: "boolean",
178
+ description: "Whether the application determines spacing before automatically."
179
+ },
180
+ afterAutospacing: {
181
+ type: "boolean",
182
+ description: "Whether the application determines spacing after automatically."
183
+ }
184
+ },
185
+ minProperties: 1,
186
+ additionalProperties: false
187
+ }, { type: "null" }],
188
+ description: "Complete direct paragraph spacing (`w:spacing`); omitted attributes stay absent, while zero and false remain explicit. Null removes the direct spacing child and restores style inheritance."
189
+ };
145
190
  /**
146
191
  * JSON Schema (draft-07 compatible) for ONE document operation: the full
147
192
  * union accepted by `parseFolioDocumentOperationBatch` in
@@ -273,7 +318,7 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
273
318
  blockId: blockIdProperty,
274
319
  text: {
275
320
  type: "string",
276
- description: "The paragraph text to insert. A line break splits this into consecutive paragraphs at the same anchor instead of one paragraph with embedded newlines — only the first paragraph gets `styleId` / `alignment` / `inheritFormatting`, later ones use body formatting. Prefer one paragraph per operation; only rely on the split for a heading immediately followed by its body text."
321
+ description: "The paragraph text to insert. A line break splits this into consecutive paragraphs at the same anchor instead of one paragraph with embedded newlines — only the first paragraph gets `styleId` / `alignment` / `spacing` / `inheritFormatting`, later ones use body formatting. Prefer one paragraph per operation; only rely on the split for a heading immediately followed by its body text."
277
322
  },
278
323
  inheritFormatting: {
279
324
  type: "boolean",
@@ -292,6 +337,7 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
292
337
  }, { type: "null" }],
293
338
  description: "Direct paragraph alignment; null restores style inheritance."
294
339
  },
340
+ spacing: FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA,
295
341
  moveId: {
296
342
  type: "string",
297
343
  description: "Links this operation to the other half of one relocation: a `deleteBlock` and an insertion sharing a `moveId` are written as `w:moveFrom` / `w:moveTo`. An id that does not name exactly one of each applies as an ordinary edit."
@@ -319,7 +365,7 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
319
365
  blockId: blockIdProperty,
320
366
  text: {
321
367
  type: "string",
322
- description: "The paragraph text to insert. A line break splits this into consecutive paragraphs at the same anchor instead of one paragraph with embedded newlines — only the first paragraph gets `styleId` / `alignment` / `inheritFormatting`, later ones use body formatting. Prefer one paragraph per operation; only rely on the split for a heading immediately followed by its body text."
368
+ description: "The paragraph text to insert. A line break splits this into consecutive paragraphs at the same anchor instead of one paragraph with embedded newlines — only the first paragraph gets `styleId` / `alignment` / `spacing` / `inheritFormatting`, later ones use body formatting. Prefer one paragraph per operation; only rely on the split for a heading immediately followed by its body text."
323
369
  },
324
370
  inheritFormatting: {
325
371
  type: "boolean",
@@ -338,6 +384,7 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
338
384
  }, { type: "null" }],
339
385
  description: "Direct paragraph alignment; null restores style inheritance."
340
386
  },
387
+ spacing: FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA,
341
388
  moveId: {
342
389
  type: "string",
343
390
  description: "Links this operation to the other half of one relocation: a `deleteBlock` and an insertion sharing a `moveId` are written as `w:moveFrom` / `w:moveTo`. An id that does not name exactly one of each applies as an ordinary edit."
@@ -420,6 +467,7 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
420
467
  offset: {
421
468
  type: "integer",
422
469
  minimum: 0,
470
+ maximum: Number.MAX_SAFE_INTEGER,
423
471
  description: "Character offset in the block's text where the break goes. Must fall strictly inside it."
424
472
  },
425
473
  separator: {
@@ -481,7 +529,8 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
481
529
  enum: FOLIO_PARAGRAPH_ALIGNMENT_VALUES
482
530
  }, { type: "null" }],
483
531
  description: "Direct paragraph alignment; null restores style inheritance."
484
- }
532
+ },
533
+ spacing: FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA
485
534
  },
486
535
  minProperties: 1,
487
536
  additionalProperties: false
@@ -736,6 +785,7 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
736
785
  rowCount: {
737
786
  type: "integer",
738
787
  minimum: 2,
788
+ maximum: Number.MAX_SAFE_INTEGER,
739
789
  description: "Number of grid rows to merge downward from the anchored cell."
740
790
  }
741
791
  },
@@ -871,4 +921,4 @@ const folioDocumentOperationBatchSchema = {
871
921
  jsonSchema: FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA
872
922
  };
873
923
  //#endregion
874
- export { FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_STYLE_ID_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, FOLIO_PRECONDITION_JSON_SCHEMA, FOLIO_TEXT_RANGE_JSON_SCHEMA, folioDocumentOperationBatchSchema };
924
+ export { FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_STYLE_ID_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, FOLIO_PRECONDITION_JSON_SCHEMA, FOLIO_TEXT_RANGE_JSON_SCHEMA, folioDocumentOperationBatchSchema };
package/dist/tools.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FOLIO_COMMENT_ID_JSON_SCHEMA, FOLIO_SCOPED_HANDLE_JSON_SCHEMA, FOLIO_SECTION_HANDLE_JSON_SCHEMA, FOLIO_STORY_HANDLE_JSON_SCHEMA } from "./codecs.js";
2
- import { FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_STYLE_ID_JSON_SCHEMA, FOLIO_PRECONDITION_JSON_SCHEMA, FOLIO_TEXT_RANGE_JSON_SCHEMA } from "./operation-schema.js";
2
+ import { FOLIO_CLEARABLE_LIST_LEVEL_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA, FOLIO_CLEARABLE_PARAGRAPH_STYLE_ID_JSON_SCHEMA, FOLIO_PRECONDITION_JSON_SCHEMA, FOLIO_TEXT_RANGE_JSON_SCHEMA } from "./operation-schema.js";
3
3
  import { DEFAULT_SUGGEST_CHANGES_OPERATION_TYPES, resolveSuggestChangesOptions } from "./suggest-changes-options.js";
4
4
  import { defineFolioAgentToolDefinition } from "./tool-contract.js";
5
5
  import { FOLIO_AGENT_TOOL_NAMES } from "./types.js";
@@ -25,13 +25,13 @@ const OPERATION_TYPE_SUMMARIES = {
25
25
  replaceRange: "replace the text covered by a `range` copied from find_text",
26
26
  commentOnRange: "attach a comment to a `range` copied from find_text",
27
27
  formatRange: "toggle bold, italic, or underline on a `range` copied from find_text",
28
- insertAfterBlock: "insert a new paragraph after a block, with optional direct alignment",
29
- insertBeforeBlock: "insert a new paragraph before a block, with optional direct alignment",
28
+ insertAfterBlock: "insert a new paragraph after a block, with optional direct alignment and spacing",
29
+ insertBeforeBlock: "insert a new paragraph before a block, with optional direct alignment and spacing",
30
30
  replaceBlock: "replace one block's entire text",
31
31
  deleteBlock: "delete one block",
32
32
  splitBlock: "break one block in two at `offset`, moving a paragraph mark and no words",
33
33
  mergeBlockWithNext: "join one block with the block after it in the same container",
34
- setBlockParagraphProperties: "change one block's paragraph properties (list level, paragraph style, direct alignment) without touching its words",
34
+ setBlockParagraphProperties: "change one block's paragraph properties (list level, paragraph style, direct alignment or spacing) without touching its words",
35
35
  insertTable: "insert a whole table of `rows` next to the anchor block",
36
36
  deleteTable: "delete the whole table the anchor block sits in",
37
37
  commentOnBlock: "attach a comment to one block, optionally quoting text within it",
@@ -81,6 +81,7 @@ const OPERATION_PROPERTY_SCHEMAS = {
81
81
  rowCount: {
82
82
  type: "integer",
83
83
  minimum: 2,
84
+ maximum: Number.MAX_SAFE_INTEGER,
84
85
  description: "For vertical cell merging, the number of grid rows to merge downward."
85
86
  },
86
87
  range: {
@@ -119,6 +120,7 @@ const OPERATION_PROPERTY_SCHEMAS = {
119
120
  }, { type: "null" }],
120
121
  description: "For inserts: direct paragraph alignment; null restores style inheritance."
121
122
  },
123
+ spacing: FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA,
122
124
  preserveFormatting: {
123
125
  type: "boolean",
124
126
  description: "For `replaceBlock`: keep the block's existing formatting for the replacement text."
@@ -188,7 +190,8 @@ const OPERATION_PROPERTY_SCHEMAS = {
188
190
  enum: FOLIO_PARAGRAPH_ALIGNMENT_VALUES
189
191
  }, { type: "null" }],
190
192
  description: "Direct paragraph alignment; null restores style inheritance."
191
- }
193
+ },
194
+ spacing: FOLIO_CLEARABLE_PARAGRAPH_SPACING_JSON_SCHEMA
192
195
  },
193
196
  minProperties: 1,
194
197
  additionalProperties: false
@@ -197,6 +200,7 @@ const OPERATION_PROPERTY_SCHEMAS = {
197
200
  offset: {
198
201
  type: "integer",
199
202
  minimum: 0,
203
+ maximum: Number.MAX_SAFE_INTEGER,
200
204
  description: "Required for `splitBlock`: character offset in the block's text where the paragraph break goes. Must fall strictly inside the text."
201
205
  },
202
206
  separator: {
@@ -254,7 +258,7 @@ const describeResolvedCapabilities = (resolved) => {
254
258
  if (styleIdTargets.length > 0) {
255
259
  const supportsInsert = hasAnyType(resolved, ["insertAfterBlock", "insertBeforeBlock"]);
256
260
  const pageBreak = supportsInsert ? "set `pageBreakBefore: true` on an insert to start it on a new page; " : "";
257
- const insertAlignment = supportsInsert ? " Inserts also accept direct `alignment`, with null restoring style inheritance." : "";
261
+ const insertAlignment = supportsInsert ? " Inserts also accept direct `alignment` and `spacing`, with null restoring style inheritance." : "";
258
262
  lines.push(`Structural edits: ${pageBreak}set \`styleId\` on ${styleIdTargets.join(" or ")} to apply a paragraph style such as a clause heading.${insertAlignment} Never emit directive markers or markdown syntax as paragraph text.`);
259
263
  }
260
264
  if (hasAnyType(resolved, ["insertSignatureTable"])) lines.push("Signature blocks: use insertSignatureTable with `parties`; never draw one out of paragraphs.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-agents",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "description": "Framework-neutral LLM tool layer over folio's ai-edits engine: function-calling tools so an agent can read and mutate .docx documents through @stll/folio-core.",
5
5
  "keywords": [
6
6
  "agent",
@@ -54,7 +54,7 @@
54
54
  "test": "bun test src"
55
55
  },
56
56
  "dependencies": {
57
- "@stll/folio-core": "^0.36.0",
57
+ "@stll/folio-core": "^0.37.0",
58
58
  "better-result": "3.0.1"
59
59
  },
60
60
  "main": "./dist/index.js",