@fluidframework/ai-collab 2.10.0-306579

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 (168) hide show
  1. package/.eslintrc.cjs +26 -0
  2. package/CHANGELOG.md +9 -0
  3. package/LICENSE +21 -0
  4. package/README.md +280 -0
  5. package/alpha.d.ts +11 -0
  6. package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
  7. package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
  8. package/api-extractor/api-extractor-lint-bundle.json +5 -0
  9. package/api-extractor/api-extractor-lint-index.cjs.json +5 -0
  10. package/api-extractor/api-extractor-lint-index.esm.json +5 -0
  11. package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
  12. package/api-extractor/api-extractor-lint-public.esm.json +5 -0
  13. package/api-extractor-lint.json +4 -0
  14. package/api-extractor.json +4 -0
  15. package/api-report/ai-collab.alpha.api.md +164 -0
  16. package/api-report/ai-collab.beta.api.md +7 -0
  17. package/api-report/ai-collab.public.api.md +7 -0
  18. package/biome.jsonc +4 -0
  19. package/dist/aiCollab.d.ts +65 -0
  20. package/dist/aiCollab.d.ts.map +1 -0
  21. package/dist/aiCollab.js +81 -0
  22. package/dist/aiCollab.js.map +1 -0
  23. package/dist/aiCollabApi.d.ts +173 -0
  24. package/dist/aiCollabApi.d.ts.map +1 -0
  25. package/dist/aiCollabApi.js +7 -0
  26. package/dist/aiCollabApi.js.map +1 -0
  27. package/dist/alpha.d.ts +41 -0
  28. package/dist/explicit-strategy/agentEditReducer.d.ts +12 -0
  29. package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -0
  30. package/dist/explicit-strategy/agentEditReducer.js +394 -0
  31. package/dist/explicit-strategy/agentEditReducer.js.map +1 -0
  32. package/dist/explicit-strategy/agentEditTypes.d.ts +158 -0
  33. package/dist/explicit-strategy/agentEditTypes.d.ts.map +1 -0
  34. package/dist/explicit-strategy/agentEditTypes.js +50 -0
  35. package/dist/explicit-strategy/agentEditTypes.js.map +1 -0
  36. package/dist/explicit-strategy/idGenerator.d.ts +22 -0
  37. package/dist/explicit-strategy/idGenerator.d.ts.map +1 -0
  38. package/dist/explicit-strategy/idGenerator.js +74 -0
  39. package/dist/explicit-strategy/idGenerator.js.map +1 -0
  40. package/dist/explicit-strategy/index.d.ts +51 -0
  41. package/dist/explicit-strategy/index.d.ts.map +1 -0
  42. package/dist/explicit-strategy/index.js +223 -0
  43. package/dist/explicit-strategy/index.js.map +1 -0
  44. package/dist/explicit-strategy/jsonTypes.d.ts +23 -0
  45. package/dist/explicit-strategy/jsonTypes.d.ts.map +1 -0
  46. package/dist/explicit-strategy/jsonTypes.js +7 -0
  47. package/dist/explicit-strategy/jsonTypes.js.map +1 -0
  48. package/dist/explicit-strategy/promptGeneration.d.ts +51 -0
  49. package/dist/explicit-strategy/promptGeneration.d.ts.map +1 -0
  50. package/dist/explicit-strategy/promptGeneration.js +218 -0
  51. package/dist/explicit-strategy/promptGeneration.js.map +1 -0
  52. package/dist/explicit-strategy/typeGeneration.d.ts +15 -0
  53. package/dist/explicit-strategy/typeGeneration.d.ts.map +1 -0
  54. package/dist/explicit-strategy/typeGeneration.js +264 -0
  55. package/dist/explicit-strategy/typeGeneration.js.map +1 -0
  56. package/dist/explicit-strategy/utils.d.ts +37 -0
  57. package/dist/explicit-strategy/utils.d.ts.map +1 -0
  58. package/dist/explicit-strategy/utils.js +47 -0
  59. package/dist/explicit-strategy/utils.js.map +1 -0
  60. package/dist/implicit-strategy/index.d.ts +8 -0
  61. package/dist/implicit-strategy/index.d.ts.map +1 -0
  62. package/dist/implicit-strategy/index.js +18 -0
  63. package/dist/implicit-strategy/index.js.map +1 -0
  64. package/dist/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
  65. package/dist/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
  66. package/dist/implicit-strategy/sharedTreeBranchManager.js +212 -0
  67. package/dist/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
  68. package/dist/implicit-strategy/sharedTreeDiff.d.ts +102 -0
  69. package/dist/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
  70. package/dist/implicit-strategy/sharedTreeDiff.js +522 -0
  71. package/dist/implicit-strategy/sharedTreeDiff.js.map +1 -0
  72. package/dist/implicit-strategy/utils.d.ts +21 -0
  73. package/dist/implicit-strategy/utils.d.ts.map +1 -0
  74. package/dist/implicit-strategy/utils.js +49 -0
  75. package/dist/implicit-strategy/utils.js.map +1 -0
  76. package/dist/index.d.ts +16 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +24 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/package.json +3 -0
  81. package/dist/public.d.ts +19 -0
  82. package/eslintrc.cjs +11 -0
  83. package/internal.d.ts +11 -0
  84. package/lib/aiCollab.d.ts +65 -0
  85. package/lib/aiCollab.d.ts.map +1 -0
  86. package/lib/aiCollab.js +77 -0
  87. package/lib/aiCollab.js.map +1 -0
  88. package/lib/aiCollabApi.d.ts +173 -0
  89. package/lib/aiCollabApi.d.ts.map +1 -0
  90. package/lib/aiCollabApi.js +6 -0
  91. package/lib/aiCollabApi.js.map +1 -0
  92. package/lib/alpha.d.ts +41 -0
  93. package/lib/explicit-strategy/agentEditReducer.d.ts +12 -0
  94. package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -0
  95. package/lib/explicit-strategy/agentEditReducer.js +390 -0
  96. package/lib/explicit-strategy/agentEditReducer.js.map +1 -0
  97. package/lib/explicit-strategy/agentEditTypes.d.ts +158 -0
  98. package/lib/explicit-strategy/agentEditTypes.d.ts.map +1 -0
  99. package/lib/explicit-strategy/agentEditTypes.js +47 -0
  100. package/lib/explicit-strategy/agentEditTypes.js.map +1 -0
  101. package/lib/explicit-strategy/idGenerator.d.ts +22 -0
  102. package/lib/explicit-strategy/idGenerator.d.ts.map +1 -0
  103. package/lib/explicit-strategy/idGenerator.js +70 -0
  104. package/lib/explicit-strategy/idGenerator.js.map +1 -0
  105. package/lib/explicit-strategy/index.d.ts +51 -0
  106. package/lib/explicit-strategy/index.d.ts.map +1 -0
  107. package/lib/explicit-strategy/index.js +219 -0
  108. package/lib/explicit-strategy/index.js.map +1 -0
  109. package/lib/explicit-strategy/jsonTypes.d.ts +23 -0
  110. package/lib/explicit-strategy/jsonTypes.d.ts.map +1 -0
  111. package/lib/explicit-strategy/jsonTypes.js +6 -0
  112. package/lib/explicit-strategy/jsonTypes.js.map +1 -0
  113. package/lib/explicit-strategy/promptGeneration.d.ts +51 -0
  114. package/lib/explicit-strategy/promptGeneration.d.ts.map +1 -0
  115. package/lib/explicit-strategy/promptGeneration.js +208 -0
  116. package/lib/explicit-strategy/promptGeneration.js.map +1 -0
  117. package/lib/explicit-strategy/typeGeneration.d.ts +15 -0
  118. package/lib/explicit-strategy/typeGeneration.d.ts.map +1 -0
  119. package/lib/explicit-strategy/typeGeneration.js +260 -0
  120. package/lib/explicit-strategy/typeGeneration.js.map +1 -0
  121. package/lib/explicit-strategy/utils.d.ts +37 -0
  122. package/lib/explicit-strategy/utils.d.ts.map +1 -0
  123. package/lib/explicit-strategy/utils.js +41 -0
  124. package/lib/explicit-strategy/utils.js.map +1 -0
  125. package/lib/implicit-strategy/index.d.ts +8 -0
  126. package/lib/implicit-strategy/index.d.ts.map +1 -0
  127. package/lib/implicit-strategy/index.js +8 -0
  128. package/lib/implicit-strategy/index.js.map +1 -0
  129. package/lib/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
  130. package/lib/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
  131. package/lib/implicit-strategy/sharedTreeBranchManager.js +213 -0
  132. package/lib/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
  133. package/lib/implicit-strategy/sharedTreeDiff.d.ts +102 -0
  134. package/lib/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
  135. package/lib/implicit-strategy/sharedTreeDiff.js +515 -0
  136. package/lib/implicit-strategy/sharedTreeDiff.js.map +1 -0
  137. package/lib/implicit-strategy/utils.d.ts +21 -0
  138. package/lib/implicit-strategy/utils.d.ts.map +1 -0
  139. package/lib/implicit-strategy/utils.js +43 -0
  140. package/lib/implicit-strategy/utils.js.map +1 -0
  141. package/lib/index.d.ts +16 -0
  142. package/lib/index.d.ts.map +1 -0
  143. package/lib/index.js +15 -0
  144. package/lib/index.js.map +1 -0
  145. package/lib/public.d.ts +19 -0
  146. package/lib/tsdoc-metadata.json +11 -0
  147. package/mocharc.cjs +14 -0
  148. package/package.json +165 -0
  149. package/prettier.config.cjs +8 -0
  150. package/src/aiCollab.ts +86 -0
  151. package/src/aiCollabApi.ts +184 -0
  152. package/src/explicit-strategy/agentEditReducer.ts +498 -0
  153. package/src/explicit-strategy/agentEditTypes.ts +177 -0
  154. package/src/explicit-strategy/idGenerator.ts +90 -0
  155. package/src/explicit-strategy/index.ts +364 -0
  156. package/src/explicit-strategy/jsonTypes.ts +27 -0
  157. package/src/explicit-strategy/promptGeneration.ts +294 -0
  158. package/src/explicit-strategy/typeGeneration.ts +374 -0
  159. package/src/explicit-strategy/utils.ts +60 -0
  160. package/src/implicit-strategy/README.md +4 -0
  161. package/src/implicit-strategy/index.ts +21 -0
  162. package/src/implicit-strategy/sharedTreeBranchManager.ts +294 -0
  163. package/src/implicit-strategy/sharedTreeDiff.ts +735 -0
  164. package/src/implicit-strategy/utils.ts +54 -0
  165. package/src/index.ts +39 -0
  166. package/tsconfig.cjs.json +7 -0
  167. package/tsconfig.json +12 -0
  168. package/tsdoc.json +4 -0
