@fluidframework/ai-collab 2.72.0 → 2.74.0-365691
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/CHANGELOG.md +4 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -1
- package/dist/explicit-strategy/agentEditReducer.js +2 -1
- package/dist/explicit-strategy/agentEditReducer.js.map +1 -1
- package/dist/explicit-strategy/promptGeneration.js +1 -1
- package/dist/explicit-strategy/promptGeneration.js.map +1 -1
- package/dist/implicit-strategy/sharedTreeDiff.js +1 -1
- package/dist/implicit-strategy/sharedTreeDiff.js.map +1 -1
- package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -1
- package/lib/explicit-strategy/agentEditReducer.js +2 -1
- package/lib/explicit-strategy/agentEditReducer.js.map +1 -1
- package/lib/explicit-strategy/promptGeneration.js +1 -1
- package/lib/explicit-strategy/promptGeneration.js.map +1 -1
- package/lib/implicit-strategy/sharedTreeDiff.js +1 -1
- package/lib/implicit-strategy/sharedTreeDiff.js.map +1 -1
- package/package.json +10 -10
- package/src/explicit-strategy/agentEditReducer.ts +3 -2
- package/src/explicit-strategy/promptGeneration.ts +1 -1
- package/src/implicit-strategy/sharedTreeDiff.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedTreeDiff.js","sourceRoot":"","sources":["../../src/implicit-strategy/sharedTreeDiff.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+CAAoE;AAEpE,yCAA+D;AAwF/D,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAE3E;;;GAGG;AACH,MAAM,eAAe,GAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAErD;;;;GAIG;AACH,SAAgB,cAAc,CAC7B,GAAwC,EACxC,MAA2C,EAC3C,UAAmB,e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IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,+EAA+E;YAC/E,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACP,cAAc,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QAClC,CAAC;IACF,CAAC;IAED,eAAe,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;IAExC,OAAO,eAAe,CAAC;AACxB,CAAC;AAlBD,4DAkBC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,IAAgB;IAC1C,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAgB;IAC7C,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,CAAC;AAC5D,CAAC;AAFD,sCAEC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAC/B,IAAgB,EAChB,MAA+C;IAE/C,IAAI,YAAY,GAAY,MAAM,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,YAAY,GAAG,IAAA,6BAAkB,EAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type TreeArrayNode, NodeKind } from \"@fluidframework/tree\";\n\nimport { isTreeMapNode, sharedTreeTraverse } from \"./utils.js\";\n\n/**\n * Represents a path through a tree of objects.\n * number values represent array indices whereas string values represent object keys.\n *\n * @alpha\n */\nexport type ObjectPath = (string | number)[];\n\n/**\n * Represents a create operation between two branches of a tree.\n * Meaning that an attribute (a shared tree node) was identified as being created.\n *\n * @alpha\n */\nexport interface DifferenceCreate {\n\ttype: \"CREATE\";\n\tpath: ObjectPath;\n\tvalue: unknown;\n}\n\n/**\n * Represents a remove operation between two branches of a tree.\n * Meaning that an attribute (a shared tree node) was identified as being deleted.\n * When using object ids, removes are idenitified by an object with a given id no longer existing.\n *\n * @alpha\n */\nexport interface DifferenceRemove {\n\ttype: \"REMOVE\";\n\tpath: ObjectPath;\n\toldValue: unknown;\n\tobjectId?: string | number | undefined;\n}\n\n/**\n * Represents a change operation between two branches of a tree.\n * Meaning that an attribute (a shared tree node) was identified as being changed from one value to another.\n *\n * @alpha\n */\nexport interface DifferenceChange {\n\ttype: \"CHANGE\";\n\tpath: ObjectPath;\n\tvalue: unknown;\n\toldValue: unknown;\n\tobjectId?: string | number | undefined;\n}\n\n/**\n * Represents a move operation between two branches of a tree.\n * Meaning that an object (shared tree node) was identified as being moved from one index to another based on its unique id.\n *\n * @alpha\n */\nexport interface DifferenceMove {\n\ttype: \"MOVE\";\n\tpath: ObjectPath;\n\tnewIndex: number;\n\tvalue: unknown;\n\tobjectId?: string | number | undefined;\n}\n\n/**\n * Union for all possible difference types.\n *\n * @alpha\n */\nexport type Difference =\n\t| DifferenceCreate\n\t| DifferenceRemove\n\t| DifferenceChange\n\t| DifferenceMove;\n\n/**\n * Options for tree diffing.\n * @alpha\n */\nexport interface Options {\n\tcyclesFix: boolean;\n\tuseObjectIds?:\n\t\t| {\n\t\t\t\tidAttributeName: string;\n\t\t }\n\t\t| undefined;\n}\n\nconst richTypes = { Date: true, RegExp: true, String: true, Number: true };\n\n/**\n * By default, Object Diff supports cyclical references, but if you are sure that the object has no cycles like parsed JSON\n * you can disable cycles by setting the cyclesFix option to false\n */\nconst DEFAULT_OPTIONS: Options = { cyclesFix: true };\n\n/**\n * Compares two objects and returns an array of differences between them.\n *\n * @alpha\n */\nexport function sharedTreeDiff(\n\tobj: Record<string, unknown> | unknown[],\n\tnewObj: Record<string, unknown> | unknown[],\n\toptions: Options = DEFAULT_OPTIONS,\n\t_stack: (Record<string, unknown> | unknown[])[] = [],\n): Difference[] {\n\tconst diffs: Difference[] = [];\n\tconst isObjArray = isArrayOrTreeArrayNode(obj);\n\tconst isNewObjArray = isArrayOrTreeArrayNode(newObj);\n\n\t// If useObjectIds is set, we'll create a map of object ids to their index in the array.\n\tconst oldObjArrayItemIdsToIndex =\n\t\tisObjArray === false || options.useObjectIds === undefined\n\t\t\t? new Map<string | number, number>()\n\t\t\t: createObjectArrayItemIdsToIndexMap(obj, options.useObjectIds.idAttributeName);\n\n\tconst newObjArrayItemIdsToIndex =\n\t\tisNewObjArray === false || options.useObjectIds === undefined\n\t\t\t? new Map<string | number, number>()\n\t\t\t: createObjectArrayItemIdsToIndexMap(newObj, options.useObjectIds.idAttributeName);\n\n\tconst objectKeys = isTreeMapNode(obj) ? obj.keys() : Object.keys(obj);\n\t// We compare existence and values of all attributes within the old against new object, looking for removals or changes.\n\tfor (const key of objectKeys) {\n\t\tconst objValue: unknown = isTreeMapNode(obj) ? obj.get(key as string) : obj[key];\n\t\tconst path = isObjArray ? +key : key;\n\t\t// 1. First, check if the key within the old object, exists within the new object. If it doesn't exist this would be an attribute removal.\n\t\tif (!(key in newObj)) {\n\t\t\tif (options.useObjectIds === undefined) {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tobjectId: undefined,\n\t\t\t\t\toldValue: objValue,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// If we're dealing with an object in an array, we can use the object's id to check if it was moved to a new index.\n\t\t\telse if (\n\t\t\t\tisNewObjArray === true &&\n\t\t\t\tisObjArray &&\n\t\t\t\ttypeof objValue === \"object\" &&\n\t\t\t\tobjValue !== null\n\t\t\t) {\n\t\t\t\tconst objectId = objValue[options.useObjectIds.idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number\n\t\t\t\t\t| undefined;\n\t\t\t\tif (objectId !== undefined && newObjArrayItemIdsToIndex.has(objectId)) {\n\t\t\t\t\t// The index no longer exists in the new root object array, however the object that lived at this index actually still exists at a new index.\n\t\t\t\t\t// Therefore, this node was moved to a new index.\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"MOVE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tnewIndex: newObjArrayItemIdsToIndex.get(objectId) as number,\n\t\t\t\t\t\tvalue: objValue,\n\t\t\t\t\t\tobjectId,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// The object with the given id cannot be found within the new array, therefore it was removed.\n\t\t\t\telse {\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tobjectId,\n\t\t\t\t\t\toldValue: objValue,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If we're not dealing with an object in an array, we can't use id's to check for a move.\n\t\t\t// We'll assume that a missing key in the new object means that the cooresponding value was removed.\n\t\t\telse {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tobjectId: undefined,\n\t\t\t\t\toldValue: objValue,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tconst newObjValue: unknown = newObj[key];\n\t\tconst areCompatibleObjects =\n\t\t\ttypeof objValue === \"object\" &&\n\t\t\ttypeof newObjValue === \"object\" &&\n\t\t\tisArrayOrTreeArrayNode(objValue) === isArrayOrTreeArrayNode(newObjValue);\n\n\t\t// 2a. If the given old object key exists in the new object, and the value of said key in both objects is ANOTHER nested object, we need to run a recursive diff check on them.\n\t\tif (\n\t\t\tobjValue !== null &&\n\t\t\tnewObjValue !== null &&\n\t\t\tareCompatibleObjects &&\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unsafe-member-access\n\t\t\t!richTypes[Object.getPrototypeOf(objValue)?.constructor?.name] &&\n\t\t\t(!options.cyclesFix || !_stack.includes(objValue as Record<string, unknown>))\n\t\t) {\n\t\t\tif (options.useObjectIds === undefined) {\n\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\tobjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\tnewObjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\toptions,\n\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t: [],\n\t\t\t\t);\n\t\t\t\t// eslint-disable-next-line prefer-spread\n\t\t\t\tdiffs.push.apply(\n\t\t\t\t\tdiffs,\n\t\t\t\t\tnestedDiffs.map((difference) => {\n\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\treturn difference;\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Use Object Id strategy to determine if the objects should be compared for changes\n\t\t\telse {\n\t\t\t\tconst oldObjectId = (objValue as Record<string, unknown>)[\n\t\t\t\t\toptions.useObjectIds.idAttributeName\n\t\t\t\t] as string | number | undefined;\n\t\t\t\tconst newObjectId = (newObjValue as Record<string, unknown>)[\n\t\t\t\t\toptions.useObjectIds.idAttributeName\n\t\t\t\t] as string | number | undefined;\n\n\t\t\t\tif (oldObjectId !== undefined && newObjectId !== undefined) {\n\t\t\t\t\t// 2a.1 if the object id's are the same, we can continue a comparison between the two objects.\n\t\t\t\t\tif (oldObjectId === newObjectId) {\n\t\t\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\t\t\tobjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\tnewObjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdiffs.push(\n\t\t\t\t\t\t\t...nestedDiffs.map((difference) => {\n\t\t\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\t\t\treturn difference;\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\t// 2a.2 The object id's are different, their attributes cannot be compared.\n\t\t\t\t\t// We need to find the new index of the object, if it exists in the new array and do a diff comparison.\n\t\t\t\t\telse {\n\t\t\t\t\t\tconst newIndexOfOldObject = newObjArrayItemIdsToIndex.get(oldObjectId);\n\t\t\t\t\t\t// The object no longer exists in the new array, therefore it was removed.\n\t\t\t\t\t\tif (newIndexOfOldObject === undefined) {\n\t\t\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\t\t\toldValue: objValue,\n\t\t\t\t\t\t\t\tobjectId: oldObjectId,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// This object still exists but at a new index within the new array therefore it was moved.\n\t\t\t\t\t\t// At this point we can determine whether a new move is necessary or there is one that will place it at the desired index.\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\t\t\ttype: \"MOVE\",\n\t\t\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\t\t\tnewIndex: newIndexOfOldObject,\n\t\t\t\t\t\t\t\tvalue: objValue,\n\t\t\t\t\t\t\t\tobjectId: oldObjectId,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// An object could have been moved AND changed. We need to check for this.\n\t\t\t\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\t\t\t\tobj[path] as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\t\tnewObj[newIndexOfOldObject] as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tdiffs.push(\n\t\t\t\t\t\t\t\t...nestedDiffs.map((difference) => {\n\t\t\t\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\t\t\t\treturn difference;\n\t\t\t\t\t\t\t\t}),\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} else {\n\t\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\t\tobjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\tnewObjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t\t: [],\n\t\t\t\t\t);\n\t\t\t\t\tdiffs.push(\n\t\t\t\t\t\t...nestedDiffs.map((difference) => {\n\t\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\t\treturn difference;\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}\n\t\t// 2b. If the given old object key exists in the new object, and the value of said key in both objects is NOT another nested object, we need to check if the values are the same.\n\t\telse if (\n\t\t\tobjValue !== newObjValue &&\n\t\t\t// treat NaN values as equivalent\n\t\t\t!(Number.isNaN(objValue) && Number.isNaN(newObjValue)) &&\n\t\t\t!(\n\t\t\t\tareCompatibleObjects &&\n\t\t\t\t(Number.isNaN(objValue)\n\t\t\t\t\t? // eslint-disable-next-line prefer-template\n\t\t\t\t\t\tobjValue + \"\" === newObjValue + \"\"\n\t\t\t\t\t: // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t+objValue === +newObjValue)\n\t\t\t)\n\t\t) {\n\t\t\tdiffs.push({\n\t\t\t\tpath: [path],\n\t\t\t\ttype: \"CHANGE\",\n\t\t\t\tvalue: newObjValue,\n\t\t\t\toldValue: objValue,\n\t\t\t\tobjectId:\n\t\t\t\t\toptions.useObjectIds?.idAttributeName === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: (newObj[options.useObjectIds.idAttributeName] as string | number | undefined),\n\t\t\t});\n\t\t}\n\t}\n\n\t// 3. Finally, we check for new keys in the new object that did not exist in the old object.\n\t// The existence of new keys may signal new values or moved values.\n\tconst newObjKeys = isTreeMapNode(newObj) ? newObj.keys() : Object.keys(newObj);\n\tfor (const key of newObjKeys) {\n\t\tconst newObjValue: unknown = isTreeMapNode(newObj)\n\t\t\t? newObj.get(key as string)\n\t\t\t: newObj[key];\n\t\tconst path = isNewObjArray ? +key : key;\n\n\t\tconst isKeyInOldObject = isTreeMapNode(obj)\n\t\t\t? obj.has(key as string)\n\t\t\t: Object.keys(obj).includes(key as string);\n\t\tif (!isKeyInOldObject) {\n\t\t\tif (options.useObjectIds === undefined) {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t});\n\t\t\t}\n\t\t\t// If we're dealing with an object in an array, we can use the object's id to check if this new index actually\n\t\t\t// contains a prexisting object that was moved from an old index.\n\t\t\telse if (\n\t\t\t\tisObjArray === true &&\n\t\t\t\tisNewObjArray === true &&\n\t\t\t\ttypeof newObjValue === \"object\" &&\n\t\t\t\tnewObjValue !== null\n\t\t\t) {\n\t\t\t\tconst objectId = newObjValue[options.useObjectIds.idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number\n\t\t\t\t\t| undefined;\n\t\t\t\tif (objectId !== undefined && oldObjArrayItemIdsToIndex.has(objectId)) {\n\t\t\t\t\t// The new root object array contains a new index, however the object that lives at this new index previously existed at an old index.\n\t\t\t\t\t// Therefore, this object was moved to a new index.\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"MOVE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tnewIndex: newObjArrayItemIdsToIndex.get(objectId) as number,\n\t\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t\t\tobjectId,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// If either the object's id attribute does not exist or the original array does not contain an object with the given id\n\t\t\t\t// Then we assume this was a newly created object.\n\t\t\t\telse {\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If we're not dealing with an object in an array, we can't use id's to check for a move.\n\t\t\t// We'll assume that a brand new key and value pair in the new object means that a new value was created.\n\t\t\telse {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (options.useObjectIds !== undefined) {\n\t\t\t// If we're dealing with an object in an array, we can use the object's id to check if this EXISTING index\n\t\t\t// houses a new object based on a newly encountered id.\n\t\t\tif (\n\t\t\t\tisObjArray === true &&\n\t\t\t\tisNewObjArray === true &&\n\t\t\t\ttypeof newObjValue === \"object\" &&\n\t\t\t\tnewObjValue !== null\n\t\t\t) {\n\t\t\t\tconst objectId = newObjValue[options.useObjectIds.idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number\n\t\t\t\t\t| undefined;\n\t\t\t\t// If this object has an id and it does not exist in the old array, then it was created.\n\t\t\t\tif (objectId !== undefined && oldObjArrayItemIdsToIndex.has(objectId) === false) {\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t}\n\treturn diffs;\n}\n\n/**\n * Type Guard that determines if a given object is an array of type unknown[] or {@link TreeArrayNode}.\n */\nfunction isArrayOrTreeArrayNode(obj: unknown): obj is unknown[] | TreeArrayNode {\n\tif (typeof obj === \"object\" && obj !== null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\tconst maybeNodeKind: unknown = Object.getPrototypeOf(obj)?.constructor?.kind;\n\t\tconst isTreeArrayNode = maybeNodeKind === NodeKind.Array;\n\t\treturn Array.isArray(obj) || isTreeArrayNode;\n\t}\n\treturn false;\n}\n\n/**\n * Helper that creates a map of object ids to their index in an array of objects.\n */\nfunction createObjectArrayItemIdsToIndexMap(\n\tobj: unknown[],\n\tidAttributeName: string | number,\n): Map<string | number, number> {\n\tconst objArrayItemIdsToIndex = new Map<string | number, number>();\n\tfor (let i = 0; i < obj.length; i++) {\n\t\tconst objArrayItem = obj[i];\n\t\tif (typeof objArrayItem === \"object\" && objArrayItem !== null) {\n\t\t\tconst id = (objArrayItem as Record<string, unknown>)[idAttributeName] as string | number;\n\t\t\tif (objArrayItemIdsToIndex.has(id)) {\n\t\t\t\tthrow new TypeError(`Duplicate object id found: ${id}`);\n\t\t\t} else if (id !== undefined) {\n\t\t\t\tobjArrayItemIdsToIndex.set(id, i);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn objArrayItemIdsToIndex;\n}\n\n/**\n * Creates a set of mergeable diffs from a series of diffs produced by {@link sharedTreeDiff}\n * that are using the object ID strategy. These diffs don't need any modifications to be applied to the old object.\n *\n * @alpha\n */\nexport function createMergableIdDiffSeries(\n\toldObject: unknown,\n\tdiffs: Difference[],\n\tidAttributeName: string | number,\n): Difference[] {\n\t// the final series of diffs that will be returned.\n\tconst finalDiffSeries: Difference[] = [];\n\t// Diffs that aren't of type 'CHANGE'\n\tconst nonChangeDiffs: Difference[] = [];\n\n\tfor (const diff of diffs) {\n\t\tif (diff.type === \"CHANGE\") {\n\t\t\t// Changes must be applied before any other diff, ao so they are ordered first.\n\t\t\tfinalDiffSeries.push({ ...diff });\n\t\t} else {\n\t\t\tnonChangeDiffs.push({ ...diff });\n\t\t}\n\t}\n\n\t// Create sets of array diffs grouped by the array they are applying changes to.\n\tconst diffsByArrayUuid = new Map<string, Difference[]>();\n\tfor (const diff of nonChangeDiffs) {\n\t\tif (!isDiffOnArray(diff)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst arrayUuid = arrayUuidFromPath(diff.path);\n\n\t\tif (diffsByArrayUuid.has(arrayUuid) === false) {\n\t\t\tdiffsByArrayUuid.set(arrayUuid, []);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tdiffsByArrayUuid.get(arrayUuid)!.push(diff);\n\t}\n\n\tconst shiftIndexesFromMove = (\n\t\tdiff: DifferenceMove,\n\t\ttargetArray: unknown[],\n\t\tdiffAdjustedObjectIndexes: Map<string | number, number>,\n\t\tobjectId: string | number,\n\t): void => {\n\t\tconst sourceIndex = diff.path[diff.path.length - 1] as number;\n\n\t\tif (diff.newIndex > sourceIndex) {\n\t\t\t// This move diff shifts objects it moved over to the left.\n\t\t\t// |----| |----|\n\t\t\t// e.g. - shift with no length change: [{1}, {2}, {3}, {4}] -> [{2}, {3}, {1}, {4}]\n\t\t\tconst minIndex = sourceIndex;\n\t\t\tconst maxIndex = diff.newIndex;\n\t\t\tfor (const [id, index] of diffAdjustedObjectIndexes.entries()) {\n\t\t\t\tconst shouldIndexBeShifted =\n\t\t\t\t\tid !== objectId && index <= maxIndex && index >= minIndex && index - 1 >= 0;\n\t\t\t\tif (shouldIndexBeShifted) {\n\t\t\t\t\tdiffAdjustedObjectIndexes.set(id, index - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (diff.newIndex < sourceIndex) {\n\t\t\t// This move diff shifts objects it moved over to the right.\n\t\t\t// |----| |----|\n\t\t\t// e.g. - shift with no length change: [{1}, {2}, {3}, {4}] -> [{3}, {1}, {2}, {4}]\n\t\t\tconst minIndex = diff.newIndex;\n\t\t\tconst maxIndex = sourceIndex;\n\t\t\tfor (const [id, index] of diffAdjustedObjectIndexes.entries()) {\n\t\t\t\tconst shouldIndexBeShifted =\n\t\t\t\t\tid !== objectId &&\n\t\t\t\t\tindex <= maxIndex &&\n\t\t\t\t\tindex >= minIndex &&\n\t\t\t\t\tindex + 1 <= targetArray.length;\n\t\t\t\tif (shouldIndexBeShifted) {\n\t\t\t\t\tdiffAdjustedObjectIndexes.set(id, index + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\tconst shiftIndexesFromRemove = (\n\t\tdiff: DifferenceRemove,\n\t\tdiffAdjustedObjectIndexes: Map<string | number, number>,\n\t\tobjectId: string | number,\n\t): void => {\n\t\tconst removalIndex = diff.path[diff.path.length - 1] as number;\n\t\tfor (const [id, index] of diffAdjustedObjectIndexes.entries()) {\n\t\t\tconst shouldIndexBeShifted = id !== objectId && index > removalIndex && index - 1 >= 0;\n\t\t\tif (shouldIndexBeShifted) {\n\t\t\t\tdiffAdjustedObjectIndexes.set(id, index - 1);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst diffsMarkedForRemoval = new Set<Difference>();\n\tconst arrayDiffsMarkedForEndReorder = new Map<string, Difference[]>();\n\n\tfor (const [arrayUuid, arrayDiffs] of diffsByArrayUuid.entries()) {\n\t\t// The prior grouping code ensures that each map value will have atleast 1 diff.\n\t\tconst targetArray = getTargetObjectFromPath(\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tarrayDiffs[0]!.path,\n\t\t\toldObject as TreeArrayNode,\n\t\t) as unknown[];\n\t\tconst diffAdjustedObjectIndexes: Map<string | number, number> =\n\t\t\tcreateObjectArrayItemIdsToIndexMap(targetArray, idAttributeName);\n\n\t\tfor (const diff of arrayDiffs) {\n\t\t\tif (diff.type === \"MOVE\") {\n\t\t\t\tconst objectId = (diff.value as Record<string, unknown>)[idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number;\n\t\t\t\tconst sourceIndex = diff.path[diff.path.length - 1] as number;\n\n\t\t\t\t// 1. Prior moves may render the next move redundant.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst currentAdjustedIndex = diffAdjustedObjectIndexes.get(objectId)!;\n\t\t\t\tif (currentAdjustedIndex === diff.newIndex) {\n\t\t\t\t\tdiffsMarkedForRemoval.add(diff);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (currentAdjustedIndex !== sourceIndex) {\n\t\t\t\t\t// A Prior Remove or Move Diff moved the object to a new index, so update the diff source index to point to the new index.\n\t\t\t\t\tdiff.path[diff.path.length - 1] = currentAdjustedIndex;\n\t\t\t\t}\n\n\t\t\t\t// Handle index shifts\n\t\t\t\tdiffAdjustedObjectIndexes.set(objectId, diff.newIndex);\n\n\t\t\t\t// edge case: this MOVE should be applied after some series of creates that we haven't seen.\n\t\t\t\tif (diff.newIndex > targetArray.length - 1) {\n\t\t\t\t\t// It also wont shift any indexes since its moved to the total end of the array,\n\t\t\t\t\t// after creations that produce the necessary indexes.\n\t\t\t\t\tif (arrayDiffsMarkedForEndReorder.has(arrayUuid) === false) {\n\t\t\t\t\t\tarrayDiffsMarkedForEndReorder.set(arrayUuid, []);\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tarrayDiffsMarkedForEndReorder.get(arrayUuid)!.push(diff);\n\t\t\t\t} else {\n\t\t\t\t\tshiftIndexesFromMove(diff, targetArray, diffAdjustedObjectIndexes, objectId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (diff.type === \"REMOVE\") {\n\t\t\t\tconst objectId = (diff.oldValue as Record<string, unknown>)[idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number;\n\t\t\t\tconst targetIndex = diff.path[diff.path.length - 1] as number;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst currentDiffAdjustedIndex = diffAdjustedObjectIndexes.get(objectId)!;\n\t\t\t\tif (targetIndex !== diffAdjustedObjectIndexes.get(objectId)) {\n\t\t\t\t\t// A Prior Remove or Move Diff moved the object to a new index, so update the diff source index to point to the new index.\n\t\t\t\t\tdiff.path[diff.path.length - 1] = currentDiffAdjustedIndex;\n\t\t\t\t}\n\n\t\t\t\tshiftIndexesFromRemove(diff, diffAdjustedObjectIndexes, objectId);\n\t\t\t}\n\n\t\t\t// Ignoring 'CREATE' for now.\n\t\t}\n\t}\n\n\tfor (let i = 0; i < nonChangeDiffs.length; i++) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst diff = nonChangeDiffs[i]!;\n\n\t\tif (diffsMarkedForRemoval.has(diff)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isLastDiffInArraySeries = (currentIndex: number): boolean => {\n\t\t\tif (currentIndex === nonChangeDiffs.length - 1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst nextIndex = currentIndex + 1;\n\t\t\tif (nextIndex <= nonChangeDiffs.length - 1) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst diffAfter = nonChangeDiffs[nextIndex]!;\n\n\t\t\t\tif (diffsMarkedForRemoval.has(diffAfter)) {\n\t\t\t\t\treturn isLastDiffInArraySeries(nextIndex + 1);\n\t\t\t\t}\n\n\t\t\t\tconst arrayUuidAfter = arrayUuidFromPath(diffAfter.path);\n\t\t\t\tconst arrayUuid = arrayUuidFromPath(diff.path);\n\t\t\t\tif (arrayUuidAfter === arrayUuid) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tif (isDiffOnArray(diff)) {\n\t\t\tconst arrayUuid = arrayUuidFromPath(diff.path);\n\t\t\tconst endReorderDiffs = arrayDiffsMarkedForEndReorder.get(arrayUuid);\n\t\t\tconst isDiffMarkedForReorder = endReorderDiffs?.includes(diff) ?? false;\n\n\t\t\tif (isDiffMarkedForReorder === false) {\n\t\t\t\tfinalDiffSeries.push(diff);\n\t\t\t}\n\n\t\t\tif (isLastDiffInArraySeries(i) && endReorderDiffs !== undefined) {\n\t\t\t\tfinalDiffSeries.push(...endReorderDiffs);\n\t\t\t}\n\n\t\t\tcontinue;\n\t\t}\n\n\t\tfinalDiffSeries.push(diff);\n\t}\n\n\treturn finalDiffSeries;\n}\n\n/**\n * Creates a set of mergeable diffs from a series of diffs produced by {@link sharedTreeDiff}\n * that AREN'T using the object ID strategy. These diffs don't need any modifications to be applied to the old object.\n *\n * @alpha\n */\nexport function createMergableDiffSeries(diffs: Difference[]): Difference[] {\n\t// the final series of diffs that will be returned.\n\tconst finalDiffSeries: Difference[] = [];\n\t// Diffs that aren't of type 'CHANGE'\n\tconst nonChangeDiffs: Difference[] = [];\n\n\tfor (const diff of diffs) {\n\t\tif (diff.type === \"CHANGE\") {\n\t\t\t// Changes must be applied before any other diff, ao so they are ordered first.\n\t\t\tfinalDiffSeries.push({ ...diff });\n\t\t} else {\n\t\t\tnonChangeDiffs.push({ ...diff });\n\t\t}\n\t}\n\n\tfinalDiffSeries.push(...nonChangeDiffs);\n\n\treturn finalDiffSeries;\n}\n\n/**\n * Creates a UUID for the target array from a {@link Difference}'s ${@link ObjectPath}\n */\nfunction arrayUuidFromPath(path: ObjectPath): string {\n\treturn path.length === 1 ? \"\" : path.slice(0, -1).join(\"\");\n}\n\n/**\n * Determines if a given difference is on an array.\n */\nexport function isDiffOnArray(diff: Difference): boolean {\n\treturn typeof diff.path[diff.path.length - 1] === \"number\";\n}\n\n/**\n * Returns the target object that the given diff should be applied to.\n */\nfunction getTargetObjectFromPath(\n\tpath: ObjectPath,\n\tobject: Record<string, unknown> | TreeArrayNode,\n): unknown {\n\tlet targetObject: unknown = object;\n\tif (path.length > 1) {\n\t\ttargetObject = sharedTreeTraverse(object, path.slice(0, -1));\n\t}\n\treturn targetObject;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sharedTreeDiff.js","sourceRoot":"","sources":["../../src/implicit-strategy/sharedTreeDiff.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+CAAoE;AAEpE,yCAA+D;AAwF/D,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAE3E;;;GAGG;AACH,MAAM,eAAe,GAAY,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAErD;;;;GAIG;AACH,SAAgB,cAAc,CAC7B,GAAwC,EACxC,MAA2C,EAC3C,UAAmB,eAAe,EAClC,SAAkD,EAAE;IAEpD,MAAM,KAAK,GAAiB,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAErD,wFAAwF;IACxF,MAAM,yBAAyB,GAC9B,UAAU,KAAK,KAAK,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS;QACzD,CAAC,CAAC,IAAI,GAAG,EAA2B;QACpC,CAAC,CAAC,kCAAkC,CAAC,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAElF,MAAM,yBAAyB,GAC9B,aAAa,KAAK,KAAK,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS;QAC5D,CAAC,CAAC,IAAI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AAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAgB;IAC7C,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,CAAC;AAC5D,CAAC;AAFD,sCAEC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAC/B,IAAgB,EAChB,MAA+C;IAE/C,IAAI,YAAY,GAAY,MAAM,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,YAAY,GAAG,IAAA,6BAAkB,EAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type TreeArrayNode, NodeKind } from \"@fluidframework/tree\";\n\nimport { isTreeMapNode, sharedTreeTraverse } from \"./utils.js\";\n\n/**\n * Represents a path through a tree of objects.\n * number values represent array indices whereas string values represent object keys.\n *\n * @alpha\n */\nexport type ObjectPath = (string | number)[];\n\n/**\n * Represents a create operation between two branches of a tree.\n * Meaning that an attribute (a shared tree node) was identified as being created.\n *\n * @alpha\n */\nexport interface DifferenceCreate {\n\ttype: \"CREATE\";\n\tpath: ObjectPath;\n\tvalue: unknown;\n}\n\n/**\n * Represents a remove operation between two branches of a tree.\n * Meaning that an attribute (a shared tree node) was identified as being deleted.\n * When using object ids, removes are idenitified by an object with a given id no longer existing.\n *\n * @alpha\n */\nexport interface DifferenceRemove {\n\ttype: \"REMOVE\";\n\tpath: ObjectPath;\n\toldValue: unknown;\n\tobjectId?: string | number | undefined;\n}\n\n/**\n * Represents a change operation between two branches of a tree.\n * Meaning that an attribute (a shared tree node) was identified as being changed from one value to another.\n *\n * @alpha\n */\nexport interface DifferenceChange {\n\ttype: \"CHANGE\";\n\tpath: ObjectPath;\n\tvalue: unknown;\n\toldValue: unknown;\n\tobjectId?: string | number | undefined;\n}\n\n/**\n * Represents a move operation between two branches of a tree.\n * Meaning that an object (shared tree node) was identified as being moved from one index to another based on its unique id.\n *\n * @alpha\n */\nexport interface DifferenceMove {\n\ttype: \"MOVE\";\n\tpath: ObjectPath;\n\tnewIndex: number;\n\tvalue: unknown;\n\tobjectId?: string | number | undefined;\n}\n\n/**\n * Union for all possible difference types.\n *\n * @alpha\n */\nexport type Difference =\n\t| DifferenceCreate\n\t| DifferenceRemove\n\t| DifferenceChange\n\t| DifferenceMove;\n\n/**\n * Options for tree diffing.\n * @alpha\n */\nexport interface Options {\n\tcyclesFix: boolean;\n\tuseObjectIds?:\n\t\t| {\n\t\t\t\tidAttributeName: string;\n\t\t }\n\t\t| undefined;\n}\n\nconst richTypes = { Date: true, RegExp: true, String: true, Number: true };\n\n/**\n * By default, Object Diff supports cyclical references, but if you are sure that the object has no cycles like parsed JSON\n * you can disable cycles by setting the cyclesFix option to false\n */\nconst DEFAULT_OPTIONS: Options = { cyclesFix: true };\n\n/**\n * Compares two objects and returns an array of differences between them.\n *\n * @alpha\n */\nexport function sharedTreeDiff(\n\tobj: Record<string, unknown> | unknown[],\n\tnewObj: Record<string, unknown> | unknown[],\n\toptions: Options = DEFAULT_OPTIONS,\n\t_stack: (Record<string, unknown> | unknown[])[] = [],\n): Difference[] {\n\tconst diffs: Difference[] = [];\n\tconst isObjArray = isArrayOrTreeArrayNode(obj);\n\tconst isNewObjArray = isArrayOrTreeArrayNode(newObj);\n\n\t// If useObjectIds is set, we'll create a map of object ids to their index in the array.\n\tconst oldObjArrayItemIdsToIndex =\n\t\tisObjArray === false || options.useObjectIds === undefined\n\t\t\t? new Map<string | number, number>()\n\t\t\t: createObjectArrayItemIdsToIndexMap(obj, options.useObjectIds.idAttributeName);\n\n\tconst newObjArrayItemIdsToIndex =\n\t\tisNewObjArray === false || options.useObjectIds === undefined\n\t\t\t? new Map<string | number, number>()\n\t\t\t: createObjectArrayItemIdsToIndexMap(newObj, options.useObjectIds.idAttributeName);\n\n\tconst objectKeys = isTreeMapNode(obj) ? obj.keys() : Object.keys(obj);\n\t// We compare existence and values of all attributes within the old against new object, looking for removals or changes.\n\tfor (const key of objectKeys) {\n\t\tconst objValue: unknown = isTreeMapNode(obj) ? obj.get(key as string) : obj[key];\n\t\tconst path = isObjArray ? +key : key;\n\t\t// 1. First, check if the key within the old object, exists within the new object. If it doesn't exist this would be an attribute removal.\n\t\tif (!(key in newObj)) {\n\t\t\tif (options.useObjectIds === undefined) {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tobjectId: undefined,\n\t\t\t\t\toldValue: objValue,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// If we're dealing with an object in an array, we can use the object's id to check if it was moved to a new index.\n\t\t\telse if (\n\t\t\t\tisNewObjArray === true &&\n\t\t\t\tisObjArray &&\n\t\t\t\ttypeof objValue === \"object\" &&\n\t\t\t\tobjValue !== null\n\t\t\t) {\n\t\t\t\tconst objectId = objValue[options.useObjectIds.idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number\n\t\t\t\t\t| undefined;\n\t\t\t\tif (objectId !== undefined && newObjArrayItemIdsToIndex.has(objectId)) {\n\t\t\t\t\t// The index no longer exists in the new root object array, however the object that lived at this index actually still exists at a new index.\n\t\t\t\t\t// Therefore, this node was moved to a new index.\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"MOVE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tnewIndex: newObjArrayItemIdsToIndex.get(objectId) as number,\n\t\t\t\t\t\tvalue: objValue,\n\t\t\t\t\t\tobjectId,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// The object with the given id cannot be found within the new array, therefore it was removed.\n\t\t\t\telse {\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tobjectId,\n\t\t\t\t\t\toldValue: objValue,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If we're not dealing with an object in an array, we can't use id's to check for a move.\n\t\t\t// We'll assume that a missing key in the new object means that the cooresponding value was removed.\n\t\t\telse {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tobjectId: undefined,\n\t\t\t\t\toldValue: objValue,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tconst newObjValue: unknown = newObj[key];\n\t\tconst areCompatibleObjects =\n\t\t\ttypeof objValue === \"object\" &&\n\t\t\ttypeof newObjValue === \"object\" &&\n\t\t\tisArrayOrTreeArrayNode(objValue) === isArrayOrTreeArrayNode(newObjValue);\n\n\t\t// 2a. If the given old object key exists in the new object, and the value of said key in both objects is ANOTHER nested object, we need to run a recursive diff check on them.\n\t\tif (\n\t\t\tobjValue !== null &&\n\t\t\tnewObjValue !== null &&\n\t\t\tareCompatibleObjects &&\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unsafe-member-access\n\t\t\t!richTypes[Object.getPrototypeOf(objValue)?.constructor?.name] &&\n\t\t\t(!options.cyclesFix || !_stack.includes(objValue as Record<string, unknown>))\n\t\t) {\n\t\t\tif (options.useObjectIds === undefined) {\n\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\tobjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\tnewObjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\toptions,\n\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t: [],\n\t\t\t\t);\n\t\t\t\t// eslint-disable-next-line prefer-spread\n\t\t\t\tdiffs.push.apply(\n\t\t\t\t\tdiffs,\n\t\t\t\t\tnestedDiffs.map((difference) => {\n\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\treturn difference;\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Use Object Id strategy to determine if the objects should be compared for changes\n\t\t\telse {\n\t\t\t\tconst oldObjectId = (objValue as Record<string, unknown>)[\n\t\t\t\t\toptions.useObjectIds.idAttributeName\n\t\t\t\t] as string | number | undefined;\n\t\t\t\tconst newObjectId = (newObjValue as Record<string, unknown>)[\n\t\t\t\t\toptions.useObjectIds.idAttributeName\n\t\t\t\t] as string | number | undefined;\n\n\t\t\t\tif (oldObjectId !== undefined && newObjectId !== undefined) {\n\t\t\t\t\t// 2a.1 if the object id's are the same, we can continue a comparison between the two objects.\n\t\t\t\t\tif (oldObjectId === newObjectId) {\n\t\t\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\t\t\tobjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\tnewObjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdiffs.push(\n\t\t\t\t\t\t\t...nestedDiffs.map((difference) => {\n\t\t\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\t\t\treturn difference;\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\t// 2a.2 The object id's are different, their attributes cannot be compared.\n\t\t\t\t\t// We need to find the new index of the object, if it exists in the new array and do a diff comparison.\n\t\t\t\t\telse {\n\t\t\t\t\t\tconst newIndexOfOldObject = newObjArrayItemIdsToIndex.get(oldObjectId);\n\t\t\t\t\t\t// The object no longer exists in the new array, therefore it was removed.\n\t\t\t\t\t\tif (newIndexOfOldObject === undefined) {\n\t\t\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\t\t\ttype: \"REMOVE\",\n\t\t\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\t\t\toldValue: objValue,\n\t\t\t\t\t\t\t\tobjectId: oldObjectId,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// This object still exists but at a new index within the new array therefore it was moved.\n\t\t\t\t\t\t// At this point we can determine whether a new move is necessary or there is one that will place it at the desired index.\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\t\t\ttype: \"MOVE\",\n\t\t\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\t\t\tnewIndex: newIndexOfOldObject,\n\t\t\t\t\t\t\t\tvalue: objValue,\n\t\t\t\t\t\t\t\tobjectId: oldObjectId,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// An object could have been moved AND changed. We need to check for this.\n\t\t\t\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\t\t\t\tobj[path] as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\t\tnewObj[newIndexOfOldObject] as Record<string, unknown> | unknown[],\n\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tdiffs.push(\n\t\t\t\t\t\t\t\t...nestedDiffs.map((difference) => {\n\t\t\t\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\t\t\t\treturn difference;\n\t\t\t\t\t\t\t\t}),\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} else {\n\t\t\t\t\tconst nestedDiffs = sharedTreeDiff(\n\t\t\t\t\t\tobjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\tnewObjValue as Record<string, unknown> | unknown[],\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\toptions.cyclesFix === true\n\t\t\t\t\t\t\t? [..._stack, objValue as Record<string, unknown> | unknown[]]\n\t\t\t\t\t\t\t: [],\n\t\t\t\t\t);\n\t\t\t\t\tdiffs.push(\n\t\t\t\t\t\t...nestedDiffs.map((difference) => {\n\t\t\t\t\t\t\tdifference.path.unshift(path);\n\t\t\t\t\t\t\treturn difference;\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}\n\t\t// 2b. If the given old object key exists in the new object, and the value of said key in both objects is NOT another nested object, we need to check if the values are the same.\n\t\telse if (\n\t\t\tobjValue !== newObjValue &&\n\t\t\t// treat NaN values as equivalent\n\t\t\t!(Number.isNaN(objValue) && Number.isNaN(newObjValue)) &&\n\t\t\t!(\n\t\t\t\tareCompatibleObjects &&\n\t\t\t\t(Number.isNaN(objValue)\n\t\t\t\t\t? // eslint-disable-next-line prefer-template, @typescript-eslint/no-base-to-string\n\t\t\t\t\t\tobjValue + \"\" === newObjValue + \"\"\n\t\t\t\t\t: // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t+objValue === +newObjValue)\n\t\t\t)\n\t\t) {\n\t\t\tdiffs.push({\n\t\t\t\tpath: [path],\n\t\t\t\ttype: \"CHANGE\",\n\t\t\t\tvalue: newObjValue,\n\t\t\t\toldValue: objValue,\n\t\t\t\tobjectId:\n\t\t\t\t\toptions.useObjectIds?.idAttributeName === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: (newObj[options.useObjectIds.idAttributeName] as string | number | undefined),\n\t\t\t});\n\t\t}\n\t}\n\n\t// 3. Finally, we check for new keys in the new object that did not exist in the old object.\n\t// The existence of new keys may signal new values or moved values.\n\tconst newObjKeys = isTreeMapNode(newObj) ? newObj.keys() : Object.keys(newObj);\n\tfor (const key of newObjKeys) {\n\t\tconst newObjValue: unknown = isTreeMapNode(newObj)\n\t\t\t? newObj.get(key as string)\n\t\t\t: newObj[key];\n\t\tconst path = isNewObjArray ? +key : key;\n\n\t\tconst isKeyInOldObject = isTreeMapNode(obj)\n\t\t\t? obj.has(key as string)\n\t\t\t: Object.keys(obj).includes(key as string);\n\t\tif (!isKeyInOldObject) {\n\t\t\tif (options.useObjectIds === undefined) {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t});\n\t\t\t}\n\t\t\t// If we're dealing with an object in an array, we can use the object's id to check if this new index actually\n\t\t\t// contains a prexisting object that was moved from an old index.\n\t\t\telse if (\n\t\t\t\tisObjArray === true &&\n\t\t\t\tisNewObjArray === true &&\n\t\t\t\ttypeof newObjValue === \"object\" &&\n\t\t\t\tnewObjValue !== null\n\t\t\t) {\n\t\t\t\tconst objectId = newObjValue[options.useObjectIds.idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number\n\t\t\t\t\t| undefined;\n\t\t\t\tif (objectId !== undefined && oldObjArrayItemIdsToIndex.has(objectId)) {\n\t\t\t\t\t// The new root object array contains a new index, however the object that lives at this new index previously existed at an old index.\n\t\t\t\t\t// Therefore, this object was moved to a new index.\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"MOVE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tnewIndex: newObjArrayItemIdsToIndex.get(objectId) as number,\n\t\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t\t\tobjectId,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// If either the object's id attribute does not exist or the original array does not contain an object with the given id\n\t\t\t\t// Then we assume this was a newly created object.\n\t\t\t\telse {\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If we're not dealing with an object in an array, we can't use id's to check for a move.\n\t\t\t// We'll assume that a brand new key and value pair in the new object means that a new value was created.\n\t\t\telse {\n\t\t\t\tdiffs.push({\n\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\tpath: [path],\n\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (options.useObjectIds !== undefined) {\n\t\t\t// If we're dealing with an object in an array, we can use the object's id to check if this EXISTING index\n\t\t\t// houses a new object based on a newly encountered id.\n\t\t\tif (\n\t\t\t\tisObjArray === true &&\n\t\t\t\tisNewObjArray === true &&\n\t\t\t\ttypeof newObjValue === \"object\" &&\n\t\t\t\tnewObjValue !== null\n\t\t\t) {\n\t\t\t\tconst objectId = newObjValue[options.useObjectIds.idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number\n\t\t\t\t\t| undefined;\n\t\t\t\t// If this object has an id and it does not exist in the old array, then it was created.\n\t\t\t\tif (objectId !== undefined && oldObjArrayItemIdsToIndex.has(objectId) === false) {\n\t\t\t\t\tdiffs.push({\n\t\t\t\t\t\ttype: \"CREATE\",\n\t\t\t\t\t\tpath: [path],\n\t\t\t\t\t\tvalue: newObjValue,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t}\n\treturn diffs;\n}\n\n/**\n * Type Guard that determines if a given object is an array of type unknown[] or {@link TreeArrayNode}.\n */\nfunction isArrayOrTreeArrayNode(obj: unknown): obj is unknown[] | TreeArrayNode {\n\tif (typeof obj === \"object\" && obj !== null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\tconst maybeNodeKind: unknown = Object.getPrototypeOf(obj)?.constructor?.kind;\n\t\tconst isTreeArrayNode = maybeNodeKind === NodeKind.Array;\n\t\treturn Array.isArray(obj) || isTreeArrayNode;\n\t}\n\treturn false;\n}\n\n/**\n * Helper that creates a map of object ids to their index in an array of objects.\n */\nfunction createObjectArrayItemIdsToIndexMap(\n\tobj: unknown[],\n\tidAttributeName: string | number,\n): Map<string | number, number> {\n\tconst objArrayItemIdsToIndex = new Map<string | number, number>();\n\tfor (let i = 0; i < obj.length; i++) {\n\t\tconst objArrayItem = obj[i];\n\t\tif (typeof objArrayItem === \"object\" && objArrayItem !== null) {\n\t\t\tconst id = (objArrayItem as Record<string, unknown>)[idAttributeName] as string | number;\n\t\t\tif (objArrayItemIdsToIndex.has(id)) {\n\t\t\t\tthrow new TypeError(`Duplicate object id found: ${id}`);\n\t\t\t} else if (id !== undefined) {\n\t\t\t\tobjArrayItemIdsToIndex.set(id, i);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn objArrayItemIdsToIndex;\n}\n\n/**\n * Creates a set of mergeable diffs from a series of diffs produced by {@link sharedTreeDiff}\n * that are using the object ID strategy. These diffs don't need any modifications to be applied to the old object.\n *\n * @alpha\n */\nexport function createMergableIdDiffSeries(\n\toldObject: unknown,\n\tdiffs: Difference[],\n\tidAttributeName: string | number,\n): Difference[] {\n\t// the final series of diffs that will be returned.\n\tconst finalDiffSeries: Difference[] = [];\n\t// Diffs that aren't of type 'CHANGE'\n\tconst nonChangeDiffs: Difference[] = [];\n\n\tfor (const diff of diffs) {\n\t\tif (diff.type === \"CHANGE\") {\n\t\t\t// Changes must be applied before any other diff, ao so they are ordered first.\n\t\t\tfinalDiffSeries.push({ ...diff });\n\t\t} else {\n\t\t\tnonChangeDiffs.push({ ...diff });\n\t\t}\n\t}\n\n\t// Create sets of array diffs grouped by the array they are applying changes to.\n\tconst diffsByArrayUuid = new Map<string, Difference[]>();\n\tfor (const diff of nonChangeDiffs) {\n\t\tif (!isDiffOnArray(diff)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst arrayUuid = arrayUuidFromPath(diff.path);\n\n\t\tif (diffsByArrayUuid.has(arrayUuid) === false) {\n\t\t\tdiffsByArrayUuid.set(arrayUuid, []);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tdiffsByArrayUuid.get(arrayUuid)!.push(diff);\n\t}\n\n\tconst shiftIndexesFromMove = (\n\t\tdiff: DifferenceMove,\n\t\ttargetArray: unknown[],\n\t\tdiffAdjustedObjectIndexes: Map<string | number, number>,\n\t\tobjectId: string | number,\n\t): void => {\n\t\tconst sourceIndex = diff.path[diff.path.length - 1] as number;\n\n\t\tif (diff.newIndex > sourceIndex) {\n\t\t\t// This move diff shifts objects it moved over to the left.\n\t\t\t// |----| |----|\n\t\t\t// e.g. - shift with no length change: [{1}, {2}, {3}, {4}] -> [{2}, {3}, {1}, {4}]\n\t\t\tconst minIndex = sourceIndex;\n\t\t\tconst maxIndex = diff.newIndex;\n\t\t\tfor (const [id, index] of diffAdjustedObjectIndexes.entries()) {\n\t\t\t\tconst shouldIndexBeShifted =\n\t\t\t\t\tid !== objectId && index <= maxIndex && index >= minIndex && index - 1 >= 0;\n\t\t\t\tif (shouldIndexBeShifted) {\n\t\t\t\t\tdiffAdjustedObjectIndexes.set(id, index - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (diff.newIndex < sourceIndex) {\n\t\t\t// This move diff shifts objects it moved over to the right.\n\t\t\t// |----| |----|\n\t\t\t// e.g. - shift with no length change: [{1}, {2}, {3}, {4}] -> [{3}, {1}, {2}, {4}]\n\t\t\tconst minIndex = diff.newIndex;\n\t\t\tconst maxIndex = sourceIndex;\n\t\t\tfor (const [id, index] of diffAdjustedObjectIndexes.entries()) {\n\t\t\t\tconst shouldIndexBeShifted =\n\t\t\t\t\tid !== objectId &&\n\t\t\t\t\tindex <= maxIndex &&\n\t\t\t\t\tindex >= minIndex &&\n\t\t\t\t\tindex + 1 <= targetArray.length;\n\t\t\t\tif (shouldIndexBeShifted) {\n\t\t\t\t\tdiffAdjustedObjectIndexes.set(id, index + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\tconst shiftIndexesFromRemove = (\n\t\tdiff: DifferenceRemove,\n\t\tdiffAdjustedObjectIndexes: Map<string | number, number>,\n\t\tobjectId: string | number,\n\t): void => {\n\t\tconst removalIndex = diff.path[diff.path.length - 1] as number;\n\t\tfor (const [id, index] of diffAdjustedObjectIndexes.entries()) {\n\t\t\tconst shouldIndexBeShifted = id !== objectId && index > removalIndex && index - 1 >= 0;\n\t\t\tif (shouldIndexBeShifted) {\n\t\t\t\tdiffAdjustedObjectIndexes.set(id, index - 1);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst diffsMarkedForRemoval = new Set<Difference>();\n\tconst arrayDiffsMarkedForEndReorder = new Map<string, Difference[]>();\n\n\tfor (const [arrayUuid, arrayDiffs] of diffsByArrayUuid.entries()) {\n\t\t// The prior grouping code ensures that each map value will have atleast 1 diff.\n\t\tconst targetArray = getTargetObjectFromPath(\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tarrayDiffs[0]!.path,\n\t\t\toldObject as TreeArrayNode,\n\t\t) as unknown[];\n\t\tconst diffAdjustedObjectIndexes: Map<string | number, number> =\n\t\t\tcreateObjectArrayItemIdsToIndexMap(targetArray, idAttributeName);\n\n\t\tfor (const diff of arrayDiffs) {\n\t\t\tif (diff.type === \"MOVE\") {\n\t\t\t\tconst objectId = (diff.value as Record<string, unknown>)[idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number;\n\t\t\t\tconst sourceIndex = diff.path[diff.path.length - 1] as number;\n\n\t\t\t\t// 1. Prior moves may render the next move redundant.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst currentAdjustedIndex = diffAdjustedObjectIndexes.get(objectId)!;\n\t\t\t\tif (currentAdjustedIndex === diff.newIndex) {\n\t\t\t\t\tdiffsMarkedForRemoval.add(diff);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (currentAdjustedIndex !== sourceIndex) {\n\t\t\t\t\t// A Prior Remove or Move Diff moved the object to a new index, so update the diff source index to point to the new index.\n\t\t\t\t\tdiff.path[diff.path.length - 1] = currentAdjustedIndex;\n\t\t\t\t}\n\n\t\t\t\t// Handle index shifts\n\t\t\t\tdiffAdjustedObjectIndexes.set(objectId, diff.newIndex);\n\n\t\t\t\t// edge case: this MOVE should be applied after some series of creates that we haven't seen.\n\t\t\t\tif (diff.newIndex > targetArray.length - 1) {\n\t\t\t\t\t// It also wont shift any indexes since its moved to the total end of the array,\n\t\t\t\t\t// after creations that produce the necessary indexes.\n\t\t\t\t\tif (arrayDiffsMarkedForEndReorder.has(arrayUuid) === false) {\n\t\t\t\t\t\tarrayDiffsMarkedForEndReorder.set(arrayUuid, []);\n\t\t\t\t\t}\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tarrayDiffsMarkedForEndReorder.get(arrayUuid)!.push(diff);\n\t\t\t\t} else {\n\t\t\t\t\tshiftIndexesFromMove(diff, targetArray, diffAdjustedObjectIndexes, objectId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (diff.type === \"REMOVE\") {\n\t\t\t\tconst objectId = (diff.oldValue as Record<string, unknown>)[idAttributeName] as\n\t\t\t\t\t| string\n\t\t\t\t\t| number;\n\t\t\t\tconst targetIndex = diff.path[diff.path.length - 1] as number;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst currentDiffAdjustedIndex = diffAdjustedObjectIndexes.get(objectId)!;\n\t\t\t\tif (targetIndex !== diffAdjustedObjectIndexes.get(objectId)) {\n\t\t\t\t\t// A Prior Remove or Move Diff moved the object to a new index, so update the diff source index to point to the new index.\n\t\t\t\t\tdiff.path[diff.path.length - 1] = currentDiffAdjustedIndex;\n\t\t\t\t}\n\n\t\t\t\tshiftIndexesFromRemove(diff, diffAdjustedObjectIndexes, objectId);\n\t\t\t}\n\n\t\t\t// Ignoring 'CREATE' for now.\n\t\t}\n\t}\n\n\tfor (let i = 0; i < nonChangeDiffs.length; i++) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst diff = nonChangeDiffs[i]!;\n\n\t\tif (diffsMarkedForRemoval.has(diff)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst isLastDiffInArraySeries = (currentIndex: number): boolean => {\n\t\t\tif (currentIndex === nonChangeDiffs.length - 1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tconst nextIndex = currentIndex + 1;\n\t\t\tif (nextIndex <= nonChangeDiffs.length - 1) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst diffAfter = nonChangeDiffs[nextIndex]!;\n\n\t\t\t\tif (diffsMarkedForRemoval.has(diffAfter)) {\n\t\t\t\t\treturn isLastDiffInArraySeries(nextIndex + 1);\n\t\t\t\t}\n\n\t\t\t\tconst arrayUuidAfter = arrayUuidFromPath(diffAfter.path);\n\t\t\t\tconst arrayUuid = arrayUuidFromPath(diff.path);\n\t\t\t\tif (arrayUuidAfter === arrayUuid) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tif (isDiffOnArray(diff)) {\n\t\t\tconst arrayUuid = arrayUuidFromPath(diff.path);\n\t\t\tconst endReorderDiffs = arrayDiffsMarkedForEndReorder.get(arrayUuid);\n\t\t\tconst isDiffMarkedForReorder = endReorderDiffs?.includes(diff) ?? false;\n\n\t\t\tif (isDiffMarkedForReorder === false) {\n\t\t\t\tfinalDiffSeries.push(diff);\n\t\t\t}\n\n\t\t\tif (isLastDiffInArraySeries(i) && endReorderDiffs !== undefined) {\n\t\t\t\tfinalDiffSeries.push(...endReorderDiffs);\n\t\t\t}\n\n\t\t\tcontinue;\n\t\t}\n\n\t\tfinalDiffSeries.push(diff);\n\t}\n\n\treturn finalDiffSeries;\n}\n\n/**\n * Creates a set of mergeable diffs from a series of diffs produced by {@link sharedTreeDiff}\n * that AREN'T using the object ID strategy. These diffs don't need any modifications to be applied to the old object.\n *\n * @alpha\n */\nexport function createMergableDiffSeries(diffs: Difference[]): Difference[] {\n\t// the final series of diffs that will be returned.\n\tconst finalDiffSeries: Difference[] = [];\n\t// Diffs that aren't of type 'CHANGE'\n\tconst nonChangeDiffs: Difference[] = [];\n\n\tfor (const diff of diffs) {\n\t\tif (diff.type === \"CHANGE\") {\n\t\t\t// Changes must be applied before any other diff, ao so they are ordered first.\n\t\t\tfinalDiffSeries.push({ ...diff });\n\t\t} else {\n\t\t\tnonChangeDiffs.push({ ...diff });\n\t\t}\n\t}\n\n\tfinalDiffSeries.push(...nonChangeDiffs);\n\n\treturn finalDiffSeries;\n}\n\n/**\n * Creates a UUID for the target array from a {@link Difference}'s ${@link ObjectPath}\n */\nfunction arrayUuidFromPath(path: ObjectPath): string {\n\treturn path.length === 1 ? \"\" : path.slice(0, -1).join(\"\");\n}\n\n/**\n * Determines if a given difference is on an array.\n */\nexport function isDiffOnArray(diff: Difference): boolean {\n\treturn typeof diff.path[diff.path.length - 1] === \"number\";\n}\n\n/**\n * Returns the target object that the given diff should be applied to.\n */\nfunction getTargetObjectFromPath(\n\tpath: ObjectPath,\n\tobject: Record<string, unknown> | TreeArrayNode,\n): unknown {\n\tlet targetObject: unknown = object;\n\tif (path.length > 1) {\n\t\ttargetObject = sharedTreeTraverse(object, path.slice(0, -1));\n\t}\n\treturn targetObject;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentEditReducer.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAIN,KAAK,aAAa,EAClB,KAAK,QAAQ,EAEb,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,GAAG,MAAM,CA4BlE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc,CAE1F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACpD,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAyPhC;AA0DD,UAAU,SAAS;IAClB,KAAK,EAAE,aAAa,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,GAAG,SAAS,CAW9E"}
|
|
@@ -164,7 +164,7 @@ export function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator)
|
|
|
164
164
|
throw error;
|
|
165
165
|
}
|
|
166
166
|
// If the LLM attempts to use the wrong type for a field, we generate a useful error message that can be used as part of the feedback loop.
|
|
167
|
-
const isInvalidTypeError =
|
|
167
|
+
const isInvalidTypeError = /The provided data is incompatible with all of the types allowed by the schema./.exec(error.message) !== null;
|
|
168
168
|
if (isInvalidTypeError === true) {
|
|
169
169
|
const errorMessage = createInvalidModifyFeedbackMsg(treeEdit, node, "INVALID_TYPE");
|
|
170
170
|
throw new UsageError(errorMessage);
|
|
@@ -302,6 +302,7 @@ function createInvalidModifyFeedbackMsg(modifyEdit, treeNode, errorType) {
|
|
|
302
302
|
else if (errorType === "INVALID_TYPE") {
|
|
303
303
|
const allowedTypeIdentifiers = getAllowedTypeIdentifiers(modifyEdit.field);
|
|
304
304
|
// TODO: If the invalid modification is a new object, it won't be clear what part of the object is invalid for the given type. If we could give some more detailed guidance on what was wrong with the object it would be ideal.
|
|
305
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
305
306
|
messageSuffix = ` You cannot set the node's field \`${modifyEdit.field}\` to the value \`${modifyEdit.modification}\` with type \`${typeof modifyEdit.modification}\` because this type is incompatible with all of the types allowed by the field's schema. The set of allowed types are \`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(", ")}]\`.`;
|
|
306
307
|
}
|
|
307
308
|
return messagePrefix + messageSuffix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentEditReducer.js","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EACN,IAAI,EACJ,QAAQ,EAMR,SAAS,EACT,WAAW,EACX,qBAAqB,EAGrB,aAAa,EACb,eAAe,GACf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAc9C,OAAO,EASN,SAAS,EAIT,WAAW,GACX,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;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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CAAC;IACH,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACjD,CAAC;AACF,CAAC;AAOD,SAAS,mBAAmB,CAAC,IAAc;IAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,gBAAgB,GAAG,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 { isFluidError, 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\ttype IterableTreeArrayContent,\n\tSchemaFactory,\n\tArrayNodeSchema,\n} from \"@fluidframework/tree/internal\";\nimport { closest } from \"fastest-levenshtein\";\n\nimport type {\n\tArrayRangeRemoveDiff,\n\tArraySingleRemoveDiff,\n\tInsertDiff,\n\tModifyDiff,\n\tMoveRangeDiff,\n\tMoveSingleDiff,\n\tNodePath,\n\tRemoveNodeDiff,\n\tDiff,\n} from \"../diffTypes.js\";\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\ttype Modify,\n\ttype Remove,\n\ttype Move,\n\tobjectIdKey,\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\t0xa73 /* 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, 0xa74 /* Expected object schema */);\n\t\t}\n\t}\n}\n\n/**\n * Gets the schema identifier of the given content, including primitive values.\n */\nexport function getSchemaIdentifier(content: TreeEditValue): string {\n\tswitch (typeof content) {\n\t\tcase \"boolean\": {\n\t\t\treturn SchemaFactory.boolean.identifier;\n\t\t}\n\t\tcase \"number\": {\n\t\t\treturn SchemaFactory.number.identifier;\n\t\t}\n\t\tcase \"string\": {\n\t\t\treturn SchemaFactory.string.identifier;\n\t\t}\n\t\tcase \"object\": {\n\t\t\tif (content === null) {\n\t\t\t\treturn SchemaFactory.null.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 SchemaFactory.handle.identifier;\n\t\t\t}\n\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\n/**\n * Converts a tree node from a {@link TreeEdit} to a {@link TreeEditObject} with the proper object IDs.\n */\nexport function 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): { edit: TreeEdit; diff: Diff } {\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\tif (!(parentNodeSchema instanceof ArrayNodeSchema)) {\n\t\t\t\tthrow new UsageError(\"the parent node must be an arrayNode\");\n\t\t\t}\n\t\t\tconst allowedTypes = normalizeAllowedTypes(parentNodeSchema.info).evaluate();\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\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\tedit: {\n\t\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\t\tcontent: contentWithIds(insertNode, idGenerator),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdiff: createInsertDiff(insertNode, treeEdit.explanation, 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\tlet diff: RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff;\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\tconst parentArrayNode = parentNode as TreeArrayNode;\n\t\t\t\t\tdiff = createRemoveDiff(treeEdit, idGenerator);\n\t\t\t\t\tparentArrayNode.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\tdiff = createRemoveDiff(treeEdit, idGenerator);\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\tdiff = createRemoveDiff(treeEdit, idGenerator);\n\t\t\t\tarray.removeRange(startIndex, endIndex);\n\t\t\t} else {\n\t\t\t\tthrow new UsageError(\"Invalid source for remove edit\");\n\t\t\t}\n\n\t\t\treturn { edit: treeEdit, diff };\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 nodeFieldSchemas = treeNodeSchema.info as Record<string, ImplicitFieldSchema>;\n\n\t\t\tconst fieldSchema = nodeFieldSchemas[treeEdit.field];\n\n\t\t\t// If the LLM attempts to modify a field that does not exist in the target schema we generate a useful error message that can be used as part of the feedback loop.\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tconst errorMessage = createInvalidModifyFeedbackMsg(\n\t\t\t\t\ttreeEdit,\n\t\t\t\t\tnode,\n\t\t\t\t\t\"NONEXISTENT_FIELD\",\n\t\t\t\t);\n\t\t\t\tthrow new UsageError(errorMessage);\n\t\t\t}\n\n\t\t\tconst modification = treeEdit.modification;\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\tconst diff = createModifyDiff(treeEdit, idGenerator);\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\ttry {\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] = modification;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isFluidError(error)) {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\t// If the LLM attempts to use the wrong type for a field, we generate a useful error message that can be used as part of the feedback loop.\n\t\t\t\t\tconst isInvalidTypeError =\n\t\t\t\t\t\terror.message.match(\n\t\t\t\t\t\t\t/The provided data is incompatible with all of the types allowed by the schema./,\n\t\t\t\t\t\t) !== null;\n\t\t\t\t\tif (isInvalidTypeError === true) {\n\t\t\t\t\t\tconst errorMessage = createInvalidModifyFeedbackMsg(\n\t\t\t\t\t\t\ttreeEdit,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\"INVALID_TYPE\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthrow new UsageError(errorMessage);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\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\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), 0xa75 /* 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\t0xa76 /* 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}\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] = constructedModification;\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\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? { edit: treeEdit, diff }\n\t\t\t\t: {\n\t\t\t\t\t\tedit: {\n\t\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdiff,\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\t\t\tconst diff: MoveSingleDiff | MoveRangeDiff = createMoveDiff(treeEdit, idGenerator);\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\tif (destinationArraySchema instanceof ArrayNodeSchema === false) {\n\t\t\t\t\tthrow new UsageError(\"the destination node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (Tree.is(nodeToMove as TreeNode, destinationArraySchema.info)) {\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, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!Tree.is(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} else {\n\t\t\t\tthrow new Error(\"Invalid source for move edit\");\n\t\t\t}\n\t\t\treturn { edit: treeEdit, diff };\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\n/**\n * Produces a useful, context-rich error message to give as a response to the LLM when it has produced an {@link ModifyEdit} that either references a nonexistant field or an invalid type for the selected field.\n * @param errorType - The type of error message to produce. You must determine the error type before calling this function.\n * - `'NONEXISTENT_FIELD'` is used when the field does not exist in the node's schema.\n * - `'INVALID_TYPE'` is used when the field exists but the type of the modification is invalid.\n */\nfunction createInvalidModifyFeedbackMsg(\n\tmodifyEdit: Modify,\n\ttreeNode: TreeNode,\n\terrorType: \"NONEXISTENT_FIELD\" | \"INVALID_TYPE\",\n): string {\n\tconst { treeNodeSchema } = getSimpleNodeSchema(treeNode);\n\tconst nodeFieldSchemas = treeNodeSchema.info as Record<string, ImplicitFieldSchema>;\n\tconst messagePrefix = `You attempted an invalid modify edit on the node with id '${modifyEdit.target.target}' and schema '${treeNodeSchema.identifier}'.`;\n\tlet messageSuffix = \"\";\n\tconst getAllowedTypeIdentifiers = (fieldName: string): string[] => {\n\t\tconst targetFieldNodeSchema = nodeFieldSchemas[fieldName];\n\t\treturn targetFieldNodeSchema instanceof FieldSchema\n\t\t\t? [...targetFieldNodeSchema.allowedTypeSet.values()].map((schema) => schema.identifier)\n\t\t\t: [(targetFieldNodeSchema as TreeNodeSchema).identifier];\n\t};\n\n\tif (errorType === \"NONEXISTENT_FIELD\") {\n\t\tconst nodeFieldNames = Object.keys(nodeFieldSchemas);\n\t\tconst closestPossibleFieldMatch = closest(modifyEdit.field, nodeFieldNames);\n\t\tconst allowedTypeIdentifiers = getAllowedTypeIdentifiers(closestPossibleFieldMatch);\n\t\tconst closestPossibleMatchForFieldMessage = ` If you are sure you are trying to modify this node, did you mean to use the field \\`${closestPossibleFieldMatch}\\` which has the following set of allowed types: \\`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(\", \")}]\\`?`;\n\t\tmessageSuffix = ` The node's field you selected for modification \\`${modifyEdit.field}\\` does not exist in this node's schema. The set of available fields for this node are: \\`[${nodeFieldNames.map((field) => `'${field}'`).join(\", \")}]\\`.${closestPossibleMatchForFieldMessage}`;\n\t} else if (errorType === \"INVALID_TYPE\") {\n\t\tconst allowedTypeIdentifiers = getAllowedTypeIdentifiers(modifyEdit.field);\n\t\t// TODO: If the invalid modification is a new object, it won't be clear what part of the object is invalid for the given type. If we could give some more detailed guidance on what was wrong with the object it would be ideal.\n\t\tmessageSuffix = ` You cannot set the node's field \\`${modifyEdit.field}\\` to the value \\`${modifyEdit.modification}\\` with type \\`${typeof modifyEdit.modification}\\` because this type is incompatible with all of the types allowed by the field's schema. The set of allowed types are \\`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(\", \")}]\\`.`;\n\t}\n\n\treturn messagePrefix + messageSuffix;\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\n/**\n * Gets information about the range of nodes being targeted by an {@link Range}\n */\nexport function 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, 0xa79 /* 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\nconst createNodePathRecursive = (\n\tnode: TreeNode | undefined,\n\tidGenerator: IdGenerator,\n\tcurrentPath: NodePath,\n): NodePath => {\n\tif (node === undefined) {\n\t\treturn currentPath;\n\t}\n\n\tcurrentPath.push({\n\t\tshortId: Tree.shortId(node),\n\t\tschemaIdentifier: Tree.schema(node).identifier,\n\t\tparentField: Tree.key(node),\n\t});\n\n\tconst parentNode = Tree.parent(node);\n\treturn createNodePathRecursive(parentNode, idGenerator, currentPath);\n};\n\n/**\n * Creates a diff for an Insert TreeEdit.\n *\n * @remarks\n * This function is only invoked within the \"insert\" case block.\n *\n * This must only be called AFTER an insertion is made.\n * It generates the insert diff after the node has been successfully inserted, as the node's index may\n * be required to support undoing the insert operation, and we don't know that index until the insert has been made.\n */\nfunction createInsertDiff(\n\tnewlyInsertedNode: TreeNode,\n\taiExplanation: string,\n\tidGenerator: IdGenerator,\n): InsertDiff {\n\treturn {\n\t\ttype: \"insert\",\n\t\tnodePath: createNodePathRecursive(newlyInsertedNode, idGenerator, []),\n\t\tnodeContent: JSON.parse(JSON.stringify(newlyInsertedNode)),\n\t\taiExplanation,\n\t};\n}\n\n/**\n * Returns an object identical to the input except that the special 'objectIdKey' field (only intended for use by the LLM agent) is removed if present.\n * @remarks The input object is not modified.\n */\nfunction removeAgentObjectIdField(oldValue: unknown): unknown {\n\tif (typeof oldValue === \"object\" && oldValue !== null && !Array.isArray(oldValue)) {\n\t\tconst { [objectIdKey]: _, ...rest } = oldValue as Record<string, unknown>;\n\t\treturn rest;\n\t}\n\treturn oldValue;\n}\n\n/**\n * Creates a diff for a Modify TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a modify edit is applied.\n * For move operations, the diff is created before the node(s) have been successfully moved,\n * since the original index is needed to restore the node(s) if the move operation need to undo.\n */\nfunction createModifyDiff(treeEdit: Modify, idGenerator: IdGenerator): ModifyDiff {\n\tconst targetNode = getNodeFromTarget(treeEdit.target, idGenerator);\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\tconst targetNodeAtField: unknown = (targetNode as any)[treeEdit.field];\n\n\tif (isPrimitive(targetNodeAtField)) {\n\t\treturn {\n\t\t\ttype: \"modify\",\n\t\t\tnodePath: createNodePathRecursive(targetNode, idGenerator, [\n\t\t\t\t{\n\t\t\t\t\tshortId: undefined,\n\t\t\t\t\tparentField: treeEdit.field,\n\t\t\t\t\tschemaIdentifier: getSchemaIdentifier(treeEdit.modification),\n\t\t\t\t},\n\t\t\t]),\n\t\t\tnewValue: treeEdit.modification,\n\t\t\toldValue: targetNodeAtField,\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: \"modify\",\n\t\tnodePath: createNodePathRecursive(targetNodeAtField as TreeNode, idGenerator, []),\n\t\tnewValue: treeEdit.modification,\n\t\toldValue: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetNodeAtField))),\n\t\taiExplanation: treeEdit.explanation,\n\t};\n}\n\n/**\n * Creates a diff for a Remove TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a remove edit is applied.\n * It generates the remove diff before the node has been successfully removed, as the node's index may\n * be required to support undoing the remove operation, and we don't know that index until the remove has been made.\n */\nfunction createRemoveDiff(\n\ttreeEdit: Remove,\n\tidGenerator: IdGenerator,\n): RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff {\n\tconst source = treeEdit.source;\n\tif (isObjectTarget(source)) {\n\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\tconst parentNode = Tree.parent(node);\n\t\tif (parentNode === undefined) {\n\t\t\tthrow new Error(\"Unexpectedly received a root node as the target of a remove edit\");\n\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst targetRemovedNode = (parentNode as TreeArrayNode).at(nodeIndex)!;\n\n\t\t\tif (isPrimitive(targetRemovedNode)) {\n\t\t\t\t// Note that this cause should not be possible, still putting the error here in case things change so that this function is updated properly\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unexpectedly recieved a primitive node as the target of a remove edit\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttype: \"remove\",\n\t\t\t\tremovalType: \"remove-array-single\",\n\t\t\t\tnodePath: createNodePathRecursive(targetRemovedNode as TreeNode, idGenerator, []),\n\t\t\t\taiExplanation: treeEdit.explanation,\n\t\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetRemovedNode))),\n\t\t\t};\n\t\t} else {\n\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst targetNodeAtField: unknown = (parentNode as any)[fieldKey];\n\n\t\t\tif (isPrimitive(targetNodeAtField)) {\n\t\t\t\t// Note that this cause should not be possible, still putting the error here in case things change so that this function is updated properly\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unexpectedly recieved a primitive node as the target of a remove field edit\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttype: \"remove\",\n\t\t\t\tremovalType: \"remove-node\",\n\t\t\t\tnodePath: createNodePathRecursive(targetNodeAtField as TreeNode, idGenerator, []),\n\t\t\t\taiExplanation: treeEdit.explanation,\n\t\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetNodeAtField))),\n\t\t\t};\n\t\t}\n\t} else if (isRange(source)) {\n\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\tconst removedNodePaths: NodePath[] = [];\n\t\tconst removedNodes: TreeNode[] = [];\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst nodeToRemove = array.at(i)!;\n\t\t\tif (!isPrimitive(nodeToRemove)) {\n\t\t\t\tremovedNodePaths.push(\n\t\t\t\t\tcreateNodePathRecursive(nodeToRemove as TreeNode, idGenerator, []),\n\t\t\t\t);\n\t\t\t\tremovedNodes.push(nodeToRemove as TreeNode);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\ttype: \"remove\",\n\t\t\tremovalType: \"remove-array-range\",\n\t\t\tnodePaths: removedNodePaths,\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContents: removedNodes.map((node) =>\n\t\t\t\tremoveAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t\t),\n\t\t};\n\t} else {\n\t\tthrow new Error(\"Invalid source encountered when trying to create diff for remove edit\");\n\t}\n}\n\n/**\n * Creates a diff for a Move TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a move edit is applied.\n * For move operations, the diff is created before the node(s) have been successfully moved,\n * since the original index is needed to restore the node(s) if the move operation need to undo.\n */\nfunction createMoveDiff(\n\ttreeEdit: Move,\n\tidGenerator: IdGenerator,\n): MoveSingleDiff | MoveRangeDiff {\n\tconst source = treeEdit.source;\n\tconst destination = treeEdit.destination;\n\tconst { array: destinationArrayNode } = getPlaceInfo(destination, idGenerator);\n\n\tif (isObjectTarget(source)) {\n\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\treturn {\n\t\t\ttype: \"move\",\n\t\t\tmoveType: \"move-single\",\n\t\t\tsourceNodePath: createNodePathRecursive(node, idGenerator, []),\n\t\t\tdestinationNodePath: createNodePathRecursive(destinationArrayNode, idGenerator, []),\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t};\n\t} else if (isRange(source)) {\n\t\tconst {\n\t\t\tarray,\n\t\t\tstartIndex: sourceStartIndex,\n\t\t\tendIndex: sourceEndIndex,\n\t\t} = getRangeInfo(source, idGenerator);\n\n\t\tconst movedNodePaths: NodePath[] = [];\n\t\tconst movedNodes: TreeNode[] = [];\n\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\tconst nodeToMove = array.at(i);\n\t\t\tif (!isPrimitive(nodeToMove)) {\n\t\t\t\tmovedNodePaths.push(createNodePathRecursive(nodeToMove as TreeNode, idGenerator, []));\n\t\t\t\tmovedNodes.push(nodeToMove as TreeNode);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"move\",\n\t\t\tmoveType: \"move-range\",\n\t\t\tsourceNodePaths: movedNodePaths,\n\t\t\tdestinationNodePath: createNodePathRecursive(destinationArrayNode, idGenerator, []),\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContents: movedNodes.map((node) =>\n\t\t\t\tremoveAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t\t),\n\t\t};\n\t} else {\n\t\tthrow new Error(\"Invalid source for move edit\");\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"]}
|
|
1
|
+
{"version":3,"file":"agentEditReducer.js","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EACN,IAAI,EACJ,QAAQ,EAMR,SAAS,EACT,WAAW,EACX,qBAAqB,EAGrB,aAAa,EACb,eAAe,GACf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAc9C,OAAO,EASN,SAAS,EAIT,WAAW,GACX,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAA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E,CAAC;YACnF,aAAa,EAAE,QAAQ,CAAC,WAAW;YACnC,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACrC,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAC1D;SACD,CAAC;IACH,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACjD,CAAC;AACF,CAAC;AAOD,SAAS,mBAAmB,CAAC,IAAc;IAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,gBAAgB,GAAG,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 { isFluidError, 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\ttype IterableTreeArrayContent,\n\tSchemaFactory,\n\tArrayNodeSchema,\n} from \"@fluidframework/tree/internal\";\nimport { closest } from \"fastest-levenshtein\";\n\nimport type {\n\tArrayRangeRemoveDiff,\n\tArraySingleRemoveDiff,\n\tInsertDiff,\n\tModifyDiff,\n\tMoveRangeDiff,\n\tMoveSingleDiff,\n\tNodePath,\n\tRemoveNodeDiff,\n\tDiff,\n} from \"../diffTypes.js\";\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\ttype Modify,\n\ttype Remove,\n\ttype Move,\n\tobjectIdKey,\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\t0xa73 /* 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, 0xa74 /* Expected object schema */);\n\t\t}\n\t}\n}\n\n/**\n * Gets the schema identifier of the given content, including primitive values.\n */\nexport function getSchemaIdentifier(content: TreeEditValue): string {\n\tswitch (typeof content) {\n\t\tcase \"boolean\": {\n\t\t\treturn SchemaFactory.boolean.identifier;\n\t\t}\n\t\tcase \"number\": {\n\t\t\treturn SchemaFactory.number.identifier;\n\t\t}\n\t\tcase \"string\": {\n\t\t\treturn SchemaFactory.string.identifier;\n\t\t}\n\t\tcase \"object\": {\n\t\t\tif (content === null) {\n\t\t\t\treturn SchemaFactory.null.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 SchemaFactory.handle.identifier;\n\t\t\t}\n\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\n/**\n * Converts a tree node from a {@link TreeEdit} to a {@link TreeEditObject} with the proper object IDs.\n */\nexport function 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): { edit: TreeEdit; diff: Diff } {\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\tif (!(parentNodeSchema instanceof ArrayNodeSchema)) {\n\t\t\t\tthrow new UsageError(\"the parent node must be an arrayNode\");\n\t\t\t}\n\t\t\tconst allowedTypes = normalizeAllowedTypes(parentNodeSchema.info).evaluate();\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\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\tedit: {\n\t\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\t\tcontent: contentWithIds(insertNode, idGenerator),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdiff: createInsertDiff(insertNode, treeEdit.explanation, 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\tlet diff: RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff;\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\tconst parentArrayNode = parentNode as TreeArrayNode;\n\t\t\t\t\tdiff = createRemoveDiff(treeEdit, idGenerator);\n\t\t\t\t\tparentArrayNode.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\tdiff = createRemoveDiff(treeEdit, idGenerator);\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\tdiff = createRemoveDiff(treeEdit, idGenerator);\n\t\t\t\tarray.removeRange(startIndex, endIndex);\n\t\t\t} else {\n\t\t\t\tthrow new UsageError(\"Invalid source for remove edit\");\n\t\t\t}\n\n\t\t\treturn { edit: treeEdit, diff };\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 nodeFieldSchemas = treeNodeSchema.info as Record<string, ImplicitFieldSchema>;\n\n\t\t\tconst fieldSchema = nodeFieldSchemas[treeEdit.field];\n\n\t\t\t// If the LLM attempts to modify a field that does not exist in the target schema we generate a useful error message that can be used as part of the feedback loop.\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tconst errorMessage = createInvalidModifyFeedbackMsg(\n\t\t\t\t\ttreeEdit,\n\t\t\t\t\tnode,\n\t\t\t\t\t\"NONEXISTENT_FIELD\",\n\t\t\t\t);\n\t\t\t\tthrow new UsageError(errorMessage);\n\t\t\t}\n\n\t\t\tconst modification = treeEdit.modification;\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\tconst diff = createModifyDiff(treeEdit, idGenerator);\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\ttry {\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] = modification;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isFluidError(error)) {\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\t// If the LLM attempts to use the wrong type for a field, we generate a useful error message that can be used as part of the feedback loop.\n\t\t\t\t\tconst isInvalidTypeError =\n\t\t\t\t\t\t/The provided data is incompatible with all of the types allowed by the schema./.exec(\n\t\t\t\t\t\t\terror.message,\n\t\t\t\t\t\t) !== null;\n\t\t\t\t\tif (isInvalidTypeError === true) {\n\t\t\t\t\t\tconst errorMessage = createInvalidModifyFeedbackMsg(\n\t\t\t\t\t\t\ttreeEdit,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\"INVALID_TYPE\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthrow new UsageError(errorMessage);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\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\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), 0xa75 /* 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\t0xa76 /* 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}\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] = constructedModification;\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\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? { edit: treeEdit, diff }\n\t\t\t\t: {\n\t\t\t\t\t\tedit: {\n\t\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdiff,\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\t\t\tconst diff: MoveSingleDiff | MoveRangeDiff = createMoveDiff(treeEdit, idGenerator);\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\tif (destinationArraySchema instanceof ArrayNodeSchema === false) {\n\t\t\t\t\tthrow new UsageError(\"the destination node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (Tree.is(nodeToMove as TreeNode, destinationArraySchema.info)) {\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, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!Tree.is(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} else {\n\t\t\t\tthrow new Error(\"Invalid source for move edit\");\n\t\t\t}\n\t\t\treturn { edit: treeEdit, diff };\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\n/**\n * Produces a useful, context-rich error message to give as a response to the LLM when it has produced an {@link ModifyEdit} that either references a nonexistant field or an invalid type for the selected field.\n * @param errorType - The type of error message to produce. You must determine the error type before calling this function.\n * - `'NONEXISTENT_FIELD'` is used when the field does not exist in the node's schema.\n * - `'INVALID_TYPE'` is used when the field exists but the type of the modification is invalid.\n */\nfunction createInvalidModifyFeedbackMsg(\n\tmodifyEdit: Modify,\n\ttreeNode: TreeNode,\n\terrorType: \"NONEXISTENT_FIELD\" | \"INVALID_TYPE\",\n): string {\n\tconst { treeNodeSchema } = getSimpleNodeSchema(treeNode);\n\tconst nodeFieldSchemas = treeNodeSchema.info as Record<string, ImplicitFieldSchema>;\n\tconst messagePrefix = `You attempted an invalid modify edit on the node with id '${modifyEdit.target.target}' and schema '${treeNodeSchema.identifier}'.`;\n\tlet messageSuffix = \"\";\n\tconst getAllowedTypeIdentifiers = (fieldName: string): string[] => {\n\t\tconst targetFieldNodeSchema = nodeFieldSchemas[fieldName];\n\t\treturn targetFieldNodeSchema instanceof FieldSchema\n\t\t\t? [...targetFieldNodeSchema.allowedTypeSet.values()].map((schema) => schema.identifier)\n\t\t\t: [(targetFieldNodeSchema as TreeNodeSchema).identifier];\n\t};\n\n\tif (errorType === \"NONEXISTENT_FIELD\") {\n\t\tconst nodeFieldNames = Object.keys(nodeFieldSchemas);\n\t\tconst closestPossibleFieldMatch = closest(modifyEdit.field, nodeFieldNames);\n\t\tconst allowedTypeIdentifiers = getAllowedTypeIdentifiers(closestPossibleFieldMatch);\n\t\tconst closestPossibleMatchForFieldMessage = ` If you are sure you are trying to modify this node, did you mean to use the field \\`${closestPossibleFieldMatch}\\` which has the following set of allowed types: \\`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(\", \")}]\\`?`;\n\t\tmessageSuffix = ` The node's field you selected for modification \\`${modifyEdit.field}\\` does not exist in this node's schema. The set of available fields for this node are: \\`[${nodeFieldNames.map((field) => `'${field}'`).join(\", \")}]\\`.${closestPossibleMatchForFieldMessage}`;\n\t} else if (errorType === \"INVALID_TYPE\") {\n\t\tconst allowedTypeIdentifiers = getAllowedTypeIdentifiers(modifyEdit.field);\n\t\t// TODO: If the invalid modification is a new object, it won't be clear what part of the object is invalid for the given type. If we could give some more detailed guidance on what was wrong with the object it would be ideal.\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tmessageSuffix = ` You cannot set the node's field \\`${modifyEdit.field}\\` to the value \\`${modifyEdit.modification}\\` with type \\`${typeof modifyEdit.modification}\\` because this type is incompatible with all of the types allowed by the field's schema. The set of allowed types are \\`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(\", \")}]\\`.`;\n\t}\n\n\treturn messagePrefix + messageSuffix;\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\n/**\n * Gets information about the range of nodes being targeted by an {@link Range}\n */\nexport function 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, 0xa79 /* 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\nconst createNodePathRecursive = (\n\tnode: TreeNode | undefined,\n\tidGenerator: IdGenerator,\n\tcurrentPath: NodePath,\n): NodePath => {\n\tif (node === undefined) {\n\t\treturn currentPath;\n\t}\n\n\tcurrentPath.push({\n\t\tshortId: Tree.shortId(node),\n\t\tschemaIdentifier: Tree.schema(node).identifier,\n\t\tparentField: Tree.key(node),\n\t});\n\n\tconst parentNode = Tree.parent(node);\n\treturn createNodePathRecursive(parentNode, idGenerator, currentPath);\n};\n\n/**\n * Creates a diff for an Insert TreeEdit.\n *\n * @remarks\n * This function is only invoked within the \"insert\" case block.\n *\n * This must only be called AFTER an insertion is made.\n * It generates the insert diff after the node has been successfully inserted, as the node's index may\n * be required to support undoing the insert operation, and we don't know that index until the insert has been made.\n */\nfunction createInsertDiff(\n\tnewlyInsertedNode: TreeNode,\n\taiExplanation: string,\n\tidGenerator: IdGenerator,\n): InsertDiff {\n\treturn {\n\t\ttype: \"insert\",\n\t\tnodePath: createNodePathRecursive(newlyInsertedNode, idGenerator, []),\n\t\tnodeContent: JSON.parse(JSON.stringify(newlyInsertedNode)),\n\t\taiExplanation,\n\t};\n}\n\n/**\n * Returns an object identical to the input except that the special 'objectIdKey' field (only intended for use by the LLM agent) is removed if present.\n * @remarks The input object is not modified.\n */\nfunction removeAgentObjectIdField(oldValue: unknown): unknown {\n\tif (typeof oldValue === \"object\" && oldValue !== null && !Array.isArray(oldValue)) {\n\t\tconst { [objectIdKey]: _, ...rest } = oldValue as Record<string, unknown>;\n\t\treturn rest;\n\t}\n\treturn oldValue;\n}\n\n/**\n * Creates a diff for a Modify TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a modify edit is applied.\n * For move operations, the diff is created before the node(s) have been successfully moved,\n * since the original index is needed to restore the node(s) if the move operation need to undo.\n */\nfunction createModifyDiff(treeEdit: Modify, idGenerator: IdGenerator): ModifyDiff {\n\tconst targetNode = getNodeFromTarget(treeEdit.target, idGenerator);\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\tconst targetNodeAtField: unknown = (targetNode as any)[treeEdit.field];\n\n\tif (isPrimitive(targetNodeAtField)) {\n\t\treturn {\n\t\t\ttype: \"modify\",\n\t\t\tnodePath: createNodePathRecursive(targetNode, idGenerator, [\n\t\t\t\t{\n\t\t\t\t\tshortId: undefined,\n\t\t\t\t\tparentField: treeEdit.field,\n\t\t\t\t\tschemaIdentifier: getSchemaIdentifier(treeEdit.modification),\n\t\t\t\t},\n\t\t\t]),\n\t\t\tnewValue: treeEdit.modification,\n\t\t\toldValue: targetNodeAtField,\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: \"modify\",\n\t\tnodePath: createNodePathRecursive(targetNodeAtField as TreeNode, idGenerator, []),\n\t\tnewValue: treeEdit.modification,\n\t\toldValue: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetNodeAtField))),\n\t\taiExplanation: treeEdit.explanation,\n\t};\n}\n\n/**\n * Creates a diff for a Remove TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a remove edit is applied.\n * It generates the remove diff before the node has been successfully removed, as the node's index may\n * be required to support undoing the remove operation, and we don't know that index until the remove has been made.\n */\nfunction createRemoveDiff(\n\ttreeEdit: Remove,\n\tidGenerator: IdGenerator,\n): RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff {\n\tconst source = treeEdit.source;\n\tif (isObjectTarget(source)) {\n\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\tconst parentNode = Tree.parent(node);\n\t\tif (parentNode === undefined) {\n\t\t\tthrow new Error(\"Unexpectedly received a root node as the target of a remove edit\");\n\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst targetRemovedNode = (parentNode as TreeArrayNode).at(nodeIndex)!;\n\n\t\t\tif (isPrimitive(targetRemovedNode)) {\n\t\t\t\t// Note that this cause should not be possible, still putting the error here in case things change so that this function is updated properly\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unexpectedly recieved a primitive node as the target of a remove edit\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttype: \"remove\",\n\t\t\t\tremovalType: \"remove-array-single\",\n\t\t\t\tnodePath: createNodePathRecursive(targetRemovedNode as TreeNode, idGenerator, []),\n\t\t\t\taiExplanation: treeEdit.explanation,\n\t\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetRemovedNode))),\n\t\t\t};\n\t\t} else {\n\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst targetNodeAtField: unknown = (parentNode as any)[fieldKey];\n\n\t\t\tif (isPrimitive(targetNodeAtField)) {\n\t\t\t\t// Note that this cause should not be possible, still putting the error here in case things change so that this function is updated properly\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unexpectedly recieved a primitive node as the target of a remove field edit\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttype: \"remove\",\n\t\t\t\tremovalType: \"remove-node\",\n\t\t\t\tnodePath: createNodePathRecursive(targetNodeAtField as TreeNode, idGenerator, []),\n\t\t\t\taiExplanation: treeEdit.explanation,\n\t\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetNodeAtField))),\n\t\t\t};\n\t\t}\n\t} else if (isRange(source)) {\n\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\tconst removedNodePaths: NodePath[] = [];\n\t\tconst removedNodes: TreeNode[] = [];\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst nodeToRemove = array.at(i)!;\n\t\t\tif (!isPrimitive(nodeToRemove)) {\n\t\t\t\tremovedNodePaths.push(\n\t\t\t\t\tcreateNodePathRecursive(nodeToRemove as TreeNode, idGenerator, []),\n\t\t\t\t);\n\t\t\t\tremovedNodes.push(nodeToRemove as TreeNode);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\ttype: \"remove\",\n\t\t\tremovalType: \"remove-array-range\",\n\t\t\tnodePaths: removedNodePaths,\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContents: removedNodes.map((node) =>\n\t\t\t\tremoveAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t\t),\n\t\t};\n\t} else {\n\t\tthrow new Error(\"Invalid source encountered when trying to create diff for remove edit\");\n\t}\n}\n\n/**\n * Creates a diff for a Move TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a move edit is applied.\n * For move operations, the diff is created before the node(s) have been successfully moved,\n * since the original index is needed to restore the node(s) if the move operation need to undo.\n */\nfunction createMoveDiff(\n\ttreeEdit: Move,\n\tidGenerator: IdGenerator,\n): MoveSingleDiff | MoveRangeDiff {\n\tconst source = treeEdit.source;\n\tconst destination = treeEdit.destination;\n\tconst { array: destinationArrayNode } = getPlaceInfo(destination, idGenerator);\n\n\tif (isObjectTarget(source)) {\n\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\treturn {\n\t\t\ttype: \"move\",\n\t\t\tmoveType: \"move-single\",\n\t\t\tsourceNodePath: createNodePathRecursive(node, idGenerator, []),\n\t\t\tdestinationNodePath: createNodePathRecursive(destinationArrayNode, idGenerator, []),\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t};\n\t} else if (isRange(source)) {\n\t\tconst {\n\t\t\tarray,\n\t\t\tstartIndex: sourceStartIndex,\n\t\t\tendIndex: sourceEndIndex,\n\t\t} = getRangeInfo(source, idGenerator);\n\n\t\tconst movedNodePaths: NodePath[] = [];\n\t\tconst movedNodes: TreeNode[] = [];\n\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\tconst nodeToMove = array.at(i);\n\t\t\tif (!isPrimitive(nodeToMove)) {\n\t\t\t\tmovedNodePaths.push(createNodePathRecursive(nodeToMove as TreeNode, idGenerator, []));\n\t\t\t\tmovedNodes.push(nodeToMove as TreeNode);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"move\",\n\t\t\tmoveType: \"move-range\",\n\t\t\tsourceNodePaths: movedNodePaths,\n\t\t\tdestinationNodePath: createNodePathRecursive(destinationArrayNode, idGenerator, []),\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContents: movedNodes.map((node) =>\n\t\t\t\tremoveAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t\t),\n\t\t};\n\t} else {\n\t\tthrow new Error(\"Invalid source for move edit\");\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"]}
|
|
@@ -212,7 +212,7 @@ function getDef(defs, ref) {
|
|
|
212
212
|
* TBD
|
|
213
213
|
*/
|
|
214
214
|
export function getFriendlySchemaName(schemaName) {
|
|
215
|
-
const matches =
|
|
215
|
+
const matches = /[^.]+$/.exec(schemaName);
|
|
216
216
|
if (matches === null) {
|
|
217
217
|
// empty scope
|
|
218
218
|
return schemaName;
|