@fluidframework/ai-collab 2.73.0 → 2.74.0-365691
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -1
- package/dist/explicit-strategy/agentEditReducer.js +2 -1
- package/dist/explicit-strategy/agentEditReducer.js.map +1 -1
- package/dist/explicit-strategy/promptGeneration.js +1 -1
- package/dist/explicit-strategy/promptGeneration.js.map +1 -1
- package/dist/implicit-strategy/sharedTreeDiff.js +1 -1
- package/dist/implicit-strategy/sharedTreeDiff.js.map +1 -1
- package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -1
- package/lib/explicit-strategy/agentEditReducer.js +2 -1
- package/lib/explicit-strategy/agentEditReducer.js.map +1 -1
- package/lib/explicit-strategy/promptGeneration.js +1 -1
- package/lib/explicit-strategy/promptGeneration.js.map +1 -1
- package/lib/implicit-strategy/sharedTreeDiff.js +1 -1
- package/lib/implicit-strategy/sharedTreeDiff.js.map +1 -1
- package/package.json +10 -10
- package/src/explicit-strategy/agentEditReducer.ts +3 -2
- package/src/explicit-strategy/promptGeneration.ts +1 -1
- package/src/implicit-strategy/sharedTreeDiff.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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;A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AAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAyPhC;AA0DD,UAAU,SAAS;IAClB,KAAK,EAAE,aAAa,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,GAAG,SAAS,CAW9E"}
|
|
@@ -169,7 +169,7 @@ function applyAgentEdit(treeEdit, idGenerator, definitionMap, validator) {
|
|
|
169
169
|
throw error;
|
|
170
170
|
}
|
|
171
171
|
// 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.
|
|
172
|
-
const isInvalidTypeError =
|
|
172
|
+
const isInvalidTypeError = /The provided data is incompatible with all of the types allowed by the schema./.exec(error.message) !== null;
|
|
173
173
|
if (isInvalidTypeError === true) {
|
|
174
174
|
const errorMessage = createInvalidModifyFeedbackMsg(treeEdit, node, "INVALID_TYPE");
|
|
175
175
|
throw new internal_2.UsageError(errorMessage);
|
|
@@ -308,6 +308,7 @@ function createInvalidModifyFeedbackMsg(modifyEdit, treeNode, errorType) {
|
|
|
308
308
|
else if (errorType === "INVALID_TYPE") {
|
|
309
309
|
const allowedTypeIdentifiers = getAllowedTypeIdentifiers(modifyEdit.field);
|
|
310
310
|
// 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.
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
311
312
|
messageSuffix = ` You cannot set the node's field \`${modifyEdit.field}\` to the value \`${modifyEdit.modification}\` with type \`${typeof modifyEdit.modification}\` because this type is incompatible with all of the types allowed by the field's schema. The set of allowed types are \`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(", ")}]\`.`;
|
|
312
313
|
}
|
|
313
314
|
return messagePrefix + messageSuffix;
|
|
@@ -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,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,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,CAAC;QAClF,CAAC;IACF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,OAAsB;IACzD,QAAQ,OAAO,OAAO,EAAE,CAAC;QACxB,KAAK,SAAS,CAAC,CAAC,CAAC;YAChB,OAAO,wBAAa,CAAC,OAAO,CAAC,UAAU,CAAC;QACzC,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACf,OAAO,wBAAa,CAAC,MAAM,CAAC,UAAU,CAA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ACtC,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,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
|
+
{"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,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,CAAC;QAClF,CAAC;IACF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,OAAsB;IACzD,QAAQ,OAAO,OAAO,EAAE,CAAC;QACxB,KAAK,SAAS,CAAC,CAAC,CAAC;YAChB,OAAO,wBAAa,CAAC,OAAO,CAAC,UAAU,CAAC;QACzC,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACf,OAAO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AAC,CAAC;QAEtC,MAAM,cAAc,GAAe,EAAE,CAAC;QACtC,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,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\t/The provided data is incompatible with all of the types allowed by the schema./.exec(\n\t\t\t\t\t\t\terror.message,\n\t\t\t\t\t\t) !== null;\n\t\t\t\t\tif (isInvalidTypeError === true) {\n\t\t\t\t\t\tconst errorMessage = createInvalidModifyFeedbackMsg(\n\t\t\t\t\t\t\ttreeEdit,\n\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\"INVALID_TYPE\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthrow new UsageError(errorMessage);\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If the fieldSchema is a function we can grab the constructor and make an instance of that node.\n\t\t\telse if (typeof fieldSchema === \"function\") {\n\t\t\t\tconst simpleSchema = fieldSchema as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\tpopulateDefaults(modification, definitionMap);\n\t\t\t\tconst constructedModification = new simpleSchema(modification);\n\t\t\t\tvalidator?.(constructedModification);\n\n\t\t\t\tinsertedObject = constructedModification;\n\n\t\t\t\tif (Array.isArray(modification)) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst field = (node as any)[treeEdit.field] as TreeArrayNode;\n\t\t\t\t\tassert(Array.isArray(field), 0xa75 /* the field must be an array node */);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tArray.isArray(constructedModification),\n\t\t\t\t\t\t0xa76 /* the modification must be an array node */,\n\t\t\t\t\t);\n\t\t\t\t\tfield.removeRange(0);\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t}\n\t\t\t// If the fieldSchema is of type FieldSchema, we can check its allowed types and set the field.\n\t\t\telse if (fieldSchema instanceof FieldSchema) {\n\t\t\t\tif (fieldSchema.kind === FieldKind.Optional && modification === undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tfor (const allowedType of fieldSchema.allowedTypeSet.values()) {\n\t\t\t\t\t\tif (allowedType.identifier === schemaIdentifier) {\n\t\t\t\t\t\t\tif (typeof allowedType === \"function\") {\n\t\t\t\t\t\t\t\tconst simpleSchema = allowedType as unknown as new (\n\t\t\t\t\t\t\t\t\tdummy: unknown,\n\t\t\t\t\t\t\t\t) => TreeNode;\n\t\t\t\t\t\t\t\tconst constructedObject = new simpleSchema(modification);\n\t\t\t\t\t\t\t\tinsertedObject = constructedObject;\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = constructedObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? { edit: treeEdit, diff }\n\t\t\t\t: {\n\t\t\t\t\t\tedit: {\n\t\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdiff,\n\t\t\t\t\t};\n\t\t}\n\t\tcase \"move\": {\n\t\t\t// TODO: need to add schema check for valid moves\n\t\t\tconst source = treeEdit.source;\n\t\t\tconst destination = treeEdit.destination;\n\t\t\tconst { array: destinationArrayNode, index: destinationIndex } = getPlaceInfo(\n\t\t\t\tdestination,\n\t\t\t\tidGenerator,\n\t\t\t);\n\t\t\tconst diff: MoveSingleDiff | MoveRangeDiff = createMoveDiff(treeEdit, idGenerator);\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst sourceNode = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst sourceIndex = Tree.key(sourceNode) as number;\n\t\t\t\tconst sourceArrayNode = Tree.parent(sourceNode) as TreeArrayNode;\n\t\t\t\tconst sourceArraySchema = Tree.schema(sourceArrayNode);\n\t\t\t\tif (sourceArraySchema.kind !== NodeKind.Array) {\n\t\t\t\t\tthrow new UsageError(\"the source node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tif (destinationArraySchema instanceof ArrayNodeSchema === false) {\n\t\t\t\t\tthrow new UsageError(\"the destination node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (Tree.is(nodeToMove as TreeNode, destinationArraySchema.info)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!Tree.is(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new Error(\"Invalid source for move edit\");\n\t\t\t}\n\t\t\treturn { edit: treeEdit, diff };\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\n/**\n * Produces a useful, context-rich error message to give as a response to the LLM when it has produced an {@link ModifyEdit} that either references a nonexistant field or an invalid type for the selected field.\n * @param errorType - The type of error message to produce. You must determine the error type before calling this function.\n * - `'NONEXISTENT_FIELD'` is used when the field does not exist in the node's schema.\n * - `'INVALID_TYPE'` is used when the field exists but the type of the modification is invalid.\n */\nfunction createInvalidModifyFeedbackMsg(\n\tmodifyEdit: Modify,\n\ttreeNode: TreeNode,\n\terrorType: \"NONEXISTENT_FIELD\" | \"INVALID_TYPE\",\n): string {\n\tconst { treeNodeSchema } = getSimpleNodeSchema(treeNode);\n\tconst nodeFieldSchemas = treeNodeSchema.info as Record<string, ImplicitFieldSchema>;\n\tconst messagePrefix = `You attempted an invalid modify edit on the node with id '${modifyEdit.target.target}' and schema '${treeNodeSchema.identifier}'.`;\n\tlet messageSuffix = \"\";\n\tconst getAllowedTypeIdentifiers = (fieldName: string): string[] => {\n\t\tconst targetFieldNodeSchema = nodeFieldSchemas[fieldName];\n\t\treturn targetFieldNodeSchema instanceof FieldSchema\n\t\t\t? [...targetFieldNodeSchema.allowedTypeSet.values()].map((schema) => schema.identifier)\n\t\t\t: [(targetFieldNodeSchema as TreeNodeSchema).identifier];\n\t};\n\n\tif (errorType === \"NONEXISTENT_FIELD\") {\n\t\tconst nodeFieldNames = Object.keys(nodeFieldSchemas);\n\t\tconst closestPossibleFieldMatch = closest(modifyEdit.field, nodeFieldNames);\n\t\tconst allowedTypeIdentifiers = getAllowedTypeIdentifiers(closestPossibleFieldMatch);\n\t\tconst closestPossibleMatchForFieldMessage = ` If you are sure you are trying to modify this node, did you mean to use the field \\`${closestPossibleFieldMatch}\\` which has the following set of allowed types: \\`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(\", \")}]\\`?`;\n\t\tmessageSuffix = ` The node's field you selected for modification \\`${modifyEdit.field}\\` does not exist in this node's schema. The set of available fields for this node are: \\`[${nodeFieldNames.map((field) => `'${field}'`).join(\", \")}]\\`.${closestPossibleMatchForFieldMessage}`;\n\t} else if (errorType === \"INVALID_TYPE\") {\n\t\tconst allowedTypeIdentifiers = getAllowedTypeIdentifiers(modifyEdit.field);\n\t\t// TODO: If the invalid modification is a new object, it won't be clear what part of the object is invalid for the given type. If we could give some more detailed guidance on what was wrong with the object it would be ideal.\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tmessageSuffix = ` You cannot set the node's field \\`${modifyEdit.field}\\` to the value \\`${modifyEdit.modification}\\` with type \\`${typeof modifyEdit.modification}\\` because this type is incompatible with all of the types allowed by the field's schema. The set of allowed types are \\`[${allowedTypeIdentifiers.map((id) => `'${id}'`).join(\", \")}]\\`.`;\n\t}\n\n\treturn messagePrefix + messageSuffix;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\n/**\n * Gets information about the range of nodes being targeted by an {@link Range}\n */\nexport function getRangeInfo(range: Range, idGenerator: IdGenerator): RangeInfo {\n\tconst { array: arrayFrom, index: startIndex } = getPlaceInfo(range.from, idGenerator);\n\tconst { array: arrayTo, index: endIndex } = getPlaceInfo(range.to, idGenerator);\n\n\tif (arrayFrom !== arrayTo) {\n\t\tthrow new UsageError(\n\t\t\t'The \"from\" node and \"to\" nodes of the range must be in the same parent array.',\n\t\t);\n\t}\n\n\treturn { array: arrayFrom, startIndex, endIndex };\n}\n\nfunction getPlaceInfo(\n\tplace: ObjectPlace | ArrayPlace,\n\tidGenerator: IdGenerator,\n): {\n\tarray: TreeArrayNode;\n\tindex: number;\n} {\n\tif (place.type === \"arrayPlace\") {\n\t\tconst parent = idGenerator.getNode(place.parentId) ?? fail(\"Expected parent node\");\n\t\tconst child = (parent as unknown as Record<string, unknown>)[place.field];\n\t\tif (child === undefined) {\n\t\t\tthrow new UsageError(`No child under field field`);\n\t\t}\n\t\tconst schema = Tree.schema(child as TreeNode);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: child as TreeArrayNode,\n\t\t\tindex: place.location === \"start\" ? 0 : (child as TreeArrayNode).length,\n\t\t};\n\t} else {\n\t\tconst node = getNodeFromTarget(place, idGenerator);\n\t\tconst nodeIndex = Tree.key(node);\n\t\tconst parent = Tree.parent(node);\n\t\tif (parent === undefined) {\n\t\t\tthrow new UsageError(\"TODO: root node target not supported\");\n\t\t}\n\t\tconst schema = Tree.schema(parent);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: parent as unknown as TreeArrayNode,\n\t\t\tindex: place.place === \"before\" ? (nodeIndex as number) : (nodeIndex as number) + 1,\n\t\t};\n\t}\n}\n\n/**\n * Returns the target node with the matching internal objectId using the provided {@link ObjectTarget}\n */\nfunction getNodeFromTarget(target: ObjectTarget, idGenerator: IdGenerator): TreeNode {\n\tconst node = idGenerator.getNode(target.target);\n\tassert(node !== undefined, 0xa79 /* objectId does not exist in nodeMap */);\n\treturn node;\n}\n\n/**\n * Checks that the objectIds of the Tree Nodes within the givin the {@link TreeEdit} exist within the given {@link IdGenerator}\n *\n * @throws An {@link UsageError} if the objectIdKey does not exist in the {@link IdGenerator}\n */\nfunction assertObjectIdsExist(treeEdit: TreeEdit, idGenerator: IdGenerator): void {\n\tswitch (treeEdit.type) {\n\t\tcase \"insert\": {\n\t\t\tif (treeEdit.destination.type === \"objectPlace\") {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.target) === undefined) {\n\t\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.destination.target} does not exist`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.parentId) === undefined) {\n\t\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.destination.parentId} does not exist`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"remove\": {\n\t\t\tif (isRange(treeEdit.source)) {\n\t\t\t\tconst missingObjectIds = [\n\t\t\t\t\ttreeEdit.source.from.target,\n\t\t\t\t\ttreeEdit.source.to.target,\n\t\t\t\t].filter((id) => !idGenerator.getNode(id));\n\n\t\t\t\tif (missingObjectIds.length > 0) {\n\t\t\t\t\tthrow new UsageError(`objectIdKeys [${missingObjectIds}] does not exist`);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisObjectTarget(treeEdit.source) &&\n\t\t\t\tidGenerator.getNode(treeEdit.source.target) === undefined\n\t\t\t) {\n\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.source.target} does not exist`);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"modify\": {\n\t\t\tif (idGenerator.getNode(treeEdit.target.target) === undefined) {\n\t\t\t\tthrow new UsageError(`objectIdKey ${treeEdit.target.target} does not exist`);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"move\": {\n\t\t\tconst invalidObjectIds: string[] = [];\n\t\t\t// check the source\n\t\t\tif (isRange(treeEdit.source)) {\n\t\t\t\tconst missingObjectIds = [\n\t\t\t\t\ttreeEdit.source.from.target,\n\t\t\t\t\ttreeEdit.source.to.target,\n\t\t\t\t].filter((id) => !idGenerator.getNode(id));\n\n\t\t\t\tif (missingObjectIds.length > 0) {\n\t\t\t\t\tinvalidObjectIds.push(...missingObjectIds);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisObjectTarget(treeEdit.source) &&\n\t\t\t\tidGenerator.getNode(treeEdit.source.target) === undefined\n\t\t\t) {\n\t\t\t\tinvalidObjectIds.push(treeEdit.source.target);\n\t\t\t}\n\n\t\t\t// check the destination\n\t\t\tif (treeEdit.destination.type === \"objectPlace\") {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.target) === undefined) {\n\t\t\t\t\tinvalidObjectIds.push(treeEdit.destination.target);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (idGenerator.getNode(treeEdit.destination.parentId) === undefined) {\n\t\t\t\t\tinvalidObjectIds.push(treeEdit.destination.parentId);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (invalidObjectIds.length > 0) {\n\t\t\t\tthrow new UsageError(`objectIdKeys [${invalidObjectIds}] does not exist`);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tbreak;\n\t\t}\n\t}\n}\n\nconst createNodePathRecursive = (\n\tnode: TreeNode | undefined,\n\tidGenerator: IdGenerator,\n\tcurrentPath: NodePath,\n): NodePath => {\n\tif (node === undefined) {\n\t\treturn currentPath;\n\t}\n\n\tcurrentPath.push({\n\t\tshortId: Tree.shortId(node),\n\t\tschemaIdentifier: Tree.schema(node).identifier,\n\t\tparentField: Tree.key(node),\n\t});\n\n\tconst parentNode = Tree.parent(node);\n\treturn createNodePathRecursive(parentNode, idGenerator, currentPath);\n};\n\n/**\n * Creates a diff for an Insert TreeEdit.\n *\n * @remarks\n * This function is only invoked within the \"insert\" case block.\n *\n * This must only be called AFTER an insertion is made.\n * It generates the insert diff after the node has been successfully inserted, as the node's index may\n * be required to support undoing the insert operation, and we don't know that index until the insert has been made.\n */\nfunction createInsertDiff(\n\tnewlyInsertedNode: TreeNode,\n\taiExplanation: string,\n\tidGenerator: IdGenerator,\n): InsertDiff {\n\treturn {\n\t\ttype: \"insert\",\n\t\tnodePath: createNodePathRecursive(newlyInsertedNode, idGenerator, []),\n\t\tnodeContent: JSON.parse(JSON.stringify(newlyInsertedNode)),\n\t\taiExplanation,\n\t};\n}\n\n/**\n * Returns an object identical to the input except that the special 'objectIdKey' field (only intended for use by the LLM agent) is removed if present.\n * @remarks The input object is not modified.\n */\nfunction removeAgentObjectIdField(oldValue: unknown): unknown {\n\tif (typeof oldValue === \"object\" && oldValue !== null && !Array.isArray(oldValue)) {\n\t\tconst { [objectIdKey]: _, ...rest } = oldValue as Record<string, unknown>;\n\t\treturn rest;\n\t}\n\treturn oldValue;\n}\n\n/**\n * Creates a diff for a Modify TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a modify edit is applied.\n * For move operations, the diff is created before the node(s) have been successfully moved,\n * since the original index is needed to restore the node(s) if the move operation need to undo.\n */\nfunction createModifyDiff(treeEdit: Modify, idGenerator: IdGenerator): ModifyDiff {\n\tconst targetNode = getNodeFromTarget(treeEdit.target, idGenerator);\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\tconst targetNodeAtField: unknown = (targetNode as any)[treeEdit.field];\n\n\tif (isPrimitive(targetNodeAtField)) {\n\t\treturn {\n\t\t\ttype: \"modify\",\n\t\t\tnodePath: createNodePathRecursive(targetNode, idGenerator, [\n\t\t\t\t{\n\t\t\t\t\tshortId: undefined,\n\t\t\t\t\tparentField: treeEdit.field,\n\t\t\t\t\tschemaIdentifier: getSchemaIdentifier(treeEdit.modification),\n\t\t\t\t},\n\t\t\t]),\n\t\t\tnewValue: treeEdit.modification,\n\t\t\toldValue: targetNodeAtField,\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: \"modify\",\n\t\tnodePath: createNodePathRecursive(targetNodeAtField as TreeNode, idGenerator, []),\n\t\tnewValue: treeEdit.modification,\n\t\toldValue: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetNodeAtField))),\n\t\taiExplanation: treeEdit.explanation,\n\t};\n}\n\n/**\n * Creates a diff for a Remove TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a remove edit is applied.\n * It generates the remove diff before the node has been successfully removed, as the node's index may\n * be required to support undoing the remove operation, and we don't know that index until the remove has been made.\n */\nfunction createRemoveDiff(\n\ttreeEdit: Remove,\n\tidGenerator: IdGenerator,\n): RemoveNodeDiff | ArraySingleRemoveDiff | ArrayRangeRemoveDiff {\n\tconst source = treeEdit.source;\n\tif (isObjectTarget(source)) {\n\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\tconst parentNode = Tree.parent(node);\n\t\tif (parentNode === undefined) {\n\t\t\tthrow new Error(\"Unexpectedly received a root node as the target of a remove edit\");\n\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst targetRemovedNode = (parentNode as TreeArrayNode).at(nodeIndex)!;\n\n\t\t\tif (isPrimitive(targetRemovedNode)) {\n\t\t\t\t// Note that this cause should not be possible, still putting the error here in case things change so that this function is updated properly\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unexpectedly recieved a primitive node as the target of a remove edit\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttype: \"remove\",\n\t\t\t\tremovalType: \"remove-array-single\",\n\t\t\t\tnodePath: createNodePathRecursive(targetRemovedNode as TreeNode, idGenerator, []),\n\t\t\t\taiExplanation: treeEdit.explanation,\n\t\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetRemovedNode))),\n\t\t\t};\n\t\t} else {\n\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst targetNodeAtField: unknown = (parentNode as any)[fieldKey];\n\n\t\t\tif (isPrimitive(targetNodeAtField)) {\n\t\t\t\t// Note that this cause should not be possible, still putting the error here in case things change so that this function is updated properly\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unexpectedly recieved a primitive node as the target of a remove field edit\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\ttype: \"remove\",\n\t\t\t\tremovalType: \"remove-node\",\n\t\t\t\tnodePath: createNodePathRecursive(targetNodeAtField as TreeNode, idGenerator, []),\n\t\t\t\taiExplanation: treeEdit.explanation,\n\t\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(targetNodeAtField))),\n\t\t\t};\n\t\t}\n\t} else if (isRange(source)) {\n\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\tconst removedNodePaths: NodePath[] = [];\n\t\tconst removedNodes: TreeNode[] = [];\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst nodeToRemove = array.at(i)!;\n\t\t\tif (!isPrimitive(nodeToRemove)) {\n\t\t\t\tremovedNodePaths.push(\n\t\t\t\t\tcreateNodePathRecursive(nodeToRemove as TreeNode, idGenerator, []),\n\t\t\t\t);\n\t\t\t\tremovedNodes.push(nodeToRemove as TreeNode);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\ttype: \"remove\",\n\t\t\tremovalType: \"remove-array-range\",\n\t\t\tnodePaths: removedNodePaths,\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContents: removedNodes.map((node) =>\n\t\t\t\tremoveAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t\t),\n\t\t};\n\t} else {\n\t\tthrow new Error(\"Invalid source encountered when trying to create diff for remove edit\");\n\t}\n}\n\n/**\n * Creates a diff for a Move TreeEdit.\n *\n * @remarks\n * This function must only be called BEFORE a move edit is applied.\n * For move operations, the diff is created before the node(s) have been successfully moved,\n * since the original index is needed to restore the node(s) if the move operation need to undo.\n */\nfunction createMoveDiff(\n\ttreeEdit: Move,\n\tidGenerator: IdGenerator,\n): MoveSingleDiff | MoveRangeDiff {\n\tconst source = treeEdit.source;\n\tconst destination = treeEdit.destination;\n\tconst { array: destinationArrayNode } = getPlaceInfo(destination, idGenerator);\n\n\tif (isObjectTarget(source)) {\n\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\treturn {\n\t\t\ttype: \"move\",\n\t\t\tmoveType: \"move-single\",\n\t\t\tsourceNodePath: createNodePathRecursive(node, idGenerator, []),\n\t\t\tdestinationNodePath: createNodePathRecursive(destinationArrayNode, idGenerator, []),\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContent: removeAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t};\n\t} else if (isRange(source)) {\n\t\tconst {\n\t\t\tarray,\n\t\t\tstartIndex: sourceStartIndex,\n\t\t\tendIndex: sourceEndIndex,\n\t\t} = getRangeInfo(source, idGenerator);\n\n\t\tconst movedNodePaths: NodePath[] = [];\n\t\tconst movedNodes: TreeNode[] = [];\n\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\tconst nodeToMove = array.at(i);\n\t\t\tif (!isPrimitive(nodeToMove)) {\n\t\t\t\tmovedNodePaths.push(createNodePathRecursive(nodeToMove as TreeNode, idGenerator, []));\n\t\t\t\tmovedNodes.push(nodeToMove as TreeNode);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"move\",\n\t\t\tmoveType: \"move-range\",\n\t\t\tsourceNodePaths: movedNodePaths,\n\t\t\tdestinationNodePath: createNodePathRecursive(destinationArrayNode, idGenerator, []),\n\t\t\taiExplanation: treeEdit.explanation,\n\t\t\tnodeContents: movedNodes.map((node) =>\n\t\t\t\tremoveAgentObjectIdField(JSON.parse(JSON.stringify(node))),\n\t\t\t),\n\t\t};\n\t} else {\n\t\tthrow new Error(\"Invalid source for move edit\");\n\t}\n}\n\ninterface SchemaInfo {\n\ttreeNodeSchema: TreeNodeSchema;\n\tsimpleNodeSchema: new (dummy: unknown) => TreeNode;\n}\n\nfunction getSimpleNodeSchema(node: TreeNode): SchemaInfo {\n\tconst treeNodeSchema = Tree.schema(node);\n\tconst simpleNodeSchema = treeNodeSchema as unknown as new (dummy: unknown) => TreeNode;\n\treturn { treeNodeSchema, simpleNodeSchema };\n}\n"]}
|
|
@@ -221,7 +221,7 @@ function getDef(defs, ref) {
|
|
|
221
221
|
* TBD
|
|
222
222
|
*/
|
|
223
223
|
function getFriendlySchemaName(schemaName) {
|
|
224
|
-
const matches =
|
|
224
|
+
const matches = /[^.]+$/.exec(schemaName);
|
|
225
225
|
if (matches === null) {
|
|
226
226
|
// empty scope
|
|
227
227
|
return schemaName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promptGeneration.js","sourceRoot":"","sources":["../../src/explicit-strategy/promptGeneration.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,4DAauC;AACvC,wDAAwD;AACxD,sCAAsD;AAEtD,2DAAiE;AAEjE,2DAA2F;AAC3F,yCAAkC;AAWlC;;GAEG;AACH,SAAgB,eAAe,CAC9B,WAAwB,EACxB,IAAqD;IAErD,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,WAAW,GAAW,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1E,yGAAyG;YACzG,gEAAgE;YAChE,2DAA2D;YAC3D,MAAM,KAAK;YACV,iEAAiE;YACjE,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAA,eAAI,EAAC,2CAA2C,CAAC,CAAC;YAC/E,IAAA,iBAAM,EACL,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,+BAAW,CA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B;IAC9C,OAAQ,KAAuB,CAAC,IAAI,KAAK,SAAS,CAAC;AACpD,CAAC;AAED,SAAS,MAAM,CAAC,IAAoC,EAAE,GAAW;IAChE,8BAA8B;IAC9B,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAClC,IAAA,iBAAM,EAAC,OAAO,KAAK,SAAS,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC1D,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,UAAkB;IACvD,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACtB,cAAc;QACd,OAAO,UAAU,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC;AAPD,sDAOC","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 {\n\tNodeKind,\n\ttype ImplicitFieldSchema,\n\ttype TreeFieldFromImplicitField,\n\tgetJsonSchema,\n\ttype JsonFieldSchema,\n\ttype JsonNodeSchema,\n\ttype JsonSchemaRef,\n\ttype JsonTreeSchema,\n\tgetSimpleSchema,\n\tTree,\n\ttype TreeNode,\n\tKeyEncodingOptions,\n} from \"@fluidframework/tree/internal\";\n// eslint-disable-next-line import-x/no-internal-modules\nimport { createZodJsonValidator } from \"typechat/zod\";\n\nimport { objectIdKey, type TreeEdit } from \"./agentEditTypes.js\";\nimport type { IdGenerator } from \"./idGenerator.js\";\nimport { doesNodeContainArraySchema, generateGenericEditTypes } from \"./typeGeneration.js\";\nimport { fail } from \"./utils.js\";\n\n/**\n * A log of edits that have been made to a tree.\n * @remarks This is primarily used to help an LLM keep track of the active changes it has made.\n */\nexport type EditLog = {\n\tedit: TreeEdit;\n\terror?: string;\n}[];\n\n/**\n * TBD\n */\nexport function toDecoratedJson(\n\tidGenerator: IdGenerator,\n\troot: TreeFieldFromImplicitField<ImplicitFieldSchema>,\n): string {\n\tidGenerator.assignIds(root);\n\tconst stringified: string = JSON.stringify(root, (_, value) => {\n\t\tif (typeof value === \"object\" && !Array.isArray(value) && value !== null) {\n\t\t\t// TODO: SharedTree Team needs to either publish TreeNode as a class to use .instanceof() or a typeguard.\n\t\t\t// Uncomment this assertion back once we have a typeguard ready.\n\t\t\t// assert(isTreeNode(node), \"Non-TreeNode value in tree.\");\n\t\t\tconst objId =\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\tidGenerator.getId(value) ?? fail(\"ID of new node should have been assigned.\");\n\t\t\tassert(\n\t\t\t\t!Object.prototype.hasOwnProperty.call(value, objectIdKey),\n\t\t\t\t0xa7b /* Collision of object id property. */,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t[objectIdKey]: objId,\n\t\t\t\t...value,\n\t\t\t} as unknown;\n\t\t}\n\t\treturn value as unknown;\n\t});\n\treturn stringified;\n}\n\n/**\n * Generates a prompt designed to make an LLM produce a plan to edit the SharedTree to accomplish a user-specified goal.\n */\nexport function getPlanningSystemPrompt(\n\ttreeNode: TreeNode,\n\tuserPrompt: string,\n\tsystemRoleContext?: string,\n): string {\n\tconst schema = Tree.schema(treeNode);\n\n\tconst promptFriendlySchema = getPromptFriendlyTreeSchema(\n\t\tgetJsonSchema(schema, {\n\t\t\trequireFieldsWithDefaults: false,\n\t\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t}),\n\t);\n\tconst role = `I'm an agent who makes plans for another agent to achieve a user-specified goal to update the state of an application.${\n\t\tsystemRoleContext === undefined\n\t\t\t? \"\"\n\t\t\t: `\n\t\t\tThe other agent follows this guidance: ${systemRoleContext}`\n\t}`;\n\n\tconst editOptions = `modifying ${doesNodeContainArraySchema(treeNode) ? \"as well as inserting, removing, or moving\" : \"\"} elements in the tree`;\n\n\tconst systemPrompt = `\n\t${role}\n\tThe application state tree is a JSON object with the following schema: ${promptFriendlySchema}\n\tThe current state is: ${JSON.stringify(treeNode)}.\n\tThe user requested that I accomplish the following goal:\n\t\"${userPrompt}\"\n\tI've made a plan to accomplish this goal by doing a sequence of edits to the tree.\n\tEdits can include ${editOptions}.\n\tHere is my plan:`;\n\n\treturn systemPrompt;\n}\n\n/**\n * Generates a prompt that provides a history of the edits an LLM has made to a SharedTree as well as any errors that occured from attemping to apply each respsecitve edit to the tree.\n */\nexport function createEditListHistoryPrompt(edits: EditLog): string {\n\treturn edits\n\t\t.map((edit, index) => {\n\t\t\tconst error =\n\t\t\t\tedit.error === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: ` This edit produced an error, and was discarded. The error message was: \"${edit.error}\"`;\n\t\t\treturn `${index + 1}. ${JSON.stringify(edit.edit)}${error}`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n\n/**\n * Generates the main prompt of this explicit strategy.\n * This prompt is designed to give an LLM instructions on how it can modify a SharedTree using specific types of {@link TreeEdit}'s\n * and provides with both a serialized version of the current state of the provided tree node as well as the interfaces that compromise said tree nodes data.\n */\nexport function getEditingSystemPrompt(\n\tuserPrompt: string,\n\tidGenerator: IdGenerator,\n\ttreeNode: TreeNode,\n\tlog: EditLog,\n\tappGuidance?: string,\n\tplan?: string,\n): string {\n\tconst schema = Tree.schema(treeNode);\n\tconst promptFriendlySchema = getPromptFriendlyTreeSchema(\n\t\tgetJsonSchema(schema, {\n\t\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t\trequireFieldsWithDefaults: false,\n\t\t}),\n\t);\n\tconst decoratedTreeJson = toDecoratedJson(idGenerator, treeNode);\n\n\tconst role = `You are a collaborative agent who interacts with a JSON tree by performing edits to achieve a user-specified goal.${\n\t\tappGuidance === undefined\n\t\t\t? \"\"\n\t\t\t: `\\nThe application that owns the JSON tree has the following guidance about your role: \"${appGuidance}\".`\n\t}`;\n\n\tconst treeSchemaString = createZodJsonValidator(\n\t\t...generateGenericEditTypes(getSimpleSchema(schema), false),\n\t).getSchemaText();\n\n\tconst topLevelEditWrapperDescription = doesNodeContainArraySchema(treeNode)\n\t\t? `contains one of the following interfaces: \"Modify\", null or an array node only edit: \"Insert\", \"Remove\", \"Move\"`\n\t\t: `contains the interface \"Modify\" or null`;\n\n\t// TODO: security: user prompt in system prompt\n\tconst systemPrompt = `\n\t${role}\\nEdits are JSON objects that conform to the schema described below. The top-level object you produce for a given edit is an \"EditWrapper\" object which ${topLevelEditWrapperDescription}.\n\t\\nHere are the schema definitions for an edit:\\n${treeSchemaString}\\n\n\tThe tree is a JSON object with the following schema: ${promptFriendlySchema}\n\t${plan === undefined ? \"\" : `You have made a plan to accomplish the user's goal. The plan is: \"${plan}\". You will perform one or more edits that correspond to that plan to accomplish the goal.`}\n\t${\n\t\tlog.length === 0\n\t\t\t? \"\"\n\t\t\t: `You have already performed the following edits:\n\t\t\t${createEditListHistoryPrompt(log)}\n\t\t\tThis means that the current state of the tree reflects these changes.`\n\t}\n\tThe current state of the tree is: ${decoratedTreeJson}.\n\t${log.length > 0 ? \"Before you made the above edits t\" : \"T\"}he user requested you accomplish the following goal:\n\t\"${userPrompt}\"\n\tIf the goal is now completed or is impossible, you should return null.\n\tOtherwise, you should create an edit that makes progress towards the goal. It should have an English description (\"explanation\") of which edit to perform (specifying one of the allowed edit types).`;\n\treturn systemPrompt;\n}\n\n/**\n * Generates a prompt designed to make an LLM review the edits it created and applied to a SharedTree based\n * on a user-specified goal. This prompt is designed to give the LLM's ability to correct for mistakes and improve the accuracy/fidelity of its final set of tree edits\n */\nexport function getReviewSystemPrompt(\n\tuserPrompt: string,\n\tidGenerator: IdGenerator,\n\ttreeNode: TreeNode,\n\toriginalDecoratedJson: string,\n\tappGuidance?: string,\n): string {\n\tconst schema = Tree.schema(treeNode);\n\tconst promptFriendlySchema = getPromptFriendlyTreeSchema(\n\t\tgetJsonSchema(schema, {\n\t\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t\trequireFieldsWithDefaults: false,\n\t\t}),\n\t);\n\tconst decoratedTreeJson = toDecoratedJson(idGenerator, treeNode);\n\n\tconst role = `You are a collaborative agent who interacts with a JSON tree by performing edits to achieve a user-specified goal.${\n\t\tappGuidance === undefined\n\t\t\t? \"\"\n\t\t\t: `\n\t\t\tThe application that owns the JSON tree has the following guidance: ${appGuidance}`\n\t}`;\n\n\t// TODO: security: user prompt in system prompt\n\tconst systemPrompt = `\n\t${role}\n\tYou have performed a number of actions already to accomplish a user request.\n\tYou must review the resulting state to determine if the actions you performed successfully accomplished the user's goal.\n\tThe tree is a JSON object with the following schema: ${promptFriendlySchema}\n\tThe state of the tree BEFORE changes was: ${originalDecoratedJson}.\n\tThe state of the tree AFTER changes is: ${decoratedTreeJson}.\n\tThe user requested that the following goal should be accomplished:\n\t${userPrompt}\n\tWas the goal accomplished?`;\n\treturn systemPrompt;\n}\n\n/**\n * Converts a fully-qualified SharedTree schema name to a single-word name for use in textual TypeScript-style types.\n *\n * @remarks\n * - TODO: Determine what to do with user-provided names that include periods (e.g. \"Foo.Bar\").\n * - TODO: Should probably ensure name starts with an uppercase character.\n * - TODO: Should probably ensure name is a valid TypeScript identifier.\n * - TODO: Should probably ensure name is unique.\n * - TODO: Should probably take in a TreeNodeSchema or SimpleNodeSchema.\n * Note: For explicitly subclassed TreeNodeSchema, the developer/code facing name of the class can be recovered using `.name`: this might be useful.\n */\nexport function getPromptFriendlyTreeSchema(jsonSchema: JsonTreeSchema): string {\n\tlet stringifiedSchema = \"\";\n\tfor (const [name, def] of Object.entries(jsonSchema.$defs)) {\n\t\tif (def._treeNodeSchemaKind !== NodeKind.Object) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet stringifiedEntry = `interface ${getFriendlySchemaName(name)} {`;\n\n\t\tfor (const [fieldName, fieldSchema] of Object.entries(def.properties)) {\n\t\t\tlet typeString: string;\n\t\t\tif (isJsonSchemaRef(fieldSchema)) {\n\t\t\t\tconst nextFieldName = fieldSchema.$ref;\n\t\t\t\tconst nextDef = getDef(jsonSchema.$defs, nextFieldName);\n\t\t\t\ttypeString = `${getTypeString(jsonSchema.$defs, [nextFieldName, nextDef])}`;\n\t\t\t} else {\n\t\t\t\ttypeString = `${getAnyOfTypeString(jsonSchema.$defs, fieldSchema.anyOf, true)}`;\n\t\t\t}\n\t\t\tif (def.required && !def.required.includes(fieldName)) {\n\t\t\t\ttypeString = `${typeString} | undefined`;\n\t\t\t}\n\t\t\tstringifiedEntry += ` ${fieldName}: ${typeString};`;\n\t\t}\n\n\t\tstringifiedEntry += \" }\";\n\n\t\tstringifiedSchema += (stringifiedSchema === \"\" ? \"\" : \" \") + stringifiedEntry;\n\t}\n\treturn stringifiedSchema;\n}\n\nfunction getTypeString(\n\tdefs: Record<string, JsonNodeSchema>,\n\t[name, currentDef]: [string, JsonNodeSchema],\n): string {\n\tconst { _treeNodeSchemaKind } = currentDef;\n\tif (_treeNodeSchemaKind === NodeKind.Leaf) {\n\t\treturn currentDef.type;\n\t}\n\tif (_treeNodeSchemaKind === NodeKind.Object) {\n\t\treturn getFriendlySchemaName(name);\n\t}\n\tif (_treeNodeSchemaKind === NodeKind.Array) {\n\t\tconst items = currentDef.items;\n\t\tconst innerType = isJsonSchemaRef(items)\n\t\t\t? getTypeString(defs, [items.$ref, getDef(defs, items.$ref)])\n\t\t\t: getAnyOfTypeString(defs, items.anyOf);\n\t\treturn `${innerType}[]`;\n\t}\n\tfail(\"Non-object, non-leaf, non-array schema type.\");\n}\n\nfunction getAnyOfTypeString(\n\tdefs: Record<string, JsonNodeSchema>,\n\trefList: JsonSchemaRef[],\n\ttopLevel = false,\n): string {\n\tconst typeNames: string[] = [];\n\tfor (const ref of refList) {\n\t\ttypeNames.push(getTypeString(defs, [ref.$ref, getDef(defs, ref.$ref)]));\n\t}\n\tconst typeString = typeNames.join(\" | \");\n\treturn topLevel ? typeString : `(${typeString})`;\n}\n\nfunction isJsonSchemaRef(field: JsonFieldSchema): field is JsonSchemaRef {\n\treturn (field as JsonSchemaRef).$ref !== undefined;\n}\n\nfunction getDef(defs: Record<string, JsonNodeSchema>, ref: string): JsonNodeSchema {\n\t// strip the \"#/$defs/\" prefix\n\tconst strippedRef = ref.slice(8);\n\tconst nextDef = defs[strippedRef];\n\tassert(nextDef !== undefined, 0xa7c /* Ref not found. */);\n\treturn nextDef;\n}\n\n/**\n * TBD\n */\nexport function getFriendlySchemaName(schemaName: string): string {\n\tconst matches = schemaName.match(/[^.]+$/);\n\tif (matches === null) {\n\t\t// empty scope\n\t\treturn schemaName;\n\t}\n\treturn matches[0];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"promptGeneration.js","sourceRoot":"","sources":["../../src/explicit-strategy/promptGeneration.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,4DAauC;AACvC,wDAAwD;AACxD,sCAAsD;AAEtD,2DAAiE;AAEjE,2DAA2F;AAC3F,yCAAkC;AAWlC;;GAEG;AACH,SAAgB,eAAe,CAC9B,WAAwB,EACxB,IAAqD;IAErD,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,WAAW,GAAW,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1E,yGAAyG;YACzG,gEAAgE;YAChE,2DAA2D;YAC3D,MAAM,KAAK;YACV,iEAAiE;YACjE,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAA,eAAI,EAAC,2CAA2C,CAAC,CAAC;YAC/E,IAAA,iBAAM,EACL,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,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AAED,SAAS,eAAe,CAAC,KAAsB;IAC9C,OAAQ,KAAuB,CAAC,IAAI,KAAK,SAAS,CAAC;AACpD,CAAC;AAED,SAAS,MAAM,CAAC,IAAoC,EAAE,GAAW;IAChE,8BAA8B;IAC9B,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAClC,IAAA,iBAAM,EAAC,OAAO,KAAK,SAAS,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC1D,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,UAAkB;IACvD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACtB,cAAc;QACd,OAAO,UAAU,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC;AAPD,sDAOC","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 {\n\tNodeKind,\n\ttype ImplicitFieldSchema,\n\ttype TreeFieldFromImplicitField,\n\tgetJsonSchema,\n\ttype JsonFieldSchema,\n\ttype JsonNodeSchema,\n\ttype JsonSchemaRef,\n\ttype JsonTreeSchema,\n\tgetSimpleSchema,\n\tTree,\n\ttype TreeNode,\n\tKeyEncodingOptions,\n} from \"@fluidframework/tree/internal\";\n// eslint-disable-next-line import-x/no-internal-modules\nimport { createZodJsonValidator } from \"typechat/zod\";\n\nimport { objectIdKey, type TreeEdit } from \"./agentEditTypes.js\";\nimport type { IdGenerator } from \"./idGenerator.js\";\nimport { doesNodeContainArraySchema, generateGenericEditTypes } from \"./typeGeneration.js\";\nimport { fail } from \"./utils.js\";\n\n/**\n * A log of edits that have been made to a tree.\n * @remarks This is primarily used to help an LLM keep track of the active changes it has made.\n */\nexport type EditLog = {\n\tedit: TreeEdit;\n\terror?: string;\n}[];\n\n/**\n * TBD\n */\nexport function toDecoratedJson(\n\tidGenerator: IdGenerator,\n\troot: TreeFieldFromImplicitField<ImplicitFieldSchema>,\n): string {\n\tidGenerator.assignIds(root);\n\tconst stringified: string = JSON.stringify(root, (_, value) => {\n\t\tif (typeof value === \"object\" && !Array.isArray(value) && value !== null) {\n\t\t\t// TODO: SharedTree Team needs to either publish TreeNode as a class to use .instanceof() or a typeguard.\n\t\t\t// Uncomment this assertion back once we have a typeguard ready.\n\t\t\t// assert(isTreeNode(node), \"Non-TreeNode value in tree.\");\n\t\t\tconst objId =\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\t\tidGenerator.getId(value) ?? fail(\"ID of new node should have been assigned.\");\n\t\t\tassert(\n\t\t\t\t!Object.prototype.hasOwnProperty.call(value, objectIdKey),\n\t\t\t\t0xa7b /* Collision of object id property. */,\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t[objectIdKey]: objId,\n\t\t\t\t...value,\n\t\t\t} as unknown;\n\t\t}\n\t\treturn value as unknown;\n\t});\n\treturn stringified;\n}\n\n/**\n * Generates a prompt designed to make an LLM produce a plan to edit the SharedTree to accomplish a user-specified goal.\n */\nexport function getPlanningSystemPrompt(\n\ttreeNode: TreeNode,\n\tuserPrompt: string,\n\tsystemRoleContext?: string,\n): string {\n\tconst schema = Tree.schema(treeNode);\n\n\tconst promptFriendlySchema = getPromptFriendlyTreeSchema(\n\t\tgetJsonSchema(schema, {\n\t\t\trequireFieldsWithDefaults: false,\n\t\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t}),\n\t);\n\tconst role = `I'm an agent who makes plans for another agent to achieve a user-specified goal to update the state of an application.${\n\t\tsystemRoleContext === undefined\n\t\t\t? \"\"\n\t\t\t: `\n\t\t\tThe other agent follows this guidance: ${systemRoleContext}`\n\t}`;\n\n\tconst editOptions = `modifying ${doesNodeContainArraySchema(treeNode) ? \"as well as inserting, removing, or moving\" : \"\"} elements in the tree`;\n\n\tconst systemPrompt = `\n\t${role}\n\tThe application state tree is a JSON object with the following schema: ${promptFriendlySchema}\n\tThe current state is: ${JSON.stringify(treeNode)}.\n\tThe user requested that I accomplish the following goal:\n\t\"${userPrompt}\"\n\tI've made a plan to accomplish this goal by doing a sequence of edits to the tree.\n\tEdits can include ${editOptions}.\n\tHere is my plan:`;\n\n\treturn systemPrompt;\n}\n\n/**\n * Generates a prompt that provides a history of the edits an LLM has made to a SharedTree as well as any errors that occured from attemping to apply each respsecitve edit to the tree.\n */\nexport function createEditListHistoryPrompt(edits: EditLog): string {\n\treturn edits\n\t\t.map((edit, index) => {\n\t\t\tconst error =\n\t\t\t\tedit.error === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: ` This edit produced an error, and was discarded. The error message was: \"${edit.error}\"`;\n\t\t\treturn `${index + 1}. ${JSON.stringify(edit.edit)}${error}`;\n\t\t})\n\t\t.join(\"\\n\");\n}\n\n/**\n * Generates the main prompt of this explicit strategy.\n * This prompt is designed to give an LLM instructions on how it can modify a SharedTree using specific types of {@link TreeEdit}'s\n * and provides with both a serialized version of the current state of the provided tree node as well as the interfaces that compromise said tree nodes data.\n */\nexport function getEditingSystemPrompt(\n\tuserPrompt: string,\n\tidGenerator: IdGenerator,\n\ttreeNode: TreeNode,\n\tlog: EditLog,\n\tappGuidance?: string,\n\tplan?: string,\n): string {\n\tconst schema = Tree.schema(treeNode);\n\tconst promptFriendlySchema = getPromptFriendlyTreeSchema(\n\t\tgetJsonSchema(schema, {\n\t\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t\trequireFieldsWithDefaults: false,\n\t\t}),\n\t);\n\tconst decoratedTreeJson = toDecoratedJson(idGenerator, treeNode);\n\n\tconst role = `You are a collaborative agent who interacts with a JSON tree by performing edits to achieve a user-specified goal.${\n\t\tappGuidance === undefined\n\t\t\t? \"\"\n\t\t\t: `\\nThe application that owns the JSON tree has the following guidance about your role: \"${appGuidance}\".`\n\t}`;\n\n\tconst treeSchemaString = createZodJsonValidator(\n\t\t...generateGenericEditTypes(getSimpleSchema(schema), false),\n\t).getSchemaText();\n\n\tconst topLevelEditWrapperDescription = doesNodeContainArraySchema(treeNode)\n\t\t? `contains one of the following interfaces: \"Modify\", null or an array node only edit: \"Insert\", \"Remove\", \"Move\"`\n\t\t: `contains the interface \"Modify\" or null`;\n\n\t// TODO: security: user prompt in system prompt\n\tconst systemPrompt = `\n\t${role}\\nEdits are JSON objects that conform to the schema described below. The top-level object you produce for a given edit is an \"EditWrapper\" object which ${topLevelEditWrapperDescription}.\n\t\\nHere are the schema definitions for an edit:\\n${treeSchemaString}\\n\n\tThe tree is a JSON object with the following schema: ${promptFriendlySchema}\n\t${plan === undefined ? \"\" : `You have made a plan to accomplish the user's goal. The plan is: \"${plan}\". You will perform one or more edits that correspond to that plan to accomplish the goal.`}\n\t${\n\t\tlog.length === 0\n\t\t\t? \"\"\n\t\t\t: `You have already performed the following edits:\n\t\t\t${createEditListHistoryPrompt(log)}\n\t\t\tThis means that the current state of the tree reflects these changes.`\n\t}\n\tThe current state of the tree is: ${decoratedTreeJson}.\n\t${log.length > 0 ? \"Before you made the above edits t\" : \"T\"}he user requested you accomplish the following goal:\n\t\"${userPrompt}\"\n\tIf the goal is now completed or is impossible, you should return null.\n\tOtherwise, you should create an edit that makes progress towards the goal. It should have an English description (\"explanation\") of which edit to perform (specifying one of the allowed edit types).`;\n\treturn systemPrompt;\n}\n\n/**\n * Generates a prompt designed to make an LLM review the edits it created and applied to a SharedTree based\n * on a user-specified goal. This prompt is designed to give the LLM's ability to correct for mistakes and improve the accuracy/fidelity of its final set of tree edits\n */\nexport function getReviewSystemPrompt(\n\tuserPrompt: string,\n\tidGenerator: IdGenerator,\n\ttreeNode: TreeNode,\n\toriginalDecoratedJson: string,\n\tappGuidance?: string,\n): string {\n\tconst schema = Tree.schema(treeNode);\n\tconst promptFriendlySchema = getPromptFriendlyTreeSchema(\n\t\tgetJsonSchema(schema, {\n\t\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t\trequireFieldsWithDefaults: false,\n\t\t}),\n\t);\n\tconst decoratedTreeJson = toDecoratedJson(idGenerator, treeNode);\n\n\tconst role = `You are a collaborative agent who interacts with a JSON tree by performing edits to achieve a user-specified goal.${\n\t\tappGuidance === undefined\n\t\t\t? \"\"\n\t\t\t: `\n\t\t\tThe application that owns the JSON tree has the following guidance: ${appGuidance}`\n\t}`;\n\n\t// TODO: security: user prompt in system prompt\n\tconst systemPrompt = `\n\t${role}\n\tYou have performed a number of actions already to accomplish a user request.\n\tYou must review the resulting state to determine if the actions you performed successfully accomplished the user's goal.\n\tThe tree is a JSON object with the following schema: ${promptFriendlySchema}\n\tThe state of the tree BEFORE changes was: ${originalDecoratedJson}.\n\tThe state of the tree AFTER changes is: ${decoratedTreeJson}.\n\tThe user requested that the following goal should be accomplished:\n\t${userPrompt}\n\tWas the goal accomplished?`;\n\treturn systemPrompt;\n}\n\n/**\n * Converts a fully-qualified SharedTree schema name to a single-word name for use in textual TypeScript-style types.\n *\n * @remarks\n * - TODO: Determine what to do with user-provided names that include periods (e.g. \"Foo.Bar\").\n * - TODO: Should probably ensure name starts with an uppercase character.\n * - TODO: Should probably ensure name is a valid TypeScript identifier.\n * - TODO: Should probably ensure name is unique.\n * - TODO: Should probably take in a TreeNodeSchema or SimpleNodeSchema.\n * Note: For explicitly subclassed TreeNodeSchema, the developer/code facing name of the class can be recovered using `.name`: this might be useful.\n */\nexport function getPromptFriendlyTreeSchema(jsonSchema: JsonTreeSchema): string {\n\tlet stringifiedSchema = \"\";\n\tfor (const [name, def] of Object.entries(jsonSchema.$defs)) {\n\t\tif (def._treeNodeSchemaKind !== NodeKind.Object) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet stringifiedEntry = `interface ${getFriendlySchemaName(name)} {`;\n\n\t\tfor (const [fieldName, fieldSchema] of Object.entries(def.properties)) {\n\t\t\tlet typeString: string;\n\t\t\tif (isJsonSchemaRef(fieldSchema)) {\n\t\t\t\tconst nextFieldName = fieldSchema.$ref;\n\t\t\t\tconst nextDef = getDef(jsonSchema.$defs, nextFieldName);\n\t\t\t\ttypeString = `${getTypeString(jsonSchema.$defs, [nextFieldName, nextDef])}`;\n\t\t\t} else {\n\t\t\t\ttypeString = `${getAnyOfTypeString(jsonSchema.$defs, fieldSchema.anyOf, true)}`;\n\t\t\t}\n\t\t\tif (def.required && !def.required.includes(fieldName)) {\n\t\t\t\ttypeString = `${typeString} | undefined`;\n\t\t\t}\n\t\t\tstringifiedEntry += ` ${fieldName}: ${typeString};`;\n\t\t}\n\n\t\tstringifiedEntry += \" }\";\n\n\t\tstringifiedSchema += (stringifiedSchema === \"\" ? \"\" : \" \") + stringifiedEntry;\n\t}\n\treturn stringifiedSchema;\n}\n\nfunction getTypeString(\n\tdefs: Record<string, JsonNodeSchema>,\n\t[name, currentDef]: [string, JsonNodeSchema],\n): string {\n\tconst { _treeNodeSchemaKind } = currentDef;\n\tif (_treeNodeSchemaKind === NodeKind.Leaf) {\n\t\treturn currentDef.type;\n\t}\n\tif (_treeNodeSchemaKind === NodeKind.Object) {\n\t\treturn getFriendlySchemaName(name);\n\t}\n\tif (_treeNodeSchemaKind === NodeKind.Array) {\n\t\tconst items = currentDef.items;\n\t\tconst innerType = isJsonSchemaRef(items)\n\t\t\t? getTypeString(defs, [items.$ref, getDef(defs, items.$ref)])\n\t\t\t: getAnyOfTypeString(defs, items.anyOf);\n\t\treturn `${innerType}[]`;\n\t}\n\tfail(\"Non-object, non-leaf, non-array schema type.\");\n}\n\nfunction getAnyOfTypeString(\n\tdefs: Record<string, JsonNodeSchema>,\n\trefList: JsonSchemaRef[],\n\ttopLevel = false,\n): string {\n\tconst typeNames: string[] = [];\n\tfor (const ref of refList) {\n\t\ttypeNames.push(getTypeString(defs, [ref.$ref, getDef(defs, ref.$ref)]));\n\t}\n\tconst typeString = typeNames.join(\" | \");\n\treturn topLevel ? typeString : `(${typeString})`;\n}\n\nfunction isJsonSchemaRef(field: JsonFieldSchema): field is JsonSchemaRef {\n\treturn (field as JsonSchemaRef).$ref !== undefined;\n}\n\nfunction getDef(defs: Record<string, JsonNodeSchema>, ref: string): JsonNodeSchema {\n\t// strip the \"#/$defs/\" prefix\n\tconst strippedRef = ref.slice(8);\n\tconst nextDef = defs[strippedRef];\n\tassert(nextDef !== undefined, 0xa7c /* Ref not found. */);\n\treturn nextDef;\n}\n\n/**\n * TBD\n */\nexport function getFriendlySchemaName(schemaName: string): string {\n\tconst matches = /[^.]+$/.exec(schemaName);\n\tif (matches === null) {\n\t\t// empty scope\n\t\treturn schemaName;\n\t}\n\treturn matches[0];\n}\n"]}
|
|
@@ -173,7 +173,7 @@ function sharedTreeDiff(obj, newObj, options = DEFAULT_OPTIONS, _stack = []) {
|
|
|
173
173
|
!(Number.isNaN(objValue) && Number.isNaN(newObjValue)) &&
|
|
174
174
|
!(areCompatibleObjects &&
|
|
175
175
|
(Number.isNaN(objValue)
|
|
176
|
-
? // eslint-disable-next-line prefer-template
|
|
176
|
+
? // eslint-disable-next-line prefer-template, @typescript-eslint/no-base-to-string
|
|
177
177
|
objValue + "" === newObjValue + ""
|
|
178
178
|
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
179
179
|
// @ts-ignore
|