@folijs/agent 0.3.3 → 0.4.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +124 -21
  3. package/dist/changes.d.ts +23 -0
  4. package/dist/changes.d.ts.map +1 -0
  5. package/dist/changes.js +136 -0
  6. package/dist/changes.js.map +1 -0
  7. package/dist/formatting.d.ts +24 -0
  8. package/dist/formatting.d.ts.map +1 -0
  9. package/dist/formatting.js +106 -0
  10. package/dist/formatting.js.map +1 -0
  11. package/dist/handles.js +32 -12
  12. package/dist/handles.js.map +1 -1
  13. package/dist/index.d.ts +7 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +3 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/inserts.d.ts +42 -0
  18. package/dist/inserts.d.ts.map +1 -0
  19. package/dist/inserts.js +242 -0
  20. package/dist/inserts.js.map +1 -0
  21. package/dist/operations.d.ts.map +1 -1
  22. package/dist/operations.js +52 -27
  23. package/dist/operations.js.map +1 -1
  24. package/dist/paragraphs.d.ts +16 -0
  25. package/dist/paragraphs.d.ts.map +1 -0
  26. package/dist/paragraphs.js +146 -0
  27. package/dist/paragraphs.js.map +1 -0
  28. package/dist/read.d.ts +15 -1
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +138 -6
  31. package/dist/read.js.map +1 -1
  32. package/dist/schema.d.ts +25 -0
  33. package/dist/schema.d.ts.map +1 -0
  34. package/dist/schema.js +51 -0
  35. package/dist/schema.js.map +1 -0
  36. package/dist/session.d.ts +79 -2
  37. package/dist/session.d.ts.map +1 -1
  38. package/dist/session.js +141 -16
  39. package/dist/session.js.map +1 -1
  40. package/dist/stories.d.ts +2 -0
  41. package/dist/stories.d.ts.map +1 -0
  42. package/dist/stories.js +80 -0
  43. package/dist/stories.js.map +1 -0
  44. package/dist/tables.d.ts +21 -0
  45. package/dist/tables.d.ts.map +1 -0
  46. package/dist/tables.js +485 -0
  47. package/dist/tables.js.map +1 -0
  48. package/dist/tools.d.ts +89 -0
  49. package/dist/tools.d.ts.map +1 -0
  50. package/dist/tools.js +717 -0
  51. package/dist/tools.js.map +1 -0
  52. package/package.json +4 -4
  53. package/src/changes.ts +193 -0
  54. package/src/formatting.ts +149 -0
  55. package/src/handles.ts +40 -13
  56. package/src/index.ts +23 -0
  57. package/src/inserts.ts +339 -0
  58. package/src/operations.ts +71 -34
  59. package/src/paragraphs.ts +188 -0
  60. package/src/read.ts +141 -9
  61. package/src/schema.ts +74 -0
  62. package/src/session.ts +247 -18
  63. package/src/stories.ts +92 -0
  64. package/src/tables.ts +664 -0
  65. package/src/tools.ts +925 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @folijs/agent
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8d93bda: Text formatting (23.4): `formatText(handle, format, { on?, all? })` sets bold, italic, underline, strike, font, size, color, highlight and links on a paragraph or text in it, as tracked changes; `read({ formatting: true })` shows each paragraph's own run formatting (`Block.formatting`). The `format_text` tool, `read`'s `formatting` argument and `doc.formatText` in code mode. Table operations of several edits are all or nothing, and act on the row named in a vertically merged table.
8
+ - 7aa04b3: Inserting (23.6): `insertItem(handle, item, { where? })` inserts a picture (bytes, alt text, size read from PNG, JPEG or GIF and fitted to the page), a page or section break, a horizontal line, a footnote or an endnote, as tracked insertions; `imageInfo(bytes)`; the `insert` tool and `doc.insert`. `agentTools(session, host)` takes a `ToolHost` whose `picture(path)` gives the tools an image's bytes.
9
+ - a49809d: Paragraph formatting and lists (23.5): `formatParagraphs(handles, format)` sets alignment, line spacing, space before and after, indentation and bullet or numbered lists, as tracked formatting changes; `read({ formatting: true })` shows a paragraph's own properties; the `format_paragraph` tool and `doc.formatParagraphs`.
10
+ - b10816a: From a fresh model's trial (23.9): `read` shows a picture's alt text (`[picture: Revenue by month]`) and a table's style and header rows on its line (`Block.tableStyle`, `Block.headerRows`); `deleteBlock` says whether it made a tracked deletion or removed one's own insertion; the tools say what `insert_table`'s `header` does and what a new paragraph takes from its neighbour.
11
+ - aaae3e0: Review (23.8): `openSession(document, { review: true })` lets a session list (`changes()`), accept and reject (`acceptChanges`, `rejectChanges`, by id or "all") tracked changes, anyone's; `session.reviewing`; the `review` tool, offered only to a reviewing session (`toolsFor`).
12
+ - 230f4f4: Headers and footers (23.7): `read({ headers: true })` reads them after the body, each under the sections that use it, with handles `h1`…, `f1`… that the operations take (but `comment`, breaks and notes; their content controls are not filled); the read tool's `headers` argument. The instructions say so.
13
+ - 638c7c5: Tables (23.3): `insertTable`, `insertRows`, `deleteRows`, `setCells`, `tableStyles`, `setTableStyle`, `shadeCells` and `setHeaderRows` on a session, a table named by its handle or a cell paragraph's and its rows and columns as `read` numbers them, every edit a tracked change; the `edit_table` tool and their code-mode methods. `read` counts the grid columns a row leaves empty before its first cell (`gridBefore`), and marks a table whose formatting was changed as changed. Columns, merging, splitting and widths are refused: they cannot be recorded as tracked changes.
14
+ - f4f6e0b: The tools come with the package (23.1, ADR-0013): `agentTools(session)` gives a model loop each tool's name, description and JSON Schema, and a `run` that checks the arguments and answers in words; `AGENT_TOOLS` are the same over any session, `INSTRUCTIONS` what to tell the model once, `READ_LIMIT` the blocks `read` gives by default. `invalid` and the `JsonSchema` types moved here from `@folijs/mcp`, which re-exports the types.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [aaae3e0]
19
+ - Updated dependencies [d4b4d41]
20
+ - @folijs/core@1.7.0
21
+
3
22
  ## 0.3.3
