@stll/folio-agents 0.10.1 → 0.11.1
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/execute.js +5 -5
- package/dist/operation-schema.js +163 -0
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +48 -0
- package/package.json +2 -2
- package/skills/folio-agents/SKILL.md +14 -4
package/dist/execute.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getDecodedCommentHandlers } from "./bridge.js";
|
|
|
2
2
|
import { decodeCommentId, decodeMainStoryTextRangeHandle, decodeSectionHandle, decodeStoryHandle } from "./codecs.js";
|
|
3
3
|
import { explainTextTooLong, parseAddCommentInput, parseSuggestChangesInput, prepareFolioAgentDocumentOperationBatch } from "./parse.js";
|
|
4
4
|
import { FOLIO_AGENT_TOOL_NAMES } from "./types.js";
|
|
5
|
-
import { FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, createFolioAITextRangeHandle, getFolioDocumentOperationIssues, getFolioDocumentOutline, hashFolioAIBlockText, normalizeFolioAIBlockText, readFolioDocumentSection } from "@stll/folio-core/server";
|
|
5
|
+
import { FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, createFolioAITextRangeHandle, getFolioDocumentOperationIssues, getFolioDocumentOutline, hashFolioAIBlockText, isFolioAIContentBlock, normalizeFolioAIBlockText, readFolioDocumentSection } from "@stll/folio-core/server";
|
|
6
6
|
//#region src/execute.ts
|
|
7
7
|
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
8
|
const isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
@@ -55,7 +55,7 @@ const dispatch = (name, args, bridge, options) => {
|
|
|
55
55
|
return TOOL_HANDLERS[name](args, bridge, options);
|
|
56
56
|
};
|
|
57
57
|
const readDocument = (bridge) => {
|
|
58
|
-
const
|
|
58
|
+
const blocks = bridge.snapshot().blocks.filter(isFolioAIContentBlock);
|
|
59
59
|
return ok(blocks.map((block) => ({
|
|
60
60
|
blockId: block.id,
|
|
61
61
|
kind: block.kind,
|
|
@@ -215,7 +215,7 @@ const findText = (args, bridge) => {
|
|
|
215
215
|
if (matchCase !== void 0 && typeof matchCase !== "boolean") return fail("find_text's `matchCase` must be a boolean when provided.");
|
|
216
216
|
if (wholeWord !== void 0 && typeof wholeWord !== "boolean") return fail("find_text's `wholeWord` must be a boolean when provided.");
|
|
217
217
|
const scope = args["scope"];
|
|
218
|
-
let blocks = bridge.snapshot().blocks;
|
|
218
|
+
let blocks = bridge.snapshot().blocks.filter(isFolioAIContentBlock);
|
|
219
219
|
let getTargetPage;
|
|
220
220
|
let pageFilter;
|
|
221
221
|
if (scope !== void 0) {
|
|
@@ -300,8 +300,8 @@ const explainApplyNormalization = (normalization) => {
|
|
|
300
300
|
message: `\`text\` contained line breaks; split into ${normalization.paragraphCount} consecutive paragraphs (one per non-blank line) instead of one paragraph with embedded newlines.`
|
|
301
301
|
};
|
|
302
302
|
return {
|
|
303
|
-
path: `operations[id=${normalization.id}]`,
|
|
304
|
-
message:
|
|
303
|
+
path: `operations[id=${normalization.id}].moveId`,
|
|
304
|
+
message: `\`moveId\` "${normalization.moveId}" did not name exactly one deletion and one insertion in this batch, so the operation applied as an ordinary insertion or deletion rather than half of a move.`
|
|
305
305
|
};
|
|
306
306
|
};
|
|
307
307
|
const summarizeApplyResult = (result, normalizations) => ({
|
package/dist/operation-schema.js
CHANGED
|
@@ -276,6 +276,15 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
|
|
|
276
276
|
type: "string",
|
|
277
277
|
description: "Paragraph style id for the inserted block (e.g. \"ClauseHeading1\")."
|
|
278
278
|
},
|
|
279
|
+
listLevel: {
|
|
280
|
+
type: "integer",
|
|
281
|
+
minimum: 0,
|
|
282
|
+
description: "`w:numPr/w:ilvl` for the inserted block, keeping the anchor's list."
|
|
283
|
+
},
|
|
284
|
+
moveId: {
|
|
285
|
+
type: "string",
|
|
286
|
+
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."
|
|
287
|
+
},
|
|
279
288
|
comment: commentJsonSchema
|
|
280
289
|
},
|
|
281
290
|
required: [
|
|
@@ -313,6 +322,15 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
|
|
|
313
322
|
type: "string",
|
|
314
323
|
description: "Paragraph style id for the inserted block (e.g. \"ClauseHeading1\")."
|
|
315
324
|
},
|
|
325
|
+
listLevel: {
|
|
326
|
+
type: "integer",
|
|
327
|
+
minimum: 0,
|
|
328
|
+
description: "`w:numPr/w:ilvl` for the inserted block, keeping the anchor's list."
|
|
329
|
+
},
|
|
330
|
+
moveId: {
|
|
331
|
+
type: "string",
|
|
332
|
+
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."
|
|
333
|
+
},
|
|
316
334
|
comment: commentJsonSchema
|
|
317
335
|
},
|
|
318
336
|
required: [
|
|
@@ -367,6 +385,10 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
|
|
|
367
385
|
enum: ["deleteBlock"]
|
|
368
386
|
},
|
|
369
387
|
blockId: blockIdProperty,
|
|
388
|
+
moveId: {
|
|
389
|
+
type: "string",
|
|
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."
|
|
391
|
+
},
|
|
370
392
|
comment: commentJsonSchema
|
|
371
393
|
},
|
|
372
394
|
required: [
|
|
@@ -376,6 +398,147 @@ const FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA = {
|
|
|
376
398
|
],
|
|
377
399
|
additionalProperties: false
|
|
378
400
|
},
|
|
401
|
+
{
|
|
402
|
+
type: "object",
|
|
403
|
+
description: "Break one block in two at `offset`: a paragraph mark is inserted and no words change.",
|
|
404
|
+
properties: {
|
|
405
|
+
...operationMetaProperties,
|
|
406
|
+
...suggestionIdProperty,
|
|
407
|
+
type: {
|
|
408
|
+
type: "string",
|
|
409
|
+
enum: ["splitBlock"]
|
|
410
|
+
},
|
|
411
|
+
blockId: blockIdProperty,
|
|
412
|
+
offset: {
|
|
413
|
+
type: "integer",
|
|
414
|
+
minimum: 0,
|
|
415
|
+
description: "Character offset in the block's text where the break goes. Must fall strictly inside it."
|
|
416
|
+
},
|
|
417
|
+
separator: {
|
|
418
|
+
type: "string",
|
|
419
|
+
description: "Text at `offset` the break replaces, usually the space between the halves."
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
required: [
|
|
423
|
+
"id",
|
|
424
|
+
"type",
|
|
425
|
+
"blockId",
|
|
426
|
+
"offset"
|
|
427
|
+
],
|
|
428
|
+
additionalProperties: false
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
type: "object",
|
|
432
|
+
description: "Join one block with the block after it in the same container: a paragraph mark is deleted.",
|
|
433
|
+
properties: {
|
|
434
|
+
...operationMetaProperties,
|
|
435
|
+
...suggestionIdProperty,
|
|
436
|
+
type: {
|
|
437
|
+
type: "string",
|
|
438
|
+
enum: ["mergeBlockWithNext"]
|
|
439
|
+
},
|
|
440
|
+
blockId: blockIdProperty,
|
|
441
|
+
separator: {
|
|
442
|
+
type: "string",
|
|
443
|
+
description: "Text the join inserts between the two halves, usually a space."
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
required: [
|
|
447
|
+
"id",
|
|
448
|
+
"type",
|
|
449
|
+
"blockId"
|
|
450
|
+
],
|
|
451
|
+
additionalProperties: false
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
type: "object",
|
|
455
|
+
description: "Change one block's paragraph properties without touching its words, recorded as a `w:pPrChange`.",
|
|
456
|
+
properties: {
|
|
457
|
+
...operationMetaProperties,
|
|
458
|
+
...suggestionIdProperty,
|
|
459
|
+
type: {
|
|
460
|
+
type: "string",
|
|
461
|
+
enum: ["setBlockParagraphProperties"]
|
|
462
|
+
},
|
|
463
|
+
blockId: blockIdProperty,
|
|
464
|
+
properties: {
|
|
465
|
+
type: "object",
|
|
466
|
+
description: "The paragraph properties to set; at least one.",
|
|
467
|
+
properties: {
|
|
468
|
+
styleId: {
|
|
469
|
+
type: "string",
|
|
470
|
+
description: "Paragraph style id (e.g. \"ClauseHeading1\")."
|
|
471
|
+
},
|
|
472
|
+
listLevel: {
|
|
473
|
+
type: "integer",
|
|
474
|
+
minimum: 0,
|
|
475
|
+
description: "`w:numPr/w:ilvl`, the zero-based list indent level."
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
minProperties: 1,
|
|
479
|
+
additionalProperties: false
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
required: [
|
|
483
|
+
"id",
|
|
484
|
+
"type",
|
|
485
|
+
"blockId",
|
|
486
|
+
"properties"
|
|
487
|
+
],
|
|
488
|
+
additionalProperties: false
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
type: "object",
|
|
492
|
+
description: "Insert a whole table next to the anchor block.",
|
|
493
|
+
properties: {
|
|
494
|
+
...operationMetaProperties,
|
|
495
|
+
...suggestionIdProperty,
|
|
496
|
+
type: {
|
|
497
|
+
type: "string",
|
|
498
|
+
enum: ["insertTable"]
|
|
499
|
+
},
|
|
500
|
+
blockId: blockIdProperty,
|
|
501
|
+
position: {
|
|
502
|
+
type: "string",
|
|
503
|
+
enum: ["after", "before"],
|
|
504
|
+
description: "Place the table after the anchor (default) or before it."
|
|
505
|
+
},
|
|
506
|
+
rows: {
|
|
507
|
+
type: "array",
|
|
508
|
+
description: "Cell texts row by row; every row must hold the same number of cells.",
|
|
509
|
+
items: {
|
|
510
|
+
type: "array",
|
|
511
|
+
items: { type: "string" }
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
required: [
|
|
516
|
+
"id",
|
|
517
|
+
"type",
|
|
518
|
+
"blockId",
|
|
519
|
+
"rows"
|
|
520
|
+
],
|
|
521
|
+
additionalProperties: false
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
type: "object",
|
|
525
|
+
description: "Delete the whole table the anchor block sits in.",
|
|
526
|
+
properties: {
|
|
527
|
+
...operationMetaProperties,
|
|
528
|
+
...suggestionIdProperty,
|
|
529
|
+
type: {
|
|
530
|
+
type: "string",
|
|
531
|
+
enum: ["deleteTable"]
|
|
532
|
+
},
|
|
533
|
+
blockId: blockIdProperty
|
|
534
|
+
},
|
|
535
|
+
required: [
|
|
536
|
+
"id",
|
|
537
|
+
"type",
|
|
538
|
+
"blockId"
|
|
539
|
+
],
|
|
540
|
+
additionalProperties: false
|
|
541
|
+
},
|
|
379
542
|
{
|
|
380
543
|
type: "object",
|
|
381
544
|
description: "Attach a comment to one block, optionally quoting text within it.",
|
package/dist/tools.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { FolioAgentFindTextScope, FolioAgentShowInDocumentArgs } from "./tool-co
|
|
|
15
15
|
* string (the parser wraps it into `{ text }`). `suggestionId` is host-side
|
|
16
16
|
* grouping state and is never exposed to the model.
|
|
17
17
|
*/
|
|
18
|
-
declare const SUGGEST_CHANGES_OPERATION_TYPES: readonly ("replaceInBlock" | "replaceRange" | "commentOnRange" | "formatRange" | "insertAfterBlock" | "insertBeforeBlock" | "replaceBlock" | "deleteBlock" | "commentOnBlock" | "insertSignatureTable" | "insertTableRow" | "deleteTableRow" | "insertTableColumn" | "deleteTableColumn" | "mergeTableCells" | "splitTableCell")[];
|
|
18
|
+
declare const SUGGEST_CHANGES_OPERATION_TYPES: readonly ("replaceInBlock" | "replaceRange" | "commentOnRange" | "formatRange" | "insertAfterBlock" | "insertBeforeBlock" | "replaceBlock" | "deleteBlock" | "splitBlock" | "insertTable" | "deleteTable" | "setBlockParagraphProperties" | "mergeBlockWithNext" | "commentOnBlock" | "insertSignatureTable" | "insertTableRow" | "deleteTableRow" | "insertTableColumn" | "deleteTableColumn" | "mergeTableCells" | "splitTableCell")[];
|
|
19
19
|
/**
|
|
20
20
|
* Plain-language capability statement for a configured `suggest_changes`
|
|
21
21
|
* surface: the allowed operations, the structural knobs they unlock, the
|
package/dist/tools.js
CHANGED
|
@@ -29,6 +29,11 @@ const OPERATION_TYPE_SUMMARIES = {
|
|
|
29
29
|
insertBeforeBlock: "insert a new paragraph before a block",
|
|
30
30
|
replaceBlock: "replace one block's entire text",
|
|
31
31
|
deleteBlock: "delete one block",
|
|
32
|
+
splitBlock: "break one block in two at `offset`, moving a paragraph mark and no words",
|
|
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) without touching its words",
|
|
35
|
+
insertTable: "insert a whole table of `rows` next to the anchor block",
|
|
36
|
+
deleteTable: "delete the whole table the anchor block sits in",
|
|
32
37
|
commentOnBlock: "attach a comment to one block, optionally quoting text within it",
|
|
33
38
|
insertSignatureTable: "insert a side-by-side signature table for the given `parties`",
|
|
34
39
|
insertTableRow: "insert a table row next to the row containing a cell block",
|
|
@@ -142,6 +147,14 @@ const OPERATION_PROPERTY_SCHEMAS = {
|
|
|
142
147
|
additionalProperties: false
|
|
143
148
|
}
|
|
144
149
|
},
|
|
150
|
+
rows: {
|
|
151
|
+
type: "array",
|
|
152
|
+
description: "Required for `insertTable`: cell texts row by row. Every row must hold the same number of cells.",
|
|
153
|
+
items: {
|
|
154
|
+
type: "array",
|
|
155
|
+
items: { type: "string" }
|
|
156
|
+
}
|
|
157
|
+
},
|
|
145
158
|
cellTexts: {
|
|
146
159
|
type: "array",
|
|
147
160
|
description: "For row or column insertion, initial text for new physical cells in source order, up to 100,000 characters per cell.",
|
|
@@ -159,6 +172,41 @@ const OPERATION_PROPERTY_SCHEMAS = {
|
|
|
159
172
|
minProperties: 1,
|
|
160
173
|
additionalProperties: false
|
|
161
174
|
},
|
|
175
|
+
properties: {
|
|
176
|
+
type: "object",
|
|
177
|
+
description: "Required for `setBlockParagraphProperties`: the paragraph properties to set. `styleId: null` clears the style.",
|
|
178
|
+
properties: {
|
|
179
|
+
styleId: {
|
|
180
|
+
type: "string",
|
|
181
|
+
description: "Paragraph style id."
|
|
182
|
+
},
|
|
183
|
+
listLevel: {
|
|
184
|
+
type: "integer",
|
|
185
|
+
minimum: 0,
|
|
186
|
+
description: "`w:numPr/w:ilvl`, zero-based."
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
minProperties: 1,
|
|
190
|
+
additionalProperties: false
|
|
191
|
+
},
|
|
192
|
+
listLevel: {
|
|
193
|
+
type: "integer",
|
|
194
|
+
minimum: 0,
|
|
195
|
+
description: "For inserts: `w:numPr/w:ilvl` for the inserted block, keeping the anchor's list."
|
|
196
|
+
},
|
|
197
|
+
offset: {
|
|
198
|
+
type: "integer",
|
|
199
|
+
minimum: 0,
|
|
200
|
+
description: "Required for `splitBlock`: character offset in the block's text where the paragraph break goes. Must fall strictly inside the text."
|
|
201
|
+
},
|
|
202
|
+
separator: {
|
|
203
|
+
type: "string",
|
|
204
|
+
description: "For `splitBlock`, the text at `offset` the break replaces (usually a space); for `mergeBlockWithNext`, the text the join inserts between the two halves."
|
|
205
|
+
},
|
|
206
|
+
moveId: {
|
|
207
|
+
type: "string",
|
|
208
|
+
description: "Links one `deleteBlock` to one insertion as a single relocation, written as `w:moveFrom` / `w:moveTo`. An id that does not name exactly one of each applies as an ordinary deletion and insertion."
|
|
209
|
+
},
|
|
162
210
|
comment: {
|
|
163
211
|
type: "string",
|
|
164
212
|
description: "Optional comment explaining this edit, attached to the affected text, up to 100,000 characters. Required for comment operations."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/folio-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
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.
|
|
57
|
+
"@stll/folio-core": "^0.34.0",
|
|
58
58
|
"better-result": "3.0.1"
|
|
59
59
|
},
|
|
60
60
|
"main": "./dist/index.js",
|
|
@@ -124,7 +124,8 @@ stay exported for validation-only paths.
|
|
|
124
124
|
- Block ids (`blockId`) and comment ids (`commentId`) only ever come from a
|
|
125
125
|
prior tool call in the same conversation — `read_document`, `find_text`, or
|
|
126
126
|
`read_comments`. Never invent or reuse one from outside the conversation;
|
|
127
|
-
ids are
|
|
127
|
+
ids are opaque values a caller reads, never ones it constructs, and they
|
|
128
|
+
change whenever the document's structure changes.
|
|
128
129
|
- `suggest_changes` operations that get skipped (`skipped: [{ id, reason }]`)
|
|
129
130
|
return a plain-language reason, not a machine code (e.g. "the block changed
|
|
130
131
|
since your snapshot; re-read the document and retry with fresh ids"). Treat
|
|
@@ -139,12 +140,21 @@ stay exported for validation-only paths.
|
|
|
139
140
|
- The operation kinds a surface accepts are exactly the ones in its
|
|
140
141
|
`suggest_changes` schema's `type` enum (by default `replaceInBlock`,
|
|
141
142
|
`replaceRange`, `commentOnRange`, `formatRange`, `insertAfterBlock`,
|
|
142
|
-
`insertBeforeBlock`, `replaceBlock`, `deleteBlock`, `
|
|
143
|
-
`
|
|
144
|
-
`
|
|
143
|
+
`insertBeforeBlock`, `replaceBlock`, `deleteBlock`, `splitBlock`,
|
|
144
|
+
`mergeBlockWithNext`, `setBlockParagraphProperties`, `insertTable`,
|
|
145
|
+
`deleteTable`, `insertTableRow`, `deleteTableRow`,
|
|
146
|
+
`insertTableColumn`, `deleteTableColumn`, `mergeTableCells`,
|
|
147
|
+
`splitTableCell`) plus comment/reply/resolve. Do not
|
|
145
148
|
invent an operation kind or a directive marker; if a document needs a
|
|
146
149
|
structural operation the contract lacks, extend `@stll/folio-core`'s
|
|
147
150
|
ai-edits engine and the contract, then the schema follows.
|
|
151
|
+
- **A blank paragraph is a block like any other.** It has an id, it is
|
|
152
|
+
addressable, and adding or removing one is a real edit. `insertAfterBlock` /
|
|
153
|
+
`insertBeforeBlock` with `text: ""` insert a blank line; `deleteBlock` on a
|
|
154
|
+
blank removes it rather than doing nothing. Only an operation that would
|
|
155
|
+
change nothing at all is refused.
|
|
156
|
+
- `insertTableRow` builds the new row to the table's own column count, so
|
|
157
|
+
`cellTexts` fills the columns that exist and any it does not name stay empty.
|
|
148
158
|
- A `queued` list in a `suggest_changes` result means the host parked those
|
|
149
159
|
operations in its own review queue; treat it like `applied` for the purpose
|
|
150
160
|
of "the edit has been proposed", never as a failure.
|