@fluidframework/tree-agent 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/api-report/tree-agent.alpha.api.md +1 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +2 -0
- package/dist/agent.js.map +1 -1
- package/dist/methodBinding.d.ts +1 -3
- package/dist/methodBinding.d.ts.map +1 -1
- package/dist/methodBinding.js.map +1 -1
- package/dist/propertyBinding.d.ts.map +1 -1
- package/dist/propertyBinding.js.map +1 -1
- package/dist/utils.js +2 -2
- package/dist/utils.js.map +1 -1
- package/lib/agent.d.ts.map +1 -1
- package/lib/agent.js +2 -0
- package/lib/agent.js.map +1 -1
- package/lib/methodBinding.d.ts +1 -3
- package/lib/methodBinding.d.ts.map +1 -1
- package/lib/methodBinding.js.map +1 -1
- package/lib/propertyBinding.d.ts.map +1 -1
- package/lib/propertyBinding.js.map +1 -1
- package/lib/utils.js +2 -2
- package/lib/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/agent.ts +2 -0
- package/src/methodBinding.ts +2 -2
- package/src/propertyBinding.ts +1 -0
- package/src/utils.ts +2 -2
|
@@ -54,9 +54,7 @@ export type ExposableKeys<T> = {
|
|
|
54
54
|
// @alpha
|
|
55
55
|
export interface ExposedMethods {
|
|
56
56
|
// (undocumented)
|
|
57
|
-
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<
|
|
58
|
-
[P in K]: Infer<Z>;
|
|
59
|
-
}> & IExposedMethods, Z extends FunctionDef<any, any, any>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
57
|
+
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods, Z extends FunctionDef<any, any, any>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
60
58
|
instanceOf<T extends TreeNodeSchemaClass>(schema: T): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;
|
|
61
59
|
}
|
|
62
60
|
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,mBAAmB,EAGnB,MAAM,sBAAsB,CAAC;AAU9B,OAAO,KAAK,EACX,mBAAmB,EAEnB,oBAAoB,EAGpB,OAAO,EAEP,UAAU,EACV,MAAM,UAAU,CAAC;AAiBlB;;;;GAIG;AACH,qBAAa,uBAAuB,CAAC,OAAO,SAAS,mBAAmB;IAUtE,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAV1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2D;IAClF;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAS;gBAGf,MAAM,EAAE,mBAAmB,EAC5C,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EACR,OAAO,CAAC,qDAAyC;IAkCnE;;;;;OAKG;IACU,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAqEvD;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,mBAAmB,EAGnB,MAAM,sBAAsB,CAAC;AAU9B,OAAO,KAAK,EACX,mBAAmB,EAEnB,oBAAoB,EAGpB,OAAO,EAEP,UAAU,EACV,MAAM,UAAU,CAAC;AAiBlB;;;;GAIG;AACH,qBAAa,uBAAuB,CAAC,OAAO,SAAS,mBAAmB;IAUtE,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAV1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2D;IAClF;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAS;gBAGf,MAAM,EAAE,mBAAmB,EAC5C,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EACR,OAAO,CAAC,qDAAyC;IAkCnE;;;;;OAKG;IACU,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAqEvD;AAoFD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,mBAAmB,EAChE,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GACvB,OAAO,CAAC,OAAO,CAAC,CA2ClB"}
|
package/dist/agent.js
CHANGED
|
@@ -135,6 +135,7 @@ function constructTreeNode(schema, content) {
|
|
|
135
135
|
utils_js_1.llmDefault in field.metadata.custom) {
|
|
136
136
|
const defaulter = field.metadata.custom[utils_js_1.llmDefault];
|
|
137
137
|
if (typeof defaulter === "function") {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
138
139
|
const defaultValue = defaulter();
|
|
139
140
|
if (defaultValue !== undefined) {
|
|
140
141
|
contentWithDefaults[key] = defaultValue;
|
|
@@ -184,6 +185,7 @@ function createDefaultEditor() {
|
|
|
184
185
|
const context = createContext(tree);
|
|
185
186
|
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
|
186
187
|
const fn = new Function("context", code);
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
187
189
|
await fn(context);
|
|
188
190
|
};
|
|
189
191
|
}
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,+CAA0D;AAO1D,sDAA+E;AAY/E,2CAAuD;AACvD,6CAAuC;AACvC,yCAMoB;AAEpB;;;GAGG;A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AC;YACvC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,CAAC,IAAI;YACT,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,IAAI,YAAY,eAAQ,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,YAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,IAAI,KAAK,eAAQ,CAAC,GAAG,CAAC;YACrC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,EAAE,CAAC,KAAe,EAAwB,EAAE,CAAC,YAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACrE,GAAG,EAAE,CAAC,KAAe,EAAmB,EAAE,CAAC,YAAI,CAAC,GAAG,CAAC,KAAK,CAAC;KAC/B,CAAC;AAC9B,CAAC;AA7CD,sCA6CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeNodeSchema,\n} from \"@fluidframework/tree\";\nimport { NodeKind, TreeNode } from \"@fluidframework/tree\";\nimport type {\n\tReadableField,\n\tFactoryContentObject,\n\tInsertableContent,\n\tReadSchema,\n} from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema, Tree, TreeAlpha } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tSharedTreeChatModel,\n\tEditResult,\n\tSemanticAgentOptions,\n\tLogger,\n\tAsynchronousEditor,\n\tContext,\n\tSynchronousEditor,\n\tViewOrTree,\n} from \"./api.js\";\nimport { getPrompt, stringifyTree } from \"./prompt.js\";\nimport { Subtree } from \"./subtree.js\";\nimport {\n\tllmDefault,\n\tfindSchemas,\n\ttoErrorString,\n\tunqualifySchema,\n\tisNamedSchema,\n} from \"./utils.js\";\n\n/**\n * The default maximum number of sequential edits the LLM can make before we assume it's stuck in a loop.\n * @remarks This can be overridden by passing {@link SemanticAgentOptions.maximumSequentialEdits | maximumSequentialEdits} to {@link createSemanticAgent}.\n */\nconst defaultMaxSequentialEdits = 20;\n\n/**\n * An agent that uses a {@link SharedTreeChatModel} to interact with a SharedTree.\n * @remarks This class forwards user queries to the chat model, and handles the application of any edits to the tree that the model requests.\n * @alpha @sealed\n */\nexport class SharedTreeSemanticAgent<TSchema extends ImplicitFieldSchema> {\n\t// Converted from ECMAScript private fields (#name) to TypeScript private members for easier debugger inspection.\n\tprivate readonly outerTree: Subtree<TSchema>;\n\tprivate readonly editor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>;\n\t/**\n\t * Whether or not the outer tree has changed since the last query finished.\n\t */\n\tprivate outerTreeIsDirty = false;\n\n\tpublic constructor(\n\t\tprivate readonly client: SharedTreeChatModel,\n\t\ttree: ViewOrTree<TSchema>,\n\t\tprivate readonly options?: Readonly<SemanticAgentOptions<TSchema>>,\n\t) {\n\t\tif (tree instanceof TreeNode) {\n\t\t\tTree.on(tree, \"treeChanged\", () => (this.outerTreeIsDirty = true));\n\t\t} else {\n\t\t\ttree.events.on(\"changed\", () => (this.outerTreeIsDirty = true));\n\t\t}\n\n\t\tthis.outerTree = new Subtree(tree);\n\t\tthis.editor = this.options?.editor ?? createDefaultEditor();\n\t\tconst prompt = getPrompt({\n\t\t\tsubtree: this.outerTree,\n\t\t\teditToolName: this.client.editToolName,\n\t\t\tdomainHints: this.options?.domainHints,\n\t\t});\n\t\tthis.options?.logger?.log(`# Fluid Framework SharedTree AI Agent Log\\n\\n`);\n\t\tconst now = new Date();\n\t\tconst formattedDate = now.toLocaleString(undefined, {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"numeric\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t});\n\t\tthis.options?.logger?.log(`Agent created: **${formattedDate}**\\n\\n`);\n\t\tif (this.client.name !== undefined) {\n\t\t\tthis.options?.logger?.log(`Model: **${this.client.name}**\\n\\n`);\n\t\t}\n\t\tthis.client.appendContext?.(prompt);\n\t\tthis.options?.logger?.log(`## System Prompt\\n\\n${prompt}\\n\\n`);\n\t}\n\n\t/**\n\t * Given a user prompt, return a response.\n\t *\n\t * @param userPrompt - The prompt to send to the agent.\n\t * @returns The agent's response.\n\t */\n\tpublic async query(userPrompt: string): Promise<string> {\n\t\tthis.options?.logger?.log(`## User Query\\n\\n${userPrompt}\\n\\n`);\n\n\t\t// Notify the llm if the tree has changed since the last query, and if so, provide the new state of the tree.\n\t\tif (this.outerTreeIsDirty) {\n\t\t\tconst stringified = stringifyTree(this.outerTree.field);\n\t\t\tthis.client.appendContext?.(\n\t\t\t\t`The tree has changed since the last query. The new state of the tree is: \\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\``,\n\t\t\t);\n\t\t\tthis.options?.logger?.log(\n\t\t\t\t`### Latest Tree State\\n\\nThe Tree was edited by a local or remote user since the previous query. The latest state is:\\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\`\\n\\n`,\n\t\t\t);\n\t\t}\n\n\t\t// Fork a branch that will live for the lifetime of this query (which can be multiple LLM calls if the there are errors or the LLM decides to take multiple steps to accomplish a task).\n\t\t// The branch will be merged back into the outer branch if and only if the query succeeds.\n\t\tconst queryTree = this.outerTree.fork();\n\t\tconst maxEditCount = this.options?.maximumSequentialEdits ?? defaultMaxSequentialEdits;\n\t\tlet active = true;\n\t\tlet editCount = 0;\n\t\tlet rollbackEdits = false;\n\t\tconst { editToolName } = this.client;\n\t\tconst edit = async (editCode: string): Promise<EditResult> => {\n\t\t\tif (editToolName === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"disabledError\",\n\t\t\t\t\tmessage: \"Editing is not enabled for this model.\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (!active) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"expiredError\",\n\t\t\t\t\tmessage: `The query has already completed. Further edits are not allowed.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (++editCount > maxEditCount) {\n\t\t\t\trollbackEdits = true;\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"tooManyEditsError\",\n\t\t\t\t\tmessage: `The maximum number of edits (${maxEditCount}) for this query has been exceeded.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst editResult = await applyTreeFunction(\n\t\t\t\tqueryTree,\n\t\t\t\teditCode,\n\t\t\t\tthis.editor,\n\t\t\t\tthis.options?.logger,\n\t\t\t);\n\n\t\t\trollbackEdits = editResult.type !== \"success\";\n\t\t\treturn editResult;\n\t\t};\n\n\t\tconst responseMessage = await this.client.query({\n\t\t\ttext: userPrompt,\n\t\t\tedit,\n\t\t});\n\t\tactive = false;\n\n\t\tif (!rollbackEdits) {\n\t\t\tthis.outerTree.branch.merge(queryTree.branch);\n\t\t\tthis.outerTreeIsDirty = false;\n\t\t}\n\t\tthis.options?.logger?.log(`## Response\\n\\n`);\n\t\tthis.options?.logger?.log(`${responseMessage}\\n\\n`);\n\t\treturn responseMessage;\n\t}\n}\n\n/**\n * Creates an unhydrated node of the given schema with the given value.\n * @remarks If the schema is an object with {@link llmDefault | default values}, this function populates the node with those defaults.\n */\nfunction constructTreeNode(schema: TreeNodeSchema, content: FactoryContentObject): TreeNode {\n\tlet toInsert = content;\n\tif (schema instanceof ObjectNodeSchema) {\n\t\tconst contentWithDefaults: Record<string, InsertableContent | undefined> = {};\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (content[key] === undefined) {\n\t\t\t\tif (\n\t\t\t\t\ttypeof field.metadata.custom === \"object\" &&\n\t\t\t\t\tfield.metadata.custom !== null &&\n\t\t\t\t\tllmDefault in field.metadata.custom\n\t\t\t\t) {\n\t\t\t\t\tconst defaulter = field.metadata.custom[llmDefault];\n\t\t\t\t\tif (typeof defaulter === \"function\") {\n\t\t\t\t\t\tconst defaultValue: unknown = defaulter();\n\t\t\t\t\t\tif (defaultValue !== undefined) {\n\t\t\t\t\t\t\tcontentWithDefaults[key] = defaultValue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontentWithDefaults[key] = content[key];\n\t\t\t}\n\t\t}\n\t\ttoInsert = contentWithDefaults;\n\t}\n\n\t// Cast to never because tagContentSchema is typed to only accept InsertableContent, but we know that 'toInsert' (either the original content or contentWithDefaults) produces valid content for the schema.\n\treturn TreeAlpha.tagContentSchema(schema, toInsert as never);\n}\n\n/**\n * Applies the given function (as a string of JavaScript code or an actual function) to the given tree.\n */\nasync function applyTreeFunction<TSchema extends ImplicitFieldSchema>(\n\ttree: Subtree<TSchema>,\n\teditCode: string,\n\teditor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>,\n\tlogger: Logger | undefined,\n): Promise<EditResult> {\n\tlogger?.log(`### Editing Tool Invoked\\n\\n`);\n\tlogger?.log(`#### Generated Code\\n\\n\\`\\`\\`javascript\\n${editCode}\\n\\`\\`\\`\\n\\n`);\n\n\t// Fork a branch to edit. If the edit fails or produces an error, we discard this branch, otherwise we merge it.\n\tconst editTree = tree.fork();\n\ttry {\n\t\tawait editor(editTree.viewOrTree, editCode);\n\t} catch (error: unknown) {\n\t\tlogger?.log(`#### Error\\n\\n`);\n\t\tlogger?.log(`\\`\\`\\`JSON\\n${toErrorString(error)}\\n\\`\\`\\`\\n\\n`);\n\t\teditTree.branch.dispose();\n\t\treturn {\n\t\t\ttype: \"editingError\",\n\t\t\tmessage: `Running the generated code produced an error. The state of the tree will be reset to its previous state as it was before the code ran. Please try again. Here is the error: ${toErrorString(error)}`,\n\t\t};\n\t}\n\n\ttree.branch.merge(editTree.branch);\n\tlogger?.log(`#### New Tree State\\n\\n`);\n\tlogger?.log(`${`\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``}\\n\\n`);\n\treturn {\n\t\ttype: \"success\",\n\t\tmessage: `After running the code, the new state of the tree is:\\n\\n\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``,\n\t};\n}\n\nfunction createDefaultEditor<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n>(): AsynchronousEditor<TSchema> {\n\treturn async (tree, code) => {\n\t\tconst context = createContext(tree);\n\t\t// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval\n\t\tconst fn = new Function(\"context\", code);\n\t\tawait fn(context);\n\t};\n}\n\n/**\n * Creates a {@link Context} for the given subtree.\n * @alpha\n */\nexport function createContext<TSchema extends ImplicitFieldSchema>(\n\ttree: ViewOrTree<TSchema>,\n): Context<TSchema> {\n\tconst subTree = new Subtree(tree);\n\t// Stick the tree schema constructors on an object passed to the function so that the LLM can create new nodes.\n\tconst create: Record<string, (input: FactoryContentObject) => TreeNode> = {};\n\tconst is: Record<string, <T extends TreeNode>(input: unknown) => input is T> = {};\n\tfor (const schema of findSchemas(subTree.schema, (s) => isNamedSchema(s.identifier))) {\n\t\tconst name = unqualifySchema(schema.identifier);\n\t\tcreate[name] = (input: FactoryContentObject) => constructTreeNode(schema, input);\n\t\tis[name] = <T extends TreeNode>(input: unknown): input is T => Tree.is(input, schema);\n\t}\n\n\treturn {\n\t\tget root(): ReadableField<TSchema> {\n\t\t\treturn subTree.field;\n\t\t},\n\t\tset root(value: TreeFieldFromImplicitField<ReadSchema<TSchema>>) {\n\t\t\tsubTree.field = value;\n\t\t},\n\t\tcreate,\n\t\tis,\n\t\tisArray(node) {\n\t\t\tif (Array.isArray(node)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Array;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tisMap(node) {\n\t\t\tif (node instanceof Map) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Map;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tparent: (child: TreeNode): TreeNode | undefined => Tree.parent(child),\n\t\tkey: (child: TreeNode): string | number => Tree.key(child),\n\t} satisfies Context<TSchema>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,+CAA0D;AAO1D,sDAA+E;AAY/E,2CAAuD;AACvD,6CAAuC;AACvC,yCAMoB;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC;;;;GAIG;AACH,MAAa,uBAAuB;IASnC,YACkB,MAA2B,EAC5C,IAAyB,EACR,OAAiD;QAFjD,WAAM,GAAN,MAAM,CAAqB;QAE3B,YAAO,GAAP,OAAO,CAA0C;QARnE;;WAEG;QACK,qBAAgB,GAAG,KAAK,CAAC;QAOhC,IAAI,IAAI,YAAY,eAAQ,EAAE,CAAC;YAC9B,YAAI,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAC;QACpE,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,oBAAO,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,IAAI,mBAAmB,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC;YACxB,OAAO,EAAE,IAAI,CAAC,SAAS;YACvB,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;YACtC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,CAAC;QACtB,CAAC;QACD,IAAI,IAAI,CAAC,KAAsD;YAC9D,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,CAAC;QACD,MAAM;QACN,EAAE;QACF,OAAO,CAAC,IAAI;YACX,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,IAAI,YAAY,eAAQ,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,YAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,IAAI,KAAK,eAAQ,CAAC,KAAK,CAAC;YACvC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,CAAC,IAAI;YACT,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,IAAI,YAAY,eAAQ,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,YAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,IAAI,KAAK,eAAQ,CAAC,GAAG,CAAC;YACrC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,EAAE,CAAC,KAAe,EAAwB,EAAE,CAAC,YAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACrE,GAAG,EAAE,CAAC,KAAe,EAAmB,EAAE,CAAC,YAAI,CAAC,GAAG,CAAC,KAAK,CAAC;KAC/B,CAAC;AAC9B,CAAC;AA7CD,sCA6CC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeNodeSchema,\n} from \"@fluidframework/tree\";\nimport { NodeKind, TreeNode } from \"@fluidframework/tree\";\nimport type {\n\tReadableField,\n\tFactoryContentObject,\n\tInsertableContent,\n\tReadSchema,\n} from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema, Tree, TreeAlpha } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tSharedTreeChatModel,\n\tEditResult,\n\tSemanticAgentOptions,\n\tLogger,\n\tAsynchronousEditor,\n\tContext,\n\tSynchronousEditor,\n\tViewOrTree,\n} from \"./api.js\";\nimport { getPrompt, stringifyTree } from \"./prompt.js\";\nimport { Subtree } from \"./subtree.js\";\nimport {\n\tllmDefault,\n\tfindSchemas,\n\ttoErrorString,\n\tunqualifySchema,\n\tisNamedSchema,\n} from \"./utils.js\";\n\n/**\n * The default maximum number of sequential edits the LLM can make before we assume it's stuck in a loop.\n * @remarks This can be overridden by passing {@link SemanticAgentOptions.maximumSequentialEdits | maximumSequentialEdits} to {@link createSemanticAgent}.\n */\nconst defaultMaxSequentialEdits = 20;\n\n/**\n * An agent that uses a {@link SharedTreeChatModel} to interact with a SharedTree.\n * @remarks This class forwards user queries to the chat model, and handles the application of any edits to the tree that the model requests.\n * @alpha @sealed\n */\nexport class SharedTreeSemanticAgent<TSchema extends ImplicitFieldSchema> {\n\t// Converted from ECMAScript private fields (#name) to TypeScript private members for easier debugger inspection.\n\tprivate readonly outerTree: Subtree<TSchema>;\n\tprivate readonly editor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>;\n\t/**\n\t * Whether or not the outer tree has changed since the last query finished.\n\t */\n\tprivate outerTreeIsDirty = false;\n\n\tpublic constructor(\n\t\tprivate readonly client: SharedTreeChatModel,\n\t\ttree: ViewOrTree<TSchema>,\n\t\tprivate readonly options?: Readonly<SemanticAgentOptions<TSchema>>,\n\t) {\n\t\tif (tree instanceof TreeNode) {\n\t\t\tTree.on(tree, \"treeChanged\", () => (this.outerTreeIsDirty = true));\n\t\t} else {\n\t\t\ttree.events.on(\"changed\", () => (this.outerTreeIsDirty = true));\n\t\t}\n\n\t\tthis.outerTree = new Subtree(tree);\n\t\tthis.editor = this.options?.editor ?? createDefaultEditor();\n\t\tconst prompt = getPrompt({\n\t\t\tsubtree: this.outerTree,\n\t\t\teditToolName: this.client.editToolName,\n\t\t\tdomainHints: this.options?.domainHints,\n\t\t});\n\t\tthis.options?.logger?.log(`# Fluid Framework SharedTree AI Agent Log\\n\\n`);\n\t\tconst now = new Date();\n\t\tconst formattedDate = now.toLocaleString(undefined, {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"numeric\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t});\n\t\tthis.options?.logger?.log(`Agent created: **${formattedDate}**\\n\\n`);\n\t\tif (this.client.name !== undefined) {\n\t\t\tthis.options?.logger?.log(`Model: **${this.client.name}**\\n\\n`);\n\t\t}\n\t\tthis.client.appendContext?.(prompt);\n\t\tthis.options?.logger?.log(`## System Prompt\\n\\n${prompt}\\n\\n`);\n\t}\n\n\t/**\n\t * Given a user prompt, return a response.\n\t *\n\t * @param userPrompt - The prompt to send to the agent.\n\t * @returns The agent's response.\n\t */\n\tpublic async query(userPrompt: string): Promise<string> {\n\t\tthis.options?.logger?.log(`## User Query\\n\\n${userPrompt}\\n\\n`);\n\n\t\t// Notify the llm if the tree has changed since the last query, and if so, provide the new state of the tree.\n\t\tif (this.outerTreeIsDirty) {\n\t\t\tconst stringified = stringifyTree(this.outerTree.field);\n\t\t\tthis.client.appendContext?.(\n\t\t\t\t`The tree has changed since the last query. The new state of the tree is: \\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\``,\n\t\t\t);\n\t\t\tthis.options?.logger?.log(\n\t\t\t\t`### Latest Tree State\\n\\nThe Tree was edited by a local or remote user since the previous query. The latest state is:\\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\`\\n\\n`,\n\t\t\t);\n\t\t}\n\n\t\t// Fork a branch that will live for the lifetime of this query (which can be multiple LLM calls if the there are errors or the LLM decides to take multiple steps to accomplish a task).\n\t\t// The branch will be merged back into the outer branch if and only if the query succeeds.\n\t\tconst queryTree = this.outerTree.fork();\n\t\tconst maxEditCount = this.options?.maximumSequentialEdits ?? defaultMaxSequentialEdits;\n\t\tlet active = true;\n\t\tlet editCount = 0;\n\t\tlet rollbackEdits = false;\n\t\tconst { editToolName } = this.client;\n\t\tconst edit = async (editCode: string): Promise<EditResult> => {\n\t\t\tif (editToolName === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"disabledError\",\n\t\t\t\t\tmessage: \"Editing is not enabled for this model.\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (!active) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"expiredError\",\n\t\t\t\t\tmessage: `The query has already completed. Further edits are not allowed.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (++editCount > maxEditCount) {\n\t\t\t\trollbackEdits = true;\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"tooManyEditsError\",\n\t\t\t\t\tmessage: `The maximum number of edits (${maxEditCount}) for this query has been exceeded.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst editResult = await applyTreeFunction(\n\t\t\t\tqueryTree,\n\t\t\t\teditCode,\n\t\t\t\tthis.editor,\n\t\t\t\tthis.options?.logger,\n\t\t\t);\n\n\t\t\trollbackEdits = editResult.type !== \"success\";\n\t\t\treturn editResult;\n\t\t};\n\n\t\tconst responseMessage = await this.client.query({\n\t\t\ttext: userPrompt,\n\t\t\tedit,\n\t\t});\n\t\tactive = false;\n\n\t\tif (!rollbackEdits) {\n\t\t\tthis.outerTree.branch.merge(queryTree.branch);\n\t\t\tthis.outerTreeIsDirty = false;\n\t\t}\n\t\tthis.options?.logger?.log(`## Response\\n\\n`);\n\t\tthis.options?.logger?.log(`${responseMessage}\\n\\n`);\n\t\treturn responseMessage;\n\t}\n}\n\n/**\n * Creates an unhydrated node of the given schema with the given value.\n * @remarks If the schema is an object with {@link llmDefault | default values}, this function populates the node with those defaults.\n */\nfunction constructTreeNode(schema: TreeNodeSchema, content: FactoryContentObject): TreeNode {\n\tlet toInsert = content;\n\tif (schema instanceof ObjectNodeSchema) {\n\t\tconst contentWithDefaults: Record<string, InsertableContent | undefined> = {};\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (content[key] === undefined) {\n\t\t\t\tif (\n\t\t\t\t\ttypeof field.metadata.custom === \"object\" &&\n\t\t\t\t\tfield.metadata.custom !== null &&\n\t\t\t\t\tllmDefault in field.metadata.custom\n\t\t\t\t) {\n\t\t\t\t\tconst defaulter = field.metadata.custom[llmDefault];\n\t\t\t\t\tif (typeof defaulter === \"function\") {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\t\t\t\t\tconst defaultValue: unknown = defaulter();\n\t\t\t\t\t\tif (defaultValue !== undefined) {\n\t\t\t\t\t\t\tcontentWithDefaults[key] = defaultValue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontentWithDefaults[key] = content[key];\n\t\t\t}\n\t\t}\n\t\ttoInsert = contentWithDefaults;\n\t}\n\n\t// Cast to never because tagContentSchema is typed to only accept InsertableContent, but we know that 'toInsert' (either the original content or contentWithDefaults) produces valid content for the schema.\n\treturn TreeAlpha.tagContentSchema(schema, toInsert as never);\n}\n\n/**\n * Applies the given function (as a string of JavaScript code or an actual function) to the given tree.\n */\nasync function applyTreeFunction<TSchema extends ImplicitFieldSchema>(\n\ttree: Subtree<TSchema>,\n\teditCode: string,\n\teditor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>,\n\tlogger: Logger | undefined,\n): Promise<EditResult> {\n\tlogger?.log(`### Editing Tool Invoked\\n\\n`);\n\tlogger?.log(`#### Generated Code\\n\\n\\`\\`\\`javascript\\n${editCode}\\n\\`\\`\\`\\n\\n`);\n\n\t// Fork a branch to edit. If the edit fails or produces an error, we discard this branch, otherwise we merge it.\n\tconst editTree = tree.fork();\n\ttry {\n\t\tawait editor(editTree.viewOrTree, editCode);\n\t} catch (error: unknown) {\n\t\tlogger?.log(`#### Error\\n\\n`);\n\t\tlogger?.log(`\\`\\`\\`JSON\\n${toErrorString(error)}\\n\\`\\`\\`\\n\\n`);\n\t\teditTree.branch.dispose();\n\t\treturn {\n\t\t\ttype: \"editingError\",\n\t\t\tmessage: `Running the generated code produced an error. The state of the tree will be reset to its previous state as it was before the code ran. Please try again. Here is the error: ${toErrorString(error)}`,\n\t\t};\n\t}\n\n\ttree.branch.merge(editTree.branch);\n\tlogger?.log(`#### New Tree State\\n\\n`);\n\tlogger?.log(`${`\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``}\\n\\n`);\n\treturn {\n\t\ttype: \"success\",\n\t\tmessage: `After running the code, the new state of the tree is:\\n\\n\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``,\n\t};\n}\n\nfunction createDefaultEditor<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n>(): AsynchronousEditor<TSchema> {\n\treturn async (tree, code) => {\n\t\tconst context = createContext(tree);\n\t\t// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval\n\t\tconst fn = new Function(\"context\", code);\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\tawait fn(context);\n\t};\n}\n\n/**\n * Creates a {@link Context} for the given subtree.\n * @alpha\n */\nexport function createContext<TSchema extends ImplicitFieldSchema>(\n\ttree: ViewOrTree<TSchema>,\n): Context<TSchema> {\n\tconst subTree = new Subtree(tree);\n\t// Stick the tree schema constructors on an object passed to the function so that the LLM can create new nodes.\n\tconst create: Record<string, (input: FactoryContentObject) => TreeNode> = {};\n\tconst is: Record<string, <T extends TreeNode>(input: unknown) => input is T> = {};\n\tfor (const schema of findSchemas(subTree.schema, (s) => isNamedSchema(s.identifier))) {\n\t\tconst name = unqualifySchema(schema.identifier);\n\t\tcreate[name] = (input: FactoryContentObject) => constructTreeNode(schema, input);\n\t\tis[name] = <T extends TreeNode>(input: unknown): input is T => Tree.is(input, schema);\n\t}\n\n\treturn {\n\t\tget root(): ReadableField<TSchema> {\n\t\t\treturn subTree.field;\n\t\t},\n\t\tset root(value: TreeFieldFromImplicitField<ReadSchema<TSchema>>) {\n\t\t\tsubTree.field = value;\n\t\t},\n\t\tcreate,\n\t\tis,\n\t\tisArray(node) {\n\t\t\tif (Array.isArray(node)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Array;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tisMap(node) {\n\t\t\tif (node instanceof Map) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Map;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tparent: (child: TreeNode): TreeNode | undefined => Tree.parent(child),\n\t\tkey: (child: TreeNode): string | number => Tree.key(child),\n\t} satisfies Context<TSchema>;\n}\n"]}
|
package/dist/methodBinding.d.ts
CHANGED
|
@@ -80,9 +80,7 @@ export type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Res
|
|
|
80
80
|
* @alpha
|
|
81
81
|
*/
|
|
82
82
|
export interface ExposedMethods {
|
|
83
|
-
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<
|
|
84
|
-
[P in K]: Infer<Z>;
|
|
85
|
-
}> & IExposedMethods, Z extends FunctionDef<any, any, any>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
83
|
+
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods, Z extends FunctionDef<any, any, any>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
86
84
|
/**
|
|
87
85
|
* Create a Zod schema for a SharedTree schema class.
|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IAAI,EACxB,WAAW,CAAC,OAAO,CACnB,CAAC;IACH,CAAC;IAEM,UAAU,CAChB,MAAS;QAET,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,IAAA,qBAAU,EAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,WAA2B;QAI1D,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAyC,CAAC;QAC9D,IAAI,WAAW,CAAC,2BAAmB,CAAC,KAAK,SAAS,EAAE,CAAC;YACpD,WAAW,CAAC,2BAAmB,CAAC,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;QACD,OAAO;YACN,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,EAAE,cAAc,CAAC,eAAe;SAC/C,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { NodeKind, TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\n\nimport { instanceOf } from \"./utils.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny,\n\tRest extends z.ZodTypeAny | null = null,\n> {\n\tdescription?: string;\n\targs: Args;\n\trest?: Rest;\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | null,\n\t\tpublic readonly returns: z.ZodTypeAny,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n */\nexport type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest>\n\t? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<
|
|
1
|
+
{"version":3,"file":"methodBinding.js","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,yCAAwC;AA0BxC;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,WAA2B;IAI5D,OAAO,eAAe,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;AACvD,CAAC;AALD,8CAKC;AAuBD;;GAEG;AACH,MAAa,eAAe;IAG3B,YACiB,IAAY,EACZ,WAA+B,EAC/B,IAAoB;IACpC,kDAAkD;IAClC,IAAyB,EACzB,OAAqB;QALrB,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAoB;QAC/B,SAAI,GAAJ,IAAI,CAAgB;QAEpB,SAAI,GAAJ,IAAI,CAAqB;QACzB,YAAO,GAAP,OAAO,CAAc;IACnC,CAAC;CACJ;AAXD,0CAWC;AAYD;;;GAGG;AACH,SAAgB,SAAS,CAKxB,GAA2D,EAC3D,GAAG,IAAU;IAEb,OAAO;QACN,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,IAAI;QACJ,IAAI,EAAE,GAAG,CAAC,IAAI;KACd,CAAC;AACH,CAAC;AAdD,8BAcC;AA+BD;;;GAGG;AACU,QAAA,mBAAmB,GAAkB,MAAM,CAAC,KAAK,CAAC,CAAC;AAoBhE,MAAM,eAAe;IAIpB,YAAoC,WAA2B;QAA3B,gBAAW,GAAX,WAAW,CAAgB;QAH9C,YAAO,GAAoC,EAAE,CAAC;QAC9C,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEK,CAAC;IAE5D,MAAM,CAIX,MAAS,EAAE,UAAa,EAAE,WAAc;QACzC,IAAI,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,eAAe,CAC7C,UAAU,EACV,WAAW,CAAC,WAAW,EACvB,WAAW,CAAC,IAAI;QAChB,2CAA2C;QAC3C,WAAW,CAAC,IAAI,IAAI,IAAI,EACxB,WAAW,CAAC,OAAO,CACnB,CAAC;IACH,CAAC;IAEM,UAAU,CAChB,MAAS;QAET,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,IAAA,qBAAU,EAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,WAA2B;QAI1D,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAyC,CAAC;QAC9D,IAAI,WAAW,CAAC,2BAAmB,CAAC,KAAK,SAAS,EAAE,CAAC;YACpD,WAAW,CAAC,2BAAmB,CAAC,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;QACD,OAAO;YACN,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,EAAE,cAAc,CAAC,eAAe;SAC/C,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { NodeKind, TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\n\nimport { instanceOf } from \"./utils.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny,\n\tRest extends z.ZodTypeAny | null = null,\n> {\n\tdescription?: string;\n\targs: Args;\n\trest?: Rest;\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | null,\n\t\tpublic readonly returns: z.ZodTypeAny,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n */\nexport type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest>\n\t? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<any, any, any>,\n\t>(schema: S, methodName: K, zodFunction: Z): void;\n\n\t/**\n\t * Create a Zod schema for a SharedTree schema class.\n\t * @remarks\n\t * Use it to \"wrap\" schema types that are referenced as arguments or return types when exposing methods (with {@link ExposedMethods.expose}).\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * A symbol used to expose methods to the LLM.\n * @alpha\n */\nexport const exposeMethodsSymbol: unique symbol = Symbol(\"run\");\n\n/**\n * An interface that SharedTree schema classes should implement to expose their methods to the LLM.\n *\n * @remarks\n * The `getExposedMethods` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedMethods {\n\t[exposeMethodsSymbol](methods: ExposedMethods): void;\n}\n\nclass ExposedMethodsI implements ExposedMethods {\n\tprivate readonly methods: Record<string, FunctionWrapper> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic expose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>,\n\t>(schema: S, methodName: K, functionDef: Z): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose methods on the \"this\" object');\n\t\t}\n\t\tthis.methods[methodName] = new FunctionWrapper(\n\t\t\tmethodName,\n\t\t\tfunctionDef.description,\n\t\t\tfunctionDef.args,\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tfunctionDef.rest ?? null,\n\t\t\tfunctionDef.returns,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedMethods(schemaClass: BindableSchema): {\n\t\tmethods: Record<string, FunctionWrapper>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposedMethods = new ExposedMethodsI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedMethods;\n\t\tif (extractable[exposeMethodsSymbol] !== undefined) {\n\t\t\textractable[exposeMethodsSymbol](exposedMethods);\n\t\t}\n\t\treturn {\n\t\t\tmethods: exposedMethods.methods,\n\t\t\treferencedTypes: exposedMethods.referencedTypes,\n\t\t};\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertyBinding.d.ts","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG/D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,OAAO,MAE3C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;KAC7B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,KAAK,GAAG,CAAC;CACjE,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CACxF,CAAC,OACK,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GACvB,CAAC,GACD,CAAC,CAAC;AAEL;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;
|
|
1
|
+
{"version":3,"file":"propertyBinding.d.ts","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KA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;;;;;;;;;GAaG;AACH,MAAM,WAAW,kBAAkB;IAClC,CAAC,sBAAsB,CAAC,CAAC,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC/D;AAoDD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,cAAc,GAAG;IAClE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACxC,eAAe,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CACrC,CAEA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertyBinding.js","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,yCAAwC;AAExC;;;GAGG;AACU,QAAA,sBAAsB,GAAkB,MAAM,CAAC,GAAG,CAC9D,6CAA6C,CAC7C,CAAC;
|
|
1
|
+
{"version":3,"file":"propertyBinding.js","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,yCAAwC;AAExC;;;GAGG;AACU,QAAA,sBAAsB,GAAkB,MAAM,CAAC,GAAG,CAC9D,6CAA6C,CAC7C,CAAC;AAmDF;;;GAGG;AACH,MAAa,WAAW;IACvB,YACiB,IAAY,EACZ,WAA+B,EAC/B,MAAkB,EAClB,QAAiB;QAHjB,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAoB;QAC/B,WAAM,GAAN,MAAM,CAAY;QAClB,aAAQ,GAAR,QAAQ,CAAS;IAC/B,CAAC;CACJ;AAPD,kCAOC;AAyCD,MAAM,kBAAkB;IAIvB,YAAoC,WAA2B;QAA3B,gBAAW,GAAX,WAAW,CAAgB;QAH9C,eAAU,GAAgC,EAAE,CAAC;QAC7C,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEK,CAAC;IAE5D,cAAc,CAKpB,MAAS,EACT,IAAO,EACP,GACmD;QAEnD,IAAI,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,WAAW,CACtC,IAAI,EACJ,GAAG,CAAC,WAAW,EACf,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,QAAQ,KAAK,IAAI,CACrB,CAAC;IACH,CAAC;IAEM,UAAU,CAChB,MAAS;QAET,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,IAAA,qBAAU,EAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,oBAAoB,CAAC,WAA2B;QAI7D,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACpD,MAAM,WAAW,GAAG,WAA4C,CAAC;QACjE,IAAI,WAAW,CAAC,8BAAsB,CAAC,KAAK,SAAS,EAAE,CAAC;YACvD,WAAW,CAAC,8BAAsB,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO;YACN,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,eAAe,EAAE,OAAO,CAAC,eAAe;SACxC,CAAC;IACH,CAAC;CACD;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,WAA2B;IAI/D,OAAO,kBAAkB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC;AALD,oDAKC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { ZodType, ZodTypeAny, ZodTypeDef, infer as ZodInfer } from \"zod\";\n\nimport type { BindableSchema, Ctor } from \"./methodBinding.js\";\nimport { instanceOf } from \"./utils.js\";\n\n/**\n * A symbol used to expose properties to the LLM.\n * @alpha\n */\nexport const exposePropertiesSymbol: unique symbol = Symbol.for(\n\t\"@fluidframework/tree-agent/exposeProperties\",\n);\n\n/**\n * Set of property keys from `T` that are not methods.\n * @alpha\n */\nexport type ExposableKeys<T> = {\n\t[K in keyof T]?: T[K] extends (...args: any[]) => any ? never : K;\n}[keyof T];\n\n/**\n * Type-level equality test used as a helper to evaluate readonly keys.\n * - If X and Y are the same type, it evaluates to A.\n * - If X and Y are different, it evaluates to B.\n * @alpha\n */\nexport type IfEquals<X, Y, A = true, B = false> = (<T>() => T extends X ? 1 : 2) extends <\n\tT,\n>() => T extends Y ? 1 : 2\n\t? A\n\t: B;\n\n/**\n * Produces a union of keys of `T` which are readonly.\n * @alpha\n */\nexport type ReadonlyKeys<T> = {\n\t// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\n\t[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>;\n}[keyof T];\n\n/**\n * Type to enforce `readOnly: true` for readonly properties.\n * @alpha\n */\nexport type ReadOnlyRequirement<TObj, K extends keyof TObj> = {\n\t[P in K]-?: P extends ReadonlyKeys<TObj> ? { readOnly: true } : { readOnly?: false };\n}[K];\n\n/**\n * Emits compile-time error when there is a type mismatch.\n * @alpha\n */\nexport type TypeMatchOrError<Expected, Received> = [Received] extends [Expected]\n\t? unknown\n\t: {\n\t\t\t__error__: \"Zod schema value type does not match the property's declared type\";\n\t\t\texpected: Expected;\n\t\t\treceived: Received;\n\t\t};\n\n/**\n * A property definition class that describes the structure of the property\n * @alpha\n */\nexport class PropertyDef {\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly schema: ZodTypeAny,\n\t\tpublic readonly readOnly: boolean,\n\t) {}\n}\n\n/**\n * An interface for exposing properties of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedProperties {\n\texposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>,\n\t): void;\n\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * An interface that SharedTree schema classes should implement to expose their properties to the LLM.\n *\n * @remarks\n * The `getExposedProperties` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedProperties {\n\t[exposePropertiesSymbol]?(properties: ExposedProperties): void;\n}\n\nclass ExposedPropertiesI implements ExposedProperties {\n\tprivate readonly properties: Record<string, PropertyDef> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic exposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>,\n\t): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose properties on the \"this\" schema class');\n\t\t}\n\t\tthis.properties[name] = new PropertyDef(\n\t\t\tname,\n\t\t\tdef.description,\n\t\t\tdef.schema,\n\t\t\tdef.readOnly === true,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedProperties(schemaClass: BindableSchema): {\n\t\tproperties: Record<string, PropertyDef>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposed = new ExposedPropertiesI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedProperties;\n\t\tif (extractable[exposePropertiesSymbol] !== undefined) {\n\t\t\textractable[exposePropertiesSymbol](exposed);\n\t\t}\n\t\treturn {\n\t\t\tproperties: exposed.properties,\n\t\t\treferencedTypes: exposed.referencedTypes,\n\t\t};\n\t}\n}\n\n/**\n * Get the exposed properties of a schema class.\n * @param schemaClass - The schema class to extract properties from.\n * @returns A record of property names and their corresponding Zod types.\n */\nexport function getExposedProperties(schemaClass: BindableSchema): {\n\tproperties: Record<string, PropertyDef>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedPropertiesI.getExposedProperties(schemaClass);\n}\n"]}
|
package/dist/utils.js
CHANGED
|
@@ -139,7 +139,7 @@ function isNamedSchema(schemaIdentifier) {
|
|
|
139
139
|
if (["string", "number", "boolean", "null", "handle"].includes(unqualifySchema(schemaIdentifier))) {
|
|
140
140
|
return false;
|
|
141
141
|
}
|
|
142
|
-
return
|
|
142
|
+
return /(?:Array|Map|Record)<\["(.*)"]>/.exec(schemaIdentifier) === null;
|
|
143
143
|
}
|
|
144
144
|
exports.isNamedSchema = isNamedSchema;
|
|
145
145
|
/**
|
|
@@ -149,7 +149,7 @@ exports.isNamedSchema = isNamedSchema;
|
|
|
149
149
|
*/
|
|
150
150
|
function unqualifySchema(schemaIdentifier) {
|
|
151
151
|
// Get the unqualified name by removing the scope (everything before the last dot).
|
|
152
|
-
const matches =
|
|
152
|
+
const matches = /[^.]+$/.exec(schemaIdentifier);
|
|
153
153
|
if (matches === null) {
|
|
154
154
|
return schemaIdentifier; // Return the original name if it is unscoped.
|
|
155
155
|
}
|
package/dist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FD,8BAEC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC;AATD,sCASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeNode,\n\tTreeNodeSchema,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport { FunctionWrapper } from \"./methodBinding.js\";\nimport { PropertyDef } from \"./propertyBinding.js\";\n\n/**\n * Subset of Map interface.\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * TBD\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function getOrCreate<K, V>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(\"Unexpected node schema\");\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn schemaIdentifier.match(/(?:Array|Map|Record)<\\[\"(.*)\"]>/) === null;\n}\n\n/**\n * Returns the unqualified name of a schema (e.g. `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks This works by removing all characters before the last dot in the schema name.\n * If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = schemaIdentifier.match(/[^.]+$/);\n\tif (matches === null) {\n\t\treturn schemaIdentifier; // Return the original name if it is unscoped.\n\t}\n\treturn matches[0];\n}\n\n/**\n * Details about the properties of a TypeScript schema represented as Zod.\n */\nexport interface SchemaDetails {\n\thasHelperMethods: boolean;\n}\n\n// TODO: yuck, this entire file has too many statics. we should rewrite it as a generic zod schema walk.\nlet detailsI: SchemaDetails = {\n\thasHelperMethods: false,\n};\n\n/**\n * Returns the TypeScript source code corresponding to a Zod schema. The schema is supplied as an object where each\n * property provides a name for an associated Zod type. The return value is a string containing the TypeScript source\n * code corresponding to the schema. Each property of the schema object is emitted as a named `interface` or `type`\n * declaration for the associated type and is referenced by that name in the emitted type declarations. Other types\n * referenced in the schema are emitted in their structural form.\n * @param schema - A schema object where each property provides a name for an associated Zod type.\n * @param details - Optional details about the schema. The fields will be set according to the details in the given schema.\n * @returns The TypeScript source code corresponding to the schema.\n */\nexport function getZodSchemaAsTypeScript(\n\tschema: Record<string, z.ZodType>,\n\tdetails?: SchemaDetails,\n): string {\n\tdetailsI = details ?? { hasHelperMethods: false };\n\tlet result = \"\";\n\tlet startOfLine = true;\n\tlet indent = 0;\n\tconst entries = [...Object.entries(schema)];\n\tconst namedTypes = new Map<object, string>(\n\t\tentries.map(([name, type]) => [getTypeIdentity(type), name]),\n\t);\n\tfor (const [name, type] of entries) {\n\t\tif (result) {\n\t\t\tappendNewLine();\n\t\t}\n\t\tconst description = type._def.description;\n\t\tif (description !== undefined && description !== \"\") {\n\t\t\tfor (const comment of description.split(\"\\n\")) {\n\t\t\t\tappend(`// ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodObject) {\n\t\t\tappend(`interface ${name} `);\n\t\t\tappendObjectType(type as z.ZodObject<z.ZodRawShape>);\n\t\t} else {\n\t\t\tappend(`type ${name} = `);\n\t\t\tappendTypeDefinition(type);\n\t\t\tappend(\";\");\n\t\t}\n\t\tappendNewLine();\n\t}\n\treturn result;\n\n\tfunction append(s: string) {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine() {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendType(type: z.ZodType, minPrecedence = TypePrecedence.Object) {\n\t\tconst name = namedTypes.get(getTypeIdentity(type));\n\t\tif (name === undefined) {\n\t\t\tconst parenthesize = getTypePrecendece(type) < minPrecedence;\n\t\t\tif (parenthesize) append(\"(\");\n\t\t\tappendTypeDefinition(type);\n\t\t\tif (parenthesize) append(\")\");\n\t\t} else {\n\t\t\tappend(name);\n\t\t}\n\t}\n\n\tfunction appendTypeDefinition(type: z.ZodType) {\n\t\tswitch (getTypeKind(type)) {\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodString: {\n\t\t\t\treturn append(\"string\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNumber: {\n\t\t\t\treturn append(\"number\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodBoolean: {\n\t\t\t\treturn append(\"boolean\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDate: {\n\t\t\t\treturn append(\"Date\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUndefined: {\n\t\t\t\treturn append(\"undefined\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNull: {\n\t\t\t\treturn append(\"null\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnknown: {\n\t\t\t\treturn append(\"unknown\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodArray: {\n\t\t\t\treturn appendArrayType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\t\treturn appendObjectType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t(type._def as z.ZodUnionDef).options,\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[...(type._def as z.ZodDiscriminatedUnionDef<string>).options.values()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).left,\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).right,\n\t\t\t\t\t],\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodTuple: {\n\t\t\t\treturn appendTupleType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodRecord: {\n\t\t\t\treturn appendRecordType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodMap: {\n\t\t\t\treturn appendMapType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLiteral: {\n\t\t\t\treturn appendLiteral((type._def as z.ZodLiteralDef).value);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\t\treturn append(\n\t\t\t\t\t(type._def as z.ZodEnumDef).values.map((value) => JSON.stringify(value)).join(\" | \"),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodOptional: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[(type._def as z.ZodOptionalDef).innerType, z.undefined()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodReadonly: {\n\t\t\t\treturn appendReadonlyType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEffects: {\n\t\t\t\t// Currently, this only handles schema class instances, but there are other cases in which a ZodEffects could theoretically be used.\n\t\t\t\tif (instanceOfs.has(type)) {\n\t\t\t\t\tconst objectNodeSchema = instanceOfs.get(type);\n\t\t\t\t\tif (objectNodeSchema === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported zod effects type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn append(getFriendlyName(objectNodeSchema));\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unsupported zod effects type. Did you use z.instanceOf? Use ExposedMethods.instanceOf function to reference schema classes in methods.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodVoid: {\n\t\t\t\treturn append(\"void\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLazy: {\n\t\t\t\treturn appendType((type._def as z.ZodLazyDef).getter());\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundMethods(boundType: z.ZodType): void {\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((boundType._def as z.ZodObjectDef).shape())) {\n\t\t\t// Special handling of methods on objects\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method !== undefined && method instanceof FunctionWrapper) {\n\t\t\t\tdetailsI.hasHelperMethods = true;\n\t\t\t\tappend(name);\n\t\t\t\tappend(\"(\");\n\t\t\t\tlet first = true;\n\t\t\t\tfor (const [argName, argType] of method.args) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tif (getTypeKind(argType) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\t\tappend(`${argName}?: `);\n\t\t\t\t\t\tappendType((argType._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tappend(`${argName}: `);\n\t\t\t\t\t\tappendType(argType);\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t}\n\t\t\t\tif (method.rest !== null) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tappend(\"...rest: \");\n\t\t\t\t\tappendType(method.rest, TypePrecedence.Object);\n\t\t\t\t\tappend(\"[]\");\n\t\t\t\t}\n\t\t\t\tappend(`): `);\n\t\t\t\tappendType(method.returns, TypePrecedence.Object);\n\t\t\t\tappend(\";\");\n\t\t\t\tif (method.description !== undefined) {\n\t\t\t\t\tappend(` // ${method.description}`);\n\t\t\t\t}\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundProperties(type: z.ZodType): void {\n\t\tconst property = (type as unknown as { property?: PropertyDef }).property;\n\n\t\tif (!(property instanceof PropertyDef)) {\n\t\t\tif (type.description !== undefined && type.description !== \"\") {\n\t\t\t\tappend(` // ${type.description}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (property.readOnly === true) {\n\t\t\tappend(\" // readonly\");\n\t\t}\n\t\tif (property.description !== undefined && property.description !== \"\") {\n\t\t\tappend(` - ${property.description}`);\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: z.ZodType) {\n\t\tappendType((arrayType._def as z.ZodArrayDef).type, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendObjectType(objectType: z.ZodType) {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((objectType._def as z.ZodObjectDef).shape())) {\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\n\t\t\tif (method === undefined || !(method instanceof FunctionWrapper)) {\n\t\t\t\tappend(name);\n\t\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\tappend(\"?\");\n\t\t\t\t\ttype = (type._def as z.ZodOptionalDef).innerType;\n\t\t\t\t}\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type);\n\t\t\t\tappend(\";\");\n\t\t\t\tappendBoundProperties(type);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tappendBoundMethods(objectType);\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionOrIntersectionTypes(\n\t\ttypes: readonly z.ZodType[],\n\t\tminPrecedence: TypePrecedence,\n\t) {\n\t\tlet first = true;\n\t\tfor (const type of types) {\n\t\t\tif (!first) append(minPrecedence === TypePrecedence.Intersection ? \" & \" : \" | \");\n\t\t\tappendType(type, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: z.ZodType) {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const type of (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType>).items) {\n\t\t\tif (!first) append(\", \");\n\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\tappendType((type._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(type);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tconst rest = (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType | null>).rest;\n\t\tif (rest !== null) {\n\t\t\tif (!first) append(\", \");\n\t\t\tappend(\"...\");\n\t\t\tappendType(rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: z.ZodType) {\n\t\tappend(\"Record<\");\n\t\tappendType((recordType._def as z.ZodRecordDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((recordType._def as z.ZodRecordDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: z.ZodType) {\n\t\tappend(\"Map<\");\n\t\tappendType((mapType._def as z.ZodMapDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((mapType._def as z.ZodMapDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: unknown) {\n\t\tappend(\n\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\"\n\t\t\t\t? JSON.stringify(value)\n\t\t\t\t: \"any\",\n\t\t);\n\t}\n\n\tfunction appendReadonlyType(readonlyType: z.ZodType) {\n\t\tappend(\"Readonly<\");\n\t\tappendType((readonlyType._def as z.ZodReadonlyDef).innerType);\n\t\tappend(\">\");\n\t}\n}\n\nfunction getTypeKind(type: z.ZodType): z.ZodFirstPartyTypeKind {\n\treturn (type._def as z.ZodTypeDef & { typeName: z.ZodFirstPartyTypeKind }).typeName;\n}\n\nfunction getTypeIdentity(type: z.ZodType): object {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\treturn (type._def as z.ZodObjectDef).shape();\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\treturn (type._def as z.ZodEnumDef).values;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\treturn (type._def as z.ZodUnionDef).options;\n\t\t}\n\t\tdefault: {\n\t\t\treturn type;\n\t\t}\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecendece(type: z.ZodType): TypePrecedence {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum:\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion:\n\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n\n/**\n * Create a Zod schema for a SharedTree schema class.\n * @alpha\n */\nexport function instanceOf<T extends TreeNodeSchemaClass>(\n\tschema: T,\n): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\tthrow new UsageError(`${schema.identifier} must be an instance of ObjectNodeSchema.`);\n\t}\n\tconst effect = z.instanceof(schema);\n\tinstanceOfs.set(effect, schema);\n\treturn effect;\n}\n\nconst instanceOfs = new WeakMap<z.ZodTypeAny, ObjectNodeSchema>();\n\n/**\n * Adds all (optionally filtered) schemas reachable from the given schema to the given set.\n * @returns The set of schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findSchemas(\n\tschema: ImplicitFieldSchema,\n\tfilter: (schema: TreeNodeSchema) => boolean = () => true,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!schemas.has(nodeSchema)) {\n\t\t\tif (filter(nodeSchema)) {\n\t\t\t\tschemas.add(nodeSchema);\n\t\t\t}\n\t\t\tfindSchemas([...nodeSchema.childTypes], filter, schemas);\n\t\t}\n\t}\n\treturn schemas;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,0DAA0D;AAC1D,qEAAqE;AAErE,kEAA6D;AAC7D,iEAA8D;AAC9D,uEAAsE;AAQtE,sDAMoC;AACpC,4DAA+E;AAC/E,6BAAwB;AAExB,yDAAqD;AACrD,6DAAmD;AAYnD;;GAEG;AACH,SAAgB,IAAI,CAAC,OAAe;IACnC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAFD,oBAEC;AAED;;;;;;;GAOG;AACH,QAAe,CAAC,CAAC,WAAW,CAC3B,QAAqB,EACrB,GAAgB;IAEhB,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACd,CAAC;AACF,CAAC;AAPD,kCAOC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAC1B,GAAoB,EACpB,GAAM,EACN,YAA2B;IAE3B,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAXD,kCAWC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAI,GAAmB;IACrD,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACpB,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;YACxB,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;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAFD,8BAEC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC;AATD,sCASC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeNode,\n\tTreeNodeSchema,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport { FunctionWrapper } from \"./methodBinding.js\";\nimport { PropertyDef } from \"./propertyBinding.js\";\n\n/**\n * Subset of Map interface.\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * TBD\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function getOrCreate<K, V>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(\"Unexpected node schema\");\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn /(?:Array|Map|Record)<\\[\"(.*)\"]>/.exec(schemaIdentifier) === null;\n}\n\n/**\n * Returns the unqualified name of a schema (e.g. `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks This works by removing all characters before the last dot in the schema name.\n * If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = /[^.]+$/.exec(schemaIdentifier);\n\tif (matches === null) {\n\t\treturn schemaIdentifier; // Return the original name if it is unscoped.\n\t}\n\treturn matches[0];\n}\n\n/**\n * Details about the properties of a TypeScript schema represented as Zod.\n */\nexport interface SchemaDetails {\n\thasHelperMethods: boolean;\n}\n\n// TODO: yuck, this entire file has too many statics. we should rewrite it as a generic zod schema walk.\nlet detailsI: SchemaDetails = {\n\thasHelperMethods: false,\n};\n\n/**\n * Returns the TypeScript source code corresponding to a Zod schema. The schema is supplied as an object where each\n * property provides a name for an associated Zod type. The return value is a string containing the TypeScript source\n * code corresponding to the schema. Each property of the schema object is emitted as a named `interface` or `type`\n * declaration for the associated type and is referenced by that name in the emitted type declarations. Other types\n * referenced in the schema are emitted in their structural form.\n * @param schema - A schema object where each property provides a name for an associated Zod type.\n * @param details - Optional details about the schema. The fields will be set according to the details in the given schema.\n * @returns The TypeScript source code corresponding to the schema.\n */\nexport function getZodSchemaAsTypeScript(\n\tschema: Record<string, z.ZodType>,\n\tdetails?: SchemaDetails,\n): string {\n\tdetailsI = details ?? { hasHelperMethods: false };\n\tlet result = \"\";\n\tlet startOfLine = true;\n\tlet indent = 0;\n\tconst entries = [...Object.entries(schema)];\n\tconst namedTypes = new Map<object, string>(\n\t\tentries.map(([name, type]) => [getTypeIdentity(type), name]),\n\t);\n\tfor (const [name, type] of entries) {\n\t\tif (result) {\n\t\t\tappendNewLine();\n\t\t}\n\t\tconst description = type._def.description;\n\t\tif (description !== undefined && description !== \"\") {\n\t\t\tfor (const comment of description.split(\"\\n\")) {\n\t\t\t\tappend(`// ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodObject) {\n\t\t\tappend(`interface ${name} `);\n\t\t\tappendObjectType(type as z.ZodObject<z.ZodRawShape>);\n\t\t} else {\n\t\t\tappend(`type ${name} = `);\n\t\t\tappendTypeDefinition(type);\n\t\t\tappend(\";\");\n\t\t}\n\t\tappendNewLine();\n\t}\n\treturn result;\n\n\tfunction append(s: string) {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine() {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendType(type: z.ZodType, minPrecedence = TypePrecedence.Object) {\n\t\tconst name = namedTypes.get(getTypeIdentity(type));\n\t\tif (name === undefined) {\n\t\t\tconst parenthesize = getTypePrecendece(type) < minPrecedence;\n\t\t\tif (parenthesize) append(\"(\");\n\t\t\tappendTypeDefinition(type);\n\t\t\tif (parenthesize) append(\")\");\n\t\t} else {\n\t\t\tappend(name);\n\t\t}\n\t}\n\n\tfunction appendTypeDefinition(type: z.ZodType) {\n\t\tswitch (getTypeKind(type)) {\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodString: {\n\t\t\t\treturn append(\"string\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNumber: {\n\t\t\t\treturn append(\"number\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodBoolean: {\n\t\t\t\treturn append(\"boolean\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDate: {\n\t\t\t\treturn append(\"Date\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUndefined: {\n\t\t\t\treturn append(\"undefined\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNull: {\n\t\t\t\treturn append(\"null\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnknown: {\n\t\t\t\treturn append(\"unknown\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodArray: {\n\t\t\t\treturn appendArrayType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\t\treturn appendObjectType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t(type._def as z.ZodUnionDef).options,\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[...(type._def as z.ZodDiscriminatedUnionDef<string>).options.values()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).left,\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).right,\n\t\t\t\t\t],\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodTuple: {\n\t\t\t\treturn appendTupleType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodRecord: {\n\t\t\t\treturn appendRecordType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodMap: {\n\t\t\t\treturn appendMapType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLiteral: {\n\t\t\t\treturn appendLiteral((type._def as z.ZodLiteralDef).value);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\t\treturn append(\n\t\t\t\t\t(type._def as z.ZodEnumDef).values.map((value) => JSON.stringify(value)).join(\" | \"),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodOptional: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[(type._def as z.ZodOptionalDef).innerType, z.undefined()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodReadonly: {\n\t\t\t\treturn appendReadonlyType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEffects: {\n\t\t\t\t// Currently, this only handles schema class instances, but there are other cases in which a ZodEffects could theoretically be used.\n\t\t\t\tif (instanceOfs.has(type)) {\n\t\t\t\t\tconst objectNodeSchema = instanceOfs.get(type);\n\t\t\t\t\tif (objectNodeSchema === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported zod effects type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn append(getFriendlyName(objectNodeSchema));\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unsupported zod effects type. Did you use z.instanceOf? Use ExposedMethods.instanceOf function to reference schema classes in methods.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodVoid: {\n\t\t\t\treturn append(\"void\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLazy: {\n\t\t\t\treturn appendType((type._def as z.ZodLazyDef).getter());\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundMethods(boundType: z.ZodType): void {\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((boundType._def as z.ZodObjectDef).shape())) {\n\t\t\t// Special handling of methods on objects\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method !== undefined && method instanceof FunctionWrapper) {\n\t\t\t\tdetailsI.hasHelperMethods = true;\n\t\t\t\tappend(name);\n\t\t\t\tappend(\"(\");\n\t\t\t\tlet first = true;\n\t\t\t\tfor (const [argName, argType] of method.args) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tif (getTypeKind(argType) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\t\tappend(`${argName}?: `);\n\t\t\t\t\t\tappendType((argType._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tappend(`${argName}: `);\n\t\t\t\t\t\tappendType(argType);\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t}\n\t\t\t\tif (method.rest !== null) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tappend(\"...rest: \");\n\t\t\t\t\tappendType(method.rest, TypePrecedence.Object);\n\t\t\t\t\tappend(\"[]\");\n\t\t\t\t}\n\t\t\t\tappend(`): `);\n\t\t\t\tappendType(method.returns, TypePrecedence.Object);\n\t\t\t\tappend(\";\");\n\t\t\t\tif (method.description !== undefined) {\n\t\t\t\t\tappend(` // ${method.description}`);\n\t\t\t\t}\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundProperties(type: z.ZodType): void {\n\t\tconst property = (type as unknown as { property?: PropertyDef }).property;\n\n\t\tif (!(property instanceof PropertyDef)) {\n\t\t\tif (type.description !== undefined && type.description !== \"\") {\n\t\t\t\tappend(` // ${type.description}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (property.readOnly === true) {\n\t\t\tappend(\" // readonly\");\n\t\t}\n\t\tif (property.description !== undefined && property.description !== \"\") {\n\t\t\tappend(` - ${property.description}`);\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: z.ZodType) {\n\t\tappendType((arrayType._def as z.ZodArrayDef).type, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendObjectType(objectType: z.ZodType) {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((objectType._def as z.ZodObjectDef).shape())) {\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\n\t\t\tif (method === undefined || !(method instanceof FunctionWrapper)) {\n\t\t\t\tappend(name);\n\t\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\tappend(\"?\");\n\t\t\t\t\ttype = (type._def as z.ZodOptionalDef).innerType;\n\t\t\t\t}\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type);\n\t\t\t\tappend(\";\");\n\t\t\t\tappendBoundProperties(type);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tappendBoundMethods(objectType);\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionOrIntersectionTypes(\n\t\ttypes: readonly z.ZodType[],\n\t\tminPrecedence: TypePrecedence,\n\t) {\n\t\tlet first = true;\n\t\tfor (const type of types) {\n\t\t\tif (!first) append(minPrecedence === TypePrecedence.Intersection ? \" & \" : \" | \");\n\t\t\tappendType(type, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: z.ZodType) {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const type of (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType>).items) {\n\t\t\tif (!first) append(\", \");\n\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\tappendType((type._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(type);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tconst rest = (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType | null>).rest;\n\t\tif (rest !== null) {\n\t\t\tif (!first) append(\", \");\n\t\t\tappend(\"...\");\n\t\t\tappendType(rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: z.ZodType) {\n\t\tappend(\"Record<\");\n\t\tappendType((recordType._def as z.ZodRecordDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((recordType._def as z.ZodRecordDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: z.ZodType) {\n\t\tappend(\"Map<\");\n\t\tappendType((mapType._def as z.ZodMapDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((mapType._def as z.ZodMapDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: unknown) {\n\t\tappend(\n\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\"\n\t\t\t\t? JSON.stringify(value)\n\t\t\t\t: \"any\",\n\t\t);\n\t}\n\n\tfunction appendReadonlyType(readonlyType: z.ZodType) {\n\t\tappend(\"Readonly<\");\n\t\tappendType((readonlyType._def as z.ZodReadonlyDef).innerType);\n\t\tappend(\">\");\n\t}\n}\n\nfunction getTypeKind(type: z.ZodType): z.ZodFirstPartyTypeKind {\n\treturn (type._def as z.ZodTypeDef & { typeName: z.ZodFirstPartyTypeKind }).typeName;\n}\n\nfunction getTypeIdentity(type: z.ZodType): object {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\treturn (type._def as z.ZodObjectDef).shape();\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\treturn (type._def as z.ZodEnumDef).values;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\treturn (type._def as z.ZodUnionDef).options;\n\t\t}\n\t\tdefault: {\n\t\t\treturn type;\n\t\t}\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecendece(type: z.ZodType): TypePrecedence {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum:\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion:\n\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n\n/**\n * Create a Zod schema for a SharedTree schema class.\n * @alpha\n */\nexport function instanceOf<T extends TreeNodeSchemaClass>(\n\tschema: T,\n): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\tthrow new UsageError(`${schema.identifier} must be an instance of ObjectNodeSchema.`);\n\t}\n\tconst effect = z.instanceof(schema);\n\tinstanceOfs.set(effect, schema);\n\treturn effect;\n}\n\nconst instanceOfs = new WeakMap<z.ZodTypeAny, ObjectNodeSchema>();\n\n/**\n * Adds all (optionally filtered) schemas reachable from the given schema to the given set.\n * @returns The set of schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findSchemas(\n\tschema: ImplicitFieldSchema,\n\tfilter: (schema: TreeNodeSchema) => boolean = () => true,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!schemas.has(nodeSchema)) {\n\t\t\tif (filter(nodeSchema)) {\n\t\t\t\tschemas.add(nodeSchema);\n\t\t\t}\n\t\t\tfindSchemas([...nodeSchema.childTypes], filter, schemas);\n\t\t}\n\t}\n\treturn schemas;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
|
package/lib/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,mBAAmB,EAGnB,MAAM,sBAAsB,CAAC;AAU9B,OAAO,KAAK,EACX,mBAAmB,EAEnB,oBAAoB,EAGpB,OAAO,EAEP,UAAU,EACV,MAAM,UAAU,CAAC;AAiBlB;;;;GAIG;AACH,qBAAa,uBAAuB,CAAC,OAAO,SAAS,mBAAmB;IAUtE,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAV1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2D;IAClF;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAS;gBAGf,MAAM,EAAE,mBAAmB,EAC5C,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EACR,OAAO,CAAC,qDAAyC;IAkCnE;;;;;OAKG;IACU,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAqEvD;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,mBAAmB,EAGnB,MAAM,sBAAsB,CAAC;AAU9B,OAAO,KAAK,EACX,mBAAmB,EAEnB,oBAAoB,EAGpB,OAAO,EAEP,UAAU,EACV,MAAM,UAAU,CAAC;AAiBlB;;;;GAIG;AACH,qBAAa,uBAAuB,CAAC,OAAO,SAAS,mBAAmB;IAUtE,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IAV1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2D;IAClF;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAAS;gBAGf,MAAM,EAAE,mBAAmB,EAC5C,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EACR,OAAO,CAAC,qDAAyC;IAkCnE;;;;;OAKG;IACU,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAqEvD;AAoFD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,mBAAmB,EAChE,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GACvB,OAAO,CAAC,OAAO,CAAC,CA2ClB"}
|
package/lib/agent.js
CHANGED
|
@@ -131,6 +131,7 @@ function constructTreeNode(schema, content) {
|
|
|
131
131
|
llmDefault in field.metadata.custom) {
|
|
132
132
|
const defaulter = field.metadata.custom[llmDefault];
|
|
133
133
|
if (typeof defaulter === "function") {
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
134
135
|
const defaultValue = defaulter();
|
|
135
136
|
if (defaultValue !== undefined) {
|
|
136
137
|
contentWithDefaults[key] = defaultValue;
|
|
@@ -180,6 +181,7 @@ function createDefaultEditor() {
|
|
|
180
181
|
const context = createContext(tree);
|
|
181
182
|
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
|
182
183
|
const fn = new Function("context", code);
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
183
185
|
await fn(context);
|
|
184
186
|
};
|
|
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C,KAAK,CAAC;QACtB,CAAC;QACD,IAAI,IAAI,CAAC,KAAsD;YAC9D,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,CAAC;QACD,MAAM;QACN,EAAE;QACF,OAAO,CAAC,IAAI;YACX,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,KAAK,CAAC;YACvC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,CAAC,IAAI;YACT,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;gBAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,GAAG,CAAC;YACrC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,EAAE,CAAC,KAAe,EAAwB,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACrE,GAAG,EAAE,CAAC,KAAe,EAAmB,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;KAC/B,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeNodeSchema,\n} from \"@fluidframework/tree\";\nimport { NodeKind, TreeNode } from \"@fluidframework/tree\";\nimport type {\n\tReadableField,\n\tFactoryContentObject,\n\tInsertableContent,\n\tReadSchema,\n} from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema, Tree, TreeAlpha } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tSharedTreeChatModel,\n\tEditResult,\n\tSemanticAgentOptions,\n\tLogger,\n\tAsynchronousEditor,\n\tContext,\n\tSynchronousEditor,\n\tViewOrTree,\n} from \"./api.js\";\nimport { getPrompt, stringifyTree } from \"./prompt.js\";\nimport { Subtree } from \"./subtree.js\";\nimport {\n\tllmDefault,\n\tfindSchemas,\n\ttoErrorString,\n\tunqualifySchema,\n\tisNamedSchema,\n} from \"./utils.js\";\n\n/**\n * The default maximum number of sequential edits the LLM can make before we assume it's stuck in a loop.\n * @remarks This can be overridden by passing {@link SemanticAgentOptions.maximumSequentialEdits | maximumSequentialEdits} to {@link createSemanticAgent}.\n */\nconst defaultMaxSequentialEdits = 20;\n\n/**\n * An agent that uses a {@link SharedTreeChatModel} to interact with a SharedTree.\n * @remarks This class forwards user queries to the chat model, and handles the application of any edits to the tree that the model requests.\n * @alpha @sealed\n */\nexport class SharedTreeSemanticAgent<TSchema extends ImplicitFieldSchema> {\n\t// Converted from ECMAScript private fields (#name) to TypeScript private members for easier debugger inspection.\n\tprivate readonly outerTree: Subtree<TSchema>;\n\tprivate readonly editor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>;\n\t/**\n\t * Whether or not the outer tree has changed since the last query finished.\n\t */\n\tprivate outerTreeIsDirty = false;\n\n\tpublic constructor(\n\t\tprivate readonly client: SharedTreeChatModel,\n\t\ttree: ViewOrTree<TSchema>,\n\t\tprivate readonly options?: Readonly<SemanticAgentOptions<TSchema>>,\n\t) {\n\t\tif (tree instanceof TreeNode) {\n\t\t\tTree.on(tree, \"treeChanged\", () => (this.outerTreeIsDirty = true));\n\t\t} else {\n\t\t\ttree.events.on(\"changed\", () => (this.outerTreeIsDirty = true));\n\t\t}\n\n\t\tthis.outerTree = new Subtree(tree);\n\t\tthis.editor = this.options?.editor ?? createDefaultEditor();\n\t\tconst prompt = getPrompt({\n\t\t\tsubtree: this.outerTree,\n\t\t\teditToolName: this.client.editToolName,\n\t\t\tdomainHints: this.options?.domainHints,\n\t\t});\n\t\tthis.options?.logger?.log(`# Fluid Framework SharedTree AI Agent Log\\n\\n`);\n\t\tconst now = new Date();\n\t\tconst formattedDate = now.toLocaleString(undefined, {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"numeric\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t});\n\t\tthis.options?.logger?.log(`Agent created: **${formattedDate}**\\n\\n`);\n\t\tif (this.client.name !== undefined) {\n\t\t\tthis.options?.logger?.log(`Model: **${this.client.name}**\\n\\n`);\n\t\t}\n\t\tthis.client.appendContext?.(prompt);\n\t\tthis.options?.logger?.log(`## System Prompt\\n\\n${prompt}\\n\\n`);\n\t}\n\n\t/**\n\t * Given a user prompt, return a response.\n\t *\n\t * @param userPrompt - The prompt to send to the agent.\n\t * @returns The agent's response.\n\t */\n\tpublic async query(userPrompt: string): Promise<string> {\n\t\tthis.options?.logger?.log(`## User Query\\n\\n${userPrompt}\\n\\n`);\n\n\t\t// Notify the llm if the tree has changed since the last query, and if so, provide the new state of the tree.\n\t\tif (this.outerTreeIsDirty) {\n\t\t\tconst stringified = stringifyTree(this.outerTree.field);\n\t\t\tthis.client.appendContext?.(\n\t\t\t\t`The tree has changed since the last query. The new state of the tree is: \\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\``,\n\t\t\t);\n\t\t\tthis.options?.logger?.log(\n\t\t\t\t`### Latest Tree State\\n\\nThe Tree was edited by a local or remote user since the previous query. The latest state is:\\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\`\\n\\n`,\n\t\t\t);\n\t\t}\n\n\t\t// Fork a branch that will live for the lifetime of this query (which can be multiple LLM calls if the there are errors or the LLM decides to take multiple steps to accomplish a task).\n\t\t// The branch will be merged back into the outer branch if and only if the query succeeds.\n\t\tconst queryTree = this.outerTree.fork();\n\t\tconst maxEditCount = this.options?.maximumSequentialEdits ?? defaultMaxSequentialEdits;\n\t\tlet active = true;\n\t\tlet editCount = 0;\n\t\tlet rollbackEdits = false;\n\t\tconst { editToolName } = this.client;\n\t\tconst edit = async (editCode: string): Promise<EditResult> => {\n\t\t\tif (editToolName === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"disabledError\",\n\t\t\t\t\tmessage: \"Editing is not enabled for this model.\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (!active) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"expiredError\",\n\t\t\t\t\tmessage: `The query has already completed. Further edits are not allowed.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (++editCount > maxEditCount) {\n\t\t\t\trollbackEdits = true;\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"tooManyEditsError\",\n\t\t\t\t\tmessage: `The maximum number of edits (${maxEditCount}) for this query has been exceeded.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst editResult = await applyTreeFunction(\n\t\t\t\tqueryTree,\n\t\t\t\teditCode,\n\t\t\t\tthis.editor,\n\t\t\t\tthis.options?.logger,\n\t\t\t);\n\n\t\t\trollbackEdits = editResult.type !== \"success\";\n\t\t\treturn editResult;\n\t\t};\n\n\t\tconst responseMessage = await this.client.query({\n\t\t\ttext: userPrompt,\n\t\t\tedit,\n\t\t});\n\t\tactive = false;\n\n\t\tif (!rollbackEdits) {\n\t\t\tthis.outerTree.branch.merge(queryTree.branch);\n\t\t\tthis.outerTreeIsDirty = false;\n\t\t}\n\t\tthis.options?.logger?.log(`## Response\\n\\n`);\n\t\tthis.options?.logger?.log(`${responseMessage}\\n\\n`);\n\t\treturn responseMessage;\n\t}\n}\n\n/**\n * Creates an unhydrated node of the given schema with the given value.\n * @remarks If the schema is an object with {@link llmDefault | default values}, this function populates the node with those defaults.\n */\nfunction constructTreeNode(schema: TreeNodeSchema, content: FactoryContentObject): TreeNode {\n\tlet toInsert = content;\n\tif (schema instanceof ObjectNodeSchema) {\n\t\tconst contentWithDefaults: Record<string, InsertableContent | undefined> = {};\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (content[key] === undefined) {\n\t\t\t\tif (\n\t\t\t\t\ttypeof field.metadata.custom === \"object\" &&\n\t\t\t\t\tfield.metadata.custom !== null &&\n\t\t\t\t\tllmDefault in field.metadata.custom\n\t\t\t\t) {\n\t\t\t\t\tconst defaulter = field.metadata.custom[llmDefault];\n\t\t\t\t\tif (typeof defaulter === \"function\") {\n\t\t\t\t\t\tconst defaultValue: unknown = defaulter();\n\t\t\t\t\t\tif (defaultValue !== undefined) {\n\t\t\t\t\t\t\tcontentWithDefaults[key] = defaultValue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontentWithDefaults[key] = content[key];\n\t\t\t}\n\t\t}\n\t\ttoInsert = contentWithDefaults;\n\t}\n\n\t// Cast to never because tagContentSchema is typed to only accept InsertableContent, but we know that 'toInsert' (either the original content or contentWithDefaults) produces valid content for the schema.\n\treturn TreeAlpha.tagContentSchema(schema, toInsert as never);\n}\n\n/**\n * Applies the given function (as a string of JavaScript code or an actual function) to the given tree.\n */\nasync function applyTreeFunction<TSchema extends ImplicitFieldSchema>(\n\ttree: Subtree<TSchema>,\n\teditCode: string,\n\teditor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>,\n\tlogger: Logger | undefined,\n): Promise<EditResult> {\n\tlogger?.log(`### Editing Tool Invoked\\n\\n`);\n\tlogger?.log(`#### Generated Code\\n\\n\\`\\`\\`javascript\\n${editCode}\\n\\`\\`\\`\\n\\n`);\n\n\t// Fork a branch to edit. If the edit fails or produces an error, we discard this branch, otherwise we merge it.\n\tconst editTree = tree.fork();\n\ttry {\n\t\tawait editor(editTree.viewOrTree, editCode);\n\t} catch (error: unknown) {\n\t\tlogger?.log(`#### Error\\n\\n`);\n\t\tlogger?.log(`\\`\\`\\`JSON\\n${toErrorString(error)}\\n\\`\\`\\`\\n\\n`);\n\t\teditTree.branch.dispose();\n\t\treturn {\n\t\t\ttype: \"editingError\",\n\t\t\tmessage: `Running the generated code produced an error. The state of the tree will be reset to its previous state as it was before the code ran. Please try again. Here is the error: ${toErrorString(error)}`,\n\t\t};\n\t}\n\n\ttree.branch.merge(editTree.branch);\n\tlogger?.log(`#### New Tree State\\n\\n`);\n\tlogger?.log(`${`\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``}\\n\\n`);\n\treturn {\n\t\ttype: \"success\",\n\t\tmessage: `After running the code, the new state of the tree is:\\n\\n\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``,\n\t};\n}\n\nfunction createDefaultEditor<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n>(): AsynchronousEditor<TSchema> {\n\treturn async (tree, code) => {\n\t\tconst context = createContext(tree);\n\t\t// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval\n\t\tconst fn = new Function(\"context\", code);\n\t\tawait fn(context);\n\t};\n}\n\n/**\n * Creates a {@link Context} for the given subtree.\n * @alpha\n */\nexport function createContext<TSchema extends ImplicitFieldSchema>(\n\ttree: ViewOrTree<TSchema>,\n): Context<TSchema> {\n\tconst subTree = new Subtree(tree);\n\t// Stick the tree schema constructors on an object passed to the function so that the LLM can create new nodes.\n\tconst create: Record<string, (input: FactoryContentObject) => TreeNode> = {};\n\tconst is: Record<string, <T extends TreeNode>(input: unknown) => input is T> = {};\n\tfor (const schema of findSchemas(subTree.schema, (s) => isNamedSchema(s.identifier))) {\n\t\tconst name = unqualifySchema(schema.identifier);\n\t\tcreate[name] = (input: FactoryContentObject) => constructTreeNode(schema, input);\n\t\tis[name] = <T extends TreeNode>(input: unknown): input is T => Tree.is(input, schema);\n\t}\n\n\treturn {\n\t\tget root(): ReadableField<TSchema> {\n\t\t\treturn subTree.field;\n\t\t},\n\t\tset root(value: TreeFieldFromImplicitField<ReadSchema<TSchema>>) {\n\t\t\tsubTree.field = value;\n\t\t},\n\t\tcreate,\n\t\tis,\n\t\tisArray(node) {\n\t\t\tif (Array.isArray(node)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Array;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tisMap(node) {\n\t\t\tif (node instanceof Map) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Map;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tparent: (child: TreeNode): TreeNode | undefined => Tree.parent(child),\n\t\tkey: (child: TreeNode): string | number => Tree.key(child),\n\t} satisfies Context<TSchema>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAO1D,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAY/E,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACN,UAAU,EACV,WAAW,EACX,aAAa,EACb,eAAe,EACf,aAAa,GACb,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IASnC,YACkB,MAA2B,EAC5C,IAAyB,EACR,OAAiD;QAFjD,WAAM,GAAN,MAAM,CAAqB;QAE3B,YAAO,GAAP,OAAO,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CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACjC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,GAAG,CAAC;YACrC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,EAAE,CAAC,KAAe,EAAwB,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACrE,GAAG,EAAE,CAAC,KAAe,EAAmB,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;KAC/B,CAAC;AAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeNodeSchema,\n} from \"@fluidframework/tree\";\nimport { NodeKind, TreeNode } from \"@fluidframework/tree\";\nimport type {\n\tReadableField,\n\tFactoryContentObject,\n\tInsertableContent,\n\tReadSchema,\n} from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema, Tree, TreeAlpha } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tSharedTreeChatModel,\n\tEditResult,\n\tSemanticAgentOptions,\n\tLogger,\n\tAsynchronousEditor,\n\tContext,\n\tSynchronousEditor,\n\tViewOrTree,\n} from \"./api.js\";\nimport { getPrompt, stringifyTree } from \"./prompt.js\";\nimport { Subtree } from \"./subtree.js\";\nimport {\n\tllmDefault,\n\tfindSchemas,\n\ttoErrorString,\n\tunqualifySchema,\n\tisNamedSchema,\n} from \"./utils.js\";\n\n/**\n * The default maximum number of sequential edits the LLM can make before we assume it's stuck in a loop.\n * @remarks This can be overridden by passing {@link SemanticAgentOptions.maximumSequentialEdits | maximumSequentialEdits} to {@link createSemanticAgent}.\n */\nconst defaultMaxSequentialEdits = 20;\n\n/**\n * An agent that uses a {@link SharedTreeChatModel} to interact with a SharedTree.\n * @remarks This class forwards user queries to the chat model, and handles the application of any edits to the tree that the model requests.\n * @alpha @sealed\n */\nexport class SharedTreeSemanticAgent<TSchema extends ImplicitFieldSchema> {\n\t// Converted from ECMAScript private fields (#name) to TypeScript private members for easier debugger inspection.\n\tprivate readonly outerTree: Subtree<TSchema>;\n\tprivate readonly editor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>;\n\t/**\n\t * Whether or not the outer tree has changed since the last query finished.\n\t */\n\tprivate outerTreeIsDirty = false;\n\n\tpublic constructor(\n\t\tprivate readonly client: SharedTreeChatModel,\n\t\ttree: ViewOrTree<TSchema>,\n\t\tprivate readonly options?: Readonly<SemanticAgentOptions<TSchema>>,\n\t) {\n\t\tif (tree instanceof TreeNode) {\n\t\t\tTree.on(tree, \"treeChanged\", () => (this.outerTreeIsDirty = true));\n\t\t} else {\n\t\t\ttree.events.on(\"changed\", () => (this.outerTreeIsDirty = true));\n\t\t}\n\n\t\tthis.outerTree = new Subtree(tree);\n\t\tthis.editor = this.options?.editor ?? createDefaultEditor();\n\t\tconst prompt = getPrompt({\n\t\t\tsubtree: this.outerTree,\n\t\t\teditToolName: this.client.editToolName,\n\t\t\tdomainHints: this.options?.domainHints,\n\t\t});\n\t\tthis.options?.logger?.log(`# Fluid Framework SharedTree AI Agent Log\\n\\n`);\n\t\tconst now = new Date();\n\t\tconst formattedDate = now.toLocaleString(undefined, {\n\t\t\tweekday: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\tmonth: \"long\",\n\t\t\tday: \"numeric\",\n\t\t\thour: \"numeric\",\n\t\t\tminute: \"2-digit\",\n\t\t\tsecond: \"2-digit\",\n\t\t});\n\t\tthis.options?.logger?.log(`Agent created: **${formattedDate}**\\n\\n`);\n\t\tif (this.client.name !== undefined) {\n\t\t\tthis.options?.logger?.log(`Model: **${this.client.name}**\\n\\n`);\n\t\t}\n\t\tthis.client.appendContext?.(prompt);\n\t\tthis.options?.logger?.log(`## System Prompt\\n\\n${prompt}\\n\\n`);\n\t}\n\n\t/**\n\t * Given a user prompt, return a response.\n\t *\n\t * @param userPrompt - The prompt to send to the agent.\n\t * @returns The agent's response.\n\t */\n\tpublic async query(userPrompt: string): Promise<string> {\n\t\tthis.options?.logger?.log(`## User Query\\n\\n${userPrompt}\\n\\n`);\n\n\t\t// Notify the llm if the tree has changed since the last query, and if so, provide the new state of the tree.\n\t\tif (this.outerTreeIsDirty) {\n\t\t\tconst stringified = stringifyTree(this.outerTree.field);\n\t\t\tthis.client.appendContext?.(\n\t\t\t\t`The tree has changed since the last query. The new state of the tree is: \\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\``,\n\t\t\t);\n\t\t\tthis.options?.logger?.log(\n\t\t\t\t`### Latest Tree State\\n\\nThe Tree was edited by a local or remote user since the previous query. The latest state is:\\n\\n\\`\\`\\`JSON\\n${stringified}\\n\\`\\`\\`\\n\\n`,\n\t\t\t);\n\t\t}\n\n\t\t// Fork a branch that will live for the lifetime of this query (which can be multiple LLM calls if the there are errors or the LLM decides to take multiple steps to accomplish a task).\n\t\t// The branch will be merged back into the outer branch if and only if the query succeeds.\n\t\tconst queryTree = this.outerTree.fork();\n\t\tconst maxEditCount = this.options?.maximumSequentialEdits ?? defaultMaxSequentialEdits;\n\t\tlet active = true;\n\t\tlet editCount = 0;\n\t\tlet rollbackEdits = false;\n\t\tconst { editToolName } = this.client;\n\t\tconst edit = async (editCode: string): Promise<EditResult> => {\n\t\t\tif (editToolName === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"disabledError\",\n\t\t\t\t\tmessage: \"Editing is not enabled for this model.\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (!active) {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"expiredError\",\n\t\t\t\t\tmessage: `The query has already completed. Further edits are not allowed.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (++editCount > maxEditCount) {\n\t\t\t\trollbackEdits = true;\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"tooManyEditsError\",\n\t\t\t\t\tmessage: `The maximum number of edits (${maxEditCount}) for this query has been exceeded.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst editResult = await applyTreeFunction(\n\t\t\t\tqueryTree,\n\t\t\t\teditCode,\n\t\t\t\tthis.editor,\n\t\t\t\tthis.options?.logger,\n\t\t\t);\n\n\t\t\trollbackEdits = editResult.type !== \"success\";\n\t\t\treturn editResult;\n\t\t};\n\n\t\tconst responseMessage = await this.client.query({\n\t\t\ttext: userPrompt,\n\t\t\tedit,\n\t\t});\n\t\tactive = false;\n\n\t\tif (!rollbackEdits) {\n\t\t\tthis.outerTree.branch.merge(queryTree.branch);\n\t\t\tthis.outerTreeIsDirty = false;\n\t\t}\n\t\tthis.options?.logger?.log(`## Response\\n\\n`);\n\t\tthis.options?.logger?.log(`${responseMessage}\\n\\n`);\n\t\treturn responseMessage;\n\t}\n}\n\n/**\n * Creates an unhydrated node of the given schema with the given value.\n * @remarks If the schema is an object with {@link llmDefault | default values}, this function populates the node with those defaults.\n */\nfunction constructTreeNode(schema: TreeNodeSchema, content: FactoryContentObject): TreeNode {\n\tlet toInsert = content;\n\tif (schema instanceof ObjectNodeSchema) {\n\t\tconst contentWithDefaults: Record<string, InsertableContent | undefined> = {};\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (content[key] === undefined) {\n\t\t\t\tif (\n\t\t\t\t\ttypeof field.metadata.custom === \"object\" &&\n\t\t\t\t\tfield.metadata.custom !== null &&\n\t\t\t\t\tllmDefault in field.metadata.custom\n\t\t\t\t) {\n\t\t\t\t\tconst defaulter = field.metadata.custom[llmDefault];\n\t\t\t\t\tif (typeof defaulter === \"function\") {\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\t\t\t\t\tconst defaultValue: unknown = defaulter();\n\t\t\t\t\t\tif (defaultValue !== undefined) {\n\t\t\t\t\t\t\tcontentWithDefaults[key] = defaultValue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontentWithDefaults[key] = content[key];\n\t\t\t}\n\t\t}\n\t\ttoInsert = contentWithDefaults;\n\t}\n\n\t// Cast to never because tagContentSchema is typed to only accept InsertableContent, but we know that 'toInsert' (either the original content or contentWithDefaults) produces valid content for the schema.\n\treturn TreeAlpha.tagContentSchema(schema, toInsert as never);\n}\n\n/**\n * Applies the given function (as a string of JavaScript code or an actual function) to the given tree.\n */\nasync function applyTreeFunction<TSchema extends ImplicitFieldSchema>(\n\ttree: Subtree<TSchema>,\n\teditCode: string,\n\teditor: SynchronousEditor<TSchema> | AsynchronousEditor<TSchema>,\n\tlogger: Logger | undefined,\n): Promise<EditResult> {\n\tlogger?.log(`### Editing Tool Invoked\\n\\n`);\n\tlogger?.log(`#### Generated Code\\n\\n\\`\\`\\`javascript\\n${editCode}\\n\\`\\`\\`\\n\\n`);\n\n\t// Fork a branch to edit. If the edit fails or produces an error, we discard this branch, otherwise we merge it.\n\tconst editTree = tree.fork();\n\ttry {\n\t\tawait editor(editTree.viewOrTree, editCode);\n\t} catch (error: unknown) {\n\t\tlogger?.log(`#### Error\\n\\n`);\n\t\tlogger?.log(`\\`\\`\\`JSON\\n${toErrorString(error)}\\n\\`\\`\\`\\n\\n`);\n\t\teditTree.branch.dispose();\n\t\treturn {\n\t\t\ttype: \"editingError\",\n\t\t\tmessage: `Running the generated code produced an error. The state of the tree will be reset to its previous state as it was before the code ran. Please try again. Here is the error: ${toErrorString(error)}`,\n\t\t};\n\t}\n\n\ttree.branch.merge(editTree.branch);\n\tlogger?.log(`#### New Tree State\\n\\n`);\n\tlogger?.log(`${`\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``}\\n\\n`);\n\treturn {\n\t\ttype: \"success\",\n\t\tmessage: `After running the code, the new state of the tree is:\\n\\n\\`\\`\\`JSON\\n${stringifyTree(tree.field)}\\n\\`\\`\\``,\n\t};\n}\n\nfunction createDefaultEditor<\n\tTSchema extends ImplicitFieldSchema = ImplicitFieldSchema,\n>(): AsynchronousEditor<TSchema> {\n\treturn async (tree, code) => {\n\t\tconst context = createContext(tree);\n\t\t// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval\n\t\tconst fn = new Function(\"context\", code);\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\tawait fn(context);\n\t};\n}\n\n/**\n * Creates a {@link Context} for the given subtree.\n * @alpha\n */\nexport function createContext<TSchema extends ImplicitFieldSchema>(\n\ttree: ViewOrTree<TSchema>,\n): Context<TSchema> {\n\tconst subTree = new Subtree(tree);\n\t// Stick the tree schema constructors on an object passed to the function so that the LLM can create new nodes.\n\tconst create: Record<string, (input: FactoryContentObject) => TreeNode> = {};\n\tconst is: Record<string, <T extends TreeNode>(input: unknown) => input is T> = {};\n\tfor (const schema of findSchemas(subTree.schema, (s) => isNamedSchema(s.identifier))) {\n\t\tconst name = unqualifySchema(schema.identifier);\n\t\tcreate[name] = (input: FactoryContentObject) => constructTreeNode(schema, input);\n\t\tis[name] = <T extends TreeNode>(input: unknown): input is T => Tree.is(input, schema);\n\t}\n\n\treturn {\n\t\tget root(): ReadableField<TSchema> {\n\t\t\treturn subTree.field;\n\t\t},\n\t\tset root(value: TreeFieldFromImplicitField<ReadSchema<TSchema>>) {\n\t\t\tsubTree.field = value;\n\t\t},\n\t\tcreate,\n\t\tis,\n\t\tisArray(node) {\n\t\t\tif (Array.isArray(node)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Array;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tisMap(node) {\n\t\t\tif (node instanceof Map) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\treturn schema.kind === NodeKind.Map;\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tparent: (child: TreeNode): TreeNode | undefined => Tree.parent(child),\n\t\tkey: (child: TreeNode): string | number => Tree.key(child),\n\t} satisfies Context<TSchema>;\n}\n"]}
|
package/lib/methodBinding.d.ts
CHANGED
|
@@ -80,9 +80,7 @@ export type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Res
|
|
|
80
80
|
* @alpha
|
|
81
81
|
*/
|
|
82
82
|
export interface ExposedMethods {
|
|
83
|
-
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<
|
|
84
|
-
[P in K]: Infer<Z>;
|
|
85
|
-
}> & IExposedMethods, Z extends FunctionDef<any, any, any>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
83
|
+
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods, Z extends FunctionDef<any, any, any>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
86
84
|
/**
|
|
87
85
|
* Create a Zod schema for a SharedTree schema class.
|
|
88
86
|
* @remarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methodBinding.d.ts","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAI7B;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK;CAChE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,cAAc,GACvB,cAA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poration and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { NodeKind, TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\n\nimport { instanceOf } from \"./utils.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny,\n\tRest extends z.ZodTypeAny | null = null,\n> {\n\tdescription?: string;\n\targs: Args;\n\trest?: Rest;\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | null,\n\t\tpublic readonly returns: z.ZodTypeAny,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n */\nexport type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest>\n\t? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<
|
|
1
|
+
{"version":3,"file":"methodBinding.js","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA0BxC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAA2B;IAI5D,OAAO,eAAe,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;AACvD,CAAC;AAuBD;;GAEG;AACH,MAAM,OAAO,eAAe;IAG3B,YACiB,IAAY,EACZ,WAA+B,EAC/B,IAAoB;IACpC,kDAA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iB,CAAC,WAA2B;QAI1D,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAyC,CAAC;QAC9D,IAAI,WAAW,CAAC,mBAAmB,CAAC,KAAK,SAAS,EAAE,CAAC;YACpD,WAAW,CAAC,mBAAmB,CAAC,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;QACD,OAAO;YACN,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,EAAE,cAAc,CAAC,eAAe;SAC/C,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { NodeKind, TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\n\nimport { instanceOf } from \"./utils.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny,\n\tRest extends z.ZodTypeAny | null = null,\n> {\n\tdescription?: string;\n\targs: Args;\n\trest?: Rest;\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | null,\n\t\tpublic readonly returns: z.ZodTypeAny,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n */\nexport type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest>\n\t? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<any, any, any>,\n\t>(schema: S, methodName: K, zodFunction: Z): void;\n\n\t/**\n\t * Create a Zod schema for a SharedTree schema class.\n\t * @remarks\n\t * Use it to \"wrap\" schema types that are referenced as arguments or return types when exposing methods (with {@link ExposedMethods.expose}).\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * A symbol used to expose methods to the LLM.\n * @alpha\n */\nexport const exposeMethodsSymbol: unique symbol = Symbol(\"run\");\n\n/**\n * An interface that SharedTree schema classes should implement to expose their methods to the LLM.\n *\n * @remarks\n * The `getExposedMethods` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedMethods {\n\t[exposeMethodsSymbol](methods: ExposedMethods): void;\n}\n\nclass ExposedMethodsI implements ExposedMethods {\n\tprivate readonly methods: Record<string, FunctionWrapper> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic expose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>,\n\t>(schema: S, methodName: K, functionDef: Z): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose methods on the \"this\" object');\n\t\t}\n\t\tthis.methods[methodName] = new FunctionWrapper(\n\t\t\tmethodName,\n\t\t\tfunctionDef.description,\n\t\t\tfunctionDef.args,\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tfunctionDef.rest ?? null,\n\t\t\tfunctionDef.returns,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedMethods(schemaClass: BindableSchema): {\n\t\tmethods: Record<string, FunctionWrapper>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposedMethods = new ExposedMethodsI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedMethods;\n\t\tif (extractable[exposeMethodsSymbol] !== undefined) {\n\t\t\textractable[exposeMethodsSymbol](exposedMethods);\n\t\t}\n\t\treturn {\n\t\t\tmethods: exposedMethods.methods,\n\t\t\treferencedTypes: exposedMethods.referencedTypes,\n\t\t};\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propertyBinding.d.ts","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG/D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,OAAO,MAE3C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;KAC7B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,KAAK,GAAG,CAAC;CACjE,CAAC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AM,WAAW,GAAG,WAA4C,CAAC;QACjE,IAAI,WAAW,CAAC,sBAAsB,CAAC,KAAK,SAAS,EAAE,CAAC;YACvD,WAAW,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO;YACN,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,eAAe,EAAE,OAAO,CAAC,eAAe;SACxC,CAAC;IACH,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAA2B;IAI/D,OAAO,kBAAkB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { ZodType, ZodTypeAny, ZodTypeDef, infer as ZodInfer } from \"zod\";\n\nimport type { BindableSchema, Ctor } from \"./methodBinding.js\";\nimport { instanceOf } from \"./utils.js\";\n\n/**\n * A symbol used to expose properties to the LLM.\n * @alpha\n */\nexport const exposePropertiesSymbol: unique symbol = Symbol.for(\n\t\"@fluidframework/tree-agent/exposeProperties\",\n);\n\n/**\n * Set of property keys from `T` that are not methods.\n * @alpha\n */\nexport type ExposableKeys<T> = {\n\t[K in keyof T]?: T[K] extends (...args: any[]) => any ? never : K;\n}[keyof T];\n\n/**\n * Type-level equality test used as a helper to evaluate readonly keys.\n * - If X and Y are the same type, it evaluates to A.\n * - If X and Y are different, it evaluates to B.\n * @alpha\n */\nexport type IfEquals<X, Y, A = true, B = false> = (<T>() => T extends X ? 1 : 2) extends <\n\tT,\n>() => T extends Y ? 1 : 2\n\t? A\n\t: B;\n\n/**\n * Produces a union of keys of `T` which are readonly.\n * @alpha\n */\nexport type ReadonlyKeys<T> = {\n\t// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\n\t[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>;\n}[keyof T];\n\n/**\n * Type to enforce `readOnly: true` for readonly properties.\n * @alpha\n */\nexport type ReadOnlyRequirement<TObj, K extends keyof TObj> = {\n\t[P in K]-?: P extends ReadonlyKeys<TObj> ? { readOnly: true } : { readOnly?: false };\n}[K];\n\n/**\n * Emits compile-time error when there is a type mismatch.\n * @alpha\n */\nexport type TypeMatchOrError<Expected, Received> = [Received] extends [Expected]\n\t? unknown\n\t: {\n\t\t\t__error__: \"Zod schema value type does not match the property's declared type\";\n\t\t\texpected: Expected;\n\t\t\treceived: Received;\n\t\t};\n\n/**\n * A property definition class that describes the structure of the property\n * @alpha\n */\nexport class PropertyDef {\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly schema: ZodTypeAny,\n\t\tpublic readonly readOnly: boolean,\n\t) {}\n}\n\n/**\n * An interface for exposing properties of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedProperties {\n\texposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>,\n\t): void;\n\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * An interface that SharedTree schema classes should implement to expose their properties to the LLM.\n *\n * @remarks\n * The `getExposedProperties` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedProperties {\n\t[exposePropertiesSymbol]?(properties: ExposedProperties): void;\n}\n\nclass ExposedPropertiesI implements ExposedProperties {\n\tprivate readonly properties: Record<string, PropertyDef> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic exposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>,\n\t): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose properties on the \"this\" schema class');\n\t\t}\n\t\tthis.properties[name] = new PropertyDef(\n\t\t\tname,\n\t\t\tdef.description,\n\t\t\tdef.schema,\n\t\t\tdef.readOnly === true,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedProperties(schemaClass: BindableSchema): {\n\t\tproperties: Record<string, PropertyDef>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposed = new ExposedPropertiesI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedProperties;\n\t\tif (extractable[exposePropertiesSymbol] !== undefined) {\n\t\t\textractable[exposePropertiesSymbol](exposed);\n\t\t}\n\t\treturn {\n\t\t\tproperties: exposed.properties,\n\t\t\treferencedTypes: exposed.referencedTypes,\n\t\t};\n\t}\n}\n\n/**\n * Get the exposed properties of a schema class.\n * @param schemaClass - The schema class to extract properties from.\n * @returns A record of property names and their corresponding Zod types.\n */\nexport function getExposedProperties(schemaClass: BindableSchema): {\n\tproperties: Record<string, PropertyDef>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedPropertiesI.getExposedProperties(schemaClass);\n}\n"]}
|
package/lib/utils.js
CHANGED
|
@@ -128,7 +128,7 @@ export function isNamedSchema(schemaIdentifier) {
|
|
|
128
128
|
if (["string", "number", "boolean", "null", "handle"].includes(unqualifySchema(schemaIdentifier))) {
|
|
129
129
|
return false;
|
|
130
130
|
}
|
|
131
|
-
return
|
|
131
|
+
return /(?:Array|Map|Record)<\["(.*)"]>/.exec(schemaIdentifier) === null;
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
134
|
* Returns the unqualified name of a schema (e.g. `"my.scope.MyNode"` returns `"MyNode"`).
|
|
@@ -137,7 +137,7 @@ export function isNamedSchema(schemaIdentifier) {
|
|
|
137
137
|
*/
|
|
138
138
|
export function unqualifySchema(schemaIdentifier) {
|
|
139
139
|
// Get the unqualified name by removing the scope (everything before the last dot).
|
|
140
|
-
const matches =
|
|
140
|
+
const matches = /[^.]+$/.exec(schemaIdentifier);
|
|
141
141
|
if (matches === null) {
|
|
142
142
|
return schemaIdentifier; // Return the original name if it is unscoped.
|
|
143
143
|
}
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0DAA0D;AAC1D,qEAAqE;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAQtE,OAAO,EACN,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,GACT,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,CAAC,EAAE,M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ACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeNode,\n\tTreeNodeSchema,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport { FunctionWrapper } from \"./methodBinding.js\";\nimport { PropertyDef } from \"./propertyBinding.js\";\n\n/**\n * Subset of Map interface.\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * TBD\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function getOrCreate<K, V>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(\"Unexpected node schema\");\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn schemaIdentifier.match(/(?:Array|Map|Record)<\\[\"(.*)\"]>/) === null;\n}\n\n/**\n * Returns the unqualified name of a schema (e.g. `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks This works by removing all characters before the last dot in the schema name.\n * If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = schemaIdentifier.match(/[^.]+$/);\n\tif (matches === null) {\n\t\treturn schemaIdentifier; // Return the original name if it is unscoped.\n\t}\n\treturn matches[0];\n}\n\n/**\n * Details about the properties of a TypeScript schema represented as Zod.\n */\nexport interface SchemaDetails {\n\thasHelperMethods: boolean;\n}\n\n// TODO: yuck, this entire file has too many statics. we should rewrite it as a generic zod schema walk.\nlet detailsI: SchemaDetails = {\n\thasHelperMethods: false,\n};\n\n/**\n * Returns the TypeScript source code corresponding to a Zod schema. The schema is supplied as an object where each\n * property provides a name for an associated Zod type. The return value is a string containing the TypeScript source\n * code corresponding to the schema. Each property of the schema object is emitted as a named `interface` or `type`\n * declaration for the associated type and is referenced by that name in the emitted type declarations. Other types\n * referenced in the schema are emitted in their structural form.\n * @param schema - A schema object where each property provides a name for an associated Zod type.\n * @param details - Optional details about the schema. The fields will be set according to the details in the given schema.\n * @returns The TypeScript source code corresponding to the schema.\n */\nexport function getZodSchemaAsTypeScript(\n\tschema: Record<string, z.ZodType>,\n\tdetails?: SchemaDetails,\n): string {\n\tdetailsI = details ?? { hasHelperMethods: false };\n\tlet result = \"\";\n\tlet startOfLine = true;\n\tlet indent = 0;\n\tconst entries = [...Object.entries(schema)];\n\tconst namedTypes = new Map<object, string>(\n\t\tentries.map(([name, type]) => [getTypeIdentity(type), name]),\n\t);\n\tfor (const [name, type] of entries) {\n\t\tif (result) {\n\t\t\tappendNewLine();\n\t\t}\n\t\tconst description = type._def.description;\n\t\tif (description !== undefined && description !== \"\") {\n\t\t\tfor (const comment of description.split(\"\\n\")) {\n\t\t\t\tappend(`// ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodObject) {\n\t\t\tappend(`interface ${name} `);\n\t\t\tappendObjectType(type as z.ZodObject<z.ZodRawShape>);\n\t\t} else {\n\t\t\tappend(`type ${name} = `);\n\t\t\tappendTypeDefinition(type);\n\t\t\tappend(\";\");\n\t\t}\n\t\tappendNewLine();\n\t}\n\treturn result;\n\n\tfunction append(s: string) {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine() {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendType(type: z.ZodType, minPrecedence = TypePrecedence.Object) {\n\t\tconst name = namedTypes.get(getTypeIdentity(type));\n\t\tif (name === undefined) {\n\t\t\tconst parenthesize = getTypePrecendece(type) < minPrecedence;\n\t\t\tif (parenthesize) append(\"(\");\n\t\t\tappendTypeDefinition(type);\n\t\t\tif (parenthesize) append(\")\");\n\t\t} else {\n\t\t\tappend(name);\n\t\t}\n\t}\n\n\tfunction appendTypeDefinition(type: z.ZodType) {\n\t\tswitch (getTypeKind(type)) {\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodString: {\n\t\t\t\treturn append(\"string\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNumber: {\n\t\t\t\treturn append(\"number\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodBoolean: {\n\t\t\t\treturn append(\"boolean\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDate: {\n\t\t\t\treturn append(\"Date\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUndefined: {\n\t\t\t\treturn append(\"undefined\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNull: {\n\t\t\t\treturn append(\"null\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnknown: {\n\t\t\t\treturn append(\"unknown\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodArray: {\n\t\t\t\treturn appendArrayType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\t\treturn appendObjectType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t(type._def as z.ZodUnionDef).options,\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[...(type._def as z.ZodDiscriminatedUnionDef<string>).options.values()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).left,\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).right,\n\t\t\t\t\t],\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodTuple: {\n\t\t\t\treturn appendTupleType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodRecord: {\n\t\t\t\treturn appendRecordType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodMap: {\n\t\t\t\treturn appendMapType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLiteral: {\n\t\t\t\treturn appendLiteral((type._def as z.ZodLiteralDef).value);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\t\treturn append(\n\t\t\t\t\t(type._def as z.ZodEnumDef).values.map((value) => JSON.stringify(value)).join(\" | \"),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodOptional: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[(type._def as z.ZodOptionalDef).innerType, z.undefined()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodReadonly: {\n\t\t\t\treturn appendReadonlyType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEffects: {\n\t\t\t\t// Currently, this only handles schema class instances, but there are other cases in which a ZodEffects could theoretically be used.\n\t\t\t\tif (instanceOfs.has(type)) {\n\t\t\t\t\tconst objectNodeSchema = instanceOfs.get(type);\n\t\t\t\t\tif (objectNodeSchema === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported zod effects type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn append(getFriendlyName(objectNodeSchema));\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unsupported zod effects type. Did you use z.instanceOf? Use ExposedMethods.instanceOf function to reference schema classes in methods.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodVoid: {\n\t\t\t\treturn append(\"void\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLazy: {\n\t\t\t\treturn appendType((type._def as z.ZodLazyDef).getter());\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundMethods(boundType: z.ZodType): void {\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((boundType._def as z.ZodObjectDef).shape())) {\n\t\t\t// Special handling of methods on objects\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method !== undefined && method instanceof FunctionWrapper) {\n\t\t\t\tdetailsI.hasHelperMethods = true;\n\t\t\t\tappend(name);\n\t\t\t\tappend(\"(\");\n\t\t\t\tlet first = true;\n\t\t\t\tfor (const [argName, argType] of method.args) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tif (getTypeKind(argType) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\t\tappend(`${argName}?: `);\n\t\t\t\t\t\tappendType((argType._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tappend(`${argName}: `);\n\t\t\t\t\t\tappendType(argType);\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t}\n\t\t\t\tif (method.rest !== null) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tappend(\"...rest: \");\n\t\t\t\t\tappendType(method.rest, TypePrecedence.Object);\n\t\t\t\t\tappend(\"[]\");\n\t\t\t\t}\n\t\t\t\tappend(`): `);\n\t\t\t\tappendType(method.returns, TypePrecedence.Object);\n\t\t\t\tappend(\";\");\n\t\t\t\tif (method.description !== undefined) {\n\t\t\t\t\tappend(` // ${method.description}`);\n\t\t\t\t}\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundProperties(type: z.ZodType): void {\n\t\tconst property = (type as unknown as { property?: PropertyDef }).property;\n\n\t\tif (!(property instanceof PropertyDef)) {\n\t\t\tif (type.description !== undefined && type.description !== \"\") {\n\t\t\t\tappend(` // ${type.description}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (property.readOnly === true) {\n\t\t\tappend(\" // readonly\");\n\t\t}\n\t\tif (property.description !== undefined && property.description !== \"\") {\n\t\t\tappend(` - ${property.description}`);\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: z.ZodType) {\n\t\tappendType((arrayType._def as z.ZodArrayDef).type, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendObjectType(objectType: z.ZodType) {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((objectType._def as z.ZodObjectDef).shape())) {\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\n\t\t\tif (method === undefined || !(method instanceof FunctionWrapper)) {\n\t\t\t\tappend(name);\n\t\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\tappend(\"?\");\n\t\t\t\t\ttype = (type._def as z.ZodOptionalDef).innerType;\n\t\t\t\t}\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type);\n\t\t\t\tappend(\";\");\n\t\t\t\tappendBoundProperties(type);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tappendBoundMethods(objectType);\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionOrIntersectionTypes(\n\t\ttypes: readonly z.ZodType[],\n\t\tminPrecedence: TypePrecedence,\n\t) {\n\t\tlet first = true;\n\t\tfor (const type of types) {\n\t\t\tif (!first) append(minPrecedence === TypePrecedence.Intersection ? \" & \" : \" | \");\n\t\t\tappendType(type, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: z.ZodType) {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const type of (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType>).items) {\n\t\t\tif (!first) append(\", \");\n\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\tappendType((type._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(type);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tconst rest = (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType | null>).rest;\n\t\tif (rest !== null) {\n\t\t\tif (!first) append(\", \");\n\t\t\tappend(\"...\");\n\t\t\tappendType(rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: z.ZodType) {\n\t\tappend(\"Record<\");\n\t\tappendType((recordType._def as z.ZodRecordDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((recordType._def as z.ZodRecordDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: z.ZodType) {\n\t\tappend(\"Map<\");\n\t\tappendType((mapType._def as z.ZodMapDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((mapType._def as z.ZodMapDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: unknown) {\n\t\tappend(\n\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\"\n\t\t\t\t? JSON.stringify(value)\n\t\t\t\t: \"any\",\n\t\t);\n\t}\n\n\tfunction appendReadonlyType(readonlyType: z.ZodType) {\n\t\tappend(\"Readonly<\");\n\t\tappendType((readonlyType._def as z.ZodReadonlyDef).innerType);\n\t\tappend(\">\");\n\t}\n}\n\nfunction getTypeKind(type: z.ZodType): z.ZodFirstPartyTypeKind {\n\treturn (type._def as z.ZodTypeDef & { typeName: z.ZodFirstPartyTypeKind }).typeName;\n}\n\nfunction getTypeIdentity(type: z.ZodType): object {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\treturn (type._def as z.ZodObjectDef).shape();\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\treturn (type._def as z.ZodEnumDef).values;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\treturn (type._def as z.ZodUnionDef).options;\n\t\t}\n\t\tdefault: {\n\t\t\treturn type;\n\t\t}\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecendece(type: z.ZodType): TypePrecedence {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum:\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion:\n\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n\n/**\n * Create a Zod schema for a SharedTree schema class.\n * @alpha\n */\nexport function instanceOf<T extends TreeNodeSchemaClass>(\n\tschema: T,\n): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\tthrow new UsageError(`${schema.identifier} must be an instance of ObjectNodeSchema.`);\n\t}\n\tconst effect = z.instanceof(schema);\n\tinstanceOfs.set(effect, schema);\n\treturn effect;\n}\n\nconst instanceOfs = new WeakMap<z.ZodTypeAny, ObjectNodeSchema>();\n\n/**\n * Adds all (optionally filtered) schemas reachable from the given schema to the given set.\n * @returns The set of schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findSchemas(\n\tschema: ImplicitFieldSchema,\n\tfilter: (schema: TreeNodeSchema) => boolean = () => true,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!schemas.has(nodeSchema)) {\n\t\t\tif (filter(nodeSchema)) {\n\t\t\t\tschemas.add(nodeSchema);\n\t\t\t}\n\t\t\tfindSchemas([...nodeSchema.childTypes], filter, schemas);\n\t\t}\n\t}\n\treturn schemas;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0DAA0D;AAC1D,qEAAqE;AAErE,OAAO,EAAE,M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,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeNode,\n\tTreeNodeSchema,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport { FunctionWrapper } from \"./methodBinding.js\";\nimport { PropertyDef } from \"./propertyBinding.js\";\n\n/**\n * Subset of Map interface.\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * TBD\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function getOrCreate<K, V>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(\"Unexpected node schema\");\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn /(?:Array|Map|Record)<\\[\"(.*)\"]>/.exec(schemaIdentifier) === null;\n}\n\n/**\n * Returns the unqualified name of a schema (e.g. `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks This works by removing all characters before the last dot in the schema name.\n * If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = /[^.]+$/.exec(schemaIdentifier);\n\tif (matches === null) {\n\t\treturn schemaIdentifier; // Return the original name if it is unscoped.\n\t}\n\treturn matches[0];\n}\n\n/**\n * Details about the properties of a TypeScript schema represented as Zod.\n */\nexport interface SchemaDetails {\n\thasHelperMethods: boolean;\n}\n\n// TODO: yuck, this entire file has too many statics. we should rewrite it as a generic zod schema walk.\nlet detailsI: SchemaDetails = {\n\thasHelperMethods: false,\n};\n\n/**\n * Returns the TypeScript source code corresponding to a Zod schema. The schema is supplied as an object where each\n * property provides a name for an associated Zod type. The return value is a string containing the TypeScript source\n * code corresponding to the schema. Each property of the schema object is emitted as a named `interface` or `type`\n * declaration for the associated type and is referenced by that name in the emitted type declarations. Other types\n * referenced in the schema are emitted in their structural form.\n * @param schema - A schema object where each property provides a name for an associated Zod type.\n * @param details - Optional details about the schema. The fields will be set according to the details in the given schema.\n * @returns The TypeScript source code corresponding to the schema.\n */\nexport function getZodSchemaAsTypeScript(\n\tschema: Record<string, z.ZodType>,\n\tdetails?: SchemaDetails,\n): string {\n\tdetailsI = details ?? { hasHelperMethods: false };\n\tlet result = \"\";\n\tlet startOfLine = true;\n\tlet indent = 0;\n\tconst entries = [...Object.entries(schema)];\n\tconst namedTypes = new Map<object, string>(\n\t\tentries.map(([name, type]) => [getTypeIdentity(type), name]),\n\t);\n\tfor (const [name, type] of entries) {\n\t\tif (result) {\n\t\t\tappendNewLine();\n\t\t}\n\t\tconst description = type._def.description;\n\t\tif (description !== undefined && description !== \"\") {\n\t\t\tfor (const comment of description.split(\"\\n\")) {\n\t\t\t\tappend(`// ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodObject) {\n\t\t\tappend(`interface ${name} `);\n\t\t\tappendObjectType(type as z.ZodObject<z.ZodRawShape>);\n\t\t} else {\n\t\t\tappend(`type ${name} = `);\n\t\t\tappendTypeDefinition(type);\n\t\t\tappend(\";\");\n\t\t}\n\t\tappendNewLine();\n\t}\n\treturn result;\n\n\tfunction append(s: string) {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine() {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendType(type: z.ZodType, minPrecedence = TypePrecedence.Object) {\n\t\tconst name = namedTypes.get(getTypeIdentity(type));\n\t\tif (name === undefined) {\n\t\t\tconst parenthesize = getTypePrecendece(type) < minPrecedence;\n\t\t\tif (parenthesize) append(\"(\");\n\t\t\tappendTypeDefinition(type);\n\t\t\tif (parenthesize) append(\")\");\n\t\t} else {\n\t\t\tappend(name);\n\t\t}\n\t}\n\n\tfunction appendTypeDefinition(type: z.ZodType) {\n\t\tswitch (getTypeKind(type)) {\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodString: {\n\t\t\t\treturn append(\"string\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNumber: {\n\t\t\t\treturn append(\"number\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodBoolean: {\n\t\t\t\treturn append(\"boolean\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDate: {\n\t\t\t\treturn append(\"Date\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUndefined: {\n\t\t\t\treturn append(\"undefined\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNull: {\n\t\t\t\treturn append(\"null\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnknown: {\n\t\t\t\treturn append(\"unknown\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodArray: {\n\t\t\t\treturn appendArrayType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\t\treturn appendObjectType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t(type._def as z.ZodUnionDef).options,\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[...(type._def as z.ZodDiscriminatedUnionDef<string>).options.values()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).left,\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).right,\n\t\t\t\t\t],\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodTuple: {\n\t\t\t\treturn appendTupleType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodRecord: {\n\t\t\t\treturn appendRecordType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodMap: {\n\t\t\t\treturn appendMapType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLiteral: {\n\t\t\t\treturn appendLiteral((type._def as z.ZodLiteralDef).value);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\t\treturn append(\n\t\t\t\t\t(type._def as z.ZodEnumDef).values.map((value) => JSON.stringify(value)).join(\" | \"),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodOptional: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[(type._def as z.ZodOptionalDef).innerType, z.undefined()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodReadonly: {\n\t\t\t\treturn appendReadonlyType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEffects: {\n\t\t\t\t// Currently, this only handles schema class instances, but there are other cases in which a ZodEffects could theoretically be used.\n\t\t\t\tif (instanceOfs.has(type)) {\n\t\t\t\t\tconst objectNodeSchema = instanceOfs.get(type);\n\t\t\t\t\tif (objectNodeSchema === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported zod effects type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn append(getFriendlyName(objectNodeSchema));\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unsupported zod effects type. Did you use z.instanceOf? Use ExposedMethods.instanceOf function to reference schema classes in methods.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodVoid: {\n\t\t\t\treturn append(\"void\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLazy: {\n\t\t\t\treturn appendType((type._def as z.ZodLazyDef).getter());\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundMethods(boundType: z.ZodType): void {\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((boundType._def as z.ZodObjectDef).shape())) {\n\t\t\t// Special handling of methods on objects\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method !== undefined && method instanceof FunctionWrapper) {\n\t\t\t\tdetailsI.hasHelperMethods = true;\n\t\t\t\tappend(name);\n\t\t\t\tappend(\"(\");\n\t\t\t\tlet first = true;\n\t\t\t\tfor (const [argName, argType] of method.args) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tif (getTypeKind(argType) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\t\tappend(`${argName}?: `);\n\t\t\t\t\t\tappendType((argType._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tappend(`${argName}: `);\n\t\t\t\t\t\tappendType(argType);\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t}\n\t\t\t\tif (method.rest !== null) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tappend(\"...rest: \");\n\t\t\t\t\tappendType(method.rest, TypePrecedence.Object);\n\t\t\t\t\tappend(\"[]\");\n\t\t\t\t}\n\t\t\t\tappend(`): `);\n\t\t\t\tappendType(method.returns, TypePrecedence.Object);\n\t\t\t\tappend(\";\");\n\t\t\t\tif (method.description !== undefined) {\n\t\t\t\t\tappend(` // ${method.description}`);\n\t\t\t\t}\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundProperties(type: z.ZodType): void {\n\t\tconst property = (type as unknown as { property?: PropertyDef }).property;\n\n\t\tif (!(property instanceof PropertyDef)) {\n\t\t\tif (type.description !== undefined && type.description !== \"\") {\n\t\t\t\tappend(` // ${type.description}`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (property.readOnly === true) {\n\t\t\tappend(\" // readonly\");\n\t\t}\n\t\tif (property.description !== undefined && property.description !== \"\") {\n\t\t\tappend(` - ${property.description}`);\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: z.ZodType) {\n\t\tappendType((arrayType._def as z.ZodArrayDef).type, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendObjectType(objectType: z.ZodType) {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((objectType._def as z.ZodObjectDef).shape())) {\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\n\t\t\tif (method === undefined || !(method instanceof FunctionWrapper)) {\n\t\t\t\tappend(name);\n\t\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\tappend(\"?\");\n\t\t\t\t\ttype = (type._def as z.ZodOptionalDef).innerType;\n\t\t\t\t}\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type);\n\t\t\t\tappend(\";\");\n\t\t\t\tappendBoundProperties(type);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tappendBoundMethods(objectType);\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionOrIntersectionTypes(\n\t\ttypes: readonly z.ZodType[],\n\t\tminPrecedence: TypePrecedence,\n\t) {\n\t\tlet first = true;\n\t\tfor (const type of types) {\n\t\t\tif (!first) append(minPrecedence === TypePrecedence.Intersection ? \" & \" : \" | \");\n\t\t\tappendType(type, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: z.ZodType) {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const type of (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType>).items) {\n\t\t\tif (!first) append(\", \");\n\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\tappendType((type._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(type);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tconst rest = (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType | null>).rest;\n\t\tif (rest !== null) {\n\t\t\tif (!first) append(\", \");\n\t\t\tappend(\"...\");\n\t\t\tappendType(rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: z.ZodType) {\n\t\tappend(\"Record<\");\n\t\tappendType((recordType._def as z.ZodRecordDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((recordType._def as z.ZodRecordDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: z.ZodType) {\n\t\tappend(\"Map<\");\n\t\tappendType((mapType._def as z.ZodMapDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((mapType._def as z.ZodMapDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: unknown) {\n\t\tappend(\n\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\"\n\t\t\t\t? JSON.stringify(value)\n\t\t\t\t: \"any\",\n\t\t);\n\t}\n\n\tfunction appendReadonlyType(readonlyType: z.ZodType) {\n\t\tappend(\"Readonly<\");\n\t\tappendType((readonlyType._def as z.ZodReadonlyDef).innerType);\n\t\tappend(\">\");\n\t}\n}\n\nfunction getTypeKind(type: z.ZodType): z.ZodFirstPartyTypeKind {\n\treturn (type._def as z.ZodTypeDef & { typeName: z.ZodFirstPartyTypeKind }).typeName;\n}\n\nfunction getTypeIdentity(type: z.ZodType): object {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\treturn (type._def as z.ZodObjectDef).shape();\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\treturn (type._def as z.ZodEnumDef).values;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\treturn (type._def as z.ZodUnionDef).options;\n\t\t}\n\t\tdefault: {\n\t\t\treturn type;\n\t\t}\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecendece(type: z.ZodType): TypePrecedence {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum:\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion:\n\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n\n/**\n * Create a Zod schema for a SharedTree schema class.\n * @alpha\n */\nexport function instanceOf<T extends TreeNodeSchemaClass>(\n\tschema: T,\n): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\tthrow new UsageError(`${schema.identifier} must be an instance of ObjectNodeSchema.`);\n\t}\n\tconst effect = z.instanceof(schema);\n\tinstanceOfs.set(effect, schema);\n\treturn effect;\n}\n\nconst instanceOfs = new WeakMap<z.ZodTypeAny, ObjectNodeSchema>();\n\n/**\n * Adds all (optionally filtered) schemas reachable from the given schema to the given set.\n * @returns The set of schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findSchemas(\n\tschema: ImplicitFieldSchema,\n\tfilter: (schema: TreeNodeSchema) => boolean = () => true,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!schemas.has(nodeSchema)) {\n\t\t\tif (filter(nodeSchema)) {\n\t\t\t\tschemas.add(nodeSchema);\n\t\t\t}\n\t\t\tfindSchemas([...nodeSchema.childTypes], filter, schemas);\n\t\t}\n\t}\n\treturn schemas;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/tree-agent",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.74.0-365691",
|
|
4
4
|
"description": "Experimental package to simplify integrating AI into Fluid-based applications",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -70,24 +70,24 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
73
|
-
"@fluidframework/core-utils": "
|
|
74
|
-
"@fluidframework/runtime-utils": "
|
|
75
|
-
"@fluidframework/telemetry-utils": "
|
|
76
|
-
"@fluidframework/tree": "
|
|
73
|
+
"@fluidframework/core-utils": "2.74.0-365691",
|
|
74
|
+
"@fluidframework/runtime-utils": "2.74.0-365691",
|
|
75
|
+
"@fluidframework/telemetry-utils": "2.74.0-365691",
|
|
76
|
+
"@fluidframework/tree": "2.74.0-365691",
|
|
77
77
|
"uuid": "^11.1.0",
|
|
78
78
|
"zod": "^3.25.32"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
82
82
|
"@biomejs/biome": "~1.9.3",
|
|
83
|
-
"@fluid-internal/mocha-test-setup": "
|
|
83
|
+
"@fluid-internal/mocha-test-setup": "2.74.0-365691",
|
|
84
84
|
"@fluid-tools/build-cli": "^0.60.0",
|
|
85
85
|
"@fluidframework/build-common": "^2.0.3",
|
|
86
86
|
"@fluidframework/build-tools": "^0.60.0",
|
|
87
|
-
"@fluidframework/eslint-config-fluid": "
|
|
88
|
-
"@fluidframework/id-compressor": "
|
|
89
|
-
"@fluidframework/runtime-utils": "
|
|
90
|
-
"@fluidframework/test-runtime-utils": "
|
|
87
|
+
"@fluidframework/eslint-config-fluid": "2.74.0-365691",
|
|
88
|
+
"@fluidframework/id-compressor": "2.74.0-365691",
|
|
89
|
+
"@fluidframework/runtime-utils": "2.74.0-365691",
|
|
90
|
+
"@fluidframework/test-runtime-utils": "2.74.0-365691",
|
|
91
91
|
"@langchain/anthropic": "^0.3.24",
|
|
92
92
|
"@langchain/core": "^0.3.78",
|
|
93
93
|
"@langchain/google-genai": "^0.2.16",
|
package/src/agent.ts
CHANGED
|
@@ -188,6 +188,7 @@ function constructTreeNode(schema: TreeNodeSchema, content: FactoryContentObject
|
|
|
188
188
|
) {
|
|
189
189
|
const defaulter = field.metadata.custom[llmDefault];
|
|
190
190
|
if (typeof defaulter === "function") {
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
191
192
|
const defaultValue: unknown = defaulter();
|
|
192
193
|
if (defaultValue !== undefined) {
|
|
193
194
|
contentWithDefaults[key] = defaultValue;
|
|
@@ -247,6 +248,7 @@ function createDefaultEditor<
|
|
|
247
248
|
const context = createContext(tree);
|
|
248
249
|
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
|
249
250
|
const fn = new Function("context", code);
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
250
252
|
await fn(context);
|
|
251
253
|
};
|
|
252
254
|
}
|
package/src/methodBinding.ts
CHANGED
|
@@ -127,7 +127,7 @@ export type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Res
|
|
|
127
127
|
export interface ExposedMethods {
|
|
128
128
|
expose<
|
|
129
129
|
const K extends string & keyof MethodKeys<InstanceType<S>>,
|
|
130
|
-
S extends BindableSchema & Ctor<
|
|
130
|
+
S extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,
|
|
131
131
|
Z extends FunctionDef<any, any, any>,
|
|
132
132
|
>(schema: S, methodName: K, zodFunction: Z): void;
|
|
133
133
|
|
|
@@ -173,7 +173,7 @@ class ExposedMethodsI implements ExposedMethods {
|
|
|
173
173
|
|
|
174
174
|
public expose<
|
|
175
175
|
const K extends string & keyof MethodKeys<InstanceType<S>>,
|
|
176
|
-
S extends BindableSchema & Ctor<
|
|
176
|
+
S extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,
|
|
177
177
|
Z extends FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>,
|
|
178
178
|
>(schema: S, methodName: K, functionDef: Z): void {
|
|
179
179
|
if (schema !== this.schemaClass) {
|
package/src/propertyBinding.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type IfEquals<X, Y, A = true, B = false> = (<T>() => T extends X ? 1 : 2)
|
|
|
43
43
|
* @alpha
|
|
44
44
|
*/
|
|
45
45
|
export type ReadonlyKeys<T> = {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
|
|
46
47
|
[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>;
|
|
47
48
|
}[keyof T];
|
|
48
49
|
|
package/src/utils.ts
CHANGED
|
@@ -180,7 +180,7 @@ export function isNamedSchema(schemaIdentifier: string): boolean {
|
|
|
180
180
|
return false;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
return
|
|
183
|
+
return /(?:Array|Map|Record)<\["(.*)"]>/.exec(schemaIdentifier) === null;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
/**
|
|
@@ -190,7 +190,7 @@ export function isNamedSchema(schemaIdentifier: string): boolean {
|
|
|
190
190
|
*/
|
|
191
191
|
export function unqualifySchema(schemaIdentifier: string): string {
|
|
192
192
|
// Get the unqualified name by removing the scope (everything before the last dot).
|
|
193
|
-
const matches =
|
|
193
|
+
const matches = /[^.]+$/.exec(schemaIdentifier);
|
|
194
194
|
if (matches === null) {
|
|
195
195
|
return schemaIdentifier; // Return the original name if it is unscoped.
|
|
196
196
|
}
|