@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.
- package/.eslintrc.cjs +26 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +280 -0
- package/alpha.d.ts +11 -0
- package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-index.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-index.esm.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/ai-collab.alpha.api.md +164 -0
- package/api-report/ai-collab.beta.api.md +7 -0
- package/api-report/ai-collab.public.api.md +7 -0
- package/biome.jsonc +4 -0
- package/dist/aiCollab.d.ts +65 -0
- package/dist/aiCollab.d.ts.map +1 -0
- package/dist/aiCollab.js +81 -0
- package/dist/aiCollab.js.map +1 -0
- package/dist/aiCollabApi.d.ts +173 -0
- package/dist/aiCollabApi.d.ts.map +1 -0
- package/dist/aiCollabApi.js +7 -0
- package/dist/aiCollabApi.js.map +1 -0
- package/dist/alpha.d.ts +41 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts +12 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -0
- package/dist/explicit-strategy/agentEditReducer.js +394 -0
- package/dist/explicit-strategy/agentEditReducer.js.map +1 -0
- package/dist/explicit-strategy/agentEditTypes.d.ts +158 -0
- package/dist/explicit-strategy/agentEditTypes.d.ts.map +1 -0
- package/dist/explicit-strategy/agentEditTypes.js +50 -0
- package/dist/explicit-strategy/agentEditTypes.js.map +1 -0
- package/dist/explicit-strategy/idGenerator.d.ts +22 -0
- package/dist/explicit-strategy/idGenerator.d.ts.map +1 -0
- package/dist/explicit-strategy/idGenerator.js +74 -0
- package/dist/explicit-strategy/idGenerator.js.map +1 -0
- package/dist/explicit-strategy/index.d.ts +51 -0
- package/dist/explicit-strategy/index.d.ts.map +1 -0
- package/dist/explicit-strategy/index.js +223 -0
- package/dist/explicit-strategy/index.js.map +1 -0
- package/dist/explicit-strategy/jsonTypes.d.ts +23 -0
- package/dist/explicit-strategy/jsonTypes.d.ts.map +1 -0
- package/dist/explicit-strategy/jsonTypes.js +7 -0
- package/dist/explicit-strategy/jsonTypes.js.map +1 -0
- package/dist/explicit-strategy/promptGeneration.d.ts +51 -0
- package/dist/explicit-strategy/promptGeneration.d.ts.map +1 -0
- package/dist/explicit-strategy/promptGeneration.js +218 -0
- package/dist/explicit-strategy/promptGeneration.js.map +1 -0
- package/dist/explicit-strategy/typeGeneration.d.ts +15 -0
- package/dist/explicit-strategy/typeGeneration.d.ts.map +1 -0
- package/dist/explicit-strategy/typeGeneration.js +264 -0
- package/dist/explicit-strategy/typeGeneration.js.map +1 -0
- package/dist/explicit-strategy/utils.d.ts +37 -0
- package/dist/explicit-strategy/utils.d.ts.map +1 -0
- package/dist/explicit-strategy/utils.js +47 -0
- package/dist/explicit-strategy/utils.js.map +1 -0
- package/dist/implicit-strategy/index.d.ts +8 -0
- package/dist/implicit-strategy/index.d.ts.map +1 -0
- package/dist/implicit-strategy/index.js +18 -0
- package/dist/implicit-strategy/index.js.map +1 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.js +212 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
- package/dist/implicit-strategy/sharedTreeDiff.d.ts +102 -0
- package/dist/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
- package/dist/implicit-strategy/sharedTreeDiff.js +522 -0
- package/dist/implicit-strategy/sharedTreeDiff.js.map +1 -0
- package/dist/implicit-strategy/utils.d.ts +21 -0
- package/dist/implicit-strategy/utils.d.ts.map +1 -0
- package/dist/implicit-strategy/utils.js +49 -0
- package/dist/implicit-strategy/utils.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +3 -0
- package/dist/public.d.ts +19 -0
- package/eslintrc.cjs +11 -0
- package/internal.d.ts +11 -0
- package/lib/aiCollab.d.ts +65 -0
- package/lib/aiCollab.d.ts.map +1 -0
- package/lib/aiCollab.js +77 -0
- package/lib/aiCollab.js.map +1 -0
- package/lib/aiCollabApi.d.ts +173 -0
- package/lib/aiCollabApi.d.ts.map +1 -0
- package/lib/aiCollabApi.js +6 -0
- package/lib/aiCollabApi.js.map +1 -0
- package/lib/alpha.d.ts +41 -0
- package/lib/explicit-strategy/agentEditReducer.d.ts +12 -0
- package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -0
- package/lib/explicit-strategy/agentEditReducer.js +390 -0
- package/lib/explicit-strategy/agentEditReducer.js.map +1 -0
- package/lib/explicit-strategy/agentEditTypes.d.ts +158 -0
- package/lib/explicit-strategy/agentEditTypes.d.ts.map +1 -0
- package/lib/explicit-strategy/agentEditTypes.js +47 -0
- package/lib/explicit-strategy/agentEditTypes.js.map +1 -0
- package/lib/explicit-strategy/idGenerator.d.ts +22 -0
- package/lib/explicit-strategy/idGenerator.d.ts.map +1 -0
- package/lib/explicit-strategy/idGenerator.js +70 -0
- package/lib/explicit-strategy/idGenerator.js.map +1 -0
- package/lib/explicit-strategy/index.d.ts +51 -0
- package/lib/explicit-strategy/index.d.ts.map +1 -0
- package/lib/explicit-strategy/index.js +219 -0
- package/lib/explicit-strategy/index.js.map +1 -0
- package/lib/explicit-strategy/jsonTypes.d.ts +23 -0
- package/lib/explicit-strategy/jsonTypes.d.ts.map +1 -0
- package/lib/explicit-strategy/jsonTypes.js +6 -0
- package/lib/explicit-strategy/jsonTypes.js.map +1 -0
- package/lib/explicit-strategy/promptGeneration.d.ts +51 -0
- package/lib/explicit-strategy/promptGeneration.d.ts.map +1 -0
- package/lib/explicit-strategy/promptGeneration.js +208 -0
- package/lib/explicit-strategy/promptGeneration.js.map +1 -0
- package/lib/explicit-strategy/typeGeneration.d.ts +15 -0
- package/lib/explicit-strategy/typeGeneration.d.ts.map +1 -0
- package/lib/explicit-strategy/typeGeneration.js +260 -0
- package/lib/explicit-strategy/typeGeneration.js.map +1 -0
- package/lib/explicit-strategy/utils.d.ts +37 -0
- package/lib/explicit-strategy/utils.d.ts.map +1 -0
- package/lib/explicit-strategy/utils.js +41 -0
- package/lib/explicit-strategy/utils.js.map +1 -0
- package/lib/implicit-strategy/index.d.ts +8 -0
- package/lib/implicit-strategy/index.d.ts.map +1 -0
- package/lib/implicit-strategy/index.js +8 -0
- package/lib/implicit-strategy/index.js.map +1 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.js +213 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
- package/lib/implicit-strategy/sharedTreeDiff.d.ts +102 -0
- package/lib/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
- package/lib/implicit-strategy/sharedTreeDiff.js +515 -0
- package/lib/implicit-strategy/sharedTreeDiff.js.map +1 -0
- package/lib/implicit-strategy/utils.d.ts +21 -0
- package/lib/implicit-strategy/utils.d.ts.map +1 -0
- package/lib/implicit-strategy/utils.js +43 -0
- package/lib/implicit-strategy/utils.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/public.d.ts +19 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/mocharc.cjs +14 -0
- package/package.json +165 -0
- package/prettier.config.cjs +8 -0
- package/src/aiCollab.ts +86 -0
- package/src/aiCollabApi.ts +184 -0
- package/src/explicit-strategy/agentEditReducer.ts +498 -0
- package/src/explicit-strategy/agentEditTypes.ts +177 -0
- package/src/explicit-strategy/idGenerator.ts +90 -0
- package/src/explicit-strategy/index.ts +364 -0
- package/src/explicit-strategy/jsonTypes.ts +27 -0
- package/src/explicit-strategy/promptGeneration.ts +294 -0
- package/src/explicit-strategy/typeGeneration.ts +374 -0
- package/src/explicit-strategy/utils.ts +60 -0
- package/src/implicit-strategy/README.md +4 -0
- package/src/implicit-strategy/index.ts +21 -0
- package/src/implicit-strategy/sharedTreeBranchManager.ts +294 -0
- package/src/implicit-strategy/sharedTreeDiff.ts +735 -0
- package/src/implicit-strategy/utils.ts +54 -0
- package/src/index.ts +39 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +12 -0
- package/tsdoc.json +4 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
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
|
+
exports.applyAgentEdit = void 0;
|
|
8
|
+
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
9
|
+
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
10
|
+
const internal_2 = require("@fluidframework/telemetry-utils/internal");
|
|
11
|
+
const internal_3 = require("@fluidframework/tree/internal");
|
|
12
|
+
const agentEditTypes_js_1 = require("./agentEditTypes.js");
|
|
13
|
+
const promptGeneration_js_1 = require("./promptGeneration.js");
|
|
14
|
+
const utils_js_1 = require("./utils.js");
|
|
15
|
+
function populateDefaults(json, definitionMap) {
|
|
16
|
+
if (typeof json === "object") {
|
|
17
|
+
if (json === null) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(json)) {
|
|
21
|
+
for (const element of json) {
|
|
22
|
+
populateDefaults(element, definitionMap);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
(0, internal_1.assert)(typeof json[agentEditTypes_js_1.typeField] === "string", "The typeField must be present in new JSON content");
|
|
27
|
+
const nodeSchema = definitionMap.get(json[agentEditTypes_js_1.typeField]);
|
|
28
|
+
(0, internal_1.assert)(nodeSchema?.kind === internal_3.NodeKind.Object, "Expected object schema");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getSchemaIdentifier(content) {
|
|
33
|
+
switch (typeof content) {
|
|
34
|
+
case "boolean": {
|
|
35
|
+
return internal_3.booleanSchema.identifier;
|
|
36
|
+
}
|
|
37
|
+
case "number": {
|
|
38
|
+
return internal_3.numberSchema.identifier;
|
|
39
|
+
}
|
|
40
|
+
case "string": {
|
|
41
|
+
return internal_3.stringSchema.identifier;
|
|
42
|
+
}
|
|
43
|
+
case "object": {
|
|
44
|
+
if (content === null) {
|
|
45
|
+
return internal_3.nullSchema.identifier;
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(content)) {
|
|
48
|
+
throw new internal_2.UsageError("Arrays are not currently supported in this context");
|
|
49
|
+
}
|
|
50
|
+
if ((0, runtime_utils_1.isFluidHandle)(content)) {
|
|
51
|
+
return internal_3.handleSchema.identifier;
|
|
52
|
+
}
|
|
53
|
+
return content[agentEditTypes_js_1.typeField];
|
|
54
|
+
}
|
|
55
|
+
default: {
|
|
56
|
+
throw new internal_2.UsageError("Unsupported content type");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function contentWithIds(content, idGenerator) {
|
|
61
|
+
return JSON.parse((0, promptGeneration_js_1.toDecoratedJson)(idGenerator, content));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Manages applying the various types of {@link TreeEdit}'s to a a given {@link TreeNode}.
|
|
65
|
+
*/
|
|
66
|
+
function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator) {
|
|
67
|
+
assertObjectIdsExist(treeEdit, idGenerator);
|
|
68
|
+
switch (treeEdit.type) {
|
|
69
|
+
case "insert": {
|
|
70
|
+
const { array, index } = getPlaceInfo(treeEdit.destination, idGenerator);
|
|
71
|
+
const parentNodeSchema = internal_3.Tree.schema(array);
|
|
72
|
+
populateDefaults(treeEdit.content, definitionMap);
|
|
73
|
+
const schemaIdentifier = getSchemaIdentifier(treeEdit.content);
|
|
74
|
+
// We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.
|
|
75
|
+
const allowedTypes = [
|
|
76
|
+
...(0, internal_3.normalizeAllowedTypes)(parentNodeSchema.info),
|
|
77
|
+
];
|
|
78
|
+
for (const allowedType of allowedTypes.values()) {
|
|
79
|
+
if (allowedType.identifier === schemaIdentifier && typeof allowedType === "function") {
|
|
80
|
+
const simpleNodeSchema = allowedType;
|
|
81
|
+
const insertNode = new simpleNodeSchema(treeEdit.content);
|
|
82
|
+
validator?.(insertNode);
|
|
83
|
+
array.insertAt(index, insertNode);
|
|
84
|
+
return {
|
|
85
|
+
...treeEdit,
|
|
86
|
+
content: contentWithIds(insertNode, idGenerator),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
(0, utils_js_1.fail)("inserted node must be of an allowed type");
|
|
91
|
+
}
|
|
92
|
+
case "remove": {
|
|
93
|
+
const source = treeEdit.source;
|
|
94
|
+
if (isObjectTarget(source)) {
|
|
95
|
+
const node = getNodeFromTarget(source, idGenerator);
|
|
96
|
+
const parentNode = internal_3.Tree.parent(node);
|
|
97
|
+
// Case for deleting rootNode
|
|
98
|
+
if (parentNode === undefined) {
|
|
99
|
+
throw new internal_2.UsageError("The root is required, and cannot be removed. Please use modify edit instead.");
|
|
100
|
+
}
|
|
101
|
+
else if (internal_3.Tree.schema(parentNode).kind === internal_3.NodeKind.Array) {
|
|
102
|
+
const nodeIndex = internal_3.Tree.key(node);
|
|
103
|
+
parentNode.removeAt(nodeIndex);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const fieldKey = internal_3.Tree.key(node);
|
|
107
|
+
const parentSchema = internal_3.Tree.schema(parentNode);
|
|
108
|
+
const fieldSchema = parentSchema.info[fieldKey] ??
|
|
109
|
+
(0, utils_js_1.fail)("Expected field schema");
|
|
110
|
+
if (fieldSchema instanceof internal_3.FieldSchema && fieldSchema.kind === internal_3.FieldKind.Optional) {
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
112
|
+
parentNode[fieldKey] = undefined;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
throw new internal_2.UsageError(`${fieldKey} is required, and cannot be removed. Please use modify edit instead.`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (isRange(source)) {
|
|
120
|
+
const { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);
|
|
121
|
+
array.removeRange(startIndex, endIndex);
|
|
122
|
+
}
|
|
123
|
+
return treeEdit;
|
|
124
|
+
}
|
|
125
|
+
case "modify": {
|
|
126
|
+
const node = getNodeFromTarget(treeEdit.target, idGenerator);
|
|
127
|
+
const { treeNodeSchema } = getSimpleNodeSchema(node);
|
|
128
|
+
const fieldSchema = treeNodeSchema.info[treeEdit.field] ??
|
|
129
|
+
(0, utils_js_1.fail)("Expected field schema");
|
|
130
|
+
const modification = treeEdit.modification;
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
132
|
+
const schemaIdentifier = modification[agentEditTypes_js_1.typeField];
|
|
133
|
+
let insertedObject;
|
|
134
|
+
// if fieldSchema is a LeafnodeSchema, we can check that it's a valid type and set the field.
|
|
135
|
+
if (isPrimitive(modification)) {
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
137
|
+
node[treeEdit.field] = modification;
|
|
138
|
+
}
|
|
139
|
+
// If the fieldSchema is a function we can grab the constructor and make an instance of that node.
|
|
140
|
+
else if (typeof fieldSchema === "function") {
|
|
141
|
+
const simpleSchema = fieldSchema;
|
|
142
|
+
populateDefaults(modification, definitionMap);
|
|
143
|
+
const constructedModification = new simpleSchema(modification);
|
|
144
|
+
validator?.(constructedModification);
|
|
145
|
+
insertedObject = constructedModification;
|
|
146
|
+
if (Array.isArray(modification)) {
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
148
|
+
const field = node[treeEdit.field];
|
|
149
|
+
(0, internal_1.assert)(Array.isArray(field), "the field must be an array node");
|
|
150
|
+
(0, internal_1.assert)(Array.isArray(constructedModification), "the modification must be an array node");
|
|
151
|
+
field.removeRange(0);
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
153
|
+
node[treeEdit.field] = constructedModification;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
157
|
+
node[treeEdit.field] = constructedModification;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// If the fieldSchema is of type FieldSchema, we can check its allowed types and set the field.
|
|
161
|
+
else if (fieldSchema instanceof internal_3.FieldSchema) {
|
|
162
|
+
if (fieldSchema.kind === internal_3.FieldKind.Optional && modification === undefined) {
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
164
|
+
node[treeEdit.field] = undefined;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
for (const allowedType of fieldSchema.allowedTypeSet.values()) {
|
|
168
|
+
if (allowedType.identifier === schemaIdentifier) {
|
|
169
|
+
if (typeof allowedType === "function") {
|
|
170
|
+
const simpleSchema = allowedType;
|
|
171
|
+
const constructedObject = new simpleSchema(modification);
|
|
172
|
+
insertedObject = constructedObject;
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
174
|
+
node[treeEdit.field] = constructedObject;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
178
|
+
node[treeEdit.field] = modification;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return insertedObject === undefined
|
|
185
|
+
? treeEdit
|
|
186
|
+
: {
|
|
187
|
+
...treeEdit,
|
|
188
|
+
modification: contentWithIds(insertedObject, idGenerator),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
case "move": {
|
|
192
|
+
// TODO: need to add schema check for valid moves
|
|
193
|
+
const source = treeEdit.source;
|
|
194
|
+
const destination = treeEdit.destination;
|
|
195
|
+
const { array: destinationArrayNode, index: destinationIndex } = getPlaceInfo(destination, idGenerator);
|
|
196
|
+
if (isObjectTarget(source)) {
|
|
197
|
+
const sourceNode = getNodeFromTarget(source, idGenerator);
|
|
198
|
+
const sourceIndex = internal_3.Tree.key(sourceNode);
|
|
199
|
+
const sourceArrayNode = internal_3.Tree.parent(sourceNode);
|
|
200
|
+
const sourceArraySchema = internal_3.Tree.schema(sourceArrayNode);
|
|
201
|
+
if (sourceArraySchema.kind !== internal_3.NodeKind.Array) {
|
|
202
|
+
throw new internal_2.UsageError("the source node must be within an arrayNode");
|
|
203
|
+
}
|
|
204
|
+
const destinationArraySchema = internal_3.Tree.schema(destinationArrayNode);
|
|
205
|
+
const allowedTypes = [
|
|
206
|
+
...(0, internal_3.normalizeAllowedTypes)(destinationArraySchema.info),
|
|
207
|
+
];
|
|
208
|
+
const nodeToMove = sourceArrayNode.at(sourceIndex);
|
|
209
|
+
(0, internal_1.assert)(nodeToMove !== undefined, "node to move must exist");
|
|
210
|
+
if (isNodeAllowedType(nodeToMove, allowedTypes)) {
|
|
211
|
+
destinationArrayNode.moveRangeToIndex(destinationIndex, sourceIndex, sourceIndex + 1, sourceArrayNode);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
throw new internal_2.UsageError("Illegal node type in destination array");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else if (isRange(source)) {
|
|
218
|
+
const { array, startIndex: sourceStartIndex, endIndex: sourceEndIndex, } = getRangeInfo(source, idGenerator);
|
|
219
|
+
const destinationArraySchema = internal_3.Tree.schema(destinationArrayNode);
|
|
220
|
+
const allowedTypes = [
|
|
221
|
+
...(0, internal_3.normalizeAllowedTypes)(destinationArraySchema.info),
|
|
222
|
+
];
|
|
223
|
+
for (let i = sourceStartIndex; i < sourceEndIndex; i++) {
|
|
224
|
+
const nodeToMove = array.at(i);
|
|
225
|
+
(0, internal_1.assert)(nodeToMove !== undefined, "node to move must exist");
|
|
226
|
+
if (!isNodeAllowedType(nodeToMove, allowedTypes)) {
|
|
227
|
+
throw new internal_2.UsageError("Illegal node type in destination array");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
destinationArrayNode.moveRangeToIndex(destinationIndex, sourceStartIndex, sourceEndIndex, array);
|
|
231
|
+
}
|
|
232
|
+
return treeEdit;
|
|
233
|
+
}
|
|
234
|
+
default: {
|
|
235
|
+
(0, utils_js_1.fail)("invalid tree edit");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.applyAgentEdit = applyAgentEdit;
|
|
240
|
+
function isNodeAllowedType(node, allowedTypes) {
|
|
241
|
+
for (const allowedType of allowedTypes) {
|
|
242
|
+
if (internal_3.Tree.is(node, allowedType)) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
function isPrimitive(content) {
|
|
249
|
+
return (typeof content === "number" ||
|
|
250
|
+
typeof content === "string" ||
|
|
251
|
+
typeof content === "boolean" ||
|
|
252
|
+
content === undefined ||
|
|
253
|
+
content === null);
|
|
254
|
+
}
|
|
255
|
+
function isObjectTarget(selection) {
|
|
256
|
+
return Object.keys(selection).length === 1 && "target" in selection;
|
|
257
|
+
}
|
|
258
|
+
function isRange(selection) {
|
|
259
|
+
return "from" in selection && "to" in selection;
|
|
260
|
+
}
|
|
261
|
+
function getRangeInfo(range, idGenerator) {
|
|
262
|
+
const { array: arrayFrom, index: startIndex } = getPlaceInfo(range.from, idGenerator);
|
|
263
|
+
const { array: arrayTo, index: endIndex } = getPlaceInfo(range.to, idGenerator);
|
|
264
|
+
if (arrayFrom !== arrayTo) {
|
|
265
|
+
throw new internal_2.UsageError('The "from" node and "to" nodes of the range must be in the same parent array.');
|
|
266
|
+
}
|
|
267
|
+
return { array: arrayFrom, startIndex, endIndex };
|
|
268
|
+
}
|
|
269
|
+
function getPlaceInfo(place, idGenerator) {
|
|
270
|
+
if (place.type === "arrayPlace") {
|
|
271
|
+
const parent = idGenerator.getNode(place.parentId) ?? (0, utils_js_1.fail)("Expected parent node");
|
|
272
|
+
const child = parent[place.field];
|
|
273
|
+
if (child === undefined) {
|
|
274
|
+
throw new internal_2.UsageError(`No child under field field`);
|
|
275
|
+
}
|
|
276
|
+
const schema = internal_3.Tree.schema(child);
|
|
277
|
+
if (schema.kind !== internal_3.NodeKind.Array) {
|
|
278
|
+
throw new internal_2.UsageError("Expected child to be in an array node");
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
array: child,
|
|
282
|
+
index: place.location === "start" ? 0 : child.length,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
const node = getNodeFromTarget(place, idGenerator);
|
|
287
|
+
const nodeIndex = internal_3.Tree.key(node);
|
|
288
|
+
const parent = internal_3.Tree.parent(node);
|
|
289
|
+
if (parent === undefined) {
|
|
290
|
+
throw new internal_2.UsageError("TODO: root node target not supported");
|
|
291
|
+
}
|
|
292
|
+
const schema = internal_3.Tree.schema(parent);
|
|
293
|
+
if (schema.kind !== internal_3.NodeKind.Array) {
|
|
294
|
+
throw new internal_2.UsageError("Expected child to be in an array node");
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
array: parent,
|
|
298
|
+
index: place.place === "before" ? nodeIndex : nodeIndex + 1,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Returns the target node with the matching internal objectId using the provided {@link ObjectTarget}
|
|
304
|
+
*/
|
|
305
|
+
function getNodeFromTarget(target, idGenerator) {
|
|
306
|
+
const node = idGenerator.getNode(target.target);
|
|
307
|
+
(0, internal_1.assert)(node !== undefined, "objectId does not exist in nodeMap");
|
|
308
|
+
return node;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Checks that the objectIds of the Tree Nodes within the givin the {@link TreeEdit} exist within the given {@link IdGenerator}
|
|
312
|
+
*
|
|
313
|
+
* @throws An {@link UsageError} if the objectIdKey does not exist in the {@link IdGenerator}
|
|
314
|
+
*/
|
|
315
|
+
function assertObjectIdsExist(treeEdit, idGenerator) {
|
|
316
|
+
switch (treeEdit.type) {
|
|
317
|
+
case "insert": {
|
|
318
|
+
if (treeEdit.destination.type === "objectPlace") {
|
|
319
|
+
if (idGenerator.getNode(treeEdit.destination.target) === undefined) {
|
|
320
|
+
throw new internal_2.UsageError(`objectIdKey ${treeEdit.destination.target} does not exist`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
if (idGenerator.getNode(treeEdit.destination.parentId) === undefined) {
|
|
325
|
+
throw new internal_2.UsageError(`objectIdKey ${treeEdit.destination.parentId} does not exist`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
case "remove": {
|
|
331
|
+
if (isRange(treeEdit.source)) {
|
|
332
|
+
const missingObjectIds = [
|
|
333
|
+
treeEdit.source.from.target,
|
|
334
|
+
treeEdit.source.to.target,
|
|
335
|
+
].filter((id) => !idGenerator.getNode(id));
|
|
336
|
+
if (missingObjectIds.length > 0) {
|
|
337
|
+
throw new internal_2.UsageError(`objectIdKeys [${missingObjectIds}] does not exist`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else if (isObjectTarget(treeEdit.source) &&
|
|
341
|
+
idGenerator.getNode(treeEdit.source.target) === undefined) {
|
|
342
|
+
throw new internal_2.UsageError(`objectIdKey ${treeEdit.source.target} does not exist`);
|
|
343
|
+
}
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case "modify": {
|
|
347
|
+
if (idGenerator.getNode(treeEdit.target.target) === undefined) {
|
|
348
|
+
throw new internal_2.UsageError(`objectIdKey ${treeEdit.target.target} does not exist`);
|
|
349
|
+
}
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case "move": {
|
|
353
|
+
const invalidObjectIds = [];
|
|
354
|
+
// check the source
|
|
355
|
+
if (isRange(treeEdit.source)) {
|
|
356
|
+
const missingObjectIds = [
|
|
357
|
+
treeEdit.source.from.target,
|
|
358
|
+
treeEdit.source.to.target,
|
|
359
|
+
].filter((id) => !idGenerator.getNode(id));
|
|
360
|
+
if (missingObjectIds.length > 0) {
|
|
361
|
+
invalidObjectIds.push(...missingObjectIds);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else if (isObjectTarget(treeEdit.source) &&
|
|
365
|
+
idGenerator.getNode(treeEdit.source.target) === undefined) {
|
|
366
|
+
invalidObjectIds.push(treeEdit.source.target);
|
|
367
|
+
}
|
|
368
|
+
// check the destination
|
|
369
|
+
if (treeEdit.destination.type === "objectPlace") {
|
|
370
|
+
if (idGenerator.getNode(treeEdit.destination.target) === undefined) {
|
|
371
|
+
invalidObjectIds.push(treeEdit.destination.target);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
if (idGenerator.getNode(treeEdit.destination.parentId) === undefined) {
|
|
376
|
+
invalidObjectIds.push(treeEdit.destination.parentId);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (invalidObjectIds.length > 0) {
|
|
380
|
+
throw new internal_2.UsageError(`objectIdKeys [${invalidObjectIds}] does not exist`);
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
default: {
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function getSimpleNodeSchema(node) {
|
|
390
|
+
const treeNodeSchema = internal_3.Tree.schema(node);
|
|
391
|
+
const simpleNodeSchema = treeNodeSchema;
|
|
392
|
+
return { treeNodeSchema, simpleNodeSchema };
|
|
393
|
+
}
|
|
394
|
+
//# sourceMappingURL=agentEditReducer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentEditReducer.js","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,iEAA8D;AAC9D,uEAAsE;AACtE,4DAkBuC;AAEvC,2DAU6B;AAG7B,+DAAwD;AACxD,yCAAkC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAA,iBAAM,EACL,OAAO,IAAI,CAAC,6BAAS,CAAC,KAAK,QAAQ,EACnC,mDAAmD,CACnD,CAAC;YACF,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,6BAAS,CAAC,CAAC,CAAC;YACtD,IA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,cAA6D,CAAC;IACvF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tTree,\n\tNodeKind,\n\ttype ImplicitAllowedTypes,\n\ttype TreeArrayNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\ttype SimpleNodeSchema,\n\tFieldKind,\n\tFieldSchema,\n\tnormalizeAllowedTypes,\n\ttype ImplicitFieldSchema,\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n\ttype IterableTreeArrayContent,\n} from \"@fluidframework/tree/internal\";\n\nimport {\n\ttype TreeEdit,\n\ttype ObjectTarget,\n\ttype Selection,\n\ttype Range,\n\ttype ObjectPlace,\n\ttype ArrayPlace,\n\ttype TreeEditObject,\n\ttype TreeEditValue,\n\ttypeField,\n} from \"./agentEditTypes.js\";\nimport type { IdGenerator } from \"./idGenerator.js\";\nimport type { JsonValue } from \"./jsonTypes.js\";\nimport { toDecoratedJson } from \"./promptGeneration.js\";\nimport { fail } from \"./utils.js\";\n\nfunction populateDefaults(\n\tjson: JsonValue,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n): void {\n\tif (typeof json === \"object\") {\n\t\tif (json === null) {\n\t\t\treturn;\n\t\t}\n\t\tif (Array.isArray(json)) {\n\t\t\tfor (const element of json) {\n\t\t\t\tpopulateDefaults(element, definitionMap);\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof json[typeField] === \"string\",\n\t\t\t\t\"The typeField must be present in new JSON content\",\n\t\t\t);\n\t\t\tconst nodeSchema = definitionMap.get(json[typeField]);\n\t\t\tassert(nodeSchema?.kind === NodeKind.Object, \"Expected object schema\");\n\t\t}\n\t}\n}\n\nfunction getSchemaIdentifier(content: TreeEditValue): string | undefined {\n\tswitch (typeof content) {\n\t\tcase \"boolean\": {\n\t\t\treturn booleanSchema.identifier;\n\t\t}\n\t\tcase \"number\": {\n\t\t\treturn numberSchema.identifier;\n\t\t}\n\t\tcase \"string\": {\n\t\t\treturn stringSchema.identifier;\n\t\t}\n\t\tcase \"object\": {\n\t\t\tif (content === null) {\n\t\t\t\treturn nullSchema.identifier;\n\t\t\t}\n\t\t\tif (Array.isArray(content)) {\n\t\t\t\tthrow new UsageError(\"Arrays are not currently supported in this context\");\n\t\t\t}\n\t\t\tif (isFluidHandle(content)) {\n\t\t\t\treturn handleSchema.identifier;\n\t\t\t}\n\t\t\treturn content[typeField];\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new UsageError(\"Unsupported content type\");\n\t\t}\n\t}\n}\n\nfunction contentWithIds(content: TreeNode, idGenerator: IdGenerator): TreeEditObject {\n\treturn JSON.parse(toDecoratedJson(idGenerator, content)) as TreeEditObject;\n}\n\n/**\n * Manages applying the various types of {@link TreeEdit}'s to a a given {@link TreeNode}.\n */\nexport function applyAgentEdit(\n\ttreeEdit: TreeEdit,\n\tidGenerator: IdGenerator,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tvalidator?: (edit: TreeNode) => void,\n): TreeEdit {\n\tassertObjectIdsExist(treeEdit, idGenerator);\n\tswitch (treeEdit.type) {\n\t\tcase \"insert\": {\n\t\t\tconst { array, index } = getPlaceInfo(treeEdit.destination, idGenerator);\n\n\t\t\tconst parentNodeSchema = Tree.schema(array);\n\t\t\tpopulateDefaults(treeEdit.content, definitionMap);\n\n\t\t\tconst schemaIdentifier = getSchemaIdentifier(treeEdit.content);\n\n\t\t\t// We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.\n\t\t\tconst allowedTypes = [\n\t\t\t\t...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),\n\t\t\t];\n\n\t\t\tfor (const allowedType of allowedTypes.values()) {\n\t\t\t\tif (allowedType.identifier === schemaIdentifier && typeof allowedType === \"function\") {\n\t\t\t\t\tconst simpleNodeSchema = allowedType as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\t\tconst insertNode = new simpleNodeSchema(treeEdit.content);\n\t\t\t\t\tvalidator?.(insertNode);\n\t\t\t\t\tarray.insertAt(index, insertNode as unknown as IterableTreeArrayContent<never>);\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tcontent: contentWithIds(insertNode, idGenerator),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tfail(\"inserted node must be of an allowed type\");\n\t\t}\n\t\tcase \"remove\": {\n\t\t\tconst source = treeEdit.source;\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst parentNode = Tree.parent(node);\n\t\t\t\t// Case for deleting rootNode\n\t\t\t\tif (parentNode === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"The root is required, and cannot be removed. Please use modify edit instead.\",\n\t\t\t\t\t);\n\t\t\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t\t\t(parentNode as TreeArrayNode).removeAt(nodeIndex);\n\t\t\t\t} else {\n\t\t\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t\t\tconst parentSchema = Tree.schema(parentNode);\n\t\t\t\t\tconst fieldSchema =\n\t\t\t\t\t\t(parentSchema.info as Record<string, ImplicitFieldSchema>)[fieldKey] ??\n\t\t\t\t\t\tfail(\"Expected field schema\");\n\t\t\t\t\tif (fieldSchema instanceof FieldSchema && fieldSchema.kind === FieldKind.Optional) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t(parentNode as any)[fieldKey] = undefined;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`${fieldKey} is required, and cannot be removed. Please use modify edit instead.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\t\t\tarray.removeRange(startIndex, endIndex);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tcase \"modify\": {\n\t\t\tconst node = getNodeFromTarget(treeEdit.target, idGenerator);\n\t\t\tconst { treeNodeSchema } = getSimpleNodeSchema(node);\n\n\t\t\tconst fieldSchema =\n\t\t\t\t(treeNodeSchema.info as Record<string, ImplicitFieldSchema>)[treeEdit.field] ??\n\t\t\t\tfail(\"Expected field schema\");\n\n\t\t\tconst modification = treeEdit.modification;\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst schemaIdentifier = (modification as any)[typeField];\n\n\t\t\tlet insertedObject: TreeNode | undefined;\n\t\t\t// if fieldSchema is a LeafnodeSchema, we can check that it's a valid type and set the field.\n\t\t\tif (isPrimitive(modification)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t}\n\t\t\t// If the fieldSchema is a function we can grab the constructor and make an instance of that node.\n\t\t\telse if (typeof fieldSchema === \"function\") {\n\t\t\t\tconst simpleSchema = fieldSchema as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\tpopulateDefaults(modification, definitionMap);\n\t\t\t\tconst constructedModification = new simpleSchema(modification);\n\t\t\t\tvalidator?.(constructedModification);\n\t\t\t\tinsertedObject = constructedModification;\n\n\t\t\t\tif (Array.isArray(modification)) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst field = (node as any)[treeEdit.field] as TreeArrayNode;\n\t\t\t\t\tassert(Array.isArray(field), \"the field must be an array node\");\n\t\t\t\t\tassert(\n\t\t\t\t\t\tArray.isArray(constructedModification),\n\t\t\t\t\t\t\"the modification must be an array node\",\n\t\t\t\t\t);\n\t\t\t\t\tfield.removeRange(0);\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t} else {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If the fieldSchema is of type FieldSchema, we can check its allowed types and set the field.\n\t\t\telse if (fieldSchema instanceof FieldSchema) {\n\t\t\t\tif (fieldSchema.kind === FieldKind.Optional && modification === undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tfor (const allowedType of fieldSchema.allowedTypeSet.values()) {\n\t\t\t\t\t\tif (allowedType.identifier === schemaIdentifier) {\n\t\t\t\t\t\t\tif (typeof allowedType === \"function\") {\n\t\t\t\t\t\t\t\tconst simpleSchema = allowedType as unknown as new (\n\t\t\t\t\t\t\t\t\tdummy: unknown,\n\t\t\t\t\t\t\t\t) => TreeNode;\n\t\t\t\t\t\t\t\tconst constructedObject = new simpleSchema(modification);\n\t\t\t\t\t\t\t\tinsertedObject = constructedObject;\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = constructedObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? treeEdit\n\t\t\t\t: {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t};\n\t\t}\n\t\tcase \"move\": {\n\t\t\t// TODO: need to add schema check for valid moves\n\t\t\tconst source = treeEdit.source;\n\t\t\tconst destination = treeEdit.destination;\n\t\t\tconst { array: destinationArrayNode, index: destinationIndex } = getPlaceInfo(\n\t\t\t\tdestination,\n\t\t\t\tidGenerator,\n\t\t\t);\n\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst sourceNode = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst sourceIndex = Tree.key(sourceNode) as number;\n\t\t\t\tconst sourceArrayNode = Tree.parent(sourceNode) as TreeArrayNode;\n\t\t\t\tconst sourceArraySchema = Tree.schema(sourceArrayNode);\n\t\t\t\tif (sourceArraySchema.kind !== NodeKind.Array) {\n\t\t\t\t\tthrow new UsageError(\"the source node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, \"node to move must exist\");\n\t\t\t\tif (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, \"node to move must exist\");\n\t\t\t\t\tif (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\nfunction isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {\n\tfor (const allowedType of allowedTypes) {\n\t\tif (Tree.is(node, allowedType)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\nfunction getRangeInfo(range: Range, idGenerator: IdGenerator): RangeInfo {\n\tconst { array: arrayFrom, index: startIndex } = getPlaceInfo(range.from, idGenerator);\n\tconst { array: arrayTo, index: endIndex } = getPlaceInfo(range.to, idGenerator);\n\n\tif (arrayFrom !== arrayTo) {\n\t\tthrow new UsageError(\n\t\t\t'The \"from\" node and \"to\" nodes of the range must be in the same parent array.',\n\t\t);\n\t}\n\n\treturn { array: arrayFrom, startIndex, endIndex };\n}\n\nfunction getPlaceInfo(\n\tplace: ObjectPlace | ArrayPlace,\n\tidGenerator: IdGenerator,\n): {\n\tarray: TreeArrayNode;\n\tindex: number;\n} {\n\tif (place.type === \"arrayPlace\") {\n\t\tconst parent = idGenerator.getNode(place.parentId) ?? fail(\"Expected parent node\");\n\t\tconst child = (parent as unknown as Record<string, unknown>)[place.field];\n\t\tif (child === undefined) {\n\t\t\tthrow new UsageError(`No child under field field`);\n\t\t}\n\t\tconst schema = Tree.schema(child as TreeNode);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: child as TreeArrayNode,\n\t\t\tindex: place.location === \"start\" ? 0 : (child as TreeArrayNode).length,\n\t\t};\n\t} else {\n\t\tconst node = getNodeFromTarget(place, idGenerator);\n\t\tconst nodeIndex = Tree.key(node);\n\t\tconst parent = Tree.parent(node);\n\t\tif (parent === undefined) {\n\t\t\tthrow new UsageError(\"TODO: root node target not supported\");\n\t\t}\n\t\tconst schema = Tree.schema(parent);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: parent as unknown as TreeArrayNode,\n\t\t\tindex: place.place === \"before\" ? (nodeIndex as number) : (nodeIndex as number) + 1,\n\t\t};\n\t}\n}\n\n/**\n * Returns the target node with the matching internal objectId using the provided {@link ObjectTarget}\n */\nfunction getNodeFromTarget(target: ObjectTarget, idGenerator: IdGenerator): TreeNode {\n\tconst node = idGenerator.getNode(target.target);\n\tassert(node !== undefined, \"objectId does not exist in nodeMap\");\n\treturn node;\n}\n\n/**\n * Checks that the objectIds of the Tree Nodes within the givin the {@link TreeEdit} exist within the given {@link IdGenerator}\n *\n * @throws An {@link UsageError} if the objectIdKey does not exist in the {@link IdGenerator}\n */\nfunction assertObjectIdsExist(treeEdit: TreeEdit, idGenerator: IdGenerator): void {\n\tswitch (treeEdit.type) {\n\t\tcase \"insert\": {\n\t\t\tif (treeEdit.destination.type === \"objectPlace\") {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.target) === undefined) {\n\t\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.destination.target} does not exist`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.parentId) === undefined) {\n\t\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.destination.parentId} does not exist`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"remove\": {\n\t\t\tif (isRange(treeEdit.source)) {\n\t\t\t\tconst missingObjectIds = [\n\t\t\t\t\ttreeEdit.source.from.target,\n\t\t\t\t\ttreeEdit.source.to.target,\n\t\t\t\t].filter((id) => !idGenerator.getNode(id));\n\n\t\t\t\tif (missingObjectIds.length > 0) {\n\t\t\t\t\tthrow new UsageError(`objectIdKeys [${missingObjectIds}] does not exist`);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisObjectTarget(treeEdit.source) &&\n\t\t\t\tidGenerator.getNode(treeEdit.source.target) === undefined\n\t\t\t) {\n\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.source.target} does not exist`);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"modify\": {\n\t\t\tif (idGenerator.getNode(treeEdit.target.target) === undefined) {\n\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.target.target} does not exist`);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"move\": {\n\t\t\tconst invalidObjectIds: string[] = [];\n\t\t\t// check the source\n\t\t\tif (isRange(treeEdit.source)) {\n\t\t\t\tconst missingObjectIds = [\n\t\t\t\t\ttreeEdit.source.from.target,\n\t\t\t\t\ttreeEdit.source.to.target,\n\t\t\t\t].filter((id) => !idGenerator.getNode(id));\n\n\t\t\t\tif (missingObjectIds.length > 0) {\n\t\t\t\t\tinvalidObjectIds.push(...missingObjectIds);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisObjectTarget(treeEdit.source) &&\n\t\t\t\tidGenerator.getNode(treeEdit.source.target) === undefined\n\t\t\t) {\n\t\t\t\tinvalidObjectIds.push(treeEdit.source.target);\n\t\t\t}\n\n\t\t\t// check the destination\n\t\t\tif (treeEdit.destination.type === \"objectPlace\") {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.target) === undefined) {\n\t\t\t\t\tinvalidObjectIds.push(treeEdit.destination.target);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.parentId) === undefined) {\n\t\t\t\t\tinvalidObjectIds.push(treeEdit.destination.parentId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (invalidObjectIds.length > 0) {\n\t\t\t\tthrow new UsageError(`objectIdKeys [${invalidObjectIds}] does not exist`);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\ninterface SchemaInfo {\n\ttreeNodeSchema: TreeNodeSchema;\n\tsimpleNodeSchema: new (dummy: unknown) => TreeNode;\n}\n\nfunction getSimpleNodeSchema(node: TreeNode): SchemaInfo {\n\tconst treeNodeSchema = Tree.schema(node);\n\tconst simpleNodeSchema = treeNodeSchema as unknown as new (dummy: unknown) => TreeNode;\n\treturn { treeNodeSchema, simpleNodeSchema };\n}\n"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonPrimitive } from "./jsonTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* TODO: The current scheme does not allow manipulation of arrays of primitive values because you cannot refer to them.
|
|
8
|
+
* We could accomplish this via a path (probably JSON Pointer or JSONPath) from a possibly-null objectId, or wrap arrays in an identified object.
|
|
9
|
+
*
|
|
10
|
+
* TODO: 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.
|
|
11
|
+
*
|
|
12
|
+
* TODO: experiment using https://github.com/outlines-dev/outlines (and maybe a llama model) to avoid many of the annoyances of OpenAI's JSON Schema subset.
|
|
13
|
+
*
|
|
14
|
+
* TODO: without field count limits, we could generate a schema for valid paths from the root object to any field, but it's not clear how useful that would be.
|
|
15
|
+
*
|
|
16
|
+
* TODO: We don't supported nested arrays yet.
|
|
17
|
+
*
|
|
18
|
+
* TODO: Add a prompt suggestion API!
|
|
19
|
+
*
|
|
20
|
+
* TODO: Could encourage the model to output more technical explanations of the edits (e.g. "insert a new Foo after "Foo2").
|
|
21
|
+
*
|
|
22
|
+
* TODO: Get explanation strings from o1.
|
|
23
|
+
*
|
|
24
|
+
* TODO: Tests of range edits.
|
|
25
|
+
*
|
|
26
|
+
* TODO: Handle 429 rate limit error from OpenAI.
|
|
27
|
+
*
|
|
28
|
+
* TODO: Add an app-specific guidance string.
|
|
29
|
+
*
|
|
30
|
+
* TODO: Give the model a final chance to evaluate the result.
|
|
31
|
+
*
|
|
32
|
+
* TODO: Separate system prompt into [system, user, system] for security.
|
|
33
|
+
*
|
|
34
|
+
* TODO: Top level arrays are not supported with current DSL.
|
|
35
|
+
*
|
|
36
|
+
* TODO: Structured Output fails when multiple schema types have the same first field name (e.g. id: sf.identifier on multiple types).
|
|
37
|
+
*
|
|
38
|
+
* TODO: Pass descriptions from schema metadata to the generated TS types that we put in the prompt
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* This is the field we force the LLM to generate to avoid any type ambiguity (e.g. a vector and a point both have x/y and are ambiguous without the LLM telling us which it means).
|
|
42
|
+
*/
|
|
43
|
+
export declare const typeField = "__fluid_type";
|
|
44
|
+
/**
|
|
45
|
+
* A field that is auto-generated and injected into nodes before passing data to the LLM to ensure the LLM can refer to nodes in a stable way.
|
|
46
|
+
*/
|
|
47
|
+
export declare const objectIdKey = "__fluid_objectId";
|
|
48
|
+
/**
|
|
49
|
+
* Describes an edit to a field within a node.
|
|
50
|
+
* @remarks TODO: what is the [key: string] for?
|
|
51
|
+
*/
|
|
52
|
+
export interface TreeEditObject {
|
|
53
|
+
[key: string]: TreeEditValue;
|
|
54
|
+
[typeField]: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* An array of {@link TreeEditValue}'s, allowing a single {@link TreeEdit} to contain edits to multiple fields.
|
|
58
|
+
*/
|
|
59
|
+
export type TreeEditArray = TreeEditValue[];
|
|
60
|
+
/**
|
|
61
|
+
* The potential values for a given {@link TreeEdit}.
|
|
62
|
+
* @remarks These values are typically a field within a node or an entire node,
|
|
63
|
+
*/
|
|
64
|
+
export type TreeEditValue = JsonPrimitive | TreeEditObject | TreeEditArray;
|
|
65
|
+
/**
|
|
66
|
+
* This is the the final object we expected from an LLM response.
|
|
67
|
+
* @remarks Because TreeEdit can be multiple different types (polymorphic),
|
|
68
|
+
* we need to wrap to avoid anyOf at the root level when generating the necessary JSON Schema.
|
|
69
|
+
*/
|
|
70
|
+
export interface EditWrapper {
|
|
71
|
+
edit: TreeEdit | null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Union type representing all possible types of edits that can be made to a tree.
|
|
75
|
+
*/
|
|
76
|
+
export type TreeEdit = Insert | Modify | Remove | Move;
|
|
77
|
+
/**
|
|
78
|
+
* The base interface for all types of {@link TreeEdit}.
|
|
79
|
+
*/
|
|
80
|
+
export interface Edit {
|
|
81
|
+
explanation: string;
|
|
82
|
+
type: "insert" | "modify" | "remove" | "move";
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* This object provides a way to 'select' either a given node or a range of nodes in an array.
|
|
86
|
+
*/
|
|
87
|
+
export type Selection = ObjectTarget | Range;
|
|
88
|
+
/**
|
|
89
|
+
* A Target object for an {@link TreeEdit}, identified by the target object's Id
|
|
90
|
+
*/
|
|
91
|
+
export interface ObjectTarget {
|
|
92
|
+
target: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Desribes where an object can be inserted into an array.
|
|
96
|
+
* For example, if you have an array with 5 objects, and you insert an object at index 3, this differentiates whether you want
|
|
97
|
+
* the existing item at index 3 to be shifted forward (if the 'location' is 'start') or shifted backwards (if the 'location' is 'end')
|
|
98
|
+
*
|
|
99
|
+
* @remarks TODO: Allow support for nested arrays
|
|
100
|
+
*/
|
|
101
|
+
export interface ArrayPlace {
|
|
102
|
+
type: "arrayPlace";
|
|
103
|
+
parentId: string;
|
|
104
|
+
field: string;
|
|
105
|
+
location: "start" | "end";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Desribes where an object can be inserted into an array.
|
|
109
|
+
* For example, if you have an array with 5 objects, and you insert an object at index 3, this differentiates whether you want
|
|
110
|
+
* the existing item at index 3 to be shifted forward (if the 'location' is 'start') or shifted backwards (if the 'location' is 'end')
|
|
111
|
+
*
|
|
112
|
+
* @remarks Why does this and {@link ArrayPlace} exist together?
|
|
113
|
+
*/
|
|
114
|
+
export interface ObjectPlace extends ObjectTarget {
|
|
115
|
+
type: "objectPlace";
|
|
116
|
+
place: "before" | "after";
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A range of objects within an array. This allows the LLM to select multiple nodes at once,
|
|
120
|
+
* for example during an {@link Remove} operation to remove a range of nodes.
|
|
121
|
+
*/
|
|
122
|
+
export interface Range {
|
|
123
|
+
from: ObjectPlace;
|
|
124
|
+
to: ObjectPlace;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Describes an operation to insert a new node into the tree.
|
|
128
|
+
*/
|
|
129
|
+
export interface Insert extends Edit {
|
|
130
|
+
type: "insert";
|
|
131
|
+
content: TreeEditObject | JsonPrimitive;
|
|
132
|
+
destination: ObjectPlace | ArrayPlace;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Describes an operation to modify an existing node in the tree.
|
|
136
|
+
*/
|
|
137
|
+
export interface Modify extends Edit {
|
|
138
|
+
type: "modify";
|
|
139
|
+
target: ObjectTarget;
|
|
140
|
+
field: string;
|
|
141
|
+
modification: TreeEditValue;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Describes an operation to remove either a specific node or a range of nodes in an array.
|
|
145
|
+
*/
|
|
146
|
+
export interface Remove extends Edit {
|
|
147
|
+
type: "remove";
|
|
148
|
+
source: Selection;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Describes an operation to move a node within an array
|
|
152
|
+
*/
|
|
153
|
+
export interface Move extends Edit {
|
|
154
|
+
type: "move";
|
|
155
|
+
source: Selection;
|
|
156
|
+
destination: ObjectPlace | ArrayPlace;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=agentEditTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentEditTypes.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG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