4
23
 
5
24
  ### Patch Changes
package/README.md CHANGED
@@ -53,7 +53,7 @@ every tracked change accepted:
53
53
  Handles come from read: [b1], [b2]…`). `styles()`, `controls()` and `document()` return theirs
54
54
  bare. Only `openSession` throws: on a document that does not validate, or an empty author.
55
55
 
56
- Not read: headers, footers, footnotes and endnotes.
56
+ Headers and footers are read with `read({ headers: true })` (below); the text of footnotes and endnotes is not read.
57
57
 
58
58
  ## Editing
59
59
 
@@ -102,6 +102,110 @@ many), `unknown-style` (with the styles there are), `gone`, `unknown-handle`, `n
102
102
  the wrong kind), `refused` (the document would not take the change). No method of a session
103
103
  throws.
104
104
 
105
+ ## Formatting
106
+
107
+ `formatText` changes a paragraph's text, or `on` text in it (`all`: every place it is), as a
108
+ tracked formatting change; what `format` leaves out stays. `read({ formatting: true })` adds a
109
+ line under each paragraph with the formatting its text has of its own.
110
+
111
+ ```ts
112
+ session.formatText("b7", { bold: true, color: "1F3864" }, { on: "Total due" });
113
+ session.formatText("b7", { size: 14, font: "Arial" }); // the whole paragraph
114
+ session.formatText("b7", { link: "https://example.com" }, { on: "our site" }); // null: off
115
+ session.formatText("b7", { highlight: "yellow" }, { on: "TBD", all: true });
116
+ // [b7] Normal, changed: Total due: 40.
117
+ // formatting: bold, color 1F3864: "Total due"
118
+ ```
119
+
120
+ `formatParagraphs` formats paragraphs: one handle, or several (those next to each other become
121
+ one list). `read({ formatting: true })` starts a paragraph's line with its own properties.
122
+
123
+ ```ts
124
+ session.formatParagraphs("b2", { align: "center", spaceAfter: 12 });
125
+ session.formatParagraphs(["b5", "b6", "b7"], { list: "numbered" }); // null: no numbering
126
+ session.formatParagraphs("b6", { indent: "more" }); // in a list: a level deeper
127
+ // [b2] Title, changed: Prices
128
+ // formatting: paragraph centered, space after 12 pt
129
+ ```
130
+
131
+ ## Headers and footers
132
+
133
+ `read({ headers: true })` adds the headers and footers after the body, each under a line saying
134
+ where it is used (in a read in parts, after its last part). Their blocks' handles are `h1`…,
135
+ `f1`…, and the operations take them, but for `comment` (Word keeps no comments there), breaks
136
+ and notes; a header's content controls are not listed or filled.
137
+
138
+ ```ts
139
+ session.read({ headers: true });
140
+ // …
141
+ // header of sections 1–2:
142
+ // [h1] header: Quarterly Board Report - Q1 2026
143
+ // footer of sections 1–2:
144
+ // [f1] footer: Page 1 of 3
145
+ session.replaceText("h1", "Q1 2026", "Q2 2026");
146
+ ```
147
+
148
+ ## Review
149
+
150
+ A session opened with `review: true` may decide the document's tracked changes, its own and
151
+ others', as a person does in Word; without it, these refuse (an agent's edits are proposals).
152
+
153
+ ```ts
154
+ const session = openSession(document, { author: "Reviewer", review: true });
155
+ session.changes();
156
+ // [c12] inserted, Bob (2026-11-20), in [b7]: "net 30 days"
157
+ // [c13] deleted, Bob (2026-11-20), in [b7]: "net 60 days"
158
+ session.acceptChanges([12, 13]);
159
+ session.rejectChanges("all", { author: "Bob" }); // every story too
160
+ ```
161
+
162
+ ## Pictures, breaks and notes
163
+
164
+ `insertItem` inserts what is not text next to or in a paragraph, as tracked insertions: a
165
+ picture or a horizontal line as a paragraph of its own, a page or section break at the
166
+ paragraph's end (or start), a footnote or endnote at its end or after `on` text.
167
+
168
+ ```ts
169
+ session.insertItem("b4", { kind: "picture", data: bytes, alt: "Sales by region" }); // fitted to the page
170
+ session.insertItem("b4", { kind: "pageBreak" });
171
+ session.insertItem("b9", { kind: "sectionBreak", start: "continuous" });
172
+ session.insertItem("b9", { kind: "footnote", text: "Source: 2025 accounts.", on: "revenue" });
173
+ ```
174
+
175
+ The tools take a picture by path: `agentTools(session, { picture(path) { … } })` gives them its
176
+ bytes (the MCP server reads it under its root); without it, pictures are refused.
177
+
178
+ ## Tables
179
+
180
+ A table is named by its handle (its `table, 3 rows, 2 columns` line), or by a paragraph's in one
181
+ of its cells; rows and columns are numbered as `read` prints them (`r2 c1`: rows as with every
182
+ change accepted, grid columns; a merged cell by its top cell). Each returns the table as it
183
+ reads now.
184
+
185
+ ```ts
186
+ session.insertTable(
187
+ "b4",
188
+ [
189
+ ["Item", "Price"],
190
+ ["Tea", "3.50"],
191
+ ],
192
+ { header: true },
193
+ ); // after b4
194
+ session.insertRows("b9", 2, [["Cake", "2.00"]]); // after row 2; "before" as a 4th argument
195
+ session.deleteRows("b9", [3]);
196
+ session.setCells("b9", [{ row: 2, column: 2, text: "4.00" }]);
197
+ session.setTableStyle("b9", "Light List"); // session.tableStyles() lists them; null: none
198
+ session.shadeCells("b9", "D9E2F3", { row: 1 }); // a row, a column, a cell, or the table
199
+ session.setHeaderRows("b9", 1);
200
+ ```
201
+
202
+ An operation of several edits (rows, cells, a new table) is all or nothing: one that is
203
+ refused partway takes back what it did. In a vertical merge, a new row's cell the merge goes on
204
+ through takes no text (give `""`: the text is the merge's top cell's); a row whose every cell is
205
+ merged, and a merge's first row without the rows it covers, are refused.
206
+ Adding or deleting columns, merging or splitting cells and column widths are not offered: they
207
+ cannot be recorded as tracked changes. The `edit_table` tool says so, with what to do instead.
208
+
105
209
  ## Templates
