@fluidframework/ai-collab 2.33.2 → 2.40.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 (47) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +156 -0
  3. package/api-report/ai-collab.alpha.api.md +88 -0
  4. package/dist/aiCollabApi.d.ts +9 -0
  5. package/dist/aiCollabApi.d.ts.map +1 -1
  6. package/dist/aiCollabApi.js.map +1 -1
  7. package/dist/alpha.d.ts +12 -0
  8. package/dist/diffTypes.d.ts +200 -0
  9. package/dist/diffTypes.d.ts.map +1 -0
  10. package/dist/diffTypes.js +7 -0
  11. package/dist/diffTypes.js.map +1 -0
  12. package/dist/explicit-strategy/agentEditReducer.d.ts +25 -3
  13. package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -1
  14. package/dist/explicit-strategy/agentEditReducer.js +239 -15
  15. package/dist/explicit-strategy/agentEditReducer.js.map +1 -1
  16. package/dist/explicit-strategy/index.d.ts +3 -0
  17. package/dist/explicit-strategy/index.d.ts.map +1 -1
  18. package/dist/explicit-strategy/index.js +6 -2
  19. package/dist/explicit-strategy/index.js.map +1 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/lib/aiCollabApi.d.ts +9 -0
  24. package/lib/aiCollabApi.d.ts.map +1 -1
  25. package/lib/aiCollabApi.js.map +1 -1
  26. package/lib/alpha.d.ts +12 -0
  27. package/lib/diffTypes.d.ts +200 -0
  28. package/lib/diffTypes.d.ts.map +1 -0
  29. package/lib/diffTypes.js +6 -0
  30. package/lib/diffTypes.js.map +1 -0
  31. package/lib/explicit-strategy/agentEditReducer.d.ts +25 -3
  32. package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -1
  33. package/lib/explicit-strategy/agentEditReducer.js +239 -18
  34. package/lib/explicit-strategy/agentEditReducer.js.map +1 -1
  35. package/lib/explicit-strategy/index.d.ts +3 -0
  36. package/lib/explicit-strategy/index.d.ts.map +1 -1
  37. package/lib/explicit-strategy/index.js +6 -2
  38. package/lib/explicit-strategy/index.js.map +1 -1
  39. package/lib/index.d.ts +1 -0
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js.map +1 -1
  42. package/package.json +9 -9
  43. package/src/aiCollabApi.ts +10 -0
  44. package/src/diffTypes.ts +211 -0
  45. package/src/explicit-strategy/agentEditReducer.ts +296 -19
  46. package/src/explicit-strategy/index.ts +10 -2
  47. package/src/index.ts +15 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluidframework/ai-collab
2
2
 
3
+ ## 2.40.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.33.0
4
8
 
5
9
  Dependency updates only.
