@stll/folio-agents 0.2.0 → 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.
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/dist/index.d.ts CHANGED
@@ -4,7 +4,8 @@ import { CreateEditorRefBridgeOptions, FolioAgentEditorApplyDocumentOperationsOp
4
4
  import { CreateReviewerBridgeOptions, createReviewerBridge } from "./bridges/reviewer.js";
5
5
  import { FolioAgentBlockDiff, FolioAgentVersionDiff, FolioAgentVersionDiffSegment, compareDocxVersions, formatVersionDiffForLLM } from "./compare.js";
6
6
  import { executeFolioToolCall } from "./execute.js";
7
+ import { FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, folioDocumentOperationBatchSchema } from "./operation-schema.js";
7
8
  import { ParseAddCommentResult, ParseSuggestChangesResult, parseAddCommentInput, parseSuggestChangesInput } from "./parse.js";
8
9
  import { AnthropicToolDefinition, OpenAIToolDefinition, toAnthropicTools, toOpenAITools } from "./providers.js";
9
10
  import { FOLIO_AGENT_TOOLS, getFolioToolDefinitions } from "./tools.js";
10
- export { type AnthropicToolDefinition, type CreateEditorRefBridgeOptions, type CreateReviewerBridgeOptions, FOLIO_AGENT_TOOLS, FOLIO_AGENT_TOOL_NAMES, type FolioAgentApplyOperationsSummary, type FolioAgentBlock, type FolioAgentBlockDiff, type FolioAgentBridge, type FolioAgentChange, type FolioAgentComment, type FolioAgentCommentFilter, type FolioAgentCommentReply, type FolioAgentEditorApplyDocumentOperationsOptions, type FolioAgentEditorRefLike, type FolioAgentTextMatch, type FolioAgentToolDefinition, type FolioAgentToolName, type FolioAgentVersionDiff, type FolioAgentVersionDiffSegment, type FolioToolCallResult, type OpenAIToolDefinition, type ParseAddCommentResult, type ParseSuggestChangesResult, compareDocxVersions, createEditorRefBridge, createReviewerBridge, executeFolioToolCall, formatVersionDiffForLLM, getFolioToolDefinitions, parseAddCommentInput, parseSuggestChangesInput, toAnthropicTools, toOpenAITools };
11
+ export { type AnthropicToolDefinition, type CreateEditorRefBridgeOptions, type CreateReviewerBridgeOptions, FOLIO_AGENT_TOOLS, FOLIO_AGENT_TOOL_NAMES, FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, type FolioAgentApplyOperationsSummary, type FolioAgentBlock, type FolioAgentBlockDiff, type FolioAgentBridge, type FolioAgentChange, type FolioAgentComment, type FolioAgentCommentFilter, type FolioAgentCommentReply, type FolioAgentEditorApplyDocumentOperationsOptions, type FolioAgentEditorRefLike, type FolioAgentTextMatch, type FolioAgentToolDefinition, type FolioAgentToolName, type FolioAgentVersionDiff, type FolioAgentVersionDiffSegment, type FolioToolCallResult, type OpenAIToolDefinition, type ParseAddCommentResult, type ParseSuggestChangesResult, compareDocxVersions, createEditorRefBridge, createReviewerBridge, executeFolioToolCall, folioDocumentOperationBatchSchema, formatVersionDiffForLLM, getFolioToolDefinitions, parseAddCommentInput, parseSuggestChangesInput, toAnthropicTools, toOpenAITools };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { FOLIO_AGENT_TOOL_NAMES } from "./types.js";
4
4
  import { executeFolioToolCall } from "./execute.js";
5
5
  import { createEditorRefBridge } from "./bridges/editor-ref.js";
6
6
  import { createReviewerBridge } from "./bridges/reviewer.js";
7
+ import { FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, folioDocumentOperationBatchSchema } from "./operation-schema.js";
7
8
  import { toAnthropicTools, toOpenAITools } from "./providers.js";
8
9
  import { FOLIO_AGENT_TOOLS, getFolioToolDefinitions } from "./tools.js";
9
- export { FOLIO_AGENT_TOOLS, FOLIO_AGENT_TOOL_NAMES, compareDocxVersions, createEditorRefBridge, createReviewerBridge, executeFolioToolCall, formatVersionDiffForLLM, getFolioToolDefinitions, parseAddCommentInput, parseSuggestChangesInput, toAnthropicTools, toOpenAITools };
10
+ export { FOLIO_AGENT_TOOLS, FOLIO_AGENT_TOOL_NAMES, FOLIO_DOCUMENT_OPERATION_BATCH_JSON_SCHEMA, FOLIO_DOCUMENT_OPERATION_JSON_SCHEMA, compareDocxVersions, createEditorRefBridge, createReviewerBridge, executeFolioToolCall, folioDocumentOperationBatchSchema, formatVersionDiffForLLM, getFolioToolDefinitions, parseAddCommentInput, parseSuggestChangesInput, toAnthropicTools, toOpenAITools };