106
210
 
107
211
  A template's blanks are Word's content controls and merge fields. A read shows an unfilled
@@ -146,28 +250,27 @@ session.updateFields({ data: { CandidateFirstName: "Ada" } });
146
250
 
147
251
  ## For the model
148
252
 
149
- The session is a library: an app gives its methods to a model as tools. `@folijs/mcp` does that
150
- for MCP clients, over `.docx` files in a folder. What a model needs to be told fits in a system prompt:
151
-
152
- ```text
153
- You edit a document through tools. read gives it a line per block:
154
- [b7] Clause, 1.1, changed: text
155
- [b7] is the block's handle: pass it to the other tools. After it come where the block is in a
156
- table (r1 c1: row and grid column; c1-2 a cell spanning two; "merged down" or "merged up" a
157
- vertical merge, its text in the top cell), its style, its list number, "changed" if it has tracked changes, its comments;
158
- after the colon, its text. ↵ is a line break. A line "table, 3 rows, 2 columns" is a table: its
159
- cells' blocks follow, indented. A line "not editable: …" is content you cannot change.
160
- Words in brackets ([picture], [note], [empty: Offer date]) are not text: never put them in
161
- find. [empty: …] is a content control to fill with fillControl; «Name» is a merge field to fill
162
- with updateFields.
163
- A handle stays its block's while you edit; a deleted block's is refused. A tool that changes
164
- the document returns the blocks it changed as they are now: do not read again to check (after
165
- updateFields do: it returns none). A refusal says what to do instead: follow it.
166
- Give find the exact text from the line, with its capitals, long enough to be there once.
167
- Every edit you make is a tracked change a person will accept or reject: change only what the
168
- task asks, and use comment to explain a change that is not obvious.
253
+ The session is a library: an app gives its operations to a model as tools. The tools come with
254
+ the package, with the words a model reads (names, descriptions, JSON Schemas): an app that runs
255
+ its own model loop writes no schema of its own (ADR-0013).
256
+
257
+ ```ts
258
+ import { agentTools, INSTRUCTIONS, openSession } from "@folijs/agent";
259
+
260
+ const session = openSession(document, { author: "Agent" });
261
+ const tools = agentTools(session);
262
+ // Give the model INSTRUCTIONS (a system prompt's part) and, for each tool, its name,
263
+ // description and inputSchema. Pass each call it makes to the tool's run:
264
+ const answer = tools.find((t) => t.name === call.name)?.run(call.arguments);
265
+ // answer.text goes back to the model; answer.isError marks a refusal it can act on.
169
266
  ```
170
267
 
268
+ `run` checks the arguments against the schema and answers in words when they do not fit.
269
+ `AGENT_TOOLS` are the same tools over any session (`run(session, args, host?)`), for an app that holds
270
+ several: check a call's arguments with `invalid(args, tool.inputSchema)` first, as `agentTools`
271
+ does. Limits on how much a model may add are the app's (the MCP server has its own). `@folijs/mcp` serves these tools to MCP clients, over `.docx` files in a folder, and
272
+ its code mode gives a script the same operations.
273
+
171
274
  ## Showing what changed
172
275
 
173
276
  In an app, the person sees the session's editor: give `session.editor` to `FoliCanvas` (or to
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Review (23.8): the document's tracked changes listed for a model, and accepted or rejected by
3
+ * their ids or all at once, as Word's Accept and Reject do. Only in a session opened with
4
+ * `review`: an agent that edits as a tracked change does not, unasked, decide others' changes.
5
+ */
6
+ import { type ChangeKind } from "@folijs/core";
7
+ /** A tracked change as a model reads it. */
8
+ export interface ChangeInfo {
9
+ /** Its id: what `acceptChanges` and `rejectChanges` take. */
10
+ id: number;
11
+ kind: ChangeKind;
12
+ author: string;
13
+ date: string | null;
14
+ /** The handle of the block it is in (a table's for its rows and cells), when it has one. */
15
+ block: string | null;
16
+ /** The text it inserted or deleted, cut; empty for other kinds. */
17
+ text: string;
18
+ }
19
+ export interface ResolveOptions {
20
+ /** With `all`: only this author's changes. */
21
+ author?: string;
22
+ }
23
+ //# sourceMappingURL=changes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changes.d.ts","sourceRoot":"","sources":["../src/changes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAIL,KAAK,UAAU,EAKhB,MAAM,cAAc,CAAC;AAMtB,4CAA4C;AAC5C,MAAM,WAAW,UAAU;IACzB,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,4FAA4F;IAC5F,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;CACd;AAqFD,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Review (23.8): the document's tracked changes listed for a model, and accepted or rejected by
3
+ * their ids or all at once, as Word's Accept and Reject do. Only in a session opened with
4
+ * `review`: an agent that edits as a tracked change does not, unasked, decide others' changes.
5
+ */
6
+ import { acceptAllChanges, acceptChangesById, rejectAllChanges, rejectChangesById, trackedChanges, } from "@folijs/core";
7
+ import { wordContext } from "@folijs/core/internal";
8
+ import { quote } from "./operations.js";
9
+ import { readBlocks } from "./read.js";
10
+ import { refuse } from "./result.js";
11
+ const WORDS = {
12
+ insertion: "inserted",
13
+ deletion: "deleted",
14
+ formatting: "formatted text",
15
+ paragraphInsertion: "split a paragraph",
16
+ paragraphDeletion: "joined paragraphs",
17
+ paragraphFormatting: "formatted a paragraph",
18
+ sectionFormatting: "changed a section's setup",
19
+ rowInsertion: "inserted a row",
20
+ rowDeletion: "deleted a row",
21
+ tableFormatting: "formatted a table",
22
+ };
23
+ const NODE_KINDS = new Set(["rowInsertion", "rowDeletion", "tableFormatting"]);
24
+ /** The block a change is in, by its handle. */
25
+ function blockOf(context, change) {
26
+ const { doc } = context.editor.state;
27
+ const $pos = doc.resolve(Math.min(change.from + (NODE_KINDS.has(change.kind) ? 1 : 0), doc.content.size));
28
+ const wanted = (node) => NODE_KINDS.has(change.kind) ? node.type.name === "table" : node.isTextblock;
29
+ for (let d = $pos.depth; d > 0; d--) {
30
+ const node = $pos.node(d);
31
+ if (wanted(node))
32
+ return context.handles.at($pos.before(d), node);
33
+ }
34
+ return null;
35
+ }
36
+ /** The most changes one list shows; a longer list says how many more. */
37
+ const MOST = 300;
38
+ /** The body's tracked changes now, the last section's setup's included. */
39
+ const bodyChanges = (context) => {
40
+ const { state } = context.editor;
41
+ return trackedChanges(state.doc, wordContext(state)?.envelope.section);
42
+ };
43
+ /** How many tracked changes the headers, footers and notes hold. */
44
+ function storyCount(context) {
45
+ let n = 0;
46
+ for (const story of wordContext(context.editor.state)?.stories.values() ?? [])
47
+ n += trackedChanges(story.doc).length;
48
+ return n;
49
+ }
50
+ /** @internal The body's tracked changes, in document order. */
51
+ export function listChanges(context) {
52
+ const { state } = context.editor;
53
+ // Handles in document order first: a list does not number blocks out of order.
54
+ readBlocks(state, context.handles);
55
+ const changes = bodyChanges(context).map((c) => {
56
+ const shown = c.kind === "insertion" || c.kind === "deletion" || c.kind === "formatting";
57
+ const text = shown ? state.doc.textBetween(c.from, c.to, " ", " ") : "";
58
+ return {
59
+ id: c.id,
60
+ kind: c.kind,
61
+ author: c.author,
62
+ date: c.date,
63
+ block: blockOf(context, c),
64
+ text,
65
+ };
66
+ });
67
+ const lines = changes
68
+ .slice(0, MOST)
69
+ .map((c) => `[c${c.id}] ${WORDS[c.kind]}, ${c.author || "someone"}${c.date ? ` (${c.date.slice(0, 10)})` : ""}${c.block ? `, in [${c.block}]` : ""}${c.text ? `: ${quote(c.text, 80)}` : ""}`);
70
+ if (changes.length > MOST)
71
+ lines.push(`(and ${changes.length - MOST} more: decide these first, or all at once)`);
72
+ const elsewhere = storyCount(context);
73
+ const stories = elsewhere
74
+ ? `${elsewhere === 1 ? "1 change" : `${elsewhere} changes`} in headers, footers or notes, not listed: "all" decides them too.`
75
+ : "";
76
+ return {
77
+ changes,
78
+ text: [lines.length ? lines.join("\n") : "The body has no tracked changes.", stories]
79
+ .filter(Boolean)
80
+ .join("\n"),
81
+ };
82
+ }
83
+ /** @internal Accepts or rejects changes by id, or all of them (every story too). */
84
+ export function resolveChanges(context, ids, accept, options) {
85
+ const { editor } = context;
86
+ const verb = accept ? "accepted" : "rejected";
87
+ const author = options?.author;
88
+ const count = () => bodyChanges(context).length + storyCount(context);
89
+ if (ids === "all") {
90
+ if (author !== undefined && (typeof author !== "string" || !author.trim()))
91
+ return refuse("invalid", "author is the name of who made the changes, as the list shows it.");
92
+ const before = count();
93
+ if (!before)
94
+ return refuse("no-match", "There are no tracked changes.");
95
+ editor.run((accept ? acceptAllChanges : rejectAllChanges)(author));
96
+ const left = count();
97
+ const by = author ? ` by ${quote(author)}` : "";
98
+ if (left === before)
99
+ return refuse("no-match", `No change${by} could be ${verb}: there are none${by}, or they are in a locked content control.`);
100
+ return {
101
+ ok: true,
102
+ text: left && !author
103
+ ? `Changes ${verb}; ${left} could not be (in a locked content control): list them.`
104
+ : `All changes${by} ${verb}.`,
105
+ };
106
+ }
107
+ if (author !== undefined)
108
+ return refuse("invalid", 'author goes with "all": by ids, the ids say which changes.');
109
+ if (!Array.isArray(ids) || !ids.length || !ids.every((id) => Number.isInteger(id)))
110
+ return refuse("invalid", 'ids are the changes\' numbers, as the list shows them ([c12] is 12), or "all".');
111
+ const wanted = [...new Set(ids)];
112
+ const now = bodyChanges(context);
113
+ const known = new Set(now.map((c) => c.id));
114
+ const missing = wanted.filter((id) => !known.has(id));
115
+ if (missing.length)
116
+ return refuse("unknown-handle", `There is no change ${missing.map((id) => `c${id}`).join(", ")}: list the changes for their numbers.`);
117
+ // A tracked move's other end goes with it.
118
+ const moves = new Set(now.filter((c) => wanted.includes(c.id) && c.move).map((c) => c.move));
119
+ const partners = [
120
+ ...new Set(now.filter((c) => c.move && moves.has(c.move) && !wanted.includes(c.id)).map((c) => c.id)),
121
+ ];
122
+ editor.run((accept ? acceptChangesById : rejectChangesById)(wanted));
123
+ // What is left of them: a part in a locked content control, or a table Foli cannot change.
124
+ const after = new Set(bodyChanges(context).map((c) => c.id));
125
+ const stayed = [...wanted, ...partners].filter((id) => after.has(id));
126
+ const done = [...wanted, ...partners].filter((id) => !after.has(id));
127
+ const name = (list) => list.map((id) => `c${id}`).join(", ");
128
+ if (!done.length)
129
+ return refuse("read-only", `The changes could not be ${verb} (in a locked content control, or a table Foli cannot change). Nothing was changed.`);
130
+ const moved = partners.length ? ` (with the other end of its move, ${name(partners)})` : "";
131
+ return {
132
+ ok: true,
133
+ text: `${verb[0]?.toUpperCase()}${verb.slice(1)} ${name(done.filter((id) => wanted.includes(id)))}${moved}.${stayed.length ? ` ${name(stayed)} could not be, or not all of ${stayed.length === 1 ? "it" : "them"} (in a locked content control): still listed.` : ""}`,
134
+ };
135
+ }
136
+ //# sourceMappingURL=changes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changes.js","sourceRoot":"","sources":["../src/changes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAIjB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAgB,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAe,MAAM,EAAE,MAAM,aAAa,CAAC;AAelD,MAAM,KAAK,GAA+B;IACxC,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,SAAS;IACnB,UAAU,EAAE,gBAAgB;IAC5B,kBAAkB,EAAE,mBAAmB;IACvC,iBAAiB,EAAE,mBAAmB;IACtC,mBAAmB,EAAE,uBAAuB;IAC5C,iBAAiB,EAAE,2BAA2B;IAC9C,YAAY,EAAE,gBAAgB;IAC9B,WAAW,EAAE,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E,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvE,IAAI,CAAC,IAAI,CAAC,MAAM;QACd,OAAO,MAAM,CACX,WAAW,EACX,4BAA4B,IAAI,qFAAqF,CACtH,CAAC;IACJ,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,qCAAqC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5F,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,gCAAgC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,+CAA+C,CAAC,CAAC,CAAC,EAAE,EAAE;KACvQ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,24 @@
1
+ /** What to change of the text; what is left out stays as it is. */
2
+ export interface TextFormat {
3
+ bold?: boolean;
4
+ italic?: boolean;
5
+ underline?: boolean;
6
+ strike?: boolean;
7
+ /** A font's name ("Arial"); null: the style's. */
8
+ font?: string | null;
9
+ /** In points (11, 10.5); null: the style's. */
10
+ size?: number | null;
11
+ /** RRGGBB ("1F3864"); null: the style's. */
12
+ color?: string | null;
13
+ /** One of Word's highlight colors by name ("yellow"); null: none. */
14
+ highlight?: string | null;
15
+ /** A link's address; null takes the link off. */
16
+ link?: string | null;
17
+ }
18
+ export interface FormatOptions {
19
+ /** Text of the paragraph, as read shows it: only there. Default: the whole paragraph. */
20
+ on?: string;
21
+ /** With `on`: every place it is in the paragraph. */
22
+ all?: boolean;
23
+ }
24
+ //# sourceMappingURL=formatting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAsBA,mEAAmE;AACnE,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,yFAAyF;IACzF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,GAAG,CAAC,EAAE,OAAO,CAAC;CACf"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Text formatting (23.4): bold, italic, underline, strike, font, size, color, highlight and links
3
+ * on a paragraph or on text in it, each through core's command for it, so every change is
4
+ * tracked as the editor tracks it (a formatting change; a link as the text deleted and inserted
5
+ * again, 23.2).
6
+ */
7
+ import { HIGHLIGHT_HEX, isMarkActive, isSafeHref, normalizeHref, removeLink, setFontFamily, setFontSize, setHighlight, setLink, setTextColor, toggleMark, } from "@folijs/core";
8
+ import { changed, paragraphAt, placesIn, quote } from "./operations.js";
9
+ import { refuse } from "./result.js";
10
+ const TOGGLES = ["bold", "italic", "underline", "strike"];
11
+ const KEYS = new Set([...TOGGLES, "font", "size", "color", "highlight", "link"]);
12
+ const HIGHLIGHTS = Object.keys(HIGHLIGHT_HEX);
13
+ /** Why `format` cannot be applied as given, or null. */
14
+ function wrong(format) {
15
+ if (!format || typeof format !== "object" || Array.isArray(format))
16
+ return 'format is an object of what to change: { "bold": true, "color": "1F3864" }.';
17
+ const f = format;
18
+ const keys = Object.keys(f);
19
+ if (!keys.length)
20
+ return "format names nothing to change.";
21
+ const unknown = keys.find((k) => !KEYS.has(k));
22
+ if (unknown)
23
+ return `format has no ${quote(unknown)}: it takes ${[...KEYS].join(", ")}.`;
24
+ for (const k of TOGGLES)
25
+ if (f[k] !== undefined && typeof f[k] !== "boolean")
26
+ return `${k} is true or false.`;
27
+ if (f.font !== undefined && f.font !== null && (typeof f.font !== "string" || !f.font.trim()))
28
+ return "font is a font's name, or null.";
29
+ if (f.size !== undefined &&
30
+ f.size !== null &&
31
+ !(typeof f.size === "number" && f.size >= 1 && f.size <= 1638))
32
+ return "size is in points, 1 to 1638, or null.";
33
+ if (f.color !== undefined &&
34
+ f.color !== null &&
35
+ !(typeof f.color === "string" && /^#?[0-9A-Fa-f]{6}$/.test(f.color.trim())))
36
+ return 'color is RRGGBB ("1F3864"), or null.';
37
+ if (f.highlight !== undefined &&
38
+ f.highlight !== null &&
39
+ !(typeof f.highlight === "string" && HIGHLIGHTS.includes(f.highlight.trim().toLowerCase())))
40
+ return `highlight is one of Word's: ${HIGHLIGHTS.join(", ")}; or null.`;
41
+ if (f.link !== undefined && f.link !== null) {
42
+ if (typeof f.link !== "string" || !isSafeHref(normalizeHref(f.link)))
43
+ return "link is an address (https://…, mailto:…), or null to take a link off.";
44
+ }
45
+ return null;
46
+ }
47
+ /** @internal */
48
+ export function formatText(context, handle, format, options = {}) {
49
+ const { editor } = context;
50
+ const why = wrong(format);
51
+ if (why)
52
+ return refuse("invalid", why);
53
+ const target = paragraphAt(context, handle, "text is formatted in paragraphs");
54
+ if ("ok" in target)
55
+ return target;
56
+ const places = placesIn(context, handle, target, options.on, options.all === true);
57
+ if (!Array.isArray(places))
58
+ return places;
59
+ const before = editor.state.doc;
60
+ // From the last place: a link while tracking is the text deleted and inserted again, which
61
+ // moves what comes after it.
62
+ for (const { from, to } of [...places].reverse()) {
63
+ if (from === to)
64
+ continue;
65
+ const select = () => editor.select(from, to);
66
+ for (const name of TOGGLES) {
67
+ const value = format[name];
68
+ if (value === undefined)
69
+ continue;
70
+ select();
71
+ if (isMarkActive(editor.state, name) !== value)
72
+ editor.run(toggleMark(name));
73
+ }
74
+ if (format.font !== undefined) {
75
+ select();
76
+ editor.run(setFontFamily(format.font));
77
+ }
78
+ if (format.size !== undefined) {
79
+ select();
80
+ editor.run(setFontSize(format.size));
81
+ }
82
+ if (format.color !== undefined) {
83
+ select();
84
+ editor.run(setTextColor(format.color === null ? null : `#${format.color.trim().replace(/^#/, "")}`));
85
+ }
86
+ if (format.highlight !== undefined) {
87
+ select();
88
+ const name = format.highlight?.trim().toLowerCase();
89
+ editor.run(setHighlight(name ? HIGHLIGHT_HEX[name] : null));
90
+ }
91
+ if (format.link !== undefined) {
92
+ select();
93
+ editor.run(format.link === null ? removeLink : setLink(format.link));
94
+ }
95
+ }
96
+ if (editor.state.doc === before) {
97
+ const read = changed(context, [handle]);
98
+ return {
99
+ ok: true,
100
+ blocks: read.blocks,
101
+ text: `Nothing changed: the text already has that formatting (or is in a locked content control).\n${read.text}`,
102
+ };
103
+ }
104
+ return { ok: true, ...changed(context, [handle]) };
105
+ }
106
+ //# sourceMappingURL=formatting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.js","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,aAAa,EACb,YAAY,EACZ,UAAU,EACV,aAAa,EACb,UAAU,EACV,aAAa,EACb,WAAW,EACX,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAA8B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAA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AAI,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,MAAM,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QACxC,OAAO;YACL,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,+FAA+F,IAAI,CAAC,IAAI,EAAE;SACjH,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;AACrD,CAAC"}
package/dist/handles.js CHANGED
@@ -16,23 +16,43 @@ export class Handles {
16
16
  /** Each handle's position: after its block. */
17
17
  #ends = new Map();
18
18
  #byEnd = null;
19
- #issued = 0;
20
- constructor(editor) {
19
+ #prefix;
20
+ /** Shared by the stories of a kind: no handle is given twice among them. */
21
+ #counter;
22
+ #mine = new Set();
23
+ /**
24
+ * `prefix`: the body's blocks are `b1`…, a header's `h1`…, a footer's `f1`… (23.7); `counter`
25
+ * is shared by every story of one kind.
26
+ */
27
+ constructor(editor, prefix = "b", counter = { n: 0 },
28
+ /**
29
+ * A story's editor (`editor`) tells its listeners of a change without its steps: its
30
+ * handles follow the body's editor, through the story's part of each change.
31
+ */
32
+ story) {
21
33
  this.#editor = editor;
34
+ this.#prefix = prefix;
35
+ this.#counter = counter;
22
36
  let last = editor.state.doc;
23
- editor.subscribe((state, transactions) => {
37
+ const mappingOf = (tr) => story
38
+ ? // The story's positions through the change (core's, not in its published types).
39
+ tr.mapping.storyMapping(story.id)
40
+ : tr.mapping;
41
+ (story?.body ?? editor).subscribe((_state, transactions) => {
42
+ const doc = editor.state.doc;
24
43
  // `setDocument` tells without a transaction: no position of the old document holds.
25
- if (!transactions.length && state.doc !== last)
44
+ if (!transactions.length && doc !== last)
26
45
  this.#ends.clear();
27
- last = state.doc;
46
+ last = doc;
28
47
  for (const tr of transactions) {
29
- if (!tr.steps.length)
48
+ const mapping = mappingOf(tr);
49
+ if (!mapping.maps.length)
30
50
  continue;
31
51
  for (const [handle, end] of this.#ends) {
32
52
  // The two sides of the block's closing. A block removed, or joined with the next,
33
53
  // loses one of them or sees them part, and the handle goes.
34
- const before = tr.mapping.mapResult(end - 1, 1);
35
- const after = tr.mapping.mapResult(end, -1);
54
+ const before = mapping.mapResult(end - 1, 1);
55
+ const after = mapping.mapResult(end, -1);
36
56
  if (before.deleted || after.deleted || after.pos !== before.pos + 1)
37
57
  this.#ends.delete(handle);
38
58
  else
@@ -48,7 +68,8 @@ export class Handles {
48
68
  this.#byEnd ??= new Map([...this.#ends].map(([handle, at]) => [at, handle]));
49
69
  let handle = this.#byEnd.get(end);
50
70
  if (!handle) {
51
- handle = `b${++this.#issued}`;
71
+ handle = `${this.#prefix}${++this.#counter.n}`;
72
+ this.#mine.add(handle);
52
73
  this.#ends.set(handle, end);
53
74
  this.#byEnd.set(end, handle);
54
75
  }
@@ -67,10 +88,9 @@ export class Handles {
67
88
  this.#ends.set(handle, end);
68
89
  this.#byEnd = null;
69
90
  }
70
- /** Whether `handle` was ever issued. */
91
+ /** Whether `handle` was ever issued here. */
71
92
  issued(handle) {
72
- const n = /^b([1-9]\d*)$/.exec(handle);
73
- return !!n && Number(n[1]) <= this.#issued;
93
+ return this.#mine.has(handle);
74
94
  }
75
95
  /** Where the block `handle` names is now (before it), with the block; null when it is gone. */
76
96
  resolve(handle) {
@@ -1 +1 @@
1
- {"version":3,"file":"handles.js","sourceRoot":"","sources":["../src/handles.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,OAAO;IACT,OAAO,CAAS;IACzB,+CAA+C;IACtC,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,MAAM,GAA+B,IAAI,CAAC;IAC1C,OAAO,GAAG,CAAC,CAAC;IAEZ,YAAY,MAAc;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CA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AC/F,OAAO,CAAC,MAAc;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;QACnC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QAC7D,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC;QACzC,OAAO,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
+ export type { ChangeInfo, ResolveOptions } from "./changes.js";
2
+ export type { FormatOptions, TextFormat } from "./formatting.js";
3
+ export { type InsertItem, type InsertItemOptions, imageInfo, type PictureItem, } from "./inserts.js";
1
4
  export type { Changed, CommentOptions, NewParagraph, ReplaceOptions } from "./operations.js";
5
+ export type { ParagraphFormat } from "./paragraphs.js";
2
6
  export { type Block, formatBlocks } from "./read.js";
3
7
  export type { Ok, Refusal, Result } from "./result.js";
8
+ export { invalid, type JsonSchema, type JsonSchemaOrAny } from "./schema.js";
4
9
  export { type Checkpoint, openSession, type ReadOptions, type ReadResult, type Session, type SessionOptions, } from "./session.js";
10
+ export type { CellText, InsertTableOptions, ShadeOptions } from "./tables.js";
5
11
  export type { Control, Unfilled, UpdateFieldsOptions } from "./templates.js";
12
+ export { AGENT_TOOLS, type AgentTool, agentTools, INSTRUCTIONS, READ_LIMIT, type ScriptMethod, type ToolAnswer, type ToolDefinition, type ToolHost, toolsFor, } from "./tools.js";
6
13
  //# sourceMappingURL=index.d.ts.map