@fluidframework/ai-collab 2.21.0 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -1
- package/dist/explicit-strategy/agentEditReducer.js +5 -6
- package/dist/explicit-strategy/agentEditReducer.js.map +1 -1
- package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -1
- package/lib/explicit-strategy/agentEditReducer.js +5 -6
- package/lib/explicit-strategy/agentEditReducer.js.map +1 -1
- package/package.json +9 -9
- package/src/explicit-strategy/agentEditReducer.ts +5 -7
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -210,6 +210,7 @@ When making such a request please include if the configuration already works (an
|
|
|
210
210
|
### Supported Runtimes
|
|
211
211
|
|
|
212
212
|
- NodeJs ^20.10.0 except that we will drop support for it [when NodeJs 20 loses its upstream support on 2026-04-30](https://github.com/nodejs/release#release-schedule), and will support a newer LTS version of NodeJS (22) at least 1 year before 20 is end-of-life. This same policy applies to NodeJS 22 when it is end of life (2027-04-30).
|
|
213
|
+
- Running Fluid in a Node.js environment with the `--no-experimental-fetch` flag is not supported.
|
|
213
214
|
- Modern browsers supporting the es2022 standard library: in response to asks we can add explicit support for using babel to polyfill to target specific standards or runtimes (meaning we can avoid/remove use of things that don't polyfill robustly, but otherwise target modern standards).
|
|
214
215
|
|
|
215
216
|
### Supported Tools
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentEditReducer.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAKN,KAAK,QAAQ,EAEb,KAAK,gBAAgB,EAOrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACN,KAAK,QAAQ,EASb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"agentEditReducer.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAKN,KAAK,QAAQ,EAEb,KAAK,gBAAgB,EAOrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACN,KAAK,QAAQ,EASb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA6DpD;;GAEG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACpD,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAClC,QAAQ,CAyMV"}
|
|
@@ -30,26 +30,25 @@ function populateDefaults(json, definitionMap) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
function getSchemaIdentifier(content) {
|
|
33
|
-
const sf = new internal_3.SchemaFactory(undefined);
|
|
34
33
|
switch (typeof content) {
|
|
35
34
|
case "boolean": {
|
|
36
|
-
return
|
|
35
|
+
return internal_3.SchemaFactory.boolean.identifier;
|
|
37
36
|
}
|
|
38
37
|
case "number": {
|
|
39
|
-
return
|
|
38
|
+
return internal_3.SchemaFactory.number.identifier;
|
|
40
39
|
}
|
|
41
40
|
case "string": {
|
|
42
|
-
return
|
|
41
|
+
return internal_3.SchemaFactory.string.identifier;
|
|
43
42
|
}
|
|
44
43
|
case "object": {
|
|
45
44
|
if (content === null) {
|
|
46
|
-
return
|
|
45
|
+
return internal_3.SchemaFactory.null.identifier;
|
|
47
46
|
}
|
|
48
47
|
if (Array.isArray(content)) {
|
|
49
48
|
throw new internal_2.UsageError("Arrays are not currently supported in this context");
|
|
50
49
|
}
|
|
51
50
|
if ((0, runtime_utils_1.isFluidHandle)(content)) {
|
|
52
|
-
return
|
|
51
|
+
return internal_3.SchemaFactory.handle.identifier;
|
|
53
52
|
}
|
|
54
53
|
return content[agentEditTypes_js_1.typeField];
|
|
55
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentEditReducer.js","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,iEAA8D;AAC9D,uEAAsE;AACtE,4DAcuC;AAEvC,2DAU6B;AAG7B,+DAAwD;AACxD,yCAAkC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAA,iBAAM,EACL,OAAO,IAAI,CAAC,6BAAS,CAAC,KAAK,QAAQ,EACnC,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,SAAS,mBAAmB,CAAC,OAAsB;IAClD,MAAM,EAAE,GAAG,IAAI,wBAAa,CAAC,SAAS,CAAC,CAAC;IAExC,QAAQ,OAAO,OAAO,EAAE,CAAC;QACxB,KAAK,SAAS,CAAC,CAAC,CAAC;YAChB,OAAO,EAAE,C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.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tTree,\n\tNodeKind,\n\ttype ImplicitAllowedTypes,\n\ttype TreeArrayNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\ttype SimpleNodeSchema,\n\tFieldKind,\n\tFieldSchema,\n\tnormalizeAllowedTypes,\n\ttype ImplicitFieldSchema,\n\ttype IterableTreeArrayContent,\n\tSchemaFactory,\n} from \"@fluidframework/tree/internal\";\n\nimport {\n\ttype TreeEdit,\n\ttype ObjectTarget,\n\ttype Selection,\n\ttype Range,\n\ttype ObjectPlace,\n\ttype ArrayPlace,\n\ttype TreeEditObject,\n\ttype TreeEditValue,\n\ttypeField,\n} from \"./agentEditTypes.js\";\nimport type { IdGenerator } from \"./idGenerator.js\";\nimport type { JsonValue } from \"./jsonTypes.js\";\nimport { toDecoratedJson } from \"./promptGeneration.js\";\nimport { fail } from \"./utils.js\";\n\nfunction populateDefaults(\n\tjson: JsonValue,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n): void {\n\tif (typeof json === \"object\") {\n\t\tif (json === null) {\n\t\t\treturn;\n\t\t}\n\t\tif (Array.isArray(json)) {\n\t\t\tfor (const element of json) {\n\t\t\t\tpopulateDefaults(element, definitionMap);\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof json[typeField] === \"string\",\n\t\t\t\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\nfunction getSchemaIdentifier(content: TreeEditValue): string | undefined {\n\tconst sf = new SchemaFactory(undefined);\n\n\tswitch (typeof content) {\n\t\tcase \"boolean\": {\n\t\t\treturn sf.boolean.identifier;\n\t\t}\n\t\tcase \"number\": {\n\t\t\treturn sf.number.identifier;\n\t\t}\n\t\tcase \"string\": {\n\t\t\treturn sf.string.identifier;\n\t\t}\n\t\tcase \"object\": {\n\t\t\tif (content === null) {\n\t\t\t\treturn sf.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 sf.handle.identifier;\n\t\t\t}\n\t\t\treturn content[typeField];\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new UsageError(\"Unsupported content type\");\n\t\t}\n\t}\n}\n\nfunction contentWithIds(content: TreeNode, idGenerator: IdGenerator): TreeEditObject {\n\treturn JSON.parse(toDecoratedJson(idGenerator, content)) as TreeEditObject;\n}\n\n/**\n * Manages applying the various types of {@link TreeEdit}'s to a a given {@link TreeNode}.\n */\nexport function applyAgentEdit(\n\ttreeEdit: TreeEdit,\n\tidGenerator: IdGenerator,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tvalidator?: (edit: TreeNode) => void,\n): TreeEdit {\n\tassertObjectIdsExist(treeEdit, idGenerator);\n\tswitch (treeEdit.type) {\n\t\tcase \"insert\": {\n\t\t\tconst { array, index } = getPlaceInfo(treeEdit.destination, idGenerator);\n\n\t\t\tconst parentNodeSchema = Tree.schema(array);\n\t\t\tpopulateDefaults(treeEdit.content, definitionMap);\n\n\t\t\tconst schemaIdentifier = getSchemaIdentifier(treeEdit.content);\n\n\t\t\t// We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.\n\t\t\tconst allowedTypes = [\n\t\t\t\t...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),\n\t\t\t];\n\n\t\t\tfor (const allowedType of allowedTypes.values()) {\n\t\t\t\tif (allowedType.identifier === schemaIdentifier && typeof allowedType === \"function\") {\n\t\t\t\t\tconst simpleNodeSchema = allowedType as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\t\tconst insertNode = new simpleNodeSchema(treeEdit.content);\n\t\t\t\t\tvalidator?.(insertNode);\n\t\t\t\t\tarray.insertAt(index, insertNode as unknown as IterableTreeArrayContent<never>);\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tcontent: contentWithIds(insertNode, idGenerator),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tfail(\"inserted node must be of an allowed type\");\n\t\t}\n\t\tcase \"remove\": {\n\t\t\tconst source = treeEdit.source;\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst parentNode = Tree.parent(node);\n\t\t\t\t// Case for deleting rootNode\n\t\t\t\tif (parentNode === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"The root is required, and cannot be removed. Please use modify edit instead.\",\n\t\t\t\t\t);\n\t\t\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t\t\t(parentNode as TreeArrayNode).removeAt(nodeIndex);\n\t\t\t\t} else {\n\t\t\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t\t\tconst parentSchema = Tree.schema(parentNode);\n\t\t\t\t\tconst fieldSchema =\n\t\t\t\t\t\t(parentSchema.info as Record<string, ImplicitFieldSchema>)[fieldKey] ??\n\t\t\t\t\t\tfail(\"Expected field schema\");\n\t\t\t\t\tif (fieldSchema instanceof FieldSchema && fieldSchema.kind === FieldKind.Optional) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t(parentNode as any)[fieldKey] = undefined;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`${fieldKey} is required, and cannot be removed. Please use modify edit instead.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\t\t\tarray.removeRange(startIndex, endIndex);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tcase \"modify\": {\n\t\t\tconst node = getNodeFromTarget(treeEdit.target, idGenerator);\n\t\t\tconst { treeNodeSchema } = getSimpleNodeSchema(node);\n\n\t\t\tconst fieldSchema =\n\t\t\t\t(treeNodeSchema.info as Record<string, ImplicitFieldSchema>)[treeEdit.field] ??\n\t\t\t\tfail(\"Expected field schema\");\n\n\t\t\tconst modification = treeEdit.modification;\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst schemaIdentifier = (modification as any)[typeField];\n\n\t\t\tlet insertedObject: TreeNode | undefined;\n\t\t\t// if fieldSchema is a LeafnodeSchema, we can check that it's a valid type and set the field.\n\t\t\tif (isPrimitive(modification)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t}\n\t\t\t// If the fieldSchema is a function we can grab the constructor and make an instance of that node.\n\t\t\telse if (typeof fieldSchema === \"function\") {\n\t\t\t\tconst simpleSchema = fieldSchema as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\tpopulateDefaults(modification, definitionMap);\n\t\t\t\tconst constructedModification = new simpleSchema(modification);\n\t\t\t\tvalidator?.(constructedModification);\n\t\t\t\tinsertedObject = constructedModification;\n\n\t\t\t\tif (Array.isArray(modification)) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst field = (node as any)[treeEdit.field] as TreeArrayNode;\n\t\t\t\t\tassert(Array.isArray(field), 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\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t} else {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If the fieldSchema is of type FieldSchema, we can check its allowed types and set the field.\n\t\t\telse if (fieldSchema instanceof FieldSchema) {\n\t\t\t\tif (fieldSchema.kind === FieldKind.Optional && modification === undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tfor (const allowedType of fieldSchema.allowedTypeSet.values()) {\n\t\t\t\t\t\tif (allowedType.identifier === schemaIdentifier) {\n\t\t\t\t\t\t\tif (typeof allowedType === \"function\") {\n\t\t\t\t\t\t\t\tconst simpleSchema = allowedType as unknown as new (\n\t\t\t\t\t\t\t\t\tdummy: unknown,\n\t\t\t\t\t\t\t\t) => TreeNode;\n\t\t\t\t\t\t\t\tconst constructedObject = new simpleSchema(modification);\n\t\t\t\t\t\t\t\tinsertedObject = constructedObject;\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = constructedObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? treeEdit\n\t\t\t\t: {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t};\n\t\t}\n\t\tcase \"move\": {\n\t\t\t// TODO: need to add schema check for valid moves\n\t\t\tconst source = treeEdit.source;\n\t\t\tconst destination = treeEdit.destination;\n\t\t\tconst { array: destinationArrayNode, index: destinationIndex } = getPlaceInfo(\n\t\t\t\tdestination,\n\t\t\t\tidGenerator,\n\t\t\t);\n\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst sourceNode = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst sourceIndex = Tree.key(sourceNode) as number;\n\t\t\t\tconst sourceArrayNode = Tree.parent(sourceNode) as TreeArrayNode;\n\t\t\t\tconst sourceArraySchema = Tree.schema(sourceArrayNode);\n\t\t\t\tif (sourceArraySchema.kind !== NodeKind.Array) {\n\t\t\t\t\tthrow new UsageError(\"the source node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\nfunction isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {\n\tfor (const allowedType of allowedTypes) {\n\t\tif (Tree.is(node, allowedType)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\nfunction getRangeInfo(range: Range, idGenerator: IdGenerator): RangeInfo {\n\tconst { array: arrayFrom, index: startIndex } = getPlaceInfo(range.from, idGenerator);\n\tconst { array: arrayTo, index: endIndex } = getPlaceInfo(range.to, idGenerator);\n\n\tif (arrayFrom !== arrayTo) {\n\t\tthrow new UsageError(\n\t\t\t'The \"from\" node and \"to\" nodes of the range must be in the same parent array.',\n\t\t);\n\t}\n\n\treturn { array: arrayFrom, startIndex, endIndex };\n}\n\nfunction getPlaceInfo(\n\tplace: ObjectPlace | ArrayPlace,\n\tidGenerator: IdGenerator,\n): {\n\tarray: TreeArrayNode;\n\tindex: number;\n} {\n\tif (place.type === \"arrayPlace\") {\n\t\tconst parent = idGenerator.getNode(place.parentId) ?? fail(\"Expected parent node\");\n\t\tconst child = (parent as unknown as Record<string, unknown>)[place.field];\n\t\tif (child === undefined) {\n\t\t\tthrow new UsageError(`No child under field field`);\n\t\t}\n\t\tconst schema = Tree.schema(child as TreeNode);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: child as TreeArrayNode,\n\t\t\tindex: place.location === \"start\" ? 0 : (child as TreeArrayNode).length,\n\t\t};\n\t} else {\n\t\tconst node = getNodeFromTarget(place, idGenerator);\n\t\tconst nodeIndex = Tree.key(node);\n\t\tconst parent = Tree.parent(node);\n\t\tif (parent === undefined) {\n\t\t\tthrow new UsageError(\"TODO: root node target not supported\");\n\t\t}\n\t\tconst schema = Tree.schema(parent);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: parent as unknown as TreeArrayNode,\n\t\t\tindex: place.place === \"before\" ? (nodeIndex as number) : (nodeIndex as number) + 1,\n\t\t};\n\t}\n}\n\n/**\n * Returns the target node with the matching internal objectId using the provided {@link ObjectTarget}\n */\nfunction getNodeFromTarget(target: ObjectTarget, idGenerator: IdGenerator): TreeNode {\n\tconst node = idGenerator.getNode(target.target);\n\tassert(node !== undefined, 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\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,uEAAsE;AACtE,4DAcuC;AAEvC,2DAU6B;AAG7B,+DAAwD;AACxD,yCAAkC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAA,iBAAM,EACL,OAAO,IAAI,CAAC,6BAAS,CAAC,KAAK,QAAQ,EACnC,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,SAAS,mBAAmB,CAAC,OAAsB;IAClD,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,CAAC;QACxC,CAAC;QACD,KAAK,QAAQ,CAA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AC;gBACF,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/C,CAAC;YAED,wBAAwB;YACxB,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;gBACjD,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC;oBACpE,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBACpD,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;oBACtE,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;gBACtD,CAAC;YACF,CAAC;YACD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,qBAAU,CAAC,iBAAiB,gBAAgB,kBAAkB,CAAC,CAAC;YAC3E,CAAC;YACD,MAAM;QACP,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,MAAM;QACP,CAAC;IACF,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 { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tTree,\n\tNodeKind,\n\ttype ImplicitAllowedTypes,\n\ttype TreeArrayNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\ttype SimpleNodeSchema,\n\tFieldKind,\n\tFieldSchema,\n\tnormalizeAllowedTypes,\n\ttype ImplicitFieldSchema,\n\ttype IterableTreeArrayContent,\n\tSchemaFactory,\n} from \"@fluidframework/tree/internal\";\n\nimport {\n\ttype TreeEdit,\n\ttype ObjectTarget,\n\ttype Selection,\n\ttype Range,\n\ttype ObjectPlace,\n\ttype ArrayPlace,\n\ttype TreeEditObject,\n\ttype TreeEditValue,\n\ttypeField,\n} from \"./agentEditTypes.js\";\nimport type { IdGenerator } from \"./idGenerator.js\";\nimport type { JsonValue } from \"./jsonTypes.js\";\nimport { toDecoratedJson } from \"./promptGeneration.js\";\nimport { fail } from \"./utils.js\";\n\nfunction populateDefaults(\n\tjson: JsonValue,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n): void {\n\tif (typeof json === \"object\") {\n\t\tif (json === null) {\n\t\t\treturn;\n\t\t}\n\t\tif (Array.isArray(json)) {\n\t\t\tfor (const element of json) {\n\t\t\t\tpopulateDefaults(element, definitionMap);\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof json[typeField] === \"string\",\n\t\t\t\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\nfunction getSchemaIdentifier(content: TreeEditValue): string | undefined {\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\t\t\treturn content[typeField];\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new UsageError(\"Unsupported content type\");\n\t\t}\n\t}\n}\n\nfunction contentWithIds(content: TreeNode, idGenerator: IdGenerator): TreeEditObject {\n\treturn JSON.parse(toDecoratedJson(idGenerator, content)) as TreeEditObject;\n}\n\n/**\n * Manages applying the various types of {@link TreeEdit}'s to a a given {@link TreeNode}.\n */\nexport function applyAgentEdit(\n\ttreeEdit: TreeEdit,\n\tidGenerator: IdGenerator,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tvalidator?: (edit: TreeNode) => void,\n): TreeEdit {\n\tassertObjectIdsExist(treeEdit, idGenerator);\n\tswitch (treeEdit.type) {\n\t\tcase \"insert\": {\n\t\t\tconst { array, index } = getPlaceInfo(treeEdit.destination, idGenerator);\n\n\t\t\tconst parentNodeSchema = Tree.schema(array);\n\t\t\tpopulateDefaults(treeEdit.content, definitionMap);\n\n\t\t\tconst schemaIdentifier = getSchemaIdentifier(treeEdit.content);\n\n\t\t\t// We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.\n\t\t\tconst allowedTypes = [\n\t\t\t\t...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),\n\t\t\t];\n\n\t\t\tfor (const allowedType of allowedTypes.values()) {\n\t\t\t\tif (allowedType.identifier === schemaIdentifier && typeof allowedType === \"function\") {\n\t\t\t\t\tconst simpleNodeSchema = allowedType as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\t\tconst insertNode = new simpleNodeSchema(treeEdit.content);\n\t\t\t\t\tvalidator?.(insertNode);\n\t\t\t\t\tarray.insertAt(index, insertNode as unknown as IterableTreeArrayContent<never>);\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tcontent: contentWithIds(insertNode, idGenerator),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tfail(\"inserted node must be of an allowed type\");\n\t\t}\n\t\tcase \"remove\": {\n\t\t\tconst source = treeEdit.source;\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst parentNode = Tree.parent(node);\n\t\t\t\t// Case for deleting rootNode\n\t\t\t\tif (parentNode === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"The root is required, and cannot be removed. Please use modify edit instead.\",\n\t\t\t\t\t);\n\t\t\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t\t\t(parentNode as TreeArrayNode).removeAt(nodeIndex);\n\t\t\t\t} else {\n\t\t\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t\t\tconst parentSchema = Tree.schema(parentNode);\n\t\t\t\t\tconst fieldSchema =\n\t\t\t\t\t\t(parentSchema.info as Record<string, ImplicitFieldSchema>)[fieldKey] ??\n\t\t\t\t\t\tfail(\"Expected field schema\");\n\t\t\t\t\tif (fieldSchema instanceof FieldSchema && fieldSchema.kind === FieldKind.Optional) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t(parentNode as any)[fieldKey] = undefined;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`${fieldKey} is required, and cannot be removed. Please use modify edit instead.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\t\t\tarray.removeRange(startIndex, endIndex);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tcase \"modify\": {\n\t\t\tconst node = getNodeFromTarget(treeEdit.target, idGenerator);\n\t\t\tconst { treeNodeSchema } = getSimpleNodeSchema(node);\n\n\t\t\tconst fieldSchema =\n\t\t\t\t(treeNodeSchema.info as Record<string, ImplicitFieldSchema>)[treeEdit.field] ??\n\t\t\t\tfail(\"Expected field schema\");\n\n\t\t\tconst modification = treeEdit.modification;\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst schemaIdentifier = (modification as any)[typeField];\n\n\t\t\tlet insertedObject: TreeNode | undefined;\n\t\t\t// if fieldSchema is a LeafnodeSchema, we can check that it's a valid type and set the field.\n\t\t\tif (isPrimitive(modification)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t}\n\t\t\t// If the fieldSchema is a function we can grab the constructor and make an instance of that node.\n\t\t\telse if (typeof fieldSchema === \"function\") {\n\t\t\t\tconst simpleSchema = fieldSchema as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\tpopulateDefaults(modification, definitionMap);\n\t\t\t\tconst constructedModification = new simpleSchema(modification);\n\t\t\t\tvalidator?.(constructedModification);\n\t\t\t\tinsertedObject = constructedModification;\n\n\t\t\t\tif (Array.isArray(modification)) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst field = (node as any)[treeEdit.field] as TreeArrayNode;\n\t\t\t\t\tassert(Array.isArray(field), 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\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t} else {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If the fieldSchema is of type FieldSchema, we can check its allowed types and set the field.\n\t\t\telse if (fieldSchema instanceof FieldSchema) {\n\t\t\t\tif (fieldSchema.kind === FieldKind.Optional && modification === undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tfor (const allowedType of fieldSchema.allowedTypeSet.values()) {\n\t\t\t\t\t\tif (allowedType.identifier === schemaIdentifier) {\n\t\t\t\t\t\t\tif (typeof allowedType === \"function\") {\n\t\t\t\t\t\t\t\tconst simpleSchema = allowedType as unknown as new (\n\t\t\t\t\t\t\t\t\tdummy: unknown,\n\t\t\t\t\t\t\t\t) => TreeNode;\n\t\t\t\t\t\t\t\tconst constructedObject = new simpleSchema(modification);\n\t\t\t\t\t\t\t\tinsertedObject = constructedObject;\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = constructedObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? treeEdit\n\t\t\t\t: {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t};\n\t\t}\n\t\tcase \"move\": {\n\t\t\t// TODO: need to add schema check for valid moves\n\t\t\tconst source = treeEdit.source;\n\t\t\tconst destination = treeEdit.destination;\n\t\t\tconst { array: destinationArrayNode, index: destinationIndex } = getPlaceInfo(\n\t\t\t\tdestination,\n\t\t\t\tidGenerator,\n\t\t\t);\n\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst sourceNode = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst sourceIndex = Tree.key(sourceNode) as number;\n\t\t\t\tconst sourceArrayNode = Tree.parent(sourceNode) as TreeArrayNode;\n\t\t\t\tconst sourceArraySchema = Tree.schema(sourceArrayNode);\n\t\t\t\tif (sourceArraySchema.kind !== NodeKind.Array) {\n\t\t\t\t\tthrow new UsageError(\"the source node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\nfunction isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {\n\tfor (const allowedType of allowedTypes) {\n\t\tif (Tree.is(node, allowedType)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\nfunction getRangeInfo(range: Range, idGenerator: IdGenerator): RangeInfo {\n\tconst { array: arrayFrom, index: startIndex } = getPlaceInfo(range.from, idGenerator);\n\tconst { array: arrayTo, index: endIndex } = getPlaceInfo(range.to, idGenerator);\n\n\tif (arrayFrom !== arrayTo) {\n\t\tthrow new UsageError(\n\t\t\t'The \"from\" node and \"to\" nodes of the range must be in the same parent array.',\n\t\t);\n\t}\n\n\treturn { array: arrayFrom, startIndex, endIndex };\n}\n\nfunction getPlaceInfo(\n\tplace: ObjectPlace | ArrayPlace,\n\tidGenerator: IdGenerator,\n): {\n\tarray: TreeArrayNode;\n\tindex: number;\n} {\n\tif (place.type === \"arrayPlace\") {\n\t\tconst parent = idGenerator.getNode(place.parentId) ?? fail(\"Expected parent node\");\n\t\tconst child = (parent as unknown as Record<string, unknown>)[place.field];\n\t\tif (child === undefined) {\n\t\t\tthrow new UsageError(`No child under field field`);\n\t\t}\n\t\tconst schema = Tree.schema(child as TreeNode);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: child as TreeArrayNode,\n\t\t\tindex: place.location === \"start\" ? 0 : (child as TreeArrayNode).length,\n\t\t};\n\t} else {\n\t\tconst node = getNodeFromTarget(place, idGenerator);\n\t\tconst nodeIndex = Tree.key(node);\n\t\tconst parent = Tree.parent(node);\n\t\tif (parent === undefined) {\n\t\t\tthrow new UsageError(\"TODO: root node target not supported\");\n\t\t}\n\t\tconst schema = Tree.schema(parent);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: parent as unknown as TreeArrayNode,\n\t\t\tindex: place.place === \"before\" ? (nodeIndex as number) : (nodeIndex as number) + 1,\n\t\t};\n\t}\n}\n\n/**\n * Returns the target node with the matching internal objectId using the provided {@link ObjectTarget}\n */\nfunction getNodeFromTarget(target: ObjectTarget, idGenerator: IdGenerator): TreeNode {\n\tconst node = idGenerator.getNode(target.target);\n\tassert(node !== undefined, 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\ninterface SchemaInfo {\n\ttreeNodeSchema: TreeNodeSchema;\n\tsimpleNodeSchema: new (dummy: unknown) => TreeNode;\n}\n\nfunction getSimpleNodeSchema(node: TreeNode): SchemaInfo {\n\tconst treeNodeSchema = Tree.schema(node);\n\tconst simpleNodeSchema = treeNodeSchema as unknown as new (dummy: unknown) => TreeNode;\n\treturn { treeNodeSchema, simpleNodeSchema };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentEditReducer.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAKN,KAAK,QAAQ,EAEb,KAAK,gBAAgB,EAOrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACN,KAAK,QAAQ,EASb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"agentEditReducer.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAKN,KAAK,QAAQ,EAEb,KAAK,gBAAgB,EAOrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACN,KAAK,QAAQ,EASb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA6DpD;;GAEG;AACH,wBAAgB,cAAc,CAC7B,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACpD,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,GAClC,QAAQ,CAyMV"}
|
|
@@ -27,26 +27,25 @@ function populateDefaults(json, definitionMap) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
function getSchemaIdentifier(content) {
|
|
30
|
-
const sf = new SchemaFactory(undefined);
|
|
31
30
|
switch (typeof content) {
|
|
32
31
|
case "boolean": {
|
|
33
|
-
return
|
|
32
|
+
return SchemaFactory.boolean.identifier;
|
|
34
33
|
}
|
|
35
34
|
case "number": {
|
|
36
|
-
return
|
|
35
|
+
return SchemaFactory.number.identifier;
|
|
37
36
|
}
|
|
38
37
|
case "string": {
|
|
39
|
-
return
|
|
38
|
+
return SchemaFactory.string.identifier;
|
|
40
39
|
}
|
|
41
40
|
case "object": {
|
|
42
41
|
if (content === null) {
|
|
43
|
-
return
|
|
42
|
+
return SchemaFactory.null.identifier;
|
|
44
43
|
}
|
|
45
44
|
if (Array.isArray(content)) {
|
|
46
45
|
throw new UsageError("Arrays are not currently supported in this context");
|
|
47
46
|
}
|
|
48
47
|
if (isFluidHandle(content)) {
|
|
49
|
-
return
|
|
48
|
+
return SchemaFactory.handle.identifier;
|
|
50
49
|
}
|
|
51
50
|
return content[typeField];
|
|
52
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentEditReducer.js","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EACN,IAAI,EACJ,QAAQ,EAMR,SAAS,EACT,WAAW,EACX,qBAAqB,EAGrB,aAAa,GACb,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EASN,SAAS,GACT,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,CACL,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,QAAQ,EACnC,KAAK,CAAC,uDAAuD,CAC7D,CAAC;Y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AAC;AAOD,SAAS,mBAAmB,CAAC,IAAc;IAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,gBAAgB,GAAG,cAA6D,CAAC;IACvF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tTree,\n\tNodeKind,\n\ttype ImplicitAllowedTypes,\n\ttype TreeArrayNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\ttype SimpleNodeSchema,\n\tFieldKind,\n\tFieldSchema,\n\tnormalizeAllowedTypes,\n\ttype ImplicitFieldSchema,\n\ttype IterableTreeArrayContent,\n\tSchemaFactory,\n} from \"@fluidframework/tree/internal\";\n\nimport {\n\ttype TreeEdit,\n\ttype ObjectTarget,\n\ttype Selection,\n\ttype Range,\n\ttype ObjectPlace,\n\ttype ArrayPlace,\n\ttype TreeEditObject,\n\ttype TreeEditValue,\n\ttypeField,\n} from \"./agentEditTypes.js\";\nimport type { IdGenerator } from \"./idGenerator.js\";\nimport type { JsonValue } from \"./jsonTypes.js\";\nimport { toDecoratedJson } from \"./promptGeneration.js\";\nimport { fail } from \"./utils.js\";\n\nfunction populateDefaults(\n\tjson: JsonValue,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n): void {\n\tif (typeof json === \"object\") {\n\t\tif (json === null) {\n\t\t\treturn;\n\t\t}\n\t\tif (Array.isArray(json)) {\n\t\t\tfor (const element of json) {\n\t\t\t\tpopulateDefaults(element, definitionMap);\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof json[typeField] === \"string\",\n\t\t\t\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\nfunction getSchemaIdentifier(content: TreeEditValue): string | undefined {\n\tconst sf = new SchemaFactory(undefined);\n\n\tswitch (typeof content) {\n\t\tcase \"boolean\": {\n\t\t\treturn sf.boolean.identifier;\n\t\t}\n\t\tcase \"number\": {\n\t\t\treturn sf.number.identifier;\n\t\t}\n\t\tcase \"string\": {\n\t\t\treturn sf.string.identifier;\n\t\t}\n\t\tcase \"object\": {\n\t\t\tif (content === null) {\n\t\t\t\treturn sf.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 sf.handle.identifier;\n\t\t\t}\n\t\t\treturn content[typeField];\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new UsageError(\"Unsupported content type\");\n\t\t}\n\t}\n}\n\nfunction contentWithIds(content: TreeNode, idGenerator: IdGenerator): TreeEditObject {\n\treturn JSON.parse(toDecoratedJson(idGenerator, content)) as TreeEditObject;\n}\n\n/**\n * Manages applying the various types of {@link TreeEdit}'s to a a given {@link TreeNode}.\n */\nexport function applyAgentEdit(\n\ttreeEdit: TreeEdit,\n\tidGenerator: IdGenerator,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tvalidator?: (edit: TreeNode) => void,\n): TreeEdit {\n\tassertObjectIdsExist(treeEdit, idGenerator);\n\tswitch (treeEdit.type) {\n\t\tcase \"insert\": {\n\t\t\tconst { array, index } = getPlaceInfo(treeEdit.destination, idGenerator);\n\n\t\t\tconst parentNodeSchema = Tree.schema(array);\n\t\t\tpopulateDefaults(treeEdit.content, definitionMap);\n\n\t\t\tconst schemaIdentifier = getSchemaIdentifier(treeEdit.content);\n\n\t\t\t// We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.\n\t\t\tconst allowedTypes = [\n\t\t\t\t...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),\n\t\t\t];\n\n\t\t\tfor (const allowedType of allowedTypes.values()) {\n\t\t\t\tif (allowedType.identifier === schemaIdentifier && typeof allowedType === \"function\") {\n\t\t\t\t\tconst simpleNodeSchema = allowedType as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\t\tconst insertNode = new simpleNodeSchema(treeEdit.content);\n\t\t\t\t\tvalidator?.(insertNode);\n\t\t\t\t\tarray.insertAt(index, insertNode as unknown as IterableTreeArrayContent<never>);\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tcontent: contentWithIds(insertNode, idGenerator),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tfail(\"inserted node must be of an allowed type\");\n\t\t}\n\t\tcase \"remove\": {\n\t\t\tconst source = treeEdit.source;\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst parentNode = Tree.parent(node);\n\t\t\t\t// Case for deleting rootNode\n\t\t\t\tif (parentNode === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"The root is required, and cannot be removed. Please use modify edit instead.\",\n\t\t\t\t\t);\n\t\t\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t\t\t(parentNode as TreeArrayNode).removeAt(nodeIndex);\n\t\t\t\t} else {\n\t\t\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t\t\tconst parentSchema = Tree.schema(parentNode);\n\t\t\t\t\tconst fieldSchema =\n\t\t\t\t\t\t(parentSchema.info as Record<string, ImplicitFieldSchema>)[fieldKey] ??\n\t\t\t\t\t\tfail(\"Expected field schema\");\n\t\t\t\t\tif (fieldSchema instanceof FieldSchema && fieldSchema.kind === FieldKind.Optional) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t(parentNode as any)[fieldKey] = undefined;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`${fieldKey} is required, and cannot be removed. Please use modify edit instead.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\t\t\tarray.removeRange(startIndex, endIndex);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tcase \"modify\": {\n\t\t\tconst node = getNodeFromTarget(treeEdit.target, idGenerator);\n\t\t\tconst { treeNodeSchema } = getSimpleNodeSchema(node);\n\n\t\t\tconst fieldSchema =\n\t\t\t\t(treeNodeSchema.info as Record<string, ImplicitFieldSchema>)[treeEdit.field] ??\n\t\t\t\tfail(\"Expected field schema\");\n\n\t\t\tconst modification = treeEdit.modification;\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst schemaIdentifier = (modification as any)[typeField];\n\n\t\t\tlet insertedObject: TreeNode | undefined;\n\t\t\t// if fieldSchema is a LeafnodeSchema, we can check that it's a valid type and set the field.\n\t\t\tif (isPrimitive(modification)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t}\n\t\t\t// If the fieldSchema is a function we can grab the constructor and make an instance of that node.\n\t\t\telse if (typeof fieldSchema === \"function\") {\n\t\t\t\tconst simpleSchema = fieldSchema as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\tpopulateDefaults(modification, definitionMap);\n\t\t\t\tconst constructedModification = new simpleSchema(modification);\n\t\t\t\tvalidator?.(constructedModification);\n\t\t\t\tinsertedObject = constructedModification;\n\n\t\t\t\tif (Array.isArray(modification)) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst field = (node as any)[treeEdit.field] as TreeArrayNode;\n\t\t\t\t\tassert(Array.isArray(field), 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\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t} else {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If the fieldSchema is of type FieldSchema, we can check its allowed types and set the field.\n\t\t\telse if (fieldSchema instanceof FieldSchema) {\n\t\t\t\tif (fieldSchema.kind === FieldKind.Optional && modification === undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tfor (const allowedType of fieldSchema.allowedTypeSet.values()) {\n\t\t\t\t\t\tif (allowedType.identifier === schemaIdentifier) {\n\t\t\t\t\t\t\tif (typeof allowedType === \"function\") {\n\t\t\t\t\t\t\t\tconst simpleSchema = allowedType as unknown as new (\n\t\t\t\t\t\t\t\t\tdummy: unknown,\n\t\t\t\t\t\t\t\t) => TreeNode;\n\t\t\t\t\t\t\t\tconst constructedObject = new simpleSchema(modification);\n\t\t\t\t\t\t\t\tinsertedObject = constructedObject;\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = constructedObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? treeEdit\n\t\t\t\t: {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t};\n\t\t}\n\t\tcase \"move\": {\n\t\t\t// TODO: need to add schema check for valid moves\n\t\t\tconst source = treeEdit.source;\n\t\t\tconst destination = treeEdit.destination;\n\t\t\tconst { array: destinationArrayNode, index: destinationIndex } = getPlaceInfo(\n\t\t\t\tdestination,\n\t\t\t\tidGenerator,\n\t\t\t);\n\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst sourceNode = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst sourceIndex = Tree.key(sourceNode) as number;\n\t\t\t\tconst sourceArrayNode = Tree.parent(sourceNode) as TreeArrayNode;\n\t\t\t\tconst sourceArraySchema = Tree.schema(sourceArrayNode);\n\t\t\t\tif (sourceArraySchema.kind !== NodeKind.Array) {\n\t\t\t\t\tthrow new UsageError(\"the source node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\nfunction isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {\n\tfor (const allowedType of allowedTypes) {\n\t\tif (Tree.is(node, allowedType)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\nfunction getRangeInfo(range: Range, idGenerator: IdGenerator): RangeInfo {\n\tconst { array: arrayFrom, index: startIndex } = getPlaceInfo(range.from, idGenerator);\n\tconst { array: arrayTo, index: endIndex } = getPlaceInfo(range.to, idGenerator);\n\n\tif (arrayFrom !== arrayTo) {\n\t\tthrow new UsageError(\n\t\t\t'The \"from\" node and \"to\" nodes of the range must be in the same parent array.',\n\t\t);\n\t}\n\n\treturn { array: arrayFrom, startIndex, endIndex };\n}\n\nfunction getPlaceInfo(\n\tplace: ObjectPlace | ArrayPlace,\n\tidGenerator: IdGenerator,\n): {\n\tarray: TreeArrayNode;\n\tindex: number;\n} {\n\tif (place.type === \"arrayPlace\") {\n\t\tconst parent = idGenerator.getNode(place.parentId) ?? fail(\"Expected parent node\");\n\t\tconst child = (parent as unknown as Record<string, unknown>)[place.field];\n\t\tif (child === undefined) {\n\t\t\tthrow new UsageError(`No child under field field`);\n\t\t}\n\t\tconst schema = Tree.schema(child as TreeNode);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: child as TreeArrayNode,\n\t\t\tindex: place.location === \"start\" ? 0 : (child as TreeArrayNode).length,\n\t\t};\n\t} else {\n\t\tconst node = getNodeFromTarget(place, idGenerator);\n\t\tconst nodeIndex = Tree.key(node);\n\t\tconst parent = Tree.parent(node);\n\t\tif (parent === undefined) {\n\t\t\tthrow new UsageError(\"TODO: root node target not supported\");\n\t\t}\n\t\tconst schema = Tree.schema(parent);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: parent as unknown as TreeArrayNode,\n\t\t\tindex: place.place === \"before\" ? (nodeIndex as number) : (nodeIndex as number) + 1,\n\t\t};\n\t}\n}\n\n/**\n * Returns the target node with the matching internal objectId using the provided {@link ObjectTarget}\n */\nfunction getNodeFromTarget(target: ObjectTarget, idGenerator: IdGenerator): TreeNode {\n\tconst node = idGenerator.getNode(target.target);\n\tassert(node !== undefined, 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\ninterface SchemaInfo {\n\ttreeNodeSchema: TreeNodeSchema;\n\tsimpleNodeSchema: new (dummy: unknown) => TreeNode;\n}\n\nfunction getSimpleNodeSchema(node: TreeNode): SchemaInfo {\n\tconst treeNodeSchema = Tree.schema(node);\n\tconst simpleNodeSchema = treeNodeSchema as unknown as new (dummy: unknown) => TreeNode;\n\treturn { treeNodeSchema, simpleNodeSchema };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agentEditReducer.js","sourceRoot":"","sources":["../../src/explicit-strategy/agentEditReducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EACN,IAAI,EACJ,QAAQ,EAMR,SAAS,EACT,WAAW,EACX,qBAAqB,EAGrB,aAAa,GACb,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EASN,SAAS,GACT,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,SAAS,gBAAgB,CACxB,IAAe,EACf,aAAoD;IAEpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC5B,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,CACL,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,QAA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mB,CAAC,IAAc;IAC1C,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,gBAAgB,GAAG,cAA6D,CAAC;IACvF,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tTree,\n\tNodeKind,\n\ttype ImplicitAllowedTypes,\n\ttype TreeArrayNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\ttype SimpleNodeSchema,\n\tFieldKind,\n\tFieldSchema,\n\tnormalizeAllowedTypes,\n\ttype ImplicitFieldSchema,\n\ttype IterableTreeArrayContent,\n\tSchemaFactory,\n} from \"@fluidframework/tree/internal\";\n\nimport {\n\ttype TreeEdit,\n\ttype ObjectTarget,\n\ttype Selection,\n\ttype Range,\n\ttype ObjectPlace,\n\ttype ArrayPlace,\n\ttype TreeEditObject,\n\ttype TreeEditValue,\n\ttypeField,\n} from \"./agentEditTypes.js\";\nimport type { IdGenerator } from \"./idGenerator.js\";\nimport type { JsonValue } from \"./jsonTypes.js\";\nimport { toDecoratedJson } from \"./promptGeneration.js\";\nimport { fail } from \"./utils.js\";\n\nfunction populateDefaults(\n\tjson: JsonValue,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n): void {\n\tif (typeof json === \"object\") {\n\t\tif (json === null) {\n\t\t\treturn;\n\t\t}\n\t\tif (Array.isArray(json)) {\n\t\t\tfor (const element of json) {\n\t\t\t\tpopulateDefaults(element, definitionMap);\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof json[typeField] === \"string\",\n\t\t\t\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\nfunction getSchemaIdentifier(content: TreeEditValue): string | undefined {\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\t\t\treturn content[typeField];\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new UsageError(\"Unsupported content type\");\n\t\t}\n\t}\n}\n\nfunction contentWithIds(content: TreeNode, idGenerator: IdGenerator): TreeEditObject {\n\treturn JSON.parse(toDecoratedJson(idGenerator, content)) as TreeEditObject;\n}\n\n/**\n * Manages applying the various types of {@link TreeEdit}'s to a a given {@link TreeNode}.\n */\nexport function applyAgentEdit(\n\ttreeEdit: TreeEdit,\n\tidGenerator: IdGenerator,\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tvalidator?: (edit: TreeNode) => void,\n): TreeEdit {\n\tassertObjectIdsExist(treeEdit, idGenerator);\n\tswitch (treeEdit.type) {\n\t\tcase \"insert\": {\n\t\t\tconst { array, index } = getPlaceInfo(treeEdit.destination, idGenerator);\n\n\t\t\tconst parentNodeSchema = Tree.schema(array);\n\t\t\tpopulateDefaults(treeEdit.content, definitionMap);\n\n\t\t\tconst schemaIdentifier = getSchemaIdentifier(treeEdit.content);\n\n\t\t\t// We assume that the parentNode for inserts edits are guaranteed to be an arrayNode.\n\t\t\tconst allowedTypes = [\n\t\t\t\t...normalizeAllowedTypes(parentNodeSchema.info as ImplicitAllowedTypes),\n\t\t\t];\n\n\t\t\tfor (const allowedType of allowedTypes.values()) {\n\t\t\t\tif (allowedType.identifier === schemaIdentifier && typeof allowedType === \"function\") {\n\t\t\t\t\tconst simpleNodeSchema = allowedType as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\t\tconst insertNode = new simpleNodeSchema(treeEdit.content);\n\t\t\t\t\tvalidator?.(insertNode);\n\t\t\t\t\tarray.insertAt(index, insertNode as unknown as IterableTreeArrayContent<never>);\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tcontent: contentWithIds(insertNode, idGenerator),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tfail(\"inserted node must be of an allowed type\");\n\t\t}\n\t\tcase \"remove\": {\n\t\t\tconst source = treeEdit.source;\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst node = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst parentNode = Tree.parent(node);\n\t\t\t\t// Case for deleting rootNode\n\t\t\t\tif (parentNode === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"The root is required, and cannot be removed. Please use modify edit instead.\",\n\t\t\t\t\t);\n\t\t\t\t} else if (Tree.schema(parentNode).kind === NodeKind.Array) {\n\t\t\t\t\tconst nodeIndex = Tree.key(node) as number;\n\t\t\t\t\t(parentNode as TreeArrayNode).removeAt(nodeIndex);\n\t\t\t\t} else {\n\t\t\t\t\tconst fieldKey = Tree.key(node);\n\t\t\t\t\tconst parentSchema = Tree.schema(parentNode);\n\t\t\t\t\tconst fieldSchema =\n\t\t\t\t\t\t(parentSchema.info as Record<string, ImplicitFieldSchema>)[fieldKey] ??\n\t\t\t\t\t\tfail(\"Expected field schema\");\n\t\t\t\t\tif (fieldSchema instanceof FieldSchema && fieldSchema.kind === FieldKind.Optional) {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t(parentNode as any)[fieldKey] = undefined;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`${fieldKey} is required, and cannot be removed. Please use modify edit instead.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst { array, startIndex, endIndex } = getRangeInfo(source, idGenerator);\n\t\t\t\tarray.removeRange(startIndex, endIndex);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tcase \"modify\": {\n\t\t\tconst node = getNodeFromTarget(treeEdit.target, idGenerator);\n\t\t\tconst { treeNodeSchema } = getSimpleNodeSchema(node);\n\n\t\t\tconst fieldSchema =\n\t\t\t\t(treeNodeSchema.info as Record<string, ImplicitFieldSchema>)[treeEdit.field] ??\n\t\t\t\tfail(\"Expected field schema\");\n\n\t\t\tconst modification = treeEdit.modification;\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n\t\t\tconst schemaIdentifier = (modification as any)[typeField];\n\n\t\t\tlet insertedObject: TreeNode | undefined;\n\t\t\t// if fieldSchema is a LeafnodeSchema, we can check that it's a valid type and set the field.\n\t\t\tif (isPrimitive(modification)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t}\n\t\t\t// If the fieldSchema is a function we can grab the constructor and make an instance of that node.\n\t\t\telse if (typeof fieldSchema === \"function\") {\n\t\t\t\tconst simpleSchema = fieldSchema as unknown as new (dummy: unknown) => TreeNode;\n\t\t\t\tpopulateDefaults(modification, definitionMap);\n\t\t\t\tconst constructedModification = new simpleSchema(modification);\n\t\t\t\tvalidator?.(constructedModification);\n\t\t\t\tinsertedObject = constructedModification;\n\n\t\t\t\tif (Array.isArray(modification)) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst field = (node as any)[treeEdit.field] as TreeArrayNode;\n\t\t\t\t\tassert(Array.isArray(field), 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\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t} else {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = constructedModification;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If the fieldSchema is of type FieldSchema, we can check its allowed types and set the field.\n\t\t\telse if (fieldSchema instanceof FieldSchema) {\n\t\t\t\tif (fieldSchema.kind === FieldKind.Optional && modification === undefined) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t(node as any)[treeEdit.field] = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tfor (const allowedType of fieldSchema.allowedTypeSet.values()) {\n\t\t\t\t\t\tif (allowedType.identifier === schemaIdentifier) {\n\t\t\t\t\t\t\tif (typeof allowedType === \"function\") {\n\t\t\t\t\t\t\t\tconst simpleSchema = allowedType as unknown as new (\n\t\t\t\t\t\t\t\t\tdummy: unknown,\n\t\t\t\t\t\t\t\t) => TreeNode;\n\t\t\t\t\t\t\t\tconst constructedObject = new simpleSchema(modification);\n\t\t\t\t\t\t\t\tinsertedObject = constructedObject;\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = constructedObject;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t\t\t(node as any)[treeEdit.field] = modification;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn insertedObject === undefined\n\t\t\t\t? treeEdit\n\t\t\t\t: {\n\t\t\t\t\t\t...treeEdit,\n\t\t\t\t\t\tmodification: contentWithIds(insertedObject, idGenerator),\n\t\t\t\t\t};\n\t\t}\n\t\tcase \"move\": {\n\t\t\t// TODO: need to add schema check for valid moves\n\t\t\tconst source = treeEdit.source;\n\t\t\tconst destination = treeEdit.destination;\n\t\t\tconst { array: destinationArrayNode, index: destinationIndex } = getPlaceInfo(\n\t\t\t\tdestination,\n\t\t\t\tidGenerator,\n\t\t\t);\n\n\t\t\tif (isObjectTarget(source)) {\n\t\t\t\tconst sourceNode = getNodeFromTarget(source, idGenerator);\n\t\t\t\tconst sourceIndex = Tree.key(sourceNode) as number;\n\t\t\t\tconst sourceArrayNode = Tree.parent(sourceNode) as TreeArrayNode;\n\t\t\t\tconst sourceArraySchema = Tree.schema(sourceArrayNode);\n\t\t\t\tif (sourceArraySchema.kind !== NodeKind.Array) {\n\t\t\t\t\tthrow new UsageError(\"the source node must be within an arrayNode\");\n\t\t\t\t}\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tconst nodeToMove = sourceArrayNode.at(sourceIndex);\n\t\t\t\tassert(nodeToMove !== undefined, 0xa77 /* node to move must exist */);\n\t\t\t\tif (isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\t\tdestinationIndex,\n\t\t\t\t\t\tsourceIndex,\n\t\t\t\t\t\tsourceIndex + 1,\n\t\t\t\t\t\tsourceArrayNode,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t}\n\t\t\t} else if (isRange(source)) {\n\t\t\t\tconst {\n\t\t\t\t\tarray,\n\t\t\t\t\tstartIndex: sourceStartIndex,\n\t\t\t\t\tendIndex: sourceEndIndex,\n\t\t\t\t} = getRangeInfo(source, idGenerator);\n\t\t\t\tconst destinationArraySchema = Tree.schema(destinationArrayNode);\n\t\t\t\tconst allowedTypes = [\n\t\t\t\t\t...normalizeAllowedTypes(destinationArraySchema.info as ImplicitAllowedTypes),\n\t\t\t\t];\n\t\t\t\tfor (let i = sourceStartIndex; i < sourceEndIndex; i++) {\n\t\t\t\t\tconst nodeToMove = array.at(i);\n\t\t\t\t\tassert(nodeToMove !== undefined, 0xa78 /* node to move must exist */);\n\t\t\t\t\tif (!isNodeAllowedType(nodeToMove as TreeNode, allowedTypes)) {\n\t\t\t\t\t\tthrow new UsageError(\"Illegal node type in destination array\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdestinationArrayNode.moveRangeToIndex(\n\t\t\t\t\tdestinationIndex,\n\t\t\t\t\tsourceStartIndex,\n\t\t\t\t\tsourceEndIndex,\n\t\t\t\t\tarray,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn treeEdit;\n\t\t}\n\t\tdefault: {\n\t\t\tfail(\"invalid tree edit\");\n\t\t}\n\t}\n}\n\nfunction isNodeAllowedType(node: TreeNode, allowedTypes: TreeNodeSchema[]): boolean {\n\tfor (const allowedType of allowedTypes) {\n\t\tif (Tree.is(node, allowedType)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction isPrimitive(content: unknown): boolean {\n\treturn (\n\t\ttypeof content === \"number\" ||\n\t\ttypeof content === \"string\" ||\n\t\ttypeof content === \"boolean\" ||\n\t\tcontent === undefined ||\n\t\tcontent === null\n\t);\n}\n\nfunction isObjectTarget(selection: Selection): selection is ObjectTarget {\n\treturn Object.keys(selection).length === 1 && \"target\" in selection;\n}\n\nfunction isRange(selection: Selection): selection is Range {\n\treturn \"from\" in selection && \"to\" in selection;\n}\n\ninterface RangeInfo {\n\tarray: TreeArrayNode;\n\tstartIndex: number;\n\tendIndex: number;\n}\n\nfunction getRangeInfo(range: Range, idGenerator: IdGenerator): RangeInfo {\n\tconst { array: arrayFrom, index: startIndex } = getPlaceInfo(range.from, idGenerator);\n\tconst { array: arrayTo, index: endIndex } = getPlaceInfo(range.to, idGenerator);\n\n\tif (arrayFrom !== arrayTo) {\n\t\tthrow new UsageError(\n\t\t\t'The \"from\" node and \"to\" nodes of the range must be in the same parent array.',\n\t\t);\n\t}\n\n\treturn { array: arrayFrom, startIndex, endIndex };\n}\n\nfunction getPlaceInfo(\n\tplace: ObjectPlace | ArrayPlace,\n\tidGenerator: IdGenerator,\n): {\n\tarray: TreeArrayNode;\n\tindex: number;\n} {\n\tif (place.type === \"arrayPlace\") {\n\t\tconst parent = idGenerator.getNode(place.parentId) ?? fail(\"Expected parent node\");\n\t\tconst child = (parent as unknown as Record<string, unknown>)[place.field];\n\t\tif (child === undefined) {\n\t\t\tthrow new UsageError(`No child under field field`);\n\t\t}\n\t\tconst schema = Tree.schema(child as TreeNode);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: child as TreeArrayNode,\n\t\t\tindex: place.location === \"start\" ? 0 : (child as TreeArrayNode).length,\n\t\t};\n\t} else {\n\t\tconst node = getNodeFromTarget(place, idGenerator);\n\t\tconst nodeIndex = Tree.key(node);\n\t\tconst parent = Tree.parent(node);\n\t\tif (parent === undefined) {\n\t\t\tthrow new UsageError(\"TODO: root node target not supported\");\n\t\t}\n\t\tconst schema = Tree.schema(parent);\n\t\tif (schema.kind !== NodeKind.Array) {\n\t\t\tthrow new UsageError(\"Expected child to be in an array node\");\n\t\t}\n\t\treturn {\n\t\t\tarray: parent as unknown as TreeArrayNode,\n\t\t\tindex: place.place === \"before\" ? (nodeIndex as number) : (nodeIndex as number) + 1,\n\t\t};\n\t}\n}\n\n/**\n * Returns the target node with the matching internal objectId using the provided {@link ObjectTarget}\n */\nfunction getNodeFromTarget(target: ObjectTarget, idGenerator: IdGenerator): TreeNode {\n\tconst node = idGenerator.getNode(target.target);\n\tassert(node !== undefined, 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\ninterface SchemaInfo {\n\ttreeNodeSchema: TreeNodeSchema;\n\tsimpleNodeSchema: new (dummy: unknown) => TreeNode;\n}\n\nfunction getSimpleNodeSchema(node: TreeNode): SchemaInfo {\n\tconst treeNodeSchema = Tree.schema(node);\n\tconst simpleNodeSchema = treeNodeSchema as unknown as new (dummy: unknown) => TreeNode;\n\treturn { treeNodeSchema, simpleNodeSchema };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/ai-collab",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"description": "Experimental package to simplify integrating AI into Fluid-based applications",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluidframework/core-utils": "~2.
|
|
73
|
-
"@fluidframework/runtime-utils": "~2.
|
|
74
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
75
|
-
"@fluidframework/tree": "~2.
|
|
72
|
+
"@fluidframework/core-utils": "~2.22.0",
|
|
73
|
+
"@fluidframework/runtime-utils": "~2.22.0",
|
|
74
|
+
"@fluidframework/telemetry-utils": "~2.22.0",
|
|
75
|
+
"@fluidframework/tree": "~2.22.0",
|
|
76
76
|
"openai": "^4.67.3",
|
|
77
77
|
"typechat": "^0.1.1",
|
|
78
78
|
"zod": "^3.23.8"
|
|
@@ -80,14 +80,14 @@
|
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
82
82
|
"@biomejs/biome": "~1.9.3",
|
|
83
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
83
|
+
"@fluid-internal/mocha-test-setup": "~2.22.0",
|
|
84
84
|
"@fluid-tools/build-cli": "^0.51.0",
|
|
85
85
|
"@fluidframework/build-common": "^2.0.3",
|
|
86
86
|
"@fluidframework/build-tools": "^0.51.0",
|
|
87
87
|
"@fluidframework/eslint-config-fluid": "^5.7.3",
|
|
88
|
-
"@fluidframework/id-compressor": "~2.
|
|
89
|
-
"@fluidframework/runtime-utils": "~2.
|
|
90
|
-
"@fluidframework/test-runtime-utils": "~2.
|
|
88
|
+
"@fluidframework/id-compressor": "~2.22.0",
|
|
89
|
+
"@fluidframework/runtime-utils": "~2.22.0",
|
|
90
|
+
"@fluidframework/test-runtime-utils": "~2.22.0",
|
|
91
91
|
"@microsoft/api-extractor": "7.47.8",
|
|
92
92
|
"@types/mocha": "^10.0.10",
|
|
93
93
|
"@types/node": "^18.19.0",
|
|
@@ -62,27 +62,25 @@ function populateDefaults(
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function getSchemaIdentifier(content: TreeEditValue): string | undefined {
|
|
65
|
-
const sf = new SchemaFactory(undefined);
|
|
66
|
-
|
|
67
65
|
switch (typeof content) {
|
|
68
66
|
case "boolean": {
|
|
69
|
-
return
|
|
67
|
+
return SchemaFactory.boolean.identifier;
|
|
70
68
|
}
|
|
71
69
|
case "number": {
|
|
72
|
-
return
|
|
70
|
+
return SchemaFactory.number.identifier;
|
|
73
71
|
}
|
|
74
72
|
case "string": {
|
|
75
|
-
return
|
|
73
|
+
return SchemaFactory.string.identifier;
|
|
76
74
|
}
|
|
77
75
|
case "object": {
|
|
78
76
|
if (content === null) {
|
|
79
|
-
return
|
|
77
|
+
return SchemaFactory.null.identifier;
|
|
80
78
|
}
|
|
81
79
|
if (Array.isArray(content)) {
|
|
82
80
|
throw new UsageError("Arrays are not currently supported in this context");
|
|
83
81
|
}
|
|
84
82
|
if (isFluidHandle(content)) {
|
|
85
|
-
return
|
|
83
|
+
return SchemaFactory.handle.identifier;
|
|
86
84
|
}
|
|
87
85
|
return content[typeField];
|
|
88
86
|
}
|