@stll/folio-agents 0.3.0 → 0.4.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/bridge.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FolioAgentChange, FolioAgentComment } from "./types.js";
2
- import { FolioAIEditSnapshot, FolioDocumentOperationBatch, FolioDocumentOperationResult, FolioDocumentStory, FolioDocumentStoryHandle } from "@stll/folio-core/server";
2
+ import { FolioAIEditSnapshot, FolioDocumentOperationBatch, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, FolioDocumentStory, FolioDocumentStoryHandle } from "@stll/folio-core/server";
3
3
 
4
4
  //#region src/bridge.d.ts
5
5
  /**
@@ -21,7 +21,8 @@ type FolioAgentBridge = {
21
21
  * Apply a versioned operation batch against the current document. The
22
22
  * bridge decides mode (tracked-changes by default) and author internally.
23
23
  */
24
- applyDocumentOperations(batch: FolioDocumentOperationBatch): FolioDocumentOperationResult; /** The comment threads present in the document. */
24
+ applyDocumentOperations(batch: FolioDocumentOperationBatch): FolioDocumentOperationResult; /** Undo the latest unchanged batch when the execution surface supports it. */
25
+ undoDocumentOperations?(undoHandle: FolioDocumentOperationUndoHandle): FolioDocumentOperationUndoResult; /** The comment threads present in the document. */
25
26
  getComments(): FolioAgentComment[]; /** The pending tracked changes (insertions/deletions) present in the document. */
26
27
  getChanges(): FolioAgentChange[]; /** Discover typed document stories when the surface exposes package parts. */
27
28
  listStories?(): FolioDocumentStory[]; /** Read one previously discovered story. */
@@ -1,5 +1,5 @@
1
1
  import { FolioAgentBridge } from "../bridge.js";
2
- import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot, FolioDocumentOperationBatch, FolioDocumentOperationResult } from "@stll/folio-core/server";
2
+ import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot, FolioDocumentOperationBatch, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult } from "@stll/folio-core/server";
3
3
  import { FolioCommentAnchor, FolioReviewChange as FolioReviewChange$1 } from "@stll/folio-core/ai-edits";
4
4
  import { Comment } from "@stll/folio-core/types/content";
5
5
 
@@ -30,7 +30,8 @@ type FolioAgentEditorRefLike = {
30
30
  mode?: FolioAIEditApplyMode;
31
31
  author?: string;
32
32
  }): FolioAIEditApplyResult; /** `DocxEditorRef.applyDocumentOperations`, when available on newer refs. */
33
- applyDocumentOperations?(options: FolioAgentEditorApplyDocumentOperationsOptions): FolioDocumentOperationResult; /** `DocxEditorRef.scrollToBlock`. */
33
+ applyDocumentOperations?(options: FolioAgentEditorApplyDocumentOperationsOptions): FolioDocumentOperationResult; /** `DocxEditorRef.undoDocumentOperations`, when available on newer refs. */
34
+ undoDocumentOperations?(undoHandle: FolioDocumentOperationUndoHandle): FolioDocumentOperationUndoResult; /** `DocxEditorRef.scrollToBlock`. */
34
35
  scrollToBlock(blockId: string, snapshot?: FolioAIEditSnapshot): boolean; /** `DocxEditorRef.getTotalPages`. */
35
36
  getTotalPages(): number;
36
37
  /**
@@ -51,6 +51,7 @@ const paragraphPlainText = (paragraph) => {
51
51
  */
52
52
  const createEditorRefBridge = (options) => {
53
53
  const { ref, author, getComments, setComments } = options;
54
+ const undoDocumentOperations = ref.undoDocumentOperations?.bind(ref);
54
55
  const mode = options.mode ?? "tracked-changes";
55
56
  const requireSnapshot = () => {
56
57
  const snapshot = ref.createAIEditSnapshot();
@@ -75,7 +76,8 @@ const createEditorRefBridge = (options) => {
75
76
  return {
76
77
  ...result,
77
78
  issues: result.issues ?? getFolioDocumentOperationIssues(versionedBatch.operations, result.skipped),
78
- receipts: result.receipts ?? getFolioDocumentOperationReceipts(versionedBatch.operations, result.applied)
79
+ receipts: result.receipts ?? getFolioDocumentOperationReceipts(versionedBatch.operations, result.applied),
80
+ undoHandle: result.undoHandle ?? null
79
81
  };
80
82
  }
81
83
  if (versionedBatch.dryRun === true) {
@@ -89,7 +91,8 @@ const createEditorRefBridge = (options) => {
89
91
  applied: [],
90
92
  skipped,
91
93
  issues: getFolioDocumentOperationIssues(versionedBatch.operations, skipped),
92
- receipts: []
94
+ receipts: [],
95
+ undoHandle: null
93
96
  };
94
97
  }
95
98
  if (versionedBatch.atomic === true) {
@@ -103,7 +106,8 @@ const createEditorRefBridge = (options) => {
103
106
  applied: [],
104
107
  skipped,
105
108
  issues: getFolioDocumentOperationIssues(versionedBatch.operations, skipped),
106
- receipts: []
109
+ receipts: [],
110
+ undoHandle: null
107
111
  };
108
112
  }
109
113
  const result = ref.applyAIEditOperations({
@@ -117,9 +121,11 @@ const createEditorRefBridge = (options) => {
117
121
  status: "committed",
118
122
  ...result,
119
123
  issues: getFolioDocumentOperationIssues(versionedBatch.operations, result.skipped),
120
- receipts: getFolioDocumentOperationReceipts(versionedBatch.operations, result.applied)
124
+ receipts: getFolioDocumentOperationReceipts(versionedBatch.operations, result.applied),
125
+ undoHandle: null
121
126
  };
122
127
  },
128
+ ...undoDocumentOperations && { undoDocumentOperations: (undoHandle) => undoDocumentOperations(undoHandle) },
123
129
  getComments: () => {
124
130
  const comments = getComments();
125
131
  const anchors = ref.getCommentAnchors?.();
@@ -37,6 +37,7 @@ const createReviewerBridge = (reviewer, options = {}) => {
37
37
  ...batch,
38
38
  mode
39
39
  }),
40
+ undoDocumentOperations: (undoHandle) => reviewer.undoDocumentOperations(undoHandle),
40
41
  getComments: () => reviewer.getComments().map(toAgentComment),
41
42
  getChanges: () => reviewer.getChanges().map(toAgentChange),
42
43
  listStories: () => reviewer.listStories(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-agents",
3
- "version": "0.3.0",
3
+ "version": "0.4.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.4.0"
57
+ "@stll/folio-core": "^0.6.0"
58
58
  },
59
59
  "main": "./dist/index.js",
60
60
  "types": "./dist/index.d.ts"