package/.eslintrc.cjs ADDED
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ module.exports = {
7
+ extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
8
+ parserOptions: {
9
+ project: ["./tsconfig.json", "./src/test/tsconfig.json"],
10
+ },
11
+ overrides: [
12
+ {
13
+ // Rules only for test files
14
+ files: ["*.spec.ts", "src/test/**"],
15
+ rules: {
16
+ // Test files can import from submodules for testing purposes
17
+ "import/no-internal-modules": [
18
+ "error",
19
+ {
20
+ allow: ["*/index.js"],
21
+ },
22
+ ],
23
+ },
24
+ },
25
+ ],
26
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @fluidframework/ai-collab
2
+
3
+ ## 2.5.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.4.0
8
+
9
+ New package.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) Microsoft Corporation and contributors. All rights reserved.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,280 @@
1
+ # @fluidframework/ai-collab
2
+
3
+ ## Description
4
+
5
+ The ai-collab client library makes adding complex, human-like collaboration with LLM's built directly in your application as simple as one function call. Simply pass your SharedTree and ask AI to collaborate. For example,
6
+ - Task Management App: "Reorder this list of tasks in order from least to highest complexity."
7
+ - Job Board App: "Create a new job listing and add it to this job board"
8
+ - Calender App: "Manage my calender to slot in a new 2:30 appointment"
9
+
10
+ ## Usage
11
+
12
+ ### Your SharedTree types file
13
+
14
+ This file is where we define the types of our task management application's SharedTree data
15
+ ```ts
16
+ // --------- File name: "types.ts" ---------
17
+ import { SchemaFactory, type treeView } from "@fluidframework/tree";
18
+
19
+ const sf = new SchemaFactory("ai-collab-sample-application");
20
+
21
+ export class Task extends sf.object("Task", {
22
+ title: sf.required(sf.string, {
23
+ metadata: { description: `The title of the task` },
24
+ }),
25
+ id: sf.identifier,
26
+ description: sf.required(sf.string, {
27
+ metadata: { description: `The description of the task` },
28
+ }),
29
+ priority: sf.required(sf.string, {
30
+ metadata: { description: `The priority of the task in three levels, "low", "medium", "high"` },
31
+ }),
32
+ complexity: sf.required(sf.number, {
33
+ metadata: { description: `The complexity of the task as a fibonacci number` },
34
+ }),
35
+ status: sf.required(sf.string, {
36
+ metadata: { description: `The status of the task as either "todo", "in-progress", or "done"` },
37
+ }),
38
+ assignee: sf.required(sf.string, {
39
+ metadata: { description: `The name of the tasks assignee e.g. "Bob" or "Alice"` },
40
+ }),
41
+ }) {}
42
+
43
+ export class TaskList extends sf.array("TaskList", SharedTreeTask) {}
44
+
45
+ export class Engineer extends sf.object("Engineer", {
46
+ name: sf.required(sf.string, {
47
+ metadata: { description: `The name of an engineer whom can be assigned to a task` },
48
+ }),
49
+ id: sf.identifier,
50
+ skills: sf.required(sf.string, {
51
+ metadata: { description: `A description of the engineers skills which influence what types of tasks they should be assigned to.` },
52
+ }),
53
+ maxCapacity: sf.required(sf.number, {
54
+ metadata: { description: `The maximum capacity of tasks this engineer can handle measured in in task complexity points.` },
55
+ }),
56
+ }) {}
57
+
58
+ export class EngineerList extends sf.array("EngineerList", SharedTreeEngineer) {}
59
+
60
+ export class TaskGroup extends sf.object("TaskGroup", {
61
+ description: sf.required(sf.string, {
62
+ metadata: { description: `The description of the task group, which is a collection of tasks and engineers that can be assigned to said tasks.` },
63
+ }),
64
+ id: sf.identifier,
65
+ title: sf.required(sf.string, {
66
+ metadata: { description: `The title of the task group.` },
67
+ }),
68
+ tasks: sf.required(SharedTreeTaskList, {
69
+ metadata: { description: `The lists of tasks within this task group.` },
70
+ }),
71
+ engineers: sf.required(SharedTreeEngineerList, {
72
+ metadata: { description: `The lists of engineers within this task group which can be assigned to tasks.` },
73
+ }),
74
+ }) {}
75
+
76
+ export class TaskGroupList extends sf.array("TaskGroupList", SharedTreeTaskGroup) {}
77
+
78
+ export class PlannerAppState extends sf.object("PlannerAppState", {
79
+ taskGroups: sf.required(SharedTreeTaskGroupList, {
80
+ metadata: { description: `The list of task groups that are being managed by this task management application.` },
81
+ }),
82
+ }) {}
83
+ ```
84
+
85
+ ### Example 1: Collaborate with AI
86
+
87
+ ```ts
88
+ import { aiCollab } from "@fluidframework/ai-collab/alpha";
89
+ import { PlannerAppState } from "./types.ts"
90
+ // This is not a real file, this is meant to represent how you initialize your app data.
91
+ import { initializeAppState } from "./yourAppInitializationFile.ts"
92
+
93
+ // --------- File name: "app.ts" ---------
94
+
95
+ // Initialize your app state somehow
96
+ const appState: PlannerAppState = initializeAppState({
97
+ taskGroups: [
98
+ {
99
+ title: "My First Task Group",
100
+ description: "Placeholder for first task group",
101
+ tasks: [
102
+ {
103
+ assignee: "Alice",
104
+ title: "Task #1",
105
+ description:
106
+ "This is the first Sample task.",
107
+ priority: "low",
108
+ complexity: 1,
109
+ status: "todo",
110
+ },
111
+ ],
112
+ engineers: [
113
+ {
114
+ name: "Alice",
115
+ maxCapacity: 15,
116
+ skills:
117
+ "Senior engineer capable of handling complex tasks. Versed in most languages",
118
+ },
119
+ {
120
+ name: "Charlie",
121
+ maxCapacity: 7,
122
+ skills: "Junior engineer capable of handling simple tasks. Versed in Node.JS",
123
+ },
124
+ ],
125
+ },
126
+ ],
127
+ })
128
+
129
+ // Typically, the user would input this through a UI form/input of some sort.
130
+ const userAsk = "Update the task group description to be a about creating a new Todo list application. Create a set of tasks to accomplish this and assign them to the available engineers. Keep in mind the max capacity of each engineer as you assign tasks."
131
+
132
+ // Collaborate with AI one function call.
133
+ const response = await aiCollab({
134
+ openAI: {
135
+ client: new OpenAI({
136
+ apiKey: OPENAI_API_KEY,
137
+ }),
138
+ modelName: "gpt-4o",
139
+ },
140
+ treeNode: view.root.taskGroups[0],
141
+ prompt: {
142
+ systemRoleContext:
143
+ "You are a manager that is helping out with a project management tool. You have been asked to edit a group of tasks.",
144
+ userAsk: userAsk,
145
+ },
146
+ planningStep: true,
147
+ finalReviewStep: true,
148
+ dumpDebugLog: true,
149
+ });
150
+
151
+ if (response.status === 'sucess') {
152
+ // Render the UI view of your task groups.
153
+ window.alert(`The AI has successfully completed your request.`);
154
+ } else {
155
+ window.alert(`Something went wrong! response status: ${response.status}, error message: ${response.errorMessage}`);
156
+ }
157
+
158
+ ```
159
+
160
+ Once the `aiCollab` function call is initiated, an LLM will immediately begin attempting to make changes to your Shared Tree using the provided user prompt, the types of your SharedTree and the provided app guidance. The LLM produces multiple changes, in a loop asynchronously. Meaning, you will immediatley see changes if your UI's render loop is connected to your SharedTree App State.
161
+
162
+ ### Example 2: Collaborate with AI onto a branched state and let the user merge the review and merge the branch back manually
163
+ - **Coming Soon**
164
+
165
+
166
+ ## Folder Structure
167
+
168
+ - `/explicit-strategy`: The new explicit strategy, utilizing the prototype built during the fall FHL, with a few adjustments.
169
+ - `agentEditReducer`: This file houses the logic for taking in a `TreeEdit`, which the LLM produces, and applying said edit to the
170
+ - actual SharedTree.
171
+ - `agentEditTypes.ts`: The types of edits an LLM is prompted to produce in order to modify a SharedTree.
172
+ - `idGenerator.ts`: `A manager for producing and mapping simple id's in place of UUID hashes when generating prompts for an LLM
173
+ - `jsonTypes.ts`: utility JSON related types used in parsing LLM response and generating LLM prompts.
174
+ - `promptGeneration.ts`: Logic for producing the different types of prompts sent to an LLM in order to edit a SharedTree.
175
+ - `typeGeneration.ts`: Generates serialized(/able) representations of a SharedTree Schema which is used within prompts and the generated of the structured output JSON schema
176
+ - `utils.ts`: Utilities for interacting with a SharedTree
177
+ - `/implicit-strategy`: The original implicit strategy, currently not used under the exported aiCollab API surface.
178
+
179
+ ## Known Issues & limitations
180
+
181
+ 1. Union types for a TreeNode are not present when generating App Schema. This will require extracting a field schema instead of TreeNodeSchema when passed a non root node.
182
+ 1. The Editing System prompt & structured out schema currently provide array related edits even when there are no arrays. This forces you to have an array in your schema to produce a valid json schema
183
+ 1. Optional roots are not allowed, This is because if you pass undefined as your treeNode to the API, we cannot disambiguate whether you passed the root or not.
184
+ 1. Primitive root nodes are not allowed to be passed to the API. You must use an object or array as your root.
185
+ 1. Optional nodes are not supported -- when we use optional nodes, the OpenAI API returns an error complaining that the structured output JSON schema is invalid. I have introduced a fix that should work upon manual validation of the json schema, but there looks to be an issue with their API. I have filed a ticket with OpenAI to address this
186
+ 1. The current scheme does not allow manipulation of arrays of primitive values because you cannot refer to them. We could accomplish this via a path (probably JSON Pointer or JSONPath) from a possibly-null objectId, or wrap arrays in an identified object.
187
+ 1. Only 100 object fields total are allowed by OpenAI right now, so larger schemas will fail faster if we have a bunch of schema types generated for type-specific edits.
188
+ 1. We don't support nested arrays yet.
189
+ 1. Handle 429 rate limit error from OpenAI API.
190
+ 1. Top level arrays are not supported with current DSL.
191
+ 1. Structured Output fails when multiple schema types have the same first field name (e.g. id: sf.identifier on multiple types).
192
+ 1. Your Application's SharedTree Schema must have no more than 4 levels of nesting due to OpenAI structured output limitations. (4 because we add an extra layer of nesting internally)
193
+
194
+
195
+ <!-- AUTO-GENERATED-CONTENT:START (README_FOOTER) -->
196
+
197
+ <!-- prettier-ignore-start -->
198
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
199
+
200
+ ## Minimum Client Requirements
201
+
202
+ These are the platform requirements for the current version of Fluid Framework Client Packages.
203
+ These requirements err on the side of being too strict since within a major version they can be relaxed over time, but not made stricter.
204
+ For Long Term Support (LTS) versions this can require supporting these platforms for several years.
205
+
206
+ It is likely that other configurations will work, but they are not supported: if they stop working, we do not consider that a bug.
207
+ If you would benefit from support for something not listed here, file an issue and the product team will evaluate your request.
208
+ When making such a request please include if the configuration already works (and thus the request is just that it becomes officially supported), or if changes are required to get it working.
209
+
210
+ ### Supported Runtimes
211
+
212
+ - NodeJs ^20.10.0 except that we will drop support for it [when NodeJs 20 loses its upstream support on 2026-04-30](https://github.com/nodejs/release#release-schedule), and will support a newer LTS version of NodeJS (22) at least 1 year before 20 is end-of-life. This same policy applies to NodeJS 22 when it is end of life (2027-04-30).
213
+ - Modern browsers supporting the es2022 standard library: in response to asks we can add explicit support for using babel to polyfill to target specific standards or runtimes (meaning we can avoid/remove use of things that don't polyfill robustly, but otherwise target modern standards).
214
+
215
+ ### Supported Tools
216
+
217
+ - TypeScript 5.4:
218
+ - All [`strict`](https://www.typescriptlang.org/tsconfig) options are supported.
219
+ - [`strictNullChecks`](https://www.typescriptlang.org/tsconfig) is required.
220
+ - [Configuration options deprecated in 5.0](https://github.com/microsoft/TypeScript/issues/51909) are not supported.
221
+ - `exactOptionalPropertyTypes` is currently not fully supported.
222
+ If used, narrowing members of Fluid Framework types types using `in`, `Reflect.has`, `Object.hasOwn` or `Object.prototype.hasOwnProperty` should be avoided as they may incorrectly exclude `undefined` from the possible values in some cases.
223
+ - [webpack](https://webpack.js.org/) 5
224
+ - We are not intending to be prescriptive about what bundler to use.
225
+ Other bundlers which can handle ES Modules should work, but webpack is the only one we actively test.
226
+
227
+ ### Module Resolution
228
+
229
+ [`Node16`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution) resolution should be used with TypeScript compilerOptions to follow the [Node.js v12+ ESM Resolution and Loading algorithm](https://nodejs.github.io/nodejs.dev/en/api/v20/esm/#resolution-and-loading-algorithm).
230
+ Node10 resolution is not supported as it does not support Fluid Framework's API structuring pattern that is used to distinguish stable APIs from those that are in development.
231
+
232
+ ### Module Formats
233
+
234
+ - ES Modules:
235
+ ES Modules are the preferred way to consume our client packages (including in NodeJs) and consuming our client packages from ES Modules is fully supported.
236
+ - CommonJs:
237
+ Consuming our client packages as CommonJs is supported only in NodeJS and only for the cases listed below.
238
+ This is done to accommodate some workflows without good ES Module support.
239
+ If you have a workflow you would like included in this list, file an issue.
240
+ Once this list of workflows motivating CommonJS support is empty, we may drop support for CommonJS one year after notice of the change is posted here.
241
+
242
+ - Testing with Jest (which lacks [stable ESM support](https://jestjs.io/docs/ecmascript-modules) due to [unstable APIs in NodeJs](https://github.com/nodejs/node/issues/37648))
243
+
244
+ ## Contribution Guidelines
245
+
246
+ There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
247
+
248
+ - Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
249
+ - [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
250
+ - Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
251
+ - [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
252
+
253
+ Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
254
+
255
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
256
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
257
+
258
+ This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
259
+ Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
260
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
261
+
262
+ ## Help
263
+
264
+ Not finding what you're looking for in this README? Check out [fluidframework.com](https://fluidframework.com/docs/).
265
+
266
+ Still not finding what you're looking for? Please [file an issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
267
+
268
+ Thank you!
269
+
270
+ ## Trademark
271
+
272
+ This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
273
+
274
+ Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
275
+
276
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
277
+
278
+ <!-- prettier-ignore-end -->
279
+
280
+ <!-- AUTO-GENERATED-CONTENT:END -->
package/alpha.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /*
7
+ * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
8
+ * Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
9
+ */
10
+
11
+ export * from "./lib/alpha.js";
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
+ "mainEntryPointFilePath": "<projectFolder>/dist/alpha.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
+ "mainEntryPointFilePath": "<projectFolder>/lib/alpha.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.json",
4
+ "mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
+ "mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
+ "mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
+ "mainEntryPointFilePath": "<projectFolder>/dist/public.d.ts"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-lint.entrypoint.json",
4
+ "mainEntryPointFilePath": "<projectFolder>/lib/public.d.ts"
5
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-lint.esm.primary.json"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-base.esm.no-legacy.json"
4
+ }
@@ -0,0 +1,164 @@
1
+ ## Alpha API Report File for "@fluidframework/ai-collab"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ // @alpha
8
+ export function aiCollab(options: AiCollabOptions): Promise<AiCollabSuccessResponse | AiCollabErrorResponse>;
9
+
10
+ // @alpha
11
+ export interface AiCollabErrorResponse {
12
+ readonly errorMessage: "tokenLimitExceeded" | "tooManyErrors" | "tooManyModelCalls" | "aborted";
13
+ readonly status: "failure" | "partial-failure";
14
+ readonly tokensUsed: TokenUsage;
15
+ }
16
+
17
+ // @alpha
18
+ export interface AiCollabOptions {
19
+ readonly dumpDebugLog?: boolean;
20
+ readonly finalReviewStep?: boolean;
21
+ readonly limiters?: {
22
+ readonly abortController?: AbortController;
23
+ readonly maxSequentialErrors?: number;
24
+ readonly maxModelCalls?: number;
25
+ readonly tokenLimits?: TokenLimits;
26
+ };
27
+ readonly openAI: OpenAiClientOptions;
28
+ readonly planningStep?: boolean;
29
+ readonly prompt: {
30
+ readonly systemRoleContext: string;
31
+ readonly userAsk: string;
32
+ };
33
+ readonly treeNode: TreeNode;
34
+ readonly validator?: (newContent: TreeNode) => void;
35
+ }
36
+
37
+ // @alpha
38
+ export interface AiCollabSuccessResponse {
39
+ readonly status: "success";
40
+ readonly tokensUsed: TokenUsage;
41
+ }
42
+
43
+ // @alpha
44
+ export function createMergableDiffSeries(diffs: Difference[]): Difference[];
45
+
46
+ // @alpha
47
+ export function createMergableIdDiffSeries(oldObject: unknown, diffs: Difference[], idAttributeName: string | number): Difference[];
48
+
49
+ // @alpha
50
+ export type Difference = DifferenceCreate | DifferenceRemove | DifferenceChange | DifferenceMove;
51
+
52
+ // @alpha
53
+ export interface DifferenceChange {
54
+ // (undocumented)
55
+ objectId?: string | number | undefined;
56
+ // (undocumented)
57
+ oldValue: unknown;
58
+ // (undocumented)
59
+ path: ObjectPath;
60
+ // (undocumented)
61
+ type: "CHANGE";
62
+ // (undocumented)
63
+ value: unknown;
64
+ }
65
+
66
+ // @alpha
67
+ export interface DifferenceCreate {
68
+ // (undocumented)
69
+ path: ObjectPath;
70
+ // (undocumented)
71
+ type: "CREATE";
72
+ // (undocumented)
73
+ value: unknown;
74
+ }
75
+
76
+ // @alpha
77
+ export interface DifferenceMove {
78
+ // (undocumented)
79
+ newIndex: number;
80
+ // (undocumented)
81
+ objectId?: string | number | undefined;
82
+ // (undocumented)
83
+ path: ObjectPath;
84
+ // (undocumented)
85
+ type: "MOVE";
86
+ // (undocumented)
87
+ value: unknown;
88
+ }
89
+
90
+ // @alpha
91
+ export interface DifferenceRemove {
92
+ // (undocumented)
93
+ objectId?: string | number | undefined;
94
+ // (undocumented)
95
+ oldValue: unknown;
96
+ // (undocumented)
97
+ path: ObjectPath;
98
+ // (undocumented)
99
+ type: "REMOVE";
100
+ }
101
+
102
+ // @alpha
103
+ export type ObjectPath = (string | number)[];
104
+
105
+ // @alpha
106
+ export interface OpenAiClientOptions {
107
+ client: OpenAI;
108
+ modelName?: string;
109
+ }
110
+
111
+ // @alpha
112
+ export interface Options {
113
+ // (undocumented)
114
+ cyclesFix: boolean;
115
+ // (undocumented)
116
+ useObjectIds?: {
117
+ idAttributeName: string;
118
+ } | undefined;
119
+ }
120
+
121
+ // @alpha
122
+ export class SharedTreeBranchManager {
123
+ constructor(params?: {
124
+ objectSchema?: z.Schema;
125
+ nodeIdAttributeName?: string;
126
+ });
127
+ applyDiff(diff: Difference, objectToUpdate: Record<string, unknown> | TreeArrayNode): boolean;
128
+ checkoutNewMergedBranch<T extends ImplicitFieldSchema>(treeView: TreeViewAlpha<T>, treeViewConfiguration: TreeViewConfiguration<T>, absolutePathToObjectNode: ObjectPath, llmResponse: Record<string, unknown> | unknown[]): {
129
+ differences: Difference[];
130
+ originalBranch: BranchableTree;
131
+ forkBranch: TreeBranchFork;
132
+ forkView: TreeViewAlpha<T>;
133
+ newBranchTargetNode: Record<string, unknown> | TreeArrayNode;
134
+ };
135
+ checkoutNewMergedBranchV2<T extends ImplicitFieldSchema>(treeView: TreeViewAlpha<T>, treeViewConfiguration: TreeViewConfiguration<T>, absolutePathToObjectNode: ObjectPath): {
136
+ originalBranch: BranchableTree;
137
+ forkBranch: TreeBranchFork;
138
+ forkView: TreeViewAlpha<T>;
139
+ newBranchTargetNode: Record<string, unknown> | TreeArrayNode;
140
+ };
141
+ compare(obj: Record<string, unknown> | TreeArrayNode, newObj: Record<string, unknown> | unknown[]): Difference[];
142
+ mergeDiffs(diffs: Difference[], objectToUpdate: Record<string, unknown> | TreeArrayNode): Set<Difference>;
143
+ mergeObject(obj: Record<string, unknown> | TreeArrayNode, llmResponse: Record<string, unknown> | unknown[]): Difference[];
144
+ }
145
+
146
+ // @alpha
147
+ export function sharedTreeDiff(obj: Record<string, unknown> | unknown[], newObj: Record<string, unknown> | unknown[], options?: Options, _stack?: (Record<string, unknown> | unknown[])[]): Difference[];
148
+
149
+ // @alpha
150
+ export function sharedTreeTraverse<T = unknown>(jsonObject: TreeMapNode | TreeArrayNode | Record<string, unknown>, path: ObjectPath): T | undefined;
151
+
152
+ // @alpha
153
+ export interface TokenLimits {
154
+ readonly inputTokens?: number;
155
+ readonly outputTokens?: number;
156
+ }
157
+
158
+ // @alpha
159
+ export interface TokenUsage {
160
+ inputTokens: number;
161
+ outputTokens: number;
162
+ }
163
+
164
+ ```
@@ -0,0 +1,7 @@
1
+ ## Beta API Report File for "@fluidframework/ai-collab"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ ```
@@ -0,0 +1,7 @@
1
+ ## Public API Report File for "@fluidframework/ai-collab"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ ```
package/biome.jsonc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3
+ "extends": ["../../../biome.jsonc"]
4
+ }
@@ -0,0 +1,65 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { AiCollabErrorResponse, AiCollabOptions, AiCollabSuccessResponse } from "./aiCollabApi.js";
6
+ /**
7
+ * Calls an LLM to modify the provided SharedTree in a series of real time edits based on the provided users prompt input.
8
+ * @remarks This function is designed to be a controlled "all-in-one" function that handles the entire process of calling an LLM to collaborative edit a SharedTree.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import {
13
+ * SchemaFactory,
14
+ * TreeViewConfiguration,
15
+ * type TreeView
16
+ * } from "@fluidframework/tree";
17
+ *
18
+ * const sf = new SchemaFactory("todo-app");
19
+ *
20
+ * class TodoTask extends sf.object("TodoTask", {
21
+ * title: sf.string,
22
+ * description: sf.string,
23
+ * }) {}
24
+ *
25
+ * class TodoAppState extends sf.object("TodoAppState", {
26
+ * tasks: sf.array(TodoTask),
27
+ * }) {}
28
+ *
29
+ * // Initialize your SharedTree
30
+ * const treeView: TreeView = tree.viewWith(new TreeViewConfiguration({ schema: TodoAppState }));
31
+ * treeView.initialize({ tasks: [] });
32
+ *
33
+ * // Collaborate with AI in realtime in just one function call.
34
+ * const response = await aiCollab({
35
+ * openAI: {
36
+ * client: new OpenAI({
37
+ * apiKey: OPENAI_API_KEY,
38
+ * }),
39
+ * modelName: "gpt-4o",
40
+ * },
41
+ * treeNode: view.root,
42
+ * prompt: {
43
+ * systemRoleContext:
44
+ * "You are an helpful assistant managing a todo list for a user.",
45
+ * userAsk: "Create a set of new todos to plan a vacation to Cancun.",
46
+ * },
47
+ * planningStep: true,
48
+ * finalReviewStep: true,
49
+ * dumpDebugLog: true,
50
+ * });
51
+ * ```
52
+ *
53
+ * @remarks Known Limitiations:
54
+ * - Root level array nodes are not supported
55
+ * - Nested arrays are not supported
56
+ * - Primitive nodes are not supported, e.g. 'string', 'number', 'boolean'
57
+ * - Your application's Shared Tree schema must have no more than 4 levels of nesting
58
+ * - Optional nodes are not supported in the Shared Tree schema
59
+ * - Union types are not supported in the Shared Tree schema
60
+ * - See README for more details.
61
+ *
62
+ * @alpha
63
+ */
64
+ export declare function aiCollab(options: AiCollabOptions): Promise<AiCollabSuccessResponse | AiCollabErrorResponse>;
65
+ //# sourceMappingURL=aiCollab.d.ts.map