package/README.md CHANGED
@@ -210,6 +210,7 @@ aiCollab({
210
210
  All debug events implement the `DebugEvent` interface. Some also implement `EventFlowDebugEvent`, which lets them mark a progress point in a specific logic flow within a given execution of `aiCollab()`.
211
211
 
212
212
  ### Event flow Overview
213
+
213
214
  To see detailed information about each event, please read their cooresponding [tsdoc](./src/explicit-strategy/debugEvents.ts#L46)
214
215
 
215
216
  1. **Core Event Loop** - The start and end of a single execution of aiCollab.
@@ -238,10 +239,165 @@ To see detailed information about each event, please read their cooresponding [t
238
239
 
239
240
 
240
241
  ### Using Trace Id's
242
+
241
243
  Debug Events in ai-collab have two different types of trace id's:
242
244
  - `traceId`: This field exists on all debug events and can be used to correlate all debug events that happened in a single execution of `aiCollab()`. Sorting the events by timestamp will show the proper chronological order of the events. Note that the events should already be emitted in chronological order.
243
245
  - `eventFlowTraceId`: this field exists on all `EventFlowDebugEvents` and can be used to correlate all events from a particular event flow. Additionally all LLM api call events will contain the `eventFlowTraceId` field as well as a `triggeringEventFlowName` so you can link LLM API calls to a particular event flow.
244
246
 
247
+ ## Edit Differences
248
+
249
+ `ai-collab` provides an array of `Diff` objects with its response. Each of these objects allows developers to identify tree nodes that have been modified as a result of AI collaboration and visualize them according to their needs.
250
+
251
+ Every `Diff` will include one or more `NodePaths` representing the nodes affected by a single edit created by the ai agent. A `NodePath` is an array whose items represent segment paths, beginning from the node targeted for modification (at the start of the array) all the way back to the root node passed to the ai-collab function call (at the end of the array), along with an explanation directly from the AI agent as to why it performed an edit.
252
+
253
+ Let's take a look at some examples for the following SharedTree application schema.
254
+
255
+ ```ts
256
+ import { aiCollab, DebugEvent, Diff } from "@fluidframework/ai-collab/alpha";
257
+
258
+ const sf = new SchemaFactory("testApp");
259
+
260
+ class Todo extends sf.object("Todo", {
261
+ id: sf.identifier,
262
+ title: string
263
+ description: string
264
+ }) {}
265
+
266
+ class TestAppRootObject extends sf.object("TestAppRootObject", {
267
+ id: sf.identifier,
268
+ todos: sf.array([Todo]),
269
+ innerObject: sf.object("InnerObject", {
270
+ nestedTodos: sf.array([Todo]),
271
+ }),
272
+ }) {}
273
+
274
+ const response = aiCollab({
275
+ openAI: {
276
+ client: new OpenAI({
277
+ apiKey: OPENAI_API_KEY,
278
+ }),
279
+ modelName: "gpt-4o",
280
+ },
281
+ prompt: {
282
+ systemRoleContext:
283
+ "You are a manager that is helping out with a project management tool. You have been asked to edit a group of tasks.",
284
+ userAsk: userAsk,
285
+ },
286
+ limiters: {
287
+ maxModelCalls: 25
288
+ }
289
+ planningStep: true,
290
+ finalReviewStep: true,
291
+ debugEventLogHandler: (event: DebugEvent) => {console.log(event);}
292
+ });
293
+
294
+ const diffs: Diff[] = response.diffs;
295
+ ```
296
+
297
+ Each `Diff` will contain one or more `NodePath`s. Each `NodePath` is an array of objects that detail the path from the root node passed to ai-collab, down to the node targeted for editing. The first index in the `NodePath` points to the target node and the last index is always the root node.
298
+
299
+ Let's look at an example of the Insert Diff.
300
+
301
+ ### Example Insert Diff
302
+
303
+ The following `InsertDiff` is an example of a `Diff` that would result from an AI agent inserting an object into index 1 of `TestAppRootObject.rootVectors`.
304
+
305
+ ```json
306
+ type: "insert",
307
+ nodePath: [
308
+ {
309
+ shortId: -14,
310
+ schemaIdentifier: "testApp.Todo",
311
+ parentField: 1,
312
+ },
313
+ {
314
+ shortId: undefined,
315
+ schemaIdentifier: "testApp.Array<[\"testApp.Todo\"]>",
316
+ parentField: "todos",
317
+ },
318
+ {
319
+ shortId: -1,
320
+ schemaIdentifier: "testApp.TestAppRootObject",
321
+ parentField: "rootFieldKey",
322
+ },
323
+ ],
324
+ aiExplanation: "I need to insert a todo within the todos array",
325
+ nodeContent: {
326
+ Using a `Diff`, you can identify the modified node in a number of different ways.
327
+ ```
328
+
329
+ As you can see, the object at the beginning of the `nodePath` array directly points to the newly inserted node, while each subsequent object is the parent of the preceding node, terminating in the root node that was passed to the `ai-collab` function call.
330
+
331
+ The simplest way is to use the `shortId`, where you can use the following code to identify the newly inserted node within the SharedTree.
332
+
333
+ > [!NOTE]
334
+ > The `shortId` field will only exist for objects that have a field defined as the `SchemaFactory.identifier` field.
335
+
336
+ See the above example app schema in this section to see the schema field defined as `sf.identifier`
337
+
338
+ Let's take a look at another UI example of using an array of Diffs to render changes.
339
+
340
+ ```ts
341
+ import { Tree } from "@fluidframework/tree"
342
+
343
+ function renderTodoWithDiffs(todo: Todo, Diffs: diff[]) {
344
+ const modifyDiffs = Diffs.filter((diff): diff is ModifyDiff => diff.type === "modify") ?? [];
345
+ const matchingModifyDiffs = modifyDiffs.filter(
346
+ (diff: ModifyDiff) =>
347
+ // Modify diffs are a field level edit, so the first path will be the field on the target node and the second will be the node itself.diff.nodePath.length > 1 && diff.nodePath[1]?.shortId === Tree.shortId(task),
348
+ );
349
+
350
+ const insertDiffs = Diffs.filter((diff): diff is InsertDiff => diff.type === "insert") ?? [];
351
+ const matchingInsertDiffs = insertDiffs.filter(
352
+ (diff: InsertDiff) =>
353
+ // Insert diffs are a node level edit, so the first path will be the node.
354
+ diff.nodePath[0]?.shortId === Tree.shortId(task),
355
+ );
356
+ }
357
+
358
+ if (insertDiffs.length > 0) {
359
+ renderNewlyInsertedTodo(todo)
360
+ } else if (modifyDiffs.length > 0) {
361
+ renderModifiedTodo(todo, modifiedFields)
362
+ } else {
363
+ renderTodo(todo)
364
+ }
365
+ ```
366
+
367
+ You can also use the `type` and `schemaIdentifier` fields to group related `diff`s.
368
+
369
+ ```ts
370
+ const userAsk: "user-defined prompt for what they're asking the LLM to accomplish",
371
+ const result = aiCollab({
372
+ openAI: {
373
+ client: new OpenAI({
374
+ apiKey: OPENAI_API_KEY,
375
+ }),
376
+ modelName: "gpt-4o",
377
+ },
378
+ treeNode: view.root,
379
+ prompt: {
380
+ systemRoleContext:
381
+ "You are a manager that is helping out with a project management tool. You have been asked to edit a group of tasks.",
382
+ userAsk: userAsk,
383
+ },
384
+ limiters: {
385
+ maxModelCalls: 25
386
+ }
387
+ planningStep: true,
388
+ finalReviewStep: true,
389
+ });
390
+
391
+ const Diffs: diff[] = result.diffs;
392
+
393
+ const insertDiffs = result.diffs.filter(diff => diff.type === 'insert');
394
+
395
+ const insertedVectorsDiffs = insertDiffs.filter(diff => diff.path[0]?.schemaIdentifier === TestVector.identifier)
396
+ ```
397
+
398
+ Other `Diff` types follow the same basic structure.
399
+ Read the tsdoc [here](./src/diffTypes.ts) for more info.
400
+
245
401
 
246
402
  ## Known Issues & limitations
247
403
 
@@ -9,6 +9,7 @@ export function aiCollab(options: AiCollabOptions): Promise<AiCollabSuccessRespo
9
9
 
10
10
  // @alpha
11
11
  export interface AiCollabErrorResponse {
12
+ readonly diffs: readonly Diff[];
12
13
  readonly errorMessage: "tokenLimitExceeded" | "tooManyErrors" | "tooManyModelCalls" | "aborted" | "unexpectedError";
13
14
  readonly status: "failure" | "partial-failure";
14
15
  readonly tokensUsed: TokenUsage;
@@ -36,6 +37,7 @@ export interface AiCollabOptions {
36
37
 
37
38
  // @alpha
38
39
  export interface AiCollabSuccessResponse {
40
+ readonly diffs: readonly Diff[];
39
41
  readonly status: "success";
40
42
  readonly tokensUsed: TokenUsage;
41
43
  }
@@ -66,6 +68,24 @@ export interface ApplyEditSuccess extends EventFlowDebugEvent {
66
68
  eventName: "APPLIED_EDIT_SUCCESS";
67
69
  }
68
70
 
71
+ // @alpha
72
+ export interface ArrayRangeRemoveDiff extends DiffBase {
73
+ readonly nodeContents: unknown[];
74
+ readonly nodePaths: NodePath[];
75
+ readonly removalType: "remove-array-range";
76
+ // (undocumented)
77
+ readonly type: "remove";
78
+ }
79
+
80
+ // @alpha
81
+ export interface ArraySingleRemoveDiff extends DiffBase {
82
+ readonly nodeContent: unknown;
83
+ readonly nodePath: NodePath;
84
+ readonly removalType: "remove-array-single";
85
+ // (undocumented)
86
+ readonly type: "remove";
87
+ }
88
+
69
89
  // @alpha
70
90
  export interface CoreEventLoopCompleted extends EventFlowDebugEvent {
71
91
  // (undocumented)
@@ -109,6 +129,15 @@ export interface DebugEvent {
109
129
  // @alpha
110
130
  export type DebugEventLogHandler = <T extends DebugEvent>(event: T) => unknown;
111
131
 
132
+ // @alpha
133
+ export type Diff = InsertDiff | ModifyDiff | RemoveDiff | MoveDiff;
134
+
135
+ // @alpha
136
+ export interface DiffBase {
137
+ readonly aiExplanation: string;
138
+ readonly type: string;
139
+ }
140
+
112
141
  // @alpha
113
142
  export type Difference = DifferenceCreate | DifferenceRemove | DifferenceChange | DifferenceMove;
114
143
 
@@ -227,6 +256,14 @@ export interface GenerateTreeEditStarted extends EventFlowDebugEvent {
227
256
  llmPrompt: string;
228
257
  }
229
258
 
259
+ // @alpha
260
+ export interface InsertDiff extends DiffBase {
261
+ readonly nodeContent: unknown;
262
+ readonly nodePath: NodePath;
263
+ // (undocumented)
264
+ readonly type: "insert";
265
+ }
266
+
230
267
  // @alpha
231
268
  export interface LlmApiCallDebugEvent extends DebugEvent {
232
269
  eventFlowTraceId: string;
@@ -245,6 +282,45 @@ export interface LlmApiCallDebugEvent extends DebugEvent {
245
282
  // @alpha
246
283
  export type LlmTreeEdit = Record<string, unknown>;
247
284
 
285
+ // @alpha
286
+ export interface ModifyDiff extends DiffBase {
287
+ readonly newValue: unknown;
288
+ readonly nodePath: NodePath;
289
+ readonly oldValue: unknown;
290
+ // (undocumented)
291
+ readonly type: "modify";
292
+ }
293
+
294
+ // @alpha
295
+ export type MoveDiff = MoveSingleDiff | MoveRangeDiff;
296
+
297
+ // @alpha
298
+ export interface MoveRangeDiff extends DiffBase {
299
+ readonly destinationNodePath: NodePath;
300
+ readonly moveType: "move-range";
301
+ readonly nodeContents: unknown[];
302
+ readonly sourceNodePaths: NodePath[];
303
+ // (undocumented)
304
+ readonly type: "move";
305
+ }
306
+
307
+ // @alpha
308
+ export interface MoveSingleDiff extends DiffBase {
309
+ readonly destinationNodePath: NodePath;
310
+ readonly moveType: "move-single";
311
+ readonly nodeContent: unknown;
312
+ readonly sourceNodePath: NodePath;
313
+ // (undocumented)
314
+ readonly type: "move";
315
+ }
316
+
317
+ // @alpha
318
+ export type NodePath = {
319
+ readonly shortId: string | number | undefined;
320
+ readonly schemaIdentifier: string;
321
+ readonly parentField: string | number;
322
+ }[];
323
+
248
324
  // @alpha
249
325
  export type ObjectPath = (string | number)[];
250
326
 
@@ -286,6 +362,18 @@ export interface PlanningPromptStarted extends EventFlowDebugEvent {
286
362
  eventName: "GENERATE_PLANNING_PROMPT_STARTED";
287
363
  }
288
364
 
365
+ // @alpha
366
+ export type RemoveDiff = RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff;
367
+
368
+ // @alpha
369
+ export interface RemoveNodeDiff extends DiffBase {
370
+ readonly nodeContent: unknown;
371
+ readonly nodePath: NodePath;
372
+ readonly removalType: "remove-node";
373
+ // (undocumented)
374
+ readonly type: "remove";
375
+ }
376
+
289
377
  // @alpha
290
378
  export class SharedTreeBranchManager {
291
379
  constructor(params?: {
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import type { TreeNode } from "@fluidframework/tree";
6
6
  import type OpenAI from "openai";
7
+ import type { Diff } from "./diffTypes.js";
7
8
  /**
8
9
  * Core Debug event type for the ai-collab
9
10
  * @alpha
@@ -160,6 +161,10 @@ export interface AiCollabSuccessResponse {
160
161
  * {@inheritDoc TokenUsage}
161
162
  */
162
163
  readonly tokensUsed: TokenUsage;
164
+ /**
165
+ * A list of diffs that represent the changes made by the AI collaboration.
166
+ */
167
+ readonly diffs: readonly Diff[];
163
168
  }
164
169
  /**
165
170
  * An error response from the AI collaboration.
@@ -186,6 +191,10 @@ export interface AiCollabErrorResponse {
186
191
  * {@inheritDoc TokenUsage}
187
192
  */
188
193
  readonly tokensUsed: TokenUsage;
194
+ /**
195
+ * A list of diffs that represent the changes made by the AI collaboration.
196
+ */
197
+ readonly diffs: readonly Diff[];
189
198
  }
190
199
  /**
191
200
  * Total usage of tokens by an LLM.
@@ -1 +1 @@
1
- {"version":3,"file":"aiCollabApi.d.ts","sourceRoot":"","sources":["../src/aiCollabApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACtD;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,eAAe,EAAE,SAAS,GAAG,WAAW,GAAG,aAAa,CAAC;IACzD;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;AAE/E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,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;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACrC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,iBAAiB,CAAC;IAC/C;;;;;;;OAOG;IACH,QAAQ,CAAC,YAAY,EAClB,oBAAoB,GACpB,eAAe,GACf,mBAAmB,GACnB,SAAS,GACT,iBAAiB,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"aiCollabApi.js","sourceRoot":"","sources":["../src/aiCollabApi.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { TreeNode } from \"@fluidframework/tree\";\n// eslint-disable-next-line import/no-named-as-default\nimport type OpenAI from \"openai\";\n\n/**\n * Core Debug event type for the ai-collab\n * @alpha\n */\nexport interface DebugEvent {\n\t/**\n\t * The unique id of the debug event.\n\t */\n\tid: string;\n\t/**\n\t * An id that will be shared across all debug events that originate from the same single execution of ai-collab.\n\t * @remarks This is intended to be used to correlate all debug events that originate from the same execution\n\t */\n\ttraceId: string;\n\t/**\n\t * The name of the debug event.\n\t */\n\teventName: string;\n\t/**\n\t * The date and time at which the debug event was created.\n\t */\n\ttimestamp: string;\n}\n\n/**\n * A Debug event that marks the start or end of a single core logic flow, such as generated tree edits, planning prompt, etc.\n * @alpha\n */\nexport interface EventFlowDebugEvent extends DebugEvent {\n\t/**\n\t * The name of the particular event flow.\n\t */\n\teventFlowName: string;\n\t/**\n\t * The status of the particular event flow.\n\t */\n\teventFlowStatus: \"STARTED\" | \"COMPLETED\" | \"IN_PROGRESS\";\n\t/**\n\t * A unique id that will be shared across all debug events that are part of the same event flow.\n\t */\n\teventFlowTraceId: string;\n}\n\n/**\n * A callback function that can be used to handle debug events that occur during the AI collaboration process.\n * @alpha\n */\nexport type DebugEventLogHandler = <T extends DebugEvent>(event: T) => unknown;\n\n/**\n * OpenAI client options for the {@link AiCollabOptions} interface.\n *\n * @alpha\n */\nexport interface OpenAiClientOptions {\n\t/**\n\t * The OpenAI client to use for the AI collaboration.\n\t */\n\tclient: OpenAI;\n\t/**\n\t * The name of the target OpenAI model to use for the AI collaboration.\n\t */\n\tmodelName?: string;\n}\n\n/**\n * Options for the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabOptions {\n\t/**\n\t * The OpenAI client options to use for the LLM based AI collaboration.\n\t */\n\treadonly openAI: OpenAiClientOptions;\n\t/**\n\t * The specific tree node you want the AI to collaborate on. Pass the root node of your tree if you intend\n\t * for the AI to work on the entire tree.\n\t * @remarks\n\t * - Optional root nodes are not supported\n\t * - Primitive root nodes are not supported\n\t */\n\treadonly treeNode: TreeNode;\n\t/**\n\t * The prompt context to give the LLM in order to collaborate with your applications data.\n\t */\n\treadonly prompt: {\n\t\t/**\n\t\t * The context to give the LLM about its role in the collaboration.\n\t\t * @remarks It's highly recommended to give context about your applications data model and the LLM's role in the collaboration.\n\t\t */\n\t\treadonly systemRoleContext: string;\n\t\t/**\n\t\t * The request from the users to the LLM.\n\t\t */\n\t\treadonly userAsk: string;\n\t};\n\t/**\n\t * Limiters are various optional ways to limit this library's usage of the LLM.\n\t */\n\treadonly limiters?: {\n\t\t/**\n\t\t * An optional AbortController that can be used to abort the AI collaboration while it is still in progress.\n\t\t */\n\t\treadonly abortController?: AbortController;\n\t\t/**\n\t\t * The maximum number of sequential errors the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of sequential errors is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyErrors'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxSequentialErrors?: number;\n\t\t/**\n\t\t * The maximum number of model calls the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of model calls is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyModelCalls'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxModelCalls?: number;\n\t\t/**\n\t\t * The maximum token usage limits for the LLM.\n\t\t * If the LLM exceeds the token limits, the AI collaboration will be aborted and return with the errorMessage 'tokenLimitExceeded'.\n\t\t * This happens after the first model call's token usage is calculated, meaning that the limits set may be exceeded by a certain amount.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly tokenLimits?: TokenLimits;\n\t};\n\t/**\n\t * When set to true, the LLM will be asked to first produce a plan, based on the user's ask, before generating any changes to your applications data.\n\t * This can help the LLM produce better results.\n\t * When set to false, the LLM will not be asked to produce a plan.\n\t */\n\treadonly planningStep?: boolean;\n\t/**\n\t * When set to true, the LLM will be asked to complete a final review of the changes and determine if any additional changes need to be made.\n\t * When set to false, the LLM will not be asked to complete a final review.\n\t */\n\treadonly finalReviewStep?: boolean;\n\t/**\n\t * An optional validator function that can be used to validate the new content produced by the LLM.\n\t */\n\treadonly validator?: (newContent: TreeNode) => void;\n\t/**\n\t * An optional handler for debug events that occur during the AI collaboration.\n\t */\n\treadonly debugEventLogHandler?: DebugEventLogHandler;\n}\n\n/**\n * A successful response from the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabSuccessResponse {\n\t/**\n\t * The status of the Ai Collaboration.\n\t * A 'success' status indicates that the AI collaboration was successful at creating changes.\n\t */\n\treadonly status: \"success\";\n\t/**\n\t * {@inheritDoc TokenUsage}\n\t */\n\treadonly tokensUsed: TokenUsage;\n}\n\n/**\n * An error response from the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabErrorResponse {\n\t/**\n\t * The status of the Ai Collaboration.\n\t * - A 'partial-failure' status indicates that the AI collaboration was partially successful, but was aborted due to a limiter or other error\n\t * - A \"failure\" status indicates that the AI collaboration was not successful at creating any changes.\n\t */\n\treadonly status: \"failure\" | \"partial-failure\";\n\t/**\n\t * The type of known error that occured\n\t * - 'tokenLimitExceeded' indicates that the LLM exceeded the token limits set by the user\n\t * - 'tooManyErrors' indicates that the LLM made too many errors in a row\n\t * - 'tooManyModelCalls' indicates that the LLM made too many model calls\n\t * - 'aborted' indicates that the AI collaboration was aborted by the user or a limiter\n\t * - 'unexpectedError' indicates that an unexpected error occured\n\t */\n\treadonly errorMessage:\n\t\t| \"tokenLimitExceeded\"\n\t\t| \"tooManyErrors\"\n\t\t| \"tooManyModelCalls\"\n\t\t| \"aborted\"\n\t\t| \"unexpectedError\";\n\t/**\n\t * {@inheritDoc TokenUsage}\n\t */\n\treadonly tokensUsed: TokenUsage;\n}\n\n/**\n * Total usage of tokens by an LLM.\n *\n * @alpha\n */\nexport interface TokenUsage {\n\t/**\n\t * The total number of tokens used by the LLM for input.\n\t */\n\tinputTokens: number;\n\t/**\n\t * The total number of tokens used by the LLM for output.\n\t */\n\toutputTokens: number;\n}\n\n/**\n * Maximum limits for the total tokens that can be used by an llm\n *\n * @alpha\n */\nexport interface TokenLimits {\n\t/**\n\t * The maximum number of tokens that can be used by the LLM for input.\n\t */\n\treadonly inputTokens?: number;\n\t/**\n\t * The maximum number of tokens that can be used by the LLM for output.\n\t */\n\treadonly outputTokens?: number;\n}\n"]}
1
+ {"version":3,"file":"aiCollabApi.js","sourceRoot":"","sources":["../src/aiCollabApi.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { TreeNode } from \"@fluidframework/tree\";\n// eslint-disable-next-line import/no-named-as-default\nimport type OpenAI from \"openai\";\n\nimport type { Diff } from \"./diffTypes.js\";\n\n/**\n * Core Debug event type for the ai-collab\n * @alpha\n */\nexport interface DebugEvent {\n\t/**\n\t * The unique id of the debug event.\n\t */\n\tid: string;\n\t/**\n\t * An id that will be shared across all debug events that originate from the same single execution of ai-collab.\n\t * @remarks This is intended to be used to correlate all debug events that originate from the same execution\n\t */\n\ttraceId: string;\n\t/**\n\t * The name of the debug event.\n\t */\n\teventName: string;\n\t/**\n\t * The date and time at which the debug event was created.\n\t */\n\ttimestamp: string;\n}\n\n/**\n * A Debug event that marks the start or end of a single core logic flow, such as generated tree edits, planning prompt, etc.\n * @alpha\n */\nexport interface EventFlowDebugEvent extends DebugEvent {\n\t/**\n\t * The name of the particular event flow.\n\t */\n\teventFlowName: string;\n\t/**\n\t * The status of the particular event flow.\n\t */\n\teventFlowStatus: \"STARTED\" | \"COMPLETED\" | \"IN_PROGRESS\";\n\t/**\n\t * A unique id that will be shared across all debug events that are part of the same event flow.\n\t */\n\teventFlowTraceId: string;\n}\n\n/**\n * A callback function that can be used to handle debug events that occur during the AI collaboration process.\n * @alpha\n */\nexport type DebugEventLogHandler = <T extends DebugEvent>(event: T) => unknown;\n\n/**\n * OpenAI client options for the {@link AiCollabOptions} interface.\n *\n * @alpha\n */\nexport interface OpenAiClientOptions {\n\t/**\n\t * The OpenAI client to use for the AI collaboration.\n\t */\n\tclient: OpenAI;\n\t/**\n\t * The name of the target OpenAI model to use for the AI collaboration.\n\t */\n\tmodelName?: string;\n}\n\n/**\n * Options for the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabOptions {\n\t/**\n\t * The OpenAI client options to use for the LLM based AI collaboration.\n\t */\n\treadonly openAI: OpenAiClientOptions;\n\t/**\n\t * The specific tree node you want the AI to collaborate on. Pass the root node of your tree if you intend\n\t * for the AI to work on the entire tree.\n\t * @remarks\n\t * - Optional root nodes are not supported\n\t * - Primitive root nodes are not supported\n\t */\n\treadonly treeNode: TreeNode;\n\t/**\n\t * The prompt context to give the LLM in order to collaborate with your applications data.\n\t */\n\treadonly prompt: {\n\t\t/**\n\t\t * The context to give the LLM about its role in the collaboration.\n\t\t * @remarks It's highly recommended to give context about your applications data model and the LLM's role in the collaboration.\n\t\t */\n\t\treadonly systemRoleContext: string;\n\t\t/**\n\t\t * The request from the users to the LLM.\n\t\t */\n\t\treadonly userAsk: string;\n\t};\n\t/**\n\t * Limiters are various optional ways to limit this library's usage of the LLM.\n\t */\n\treadonly limiters?: {\n\t\t/**\n\t\t * An optional AbortController that can be used to abort the AI collaboration while it is still in progress.\n\t\t */\n\t\treadonly abortController?: AbortController;\n\t\t/**\n\t\t * The maximum number of sequential errors the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of sequential errors is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyErrors'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxSequentialErrors?: number;\n\t\t/**\n\t\t * The maximum number of model calls the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of model calls is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyModelCalls'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxModelCalls?: number;\n\t\t/**\n\t\t * The maximum token usage limits for the LLM.\n\t\t * If the LLM exceeds the token limits, the AI collaboration will be aborted and return with the errorMessage 'tokenLimitExceeded'.\n\t\t * This happens after the first model call's token usage is calculated, meaning that the limits set may be exceeded by a certain amount.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly tokenLimits?: TokenLimits;\n\t};\n\t/**\n\t * When set to true, the LLM will be asked to first produce a plan, based on the user's ask, before generating any changes to your applications data.\n\t * This can help the LLM produce better results.\n\t * When set to false, the LLM will not be asked to produce a plan.\n\t */\n\treadonly planningStep?: boolean;\n\t/**\n\t * When set to true, the LLM will be asked to complete a final review of the changes and determine if any additional changes need to be made.\n\t * When set to false, the LLM will not be asked to complete a final review.\n\t */\n\treadonly finalReviewStep?: boolean;\n\t/**\n\t * An optional validator function that can be used to validate the new content produced by the LLM.\n\t */\n\treadonly validator?: (newContent: TreeNode) => void;\n\t/**\n\t * An optional handler for debug events that occur during the AI collaboration.\n\t */\n\treadonly debugEventLogHandler?: DebugEventLogHandler;\n}\n\n/**\n * A successful response from the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabSuccessResponse {\n\t/**\n\t * The status of the Ai Collaboration.\n\t * A 'success' status indicates that the AI collaboration was successful at creating changes.\n\t */\n\treadonly status: \"success\";\n\t/**\n\t * {@inheritDoc TokenUsage}\n\t */\n\treadonly tokensUsed: TokenUsage;\n\t/**\n\t * A list of diffs that represent the changes made by the AI collaboration.\n\t */\n\treadonly diffs: readonly Diff[];\n}\n\n/**\n * An error response from the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabErrorResponse {\n\t/**\n\t * The status of the Ai Collaboration.\n\t * - A 'partial-failure' status indicates that the AI collaboration was partially successful, but was aborted due to a limiter or other error\n\t * - A \"failure\" status indicates that the AI collaboration was not successful at creating any changes.\n\t */\n\treadonly status: \"failure\" | \"partial-failure\";\n\t/**\n\t * The type of known error that occured\n\t * - 'tokenLimitExceeded' indicates that the LLM exceeded the token limits set by the user\n\t * - 'tooManyErrors' indicates that the LLM made too many errors in a row\n\t * - 'tooManyModelCalls' indicates that the LLM made too many model calls\n\t * - 'aborted' indicates that the AI collaboration was aborted by the user or a limiter\n\t * - 'unexpectedError' indicates that an unexpected error occured\n\t */\n\treadonly errorMessage:\n\t\t| \"tokenLimitExceeded\"\n\t\t| \"tooManyErrors\"\n\t\t| \"tooManyModelCalls\"\n\t\t| \"aborted\"\n\t\t| \"unexpectedError\";\n\t/**\n\t * {@inheritDoc TokenUsage}\n\t */\n\treadonly tokensUsed: TokenUsage;\n\t/**\n\t * A list of diffs that represent the changes made by the AI collaboration.\n\t */\n\treadonly diffs: readonly Diff[];\n}\n\n/**\n * Total usage of tokens by an LLM.\n *\n * @alpha\n */\nexport interface TokenUsage {\n\t/**\n\t * The total number of tokens used by the LLM for input.\n\t */\n\tinputTokens: number;\n\t/**\n\t * The total number of tokens used by the LLM for output.\n\t */\n\toutputTokens: number;\n}\n\n/**\n * Maximum limits for the total tokens that can be used by an llm\n *\n * @alpha\n */\nexport interface TokenLimits {\n\t/**\n\t * The maximum number of tokens that can be used by the LLM for input.\n\t */\n\treadonly inputTokens?: number;\n\t/**\n\t * The maximum number of tokens that can be used by the LLM for output.\n\t */\n\treadonly outputTokens?: number;\n}\n"]}
package/dist/alpha.d.ts CHANGED
@@ -24,10 +24,14 @@ export {
24
24
  AiCollabSuccessResponse,
25
25
  ApplyEditFailure,
26
26
  ApplyEditSuccess,
27
+ ArrayRangeRemoveDiff,
28
+ ArraySingleRemoveDiff,
27
29
  CoreEventLoopCompleted,
28
30
  CoreEventLoopStarted,
29
31
  DebugEvent,
30
32
  DebugEventLogHandler,
33
+ Diff,
34
+ DiffBase,
31
35
  Difference,
32
36
  DifferenceChange,
33
37
  DifferenceCreate,
@@ -40,13 +44,21 @@ export {
40
44
  FinalReviewStarted,
41
45
  GenerateTreeEditCompleted,
42
46
  GenerateTreeEditStarted,
47
+ InsertDiff,
43
48
  LlmApiCallDebugEvent,
44
49
  LlmTreeEdit,
50
+ ModifyDiff,
51
+ MoveDiff,
52
+ MoveRangeDiff,
53
+ MoveSingleDiff,
54
+ NodePath,
45
55
  ObjectPath,
46
56
  OpenAiClientOptions,
47
57
  Options,
48
58
  PlanningPromptCompleted,
49
59
  PlanningPromptStarted,
60
+ RemoveDiff,
61
+ RemoveNodeDiff,
50
62
  SharedTreeBranchManager,
51
63
  TokenLimits,
52
64
  TokenUsage,
@@ -0,0 +1,200 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * A base interface to enforce consistency between all Diff objects.
7
+ * @remarks This object is not intended to be used directly.
8
+ * The union type Diff provides a better typescript experience
9
+ *
10
+ * @alpha
11
+ */
12
+ export interface DiffBase {
13
+ /**
14
+ * The operation type performed by an ai agent on a SharedTree
15
+ * @remarks This is intended to be used to correlate the diff with the operation that generated it.
16
+ */
17
+ readonly type: string;
18
+ /**
19
+ * An explanation from the ai as to why the edit is being made.
20
+ */
21
+ readonly aiExplanation: string;
22
+ }
23
+ /**
24
+ * An object that provides relevant information to visualize a single edit performed by an ai agent on a SharedTree
25
+ * @alpha
26
+ */
27
+ export type Diff = InsertDiff | ModifyDiff | RemoveDiff | MoveDiff;
28
+ /**
29
+ * A path from the root of the tree node passed to ai-collab to a specific node within the tree.
30
+ * @alpha
31
+ */
32
+ export type NodePath = {
33
+ /**
34
+ * The short id of the node.
35
+ * @remarks the root tree node and nodes without a defined SchemaFactory.identifier field will not have a short id.
36
+ */
37
+ readonly shortId: string | number | undefined;
38
+ /**
39
+ * The schema of the node.
40
+ */
41
+ readonly schemaIdentifier: string;
42
+ /**
43
+ * The field within the parent node that the node is located at.
44
+ * @remarks
45
+ * The root node will have a parentField name of 'rootFieldKey'.
46
+ * Nodes in an array use numbers to represent their index within the array.
47
+ */
48
+ readonly parentField: string | number;
49
+ }[];
50
+ /**
51
+ * An object that describes the insertion of a new node into a tree.
52
+ * @alpha
53
+ */
54
+ export interface InsertDiff extends DiffBase {
55
+ readonly type: "insert";
56
+ /**
57
+ * The path from the root node to the newly inserted node.
58
+ * The last value in the path will be the newly inserted node.
59
+ * If the newly inserted node is a primitive value, the last value in the path will be the parent array node.
60
+ */
61
+ readonly nodePath: NodePath;
62
+ /**
63
+ * The content of the newly inserted node.
64
+ */
65
+ readonly nodeContent: unknown;
66
+ }
67
+ /**
68
+ * An object that describes the modification of an existing node on a tree.
69
+ * @alpha
70
+ */
71
+ export interface ModifyDiff extends DiffBase {
72
+ readonly type: "modify";
73
+ /**
74
+ * The path from the root node to the ndoe being modified.
75
+ */
76
+ readonly nodePath: NodePath;
77
+ /**
78
+ * The new value of the node.
79
+ */
80
+ readonly newValue: unknown;
81
+ /**
82
+ * The old value of the node.
83
+ */
84
+ readonly oldValue: unknown;
85
+ }
86
+ /**
87
+ * An object that describes the removal of one or more nodes from a tree.
88
+ * @alpha
89
+ */
90
+ export type RemoveDiff = RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff;
91
+ /**
92
+ * Details about a node being removed from a field in an object node.
93
+ * @alpha
94
+ */
95
+ export interface RemoveNodeDiff extends DiffBase {
96
+ readonly type: "remove";
97
+ /**
98
+ * The type of removal being performed.
99
+ */
100
+ readonly removalType: "remove-node";
101
+ /**
102
+ * The path from the root of the tree to the node being removed.
103
+ */
104
+ readonly nodePath: NodePath;
105
+ /**
106
+ * The content of the node being removed.
107
+ */
108
+ readonly nodeContent: unknown;
109
+ }
110
+ /**
111
+ * An object that describes the removal of a single node from an array node.
112
+ * @alpha
113
+ */
114
+ export interface ArraySingleRemoveDiff extends DiffBase {
115
+ readonly type: "remove";
116
+ /**
117
+ * The type of removal being performed.
118
+ */
119
+ readonly removalType: "remove-array-single";
120
+ /**
121
+ * The path from the root of the tree to the node being removed from the array node.
122
+ */
123
+ readonly nodePath: NodePath;
124
+ /**
125
+ * The content of the node being removed from the array node.
126
+ */
127
+ readonly nodeContent: unknown;
128
+ }
129
+ /**
130
+ * An object that describes the removal of a range of nodes from an array node.
131
+ * @alpha
132
+ */
133
+ export interface ArrayRangeRemoveDiff extends DiffBase {
134
+ readonly type: "remove";
135
+ /**
136
+ * The type of removal being performed.
137
+ */
138
+ readonly removalType: "remove-array-range";
139
+ /**
140
+ * The paths to each node being removed from the array node.
141
+ */
142
+ readonly nodePaths: NodePath[];
143
+ /**
144
+ * The content of each of the nodes being removed from the array node.
145
+ */
146
+ readonly nodeContents: unknown[];
147
+ }
148
+ /**
149
+ * An object that describes the movement of nodes from one array node to another array node.
150
+ * @alpha
151
+ */
152
+ export type MoveDiff = MoveSingleDiff | MoveRangeDiff;
153
+ /**
154
+ * An object that describes the movement of a single node from one array node to another array node.
155
+ * @alpha
156
+ */
157
+ export interface MoveSingleDiff extends DiffBase {
158
+ readonly type: "move";
159
+ /**
160
+ * The type of movement being performed.
161
+ */
162
+ readonly moveType: "move-single";
163
+ /**
164
+ * The path from the root of the tree to the source node.
165
+ * The last value in the path will be the node being moved
166
+ */
167
+ readonly sourceNodePath: NodePath;
168
+ /**
169
+ * The path from the root of the tree to the destination array node.
170
+ */
171
+ readonly destinationNodePath: NodePath;
172
+ /**
173
+ * The content of the node being moved from the source array node to the destination array node.
174
+ */
175
+ readonly nodeContent: unknown;
176
+ }
177
+ /**
178
+ * An object that describes the movement of a range of nodes from one array node to another array node.
179
+ * @alpha
180
+ */
181
+ export interface MoveRangeDiff extends DiffBase {
182
+ readonly type: "move";
183
+ /**
184
+ * The type of movement being performed.
185
+ */
186
+ readonly moveType: "move-range";
187
+ /**
188
+ * The paths to each node being moved from the source array node.
189
+ */
190
+ readonly sourceNodePaths: NodePath[];
191
+ /**
192
+ * The path from the root of the tree to the destination array node.
193
+ */
194
+ readonly destinationNodePath: NodePath;
195
+ /**
196
+ * The content of each of the nodes being moved from the source array node to the destination array node.
197
+ */
198
+ readonly nodeContents: unknown[];
199
+ }
200
+ //# sourceMappingURL=diffTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diffTypes.d.ts","sourceRoot":"","sources":["../src/diffTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACxB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEnE;;;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
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=diffTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diffTypes.js","sourceRoot":"","sources":["../src/diffTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A base interface to enforce consistency between all Diff objects.\n * @remarks This object is not intended to be used directly.\n * The union type Diff provides a better typescript experience\n *\n * @alpha\n */\nexport interface DiffBase {\n\t/**\n\t * The operation type performed by an ai agent on a SharedTree\n\t * @remarks This is intended to be used to correlate the diff with the operation that generated it.\n\t */\n\treadonly type: string;\n\t/**\n\t * An explanation from the ai as to why the edit is being made.\n\t */\n\treadonly aiExplanation: string;\n}\n\n/**\n * An object that provides relevant information to visualize a single edit performed by an ai agent on a SharedTree\n * @alpha\n */\nexport type Diff = InsertDiff | ModifyDiff | RemoveDiff | MoveDiff;\n\n/**\n * A path from the root of the tree node passed to ai-collab to a specific node within the tree.\n * @alpha\n */\nexport type NodePath = {\n\t/**\n\t * The short id of the node.\n\t * @remarks the root tree node and nodes without a defined SchemaFactory.identifier field will not have a short id.\n\t */\n\treadonly shortId: string | number | undefined;\n\t/**\n\t * The schema of the node.\n\t */\n\treadonly schemaIdentifier: string;\n\t/**\n\t * The field within the parent node that the node is located at.\n\t * @remarks\n\t * The root node will have a parentField name of 'rootFieldKey'.\n\t * Nodes in an array use numbers to represent their index within the array.\n\t */\n\treadonly parentField: string | number;\n}[];\n\n/**\n * An object that describes the insertion of a new node into a tree.\n * @alpha\n */\nexport interface InsertDiff extends DiffBase {\n\treadonly type: \"insert\";\n\t/**\n\t * The path from the root node to the newly inserted node.\n\t * The last value in the path will be the newly inserted node.\n\t * If the newly inserted node is a primitive value, the last value in the path will be the parent array node.\n\t */\n\treadonly nodePath: NodePath;\n\t/**\n\t * The content of the newly inserted node.\n\t */\n\treadonly nodeContent: unknown;\n}\n\n/**\n * An object that describes the modification of an existing node on a tree.\n * @alpha\n */\nexport interface ModifyDiff extends DiffBase {\n\treadonly type: \"modify\";\n\t/**\n\t * The path from the root node to the ndoe being modified.\n\t */\n\treadonly nodePath: NodePath;\n\t/**\n\t * The new value of the node.\n\t */\n\treadonly newValue: unknown;\n\t/**\n\t * The old value of the node.\n\t */\n\treadonly oldValue: unknown;\n}\n\n/**\n * An object that describes the removal of one or more nodes from a tree.\n * @alpha\n */\nexport type RemoveDiff = RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff;\n\n/**\n * Details about a node being removed from a field in an object node.\n * @alpha\n */\nexport interface RemoveNodeDiff extends DiffBase {\n\treadonly type: \"remove\";\n\t/**\n\t * The type of removal being performed.\n\t */\n\treadonly removalType: \"remove-node\";\n\t/**\n\t * The path from the root of the tree to the node being removed.\n\t */\n\treadonly nodePath: NodePath;\n\t/**\n\t * The content of the node being removed.\n\t */\n\treadonly nodeContent: unknown;\n}\n\n/**\n * An object that describes the removal of a single node from an array node.\n * @alpha\n */\nexport interface ArraySingleRemoveDiff extends DiffBase {\n\treadonly type: \"remove\";\n\t/**\n\t * The type of removal being performed.\n\t */\n\treadonly removalType: \"remove-array-single\";\n\t/**\n\t * The path from the root of the tree to the node being removed from the array node.\n\t */\n\treadonly nodePath: NodePath;\n\t/**\n\t * The content of the node being removed from the array node.\n\t */\n\treadonly nodeContent: unknown;\n}\n\n/**\n * An object that describes the removal of a range of nodes from an array node.\n * @alpha\n */\nexport interface ArrayRangeRemoveDiff extends DiffBase {\n\treadonly type: \"remove\";\n\t/**\n\t * The type of removal being performed.\n\t */\n\treadonly removalType: \"remove-array-range\";\n\t/**\n\t * The paths to each node being removed from the array node.\n\t */\n\treadonly nodePaths: NodePath[];\n\t/**\n\t * The content of each of the nodes being removed from the array node.\n\t */\n\treadonly nodeContents: unknown[];\n}\n\n/**\n * An object that describes the movement of nodes from one array node to another array node.\n * @alpha\n */\nexport type MoveDiff = MoveSingleDiff | MoveRangeDiff;\n\n/**\n * An object that describes the movement of a single node from one array node to another array node.\n * @alpha\n */\nexport interface MoveSingleDiff extends DiffBase {\n\treadonly type: \"move\";\n\t/**\n\t * The type of movement being performed.\n\t */\n\treadonly moveType: \"move-single\";\n\t/**\n\t * The path from the root of the tree to the source node.\n\t * The last value in the path will be the node being moved\n\t */\n\treadonly sourceNodePath: NodePath;\n\t/**\n\t * The path from the root of the tree to the destination array node.\n\t */\n\treadonly destinationNodePath: NodePath;\n\t/**\n\t * The content of the node being moved from the source array node to the destination array node.\n\t */\n\treadonly nodeContent: unknown;\n}\n\n/**\n * An object that describes the movement of a range of nodes from one array node to another array node.\n * @alpha\n */\nexport interface MoveRangeDiff extends DiffBase {\n\treadonly type: \"move\";\n\t/**\n\t * The type of movement being performed.\n\t */\n\treadonly moveType: \"move-range\";\n\t/**\n\t * The paths to each node being moved from the source array node.\n\t */\n\treadonly sourceNodePaths: NodePath[];\n\t/**\n\t * The path from the root of the tree to the destination array node.\n\t */\n\treadonly destinationNodePath: NodePath;\n\t/**\n\t * The content of each of the nodes being moved from the source array node to the destination array node.\n\t */\n\treadonly nodeContents: unknown[];\n}\n"]}