@fluidframework/ai-collab 2.63.0-359286 → 2.63.0-359734

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.
@@ -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,KAAK,gBAAgB,EAOrB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EASX,IAAI,EACJ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,KAAK,QAAQ,EAGb,KAAK,KAAK,EAGV,KAAK,cAAc,EACnB,KAAK,aAAa,EAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA4BpD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,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,CAwPhC;AAkED,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"}
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,KAAK,gBAAgB,EAQrB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EASX,IAAI,EACJ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,KAAK,QAAQ,EAGb,KAAK,KAAK,EAGV,KAAK,cAAc,EACnB,KAAK,aAAa,EAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA4BpD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,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;AAyDD,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"}
@@ -81,9 +81,10 @@ function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator) {
81
81
  populateDefaults(treeEdit.content, definitionMap);
82
82
  const schemaIdentifier = getSchemaIdentifier(treeEdit.content);
83
83
  // We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.
84
- const allowedTypes = [
85
- ...(0, internal_3.normalizeAllowedTypes)(parentNodeSchema.info),
86
- ];
84
+ if (!(parentNodeSchema instanceof internal_3.ArrayNodeSchema)) {
85
+ throw new internal_2.UsageError("the parent node must be an arrayNode");
86
+ }
87
+ const allowedTypes = (0, internal_3.normalizeAllowedTypes)(parentNodeSchema.info).evaluate();
87
88
  for (const allowedType of allowedTypes.values()) {
88
89
  if (allowedType.identifier === schemaIdentifier && typeof allowedType === "function") {
89
90
  const simpleNodeSchema = allowedType;
@@ -242,12 +243,12 @@ function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator) {
242
243
  throw new internal_2.UsageError("the source node must be within an arrayNode");
243
244
  }
244
245
  const destinationArraySchema = internal_3.Tree.schema(destinationArrayNode);
245
- const allowedTypes = [
246
- ...(0, internal_3.normalizeAllowedTypes)(destinationArraySchema.info),
247
- ];
246
+ if (destinationArraySchema instanceof internal_3.ArrayNodeSchema === false) {
247
+ throw new internal_2.UsageError("the destination node must be within an arrayNode");
248
+ }
248
249
  const nodeToMove = sourceArrayNode.at(sourceIndex);
249
250
  (0, internal_1.assert)(nodeToMove !== undefined, 0xa77 /* node to move must exist */);
250
- if (isNodeAllowedType(nodeToMove, allowedTypes)) {
251
+ if (internal_3.Tree.is(nodeToMove, destinationArraySchema.info)) {
251
252
  destinationArrayNode.moveRangeToIndex(destinationIndex, sourceIndex, sourceIndex + 1, sourceArrayNode);
252
253
  }
253
254
  else {
@@ -263,7 +264,7 @@ function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator) {
263
264
  for (let i = sourceStartIndex; i < sourceEndIndex; i++) {
264
265
  const nodeToMove = array.at(i);
265
266
  (0, internal_1.assert)(nodeToMove !== undefined, 0xa78 /* node to move must exist */);
266
- if (!isNodeAllowedType(nodeToMove, allowedTypes)) {
267
+ if (!internal_3.Tree.is(nodeToMove, allowedTypes)) {
267
268
  throw new internal_2.UsageError("Illegal node type in destination array");
268
269
  }
269
270
  }
@@ -311,14 +312,6 @@ function createInvalidModifyFeedbackMsg(modifyEdit, treeNode, errorType) {
311
312
  }
312
313
  return messagePrefix + messageSuffix;
313
314
  }
314
- function isNodeAllowedType(node, allowedTypes) {
315
- for (const allowedType of allowedTypes) {
316
- if (internal_3.Tree.is(node, allowedType)) {
317
- return true;
318
- }
319
- }
320
- return false;
321
- }
322
315
  function isPrimitive(content) {
323
316
  return (typeof content === "number" ||
324
317
  typeof content === "string" ||
@@ -1 +1 @@
1
- {"version":3,"file":"agentEditReducer.js","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,iEAA8D;AAC9D,uEAAoF;AACpF,4DAcuC;AACvC,6DAA8C;AAc9C,2DAc6B;AAG7B,+DAAwD;AACxD,yCAAkC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAA,iBAAM,EACL,OAAO,IAAI,CAAC,6BAAS,CAAC,KAAK,QAAQ,EACnC,KAAK,CAAC,uDAAuD,CAC7D,CAAC;YACF,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,6BAAS,CAAC,CAAC,CAAC;YACtD,IAAA,iBAAM,EAAC,UAAU,EAAE,IAAI,KAAK,mBAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,4BAA4B,CAAC,CAA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AACF,CAAC;AAOD,SAAS,mBAAmB,CAAC,IAAc;IAC1C,MAAM,cAAc,GAAG,eAAI,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} 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\tconst allowedTypes = [\n\t\t\t\t...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),\n\t\t\t];\n\n\t\t\tfor (const allowedType of allowedTypes.values()) {\n\t\t\t\tif (allowedType.identifier === schemaIdentifier && typeof allowedType === \"function\") {\n\t\t\t\t\tconst simpleNodeSchema = allowedType as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\t\tconst insertNode = new simpleNodeSchema(treeEdit.content);\n\t\t\t\t\tvalidator?.(insertNode);\n\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\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t} 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 isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {\n\tfor (const allowedType of allowedTypes) {\n\t\tif (Tree.is(node, allowedType)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\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,kEAA6D;AAC7D,iEAA8D;AAC9D,uEAAoF;AACpF,4DAeuC;AACvC,6DAA8C;AAc9C,2DAc6B;AAG7B,+DAAwD;AACxD,yCAAkC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAA,iBAAM,EACL,OAAO,IAAI,CAAC,6BAAS,CAAC,KAAK,QAAQ,EACnC,KAAK,CAAC,uDAAuD,CAC7D,CAAC;YACF,MAAM,UAAU,GAAG,aAAa,CAA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1D;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,eAAI,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 +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,KAAK,gBAAgB,EAOrB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EASX,IAAI,EACJ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,KAAK,QAAQ,EAGb,KAAK,KAAK,EAGV,KAAK,cAAc,EACnB,KAAK,aAAa,EAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA4BpD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,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,WA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KAAK,IAAI,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAyPhC;AAyDD,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"}
@@ -5,7 +5,7 @@
5
5
  import { assert } from "@fluidframework/core-utils/internal";
6
6
  import { isFluidHandle } from "@fluidframework/runtime-utils";
7
7
  import { isFluidError, UsageError } from "@fluidframework/telemetry-utils/internal";
8
- import { Tree, NodeKind, FieldKind, FieldSchema, normalizeAllowedTypes, SchemaFactory, } from "@fluidframework/tree/internal";
8
+ import { Tree, NodeKind, FieldKind, FieldSchema, normalizeAllowedTypes, SchemaFactory, ArrayNodeSchema, } from "@fluidframework/tree/internal";
9
9
  import { closest } from "fastest-levenshtein";
10
10
  import { typeField, objectIdKey, } from "./agentEditTypes.js";
11
11
  import { toDecoratedJson } from "./promptGeneration.js";
@@ -76,9 +76,10 @@ export function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator)
76
76
  populateDefaults(treeEdit.content, definitionMap);
77
77
  const schemaIdentifier = getSchemaIdentifier(treeEdit.content);
78
78
  // We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.
79
- const allowedTypes = [
80
- ...normalizeAllowedTypes(parentNodeSchema.info),
81
- ];
79
+ if (!(parentNodeSchema instanceof ArrayNodeSchema)) {
80
+ throw new UsageError("the parent node must be an arrayNode");
81
+ }
82
+ const allowedTypes = normalizeAllowedTypes(parentNodeSchema.info).evaluate();
82
83
  for (const allowedType of allowedTypes.values()) {
83
84
  if (allowedType.identifier === schemaIdentifier && typeof allowedType === "function") {
84
85
  const simpleNodeSchema = allowedType;
@@ -237,12 +238,12 @@ export function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator)
237
238
  throw new UsageError("the source node must be within an arrayNode");
238
239
  }
239
240
  const destinationArraySchema = Tree.schema(destinationArrayNode);
240
- const allowedTypes = [
241
- ...normalizeAllowedTypes(destinationArraySchema.info),
242
- ];
241
+ if (destinationArraySchema instanceof ArrayNodeSchema === false) {
242
+ throw new UsageError("the destination node must be within an arrayNode");
243
+ }
243
244
  const nodeToMove = sourceArrayNode.at(sourceIndex);
244
245
  assert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);
245
- if (isNodeAllowedType(nodeToMove, allowedTypes)) {
246
+ if (Tree.is(nodeToMove, destinationArraySchema.info)) {
246
247
  destinationArrayNode.moveRangeToIndex(destinationIndex, sourceIndex, sourceIndex + 1, sourceArrayNode);
247
248
  }
248
249
  else {
@@ -258,7 +259,7 @@ export function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator)
258
259
  for (let i = sourceStartIndex; i < sourceEndIndex; i++) {
259
260
  const nodeToMove = array.at(i);
260
261
  assert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);
261
- if (!isNodeAllowedType(nodeToMove, allowedTypes)) {
262
+ if (!Tree.is(nodeToMove, allowedTypes)) {
262
263
  throw new UsageError("Illegal node type in destination array");
263
264
  }
264
265
  }
@@ -305,14 +306,6 @@ function createInvalidModifyFeedbackMsg(modifyEdit, treeNode, errorType) {
305
306
  }
306
307
  return messagePrefix + messageSuffix;
307
308
  }
308
- function isNodeAllowedType(node, allowedTypes) {
309
- for (const allowedType of allowedTypes) {
310
- if (Tree.is(node, allowedType)) {
311
- return true;
312
- }
313
- }
314
- return false;
315
- }
316
309
  function isPrimitive(content) {
317
310
  return (typeof content === "number" ||
318
311
  typeof content === "string" ||
@@ -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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MAAM,UAAU,GAAe,EAAE,CAAC;QAClC,KAAK,IAAI,CAAC,GAAG,gBAAgB,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC,EAAE,EAAE,CAAC;YACxD,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC9B,cAAc,CAAC,IAAI,CAAC,uBAAuB,CAAC,UAAsB,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;gBACtF,UAAU,CAAC,IAAI,CAAC,UAAsB,CAAC,CAAC;YACzC,CAAC;QACF,CAAC;QAED,OAAO;YACN,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,YAAY;YACtB,eAAe,EAAE,cAAc;YAC/B,mBAAmB,EAAE,uBAAuB,CAAC,oBAAoB,EAAE,WAAW,EAAE,EAAE,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} 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\tconst allowedTypes = [\n\t\t\t\t...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),\n\t\t\t];\n\n\t\t\tfor (const allowedType of allowedTypes.values()) {\n\t\t\t\tif (allowedType.identifier === schemaIdentifier && typeof allowedType === \"function\") {\n\t\t\t\t\tconst simpleNodeSchema = allowedType as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\t\tconst insertNode = new simpleNodeSchema(treeEdit.content);\n\t\t\t\t\tvalidator?.(insertNode);\n\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\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t} 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 isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {\n\tfor (const allowedType of allowedTypes) {\n\t\tif (Tree.is(node, allowedType)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\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,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,CACL,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,QAAQ,EACnC,KAAK,CAAC,uDAAuD,CAC7D,CAAC;YACF,MAAM,UAAU,GAAG,aAA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I,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/ai-collab",
3
- "version": "2.63.0-359286",
3
+ "version": "2.63.0-359734",
4
4
  "description": "Experimental package to simplify integrating AI into Fluid-based applications",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -69,10 +69,10 @@
69
69
  "temp-directory": "nyc/.nyc_output"
70
70
  },
71
71
  "dependencies": {
72
- "@fluidframework/core-utils": "2.63.0-359286",
73
- "@fluidframework/runtime-utils": "2.63.0-359286",
74
- "@fluidframework/telemetry-utils": "2.63.0-359286",
75
- "@fluidframework/tree": "2.63.0-359286",
72
+ "@fluidframework/core-utils": "2.63.0-359734",
73
+ "@fluidframework/runtime-utils": "2.63.0-359734",
74
+ "@fluidframework/telemetry-utils": "2.63.0-359734",
75
+ "@fluidframework/tree": "2.63.0-359734",
76
76
  "fastest-levenshtein": "^1.0.16",
77
77
  "openai": "^4.67.3",
78
78
  "typechat": "^0.1.1",
@@ -82,14 +82,14 @@
82
82
  "devDependencies": {
83
83
  "@arethetypeswrong/cli": "^0.17.1",
84
84
  "@biomejs/biome": "~1.9.3",
85
- "@fluid-internal/mocha-test-setup": "2.63.0-359286",
85
+ "@fluid-internal/mocha-test-setup": "2.63.0-359734",
86
86
  "@fluid-tools/build-cli": "^0.58.3",
87
87
  "@fluidframework/build-common": "^2.0.3",
88
88
  "@fluidframework/build-tools": "^0.58.3",
89
89
  "@fluidframework/eslint-config-fluid": "^6.0.0",
90
- "@fluidframework/id-compressor": "2.63.0-359286",
91
- "@fluidframework/runtime-utils": "2.63.0-359286",
92
- "@fluidframework/test-runtime-utils": "2.63.0-359286",
90
+ "@fluidframework/id-compressor": "2.63.0-359734",
91
+ "@fluidframework/runtime-utils": "2.63.0-359734",
92
+ "@fluidframework/test-runtime-utils": "2.63.0-359734",
93
93
  "@microsoft/api-extractor": "7.52.11",
94
94
  "@types/mocha": "^10.0.10",
95
95
  "@types/node": "^18.19.0",
@@ -20,6 +20,7 @@ import {
20
20
  type ImplicitFieldSchema,
21
21
  type IterableTreeArrayContent,
22
22
  SchemaFactory,
23
+ ArrayNodeSchema,
23
24
  } from "@fluidframework/tree/internal";
24
25
  import { closest } from "fastest-levenshtein";
25
26
 
@@ -138,9 +139,10 @@ export function applyAgentEdit(
138
139
  const schemaIdentifier = getSchemaIdentifier(treeEdit.content);
139
140
 
140
141
  // We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.
141
- const allowedTypes = [
142
- ...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),
143
- ];
142
+ if (!(parentNodeSchema instanceof ArrayNodeSchema)) {
143
+ throw new UsageError("the parent node must be an arrayNode");
144
+ }
145
+ const allowedTypes = normalizeAllowedTypes(parentNodeSchema.info).evaluate();
144
146
 
145
147
  for (const allowedType of allowedTypes.values()) {
146
148
  if (allowedType.identifier === schemaIdentifier && typeof allowedType === "function") {
@@ -327,12 +329,12 @@ export function applyAgentEdit(
327
329
  throw new UsageError("the source node must be within an arrayNode");
328
330
  }
329
331
  const destinationArraySchema = Tree.schema(destinationArrayNode);
330
- const allowedTypes = [
331
- ...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),
332
- ];
332
+ if (destinationArraySchema instanceof ArrayNodeSchema === false) {
333
+ throw new UsageError("the destination node must be within an arrayNode");
334
+ }
333
335
  const nodeToMove = sourceArrayNode.at(sourceIndex);
334
336
  assert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);
335
- if (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {
337
+ if (Tree.is(nodeToMove as TreeNode, destinationArraySchema.info)) {
336
338
  destinationArrayNode.moveRangeToIndex(
337
339
  destinationIndex,
338
340
  sourceIndex,
@@ -355,7 +357,7 @@ export function applyAgentEdit(
355
357
  for (let i = sourceStartIndex; i < sourceEndIndex; i++) {
356
358
  const nodeToMove = array.at(i);
357
359
  assert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);
358
- if (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {
360
+ if (!Tree.is(nodeToMove as TreeNode, allowedTypes)) {
359
361
  throw new UsageError("Illegal node type in destination array");
360
362
  }
361
363
  }
@@ -413,15 +415,6 @@ function createInvalidModifyFeedbackMsg(
413
415
  return messagePrefix + messageSuffix;
414
416
  }
415
417
 
416
- function isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {
417
- for (const allowedType of allowedTypes) {
418
- if (Tree.is(node, allowedType)) {
419
- return true;
420
- }
421
- }
422
- return false;
423
- }
424
-
425
418
  function isPrimitive(content: unknown): boolean {
426
419
  return (
427
420
  typeof content === "number" ||