@stll/folio-agents 0.1.1 → 0.3.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/README.md +16 -15
- package/dist/bridge.d.ts +7 -6
- package/dist/bridges/editor-ref.d.ts +9 -3
- package/dist/bridges/editor-ref.js +63 -10
- package/dist/bridges/reviewer.js +6 -1
- package/dist/compare.d.ts +10 -48
- package/dist/compare.js +15 -264
- package/dist/execute.js +65 -5
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/operation-schema.d.ts +1576 -0
- package/dist/operation-schema.js +525 -0
- package/dist/parse.js +49 -3
- package/dist/tools.d.ts +10 -1
- package/dist/tools.js +111 -43
- package/dist/types.d.ts +9 -1
- package/dist/types.js +2 -0
- package/package.json +3 -3
- package/skills/folio-agents/SKILL.md +10 -6
package/dist/tools.js
CHANGED
|
@@ -1,4 +1,75 @@
|
|
|
1
1
|
import { FOLIO_AGENT_TOOL_NAMES } from "./types.js";
|
|
2
|
+
import { FOLIO_TEXT_RANGE_JSON_SCHEMA } from "./operation-schema.js";
|
|
3
|
+
import { FOLIO_DOCUMENT_OPERATION_TYPES } from "@stll/folio-core/server";
|
|
4
|
+
//#region src/tools.ts
|
|
5
|
+
/**
|
|
6
|
+
* `suggest_changes` deliberately narrows the full document-operation contract
|
|
7
|
+
* (see `FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA` in `operation-schema.ts`):
|
|
8
|
+
* - excluded types: `formatRange` and `insertSignatureTable` (direct-only,
|
|
9
|
+
* not representable as tracked changes for human review) and
|
|
10
|
+
* `commentOnBlock` (covered by the dedicated `add_comment` tool);
|
|
11
|
+
* - `id` is optional here (auto-generated `op-1`, `op-2`, … by `parse.ts`)
|
|
12
|
+
* where the contract requires it;
|
|
13
|
+
* - `comment` is a plain string here; `parse.ts` wraps it into the contract's
|
|
14
|
+
* `{ text }` object;
|
|
15
|
+
* - the review metadata (`severity`, `area`), `precondition` guard, and the
|
|
16
|
+
* insert/replace formatting knobs (`inheritFormatting`, `pageBreakBefore`,
|
|
17
|
+
* `preserveFormatting`, `styleId`, `position`, `parties`, `quote`,
|
|
18
|
+
* `formatting`) are not exposed to the model.
|
|
19
|
+
*/
|
|
20
|
+
const SUGGEST_CHANGES_EXCLUDED_OPERATION_TYPES = /* @__PURE__ */ new Set([
|
|
21
|
+
"formatRange",
|
|
22
|
+
"commentOnBlock",
|
|
23
|
+
"insertSignatureTable"
|
|
24
|
+
]);
|
|
25
|
+
/**
|
|
26
|
+
* The contract operation types `suggest_changes` exposes to the model,
|
|
27
|
+
* derived from the shared contract constant minus the exclusions above.
|
|
28
|
+
* Exported (module-level only, not from the package index) so
|
|
29
|
+
* `parse.test.ts` can assert this enum stays in lockstep with what
|
|
30
|
+
* `parseSuggestChangesInput` actually accepts.
|
|
31
|
+
*/
|
|
32
|
+
const SUGGEST_CHANGES_OPERATION_TYPES = FOLIO_DOCUMENT_OPERATION_TYPES.filter((type) => !SUGGEST_CHANGES_EXCLUDED_OPERATION_TYPES.has(type));
|
|
33
|
+
const suggestChangesOperationSchema = {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
id: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Optional caller-supplied operation id, echoed back in `applied`/`skipped`. Auto-generated (op-1, op-2, …) when omitted."
|
|
39
|
+
},
|
|
40
|
+
type: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: SUGGEST_CHANGES_OPERATION_TYPES,
|
|
43
|
+
description: "The kind of edit to make."
|
|
44
|
+
},
|
|
45
|
+
blockId: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "The block to edit, from `read_document` or `find_text`."
|
|
48
|
+
},
|
|
49
|
+
range: {
|
|
50
|
+
...FOLIO_TEXT_RANGE_JSON_SCHEMA,
|
|
51
|
+
description: "Required for `replaceRange` and `commentOnRange`: copy the range object returned by `find_text`."
|
|
52
|
+
},
|
|
53
|
+
find: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Required for `replaceInBlock`: the exact text to find within the block, up to 100,000 characters."
|
|
56
|
+
},
|
|
57
|
+
replace: {
|
|
58
|
+
type: "string",
|
|
59
|
+
description: "Required for `replaceInBlock` and `replaceRange`: replacement text, up to 100,000 characters."
|
|
60
|
+
},
|
|
61
|
+
text: {
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Required for `insertAfterBlock` / `insertBeforeBlock` / `replaceBlock`: the text to insert or replace the block with, up to 100,000 characters."
|
|
64
|
+
},
|
|
65
|
+
comment: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Optional comment explaining this edit, attached to the affected text, up to 100,000 characters."
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
required: ["type"],
|
|
71
|
+
additionalProperties: false
|
|
72
|
+
};
|
|
2
73
|
/**
|
|
3
74
|
* The tools this package exposes, described for an LLM. Every tool that reads
|
|
4
75
|
* or mutates the document expects `blockId` values that came from
|
|
@@ -18,6 +89,44 @@ const FOLIO_AGENT_TOOLS = [
|
|
|
18
89
|
additionalProperties: false
|
|
19
90
|
}
|
|
20
91
|
},
|
|
92
|
+
{
|
|
93
|
+
name: FOLIO_AGENT_TOOL_NAMES.listStories,
|
|
94
|
+
description: "List readable document stories and their typed handles.",
|
|
95
|
+
inputSchema: {
|
|
96
|
+
type: "object",
|
|
97
|
+
properties: {},
|
|
98
|
+
required: [],
|
|
99
|
+
additionalProperties: false
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: FOLIO_AGENT_TOOL_NAMES.readStory,
|
|
104
|
+
description: "Read one document story using a handle returned by `list_stories`.",
|
|
105
|
+
inputSchema: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: { handle: {
|
|
108
|
+
type: "object",
|
|
109
|
+
properties: {
|
|
110
|
+
type: {
|
|
111
|
+
type: "string",
|
|
112
|
+
enum: [
|
|
113
|
+
"main",
|
|
114
|
+
"header",
|
|
115
|
+
"footer",
|
|
116
|
+
"footnote",
|
|
117
|
+
"endnote"
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
relationshipId: { type: "string" },
|
|
121
|
+
noteId: { type: "integer" }
|
|
122
|
+
},
|
|
123
|
+
required: ["type"],
|
|
124
|
+
additionalProperties: false
|
|
125
|
+
} },
|
|
126
|
+
required: ["handle"],
|
|
127
|
+
additionalProperties: false
|
|
128
|
+
}
|
|
129
|
+
},
|
|
21
130
|
{
|
|
22
131
|
name: FOLIO_AGENT_TOOL_NAMES.findText,
|
|
23
132
|
description: "Search the document body for a text string and return `{ matches, truncated, totalMatches }`, where each match has its block id, which occurrence within that block it is, and surrounding context. `matches` is capped at 200 entries; `truncated` is true and `totalMatches` reports the real count when there were more — narrow the query instead of assuming you saw every hit. Use this to locate the blockId for a known phrase instead of reading the whole document.",
|
|
@@ -96,48 +205,7 @@ const FOLIO_AGENT_TOOLS = [
|
|
|
96
205
|
properties: { operations: {
|
|
97
206
|
type: "array",
|
|
98
207
|
description: "The edits to propose, applied in order. At most 50 per call.",
|
|
99
|
-
items:
|
|
100
|
-
type: "object",
|
|
101
|
-
properties: {
|
|
102
|
-
id: {
|
|
103
|
-
type: "string",
|
|
104
|
-
description: "Optional caller-supplied operation id, echoed back in `applied`/`skipped`. Auto-generated (op-1, op-2, …) when omitted."
|
|
105
|
-
},
|
|
106
|
-
type: {
|
|
107
|
-
type: "string",
|
|
108
|
-
enum: [
|
|
109
|
-
"replaceInBlock",
|
|
110
|
-
"insertAfterBlock",
|
|
111
|
-
"insertBeforeBlock",
|
|
112
|
-
"replaceBlock",
|
|
113
|
-
"deleteBlock"
|
|
114
|
-
],
|
|
115
|
-
description: "The kind of edit to make."
|
|
116
|
-
},
|
|
117
|
-
blockId: {
|
|
118
|
-
type: "string",
|
|
119
|
-
description: "The block to edit, from `read_document` or `find_text`."
|
|
120
|
-
},
|
|
121
|
-
find: {
|
|
122
|
-
type: "string",
|
|
123
|
-
description: "Required for `replaceInBlock`: the exact text to find within the block, up to 100,000 characters."
|
|
124
|
-
},
|
|
125
|
-
replace: {
|
|
126
|
-
type: "string",
|
|
127
|
-
description: "Required for `replaceInBlock`: the text to replace `find` with, up to 100,000 characters."
|
|
128
|
-
},
|
|
129
|
-
text: {
|
|
130
|
-
type: "string",
|
|
131
|
-
description: "Required for `insertAfterBlock` / `insertBeforeBlock` / `replaceBlock`: the text to insert or replace the block with, up to 100,000 characters."
|
|
132
|
-
},
|
|
133
|
-
comment: {
|
|
134
|
-
type: "string",
|
|
135
|
-
description: "Optional comment explaining this edit, attached to the affected text, up to 100,000 characters."
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
required: ["type", "blockId"],
|
|
139
|
-
additionalProperties: false
|
|
140
|
-
}
|
|
208
|
+
items: suggestChangesOperationSchema
|
|
141
209
|
} },
|
|
142
210
|
required: ["operations"],
|
|
143
211
|
additionalProperties: false
|
|
@@ -221,4 +289,4 @@ const FOLIO_AGENT_TOOLS = [
|
|
|
221
289
|
/** The tool definitions this package exposes. Same array as {@link FOLIO_AGENT_TOOLS}, as a function for symmetry with the other providers. */
|
|
222
290
|
const getFolioToolDefinitions = () => FOLIO_AGENT_TOOLS;
|
|
223
291
|
//#endregion
|
|
224
|
-
export { FOLIO_AGENT_TOOLS, getFolioToolDefinitions };
|
|
292
|
+
export { FOLIO_AGENT_TOOLS, SUGGEST_CHANGES_OPERATION_TYPES, getFolioToolDefinitions };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FolioAITextRangeHandle, FolioDocumentOperationIssue, FolioDocumentOperationReceipt } from "@stll/folio-core/server";
|
|
2
|
+
|
|
1
3
|
//#region src/types.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Provider-neutral tool-layer types. `FolioAgentToolDefinition` describes a
|
|
@@ -8,6 +10,8 @@
|
|
|
8
10
|
/** Every tool name this package exposes, as a stable string union (no enums). */
|
|
9
11
|
declare const FOLIO_AGENT_TOOL_NAMES: {
|
|
10
12
|
readonly readDocument: "read_document";
|
|
13
|
+
readonly listStories: "list_stories";
|
|
14
|
+
readonly readStory: "read_story";
|
|
11
15
|
readonly findText: "find_text";
|
|
12
16
|
readonly readComments: "read_comments";
|
|
13
17
|
readonly readChanges: "read_changes";
|
|
@@ -54,7 +58,8 @@ type FolioAgentBlock = {
|
|
|
54
58
|
};
|
|
55
59
|
/** One `find_text` match: which block, which occurrence within it, and a text window around the match. */
|
|
56
60
|
type FolioAgentTextMatch = {
|
|
57
|
-
blockId: string; /**
|
|
61
|
+
blockId: string; /** Stable handle that can be passed directly to a `replaceRange` operation. */
|
|
62
|
+
range: FolioAITextRangeHandle; /** 0-based index of this occurrence within its block (multiple matches in one block increment this). */
|
|
58
63
|
occurrenceInBlock: number; /** The match plus ~40 characters of surrounding context on each side. */
|
|
59
64
|
context: string;
|
|
60
65
|
};
|
|
@@ -103,6 +108,7 @@ type FolioAgentChange = {
|
|
|
103
108
|
type FolioAgentCommentFilter = "all" | "open" | "resolved";
|
|
104
109
|
/** Result of {@link FOLIO_AGENT_TOOL_NAMES.addComment} / `suggest_changes`. */
|
|
105
110
|
type FolioAgentApplyOperationsSummary = {
|
|
111
|
+
version: typeof FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION;
|
|
106
112
|
applied: {
|
|
107
113
|
id: string;
|
|
108
114
|
}[];
|
|
@@ -110,6 +116,8 @@ type FolioAgentApplyOperationsSummary = {
|
|
|
110
116
|
id: string;
|
|
111
117
|
reason: string;
|
|
112
118
|
}[];
|
|
119
|
+
issues: FolioDocumentOperationIssue[];
|
|
120
|
+
receipts: FolioDocumentOperationReceipt[];
|
|
113
121
|
};
|
|
114
122
|
//#endregion
|
|
115
123
|
export { FOLIO_AGENT_TOOL_NAMES, FolioAgentApplyOperationsSummary, FolioAgentBlock, FolioAgentChange, FolioAgentComment, FolioAgentCommentFilter, FolioAgentCommentReply, FolioAgentFindTextResult, FolioAgentTextMatch, FolioAgentToolDefinition, FolioAgentToolName, FolioToolCallResult };
|
package/dist/types.js
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
/** Every tool name this package exposes, as a stable string union (no enums). */
|
|
9
9
|
const FOLIO_AGENT_TOOL_NAMES = {
|
|
10
10
|
readDocument: "read_document",
|
|
11
|
+
listStories: "list_stories",
|
|
12
|
+
readStory: "read_story",
|
|
11
13
|
findText: "find_text",
|
|
12
14
|
readComments: "read_comments",
|
|
13
15
|
readChanges: "read_changes",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/folio-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"build": "rm -rf dist && tsdown",
|
|
51
51
|
"prepack": "bun run build",
|
|
52
52
|
"pack:dry-run": "bun pm pack --dry-run",
|
|
53
|
-
"typecheck": "
|
|
53
|
+
"typecheck": "bun ../../scripts/tsc-native.ts --noEmit -p tsconfig.build.json",
|
|
54
54
|
"test": "bun test src"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@stll/folio-core": "^0.
|
|
57
|
+
"@stll/folio-core": "^0.4.0"
|
|
58
58
|
},
|
|
59
59
|
"main": "./dist/index.js",
|
|
60
60
|
"types": "./dist/index.d.ts"
|
|
@@ -99,14 +99,18 @@ go straight back to the model.
|
|
|
99
99
|
since your snapshot; re-read the document and retry with fresh ids"). Treat
|
|
100
100
|
a skip as a retry signal: re-read (`read_document` or `find_text`) and
|
|
101
101
|
reissue with fresh ids, not a dead end.
|
|
102
|
+
- Successful mutations return input-ordered `receipts`. Use their typed
|
|
103
|
+
`affected` targets to identify updated blocks, stable ranges, insertions,
|
|
104
|
+
and created comments without inferring effects from document text.
|
|
102
105
|
- `suggest_changes` defaults to tracked-changes mode on both shipped bridges
|
|
103
106
|
— it proposes redlines for a human to accept or reject, never edits the
|
|
104
107
|
visible text directly.
|
|
105
|
-
- The tool surface here is fixed:
|
|
106
|
-
(`replaceInBlock`, `
|
|
107
|
-
`deleteBlock`) plus
|
|
108
|
+
- The tool surface here is fixed: seven edit operation kinds
|
|
109
|
+
(`replaceInBlock`, `replaceRange`, `commentOnRange`, `insertAfterBlock`,
|
|
110
|
+
`insertBeforeBlock`, `replaceBlock`, `deleteBlock`) plus
|
|
111
|
+
comment/reply/resolve. There is no
|
|
108
112
|
`insertSignatureTable`-style structural op, and none should be invented —
|
|
109
|
-
compose the
|
|
113
|
+
compose the seven primitives, or extend `@stll/folio-core`'s ai-edits engine
|
|
110
114
|
itself if a document needs a structural operation this package doesn't
|
|
111
115
|
expose.
|
|
112
116
|
- **Untrusted documents:** `read_document`, `read_comments`, `read_changes`,
|
|
@@ -123,8 +127,8 @@ go straight back to the model.
|
|
|
123
127
|
Two different questions, two different tools:
|
|
124
128
|
|
|
125
129
|
- **Pending redlines in one document** — what a reviewer would see as tracked
|
|
126
|
-
changes right now: use the `read_changes` tool
|
|
127
|
-
|
|
130
|
+
changes right now: use the `read_changes` tool on a capable bridge or call
|
|
131
|
+
`reviewer.getChanges()` directly.
|
|
128
132
|
- **Between two saved `.docx` versions** — `compareDocxVersions(previousBuffer,
|
|
129
133
|
currentBuffer)` + `formatVersionDiffForLLM(diff)`. Both are plain async
|
|
130
134
|
functions, not tool definitions: a model can't attach two buffers to one
|