@fluidframework/tree-agent 2.70.0-360374 → 2.70.0-361092
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 +20 -3
- package/dist/agent.d.ts +30 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +57 -33
- package/dist/agent.js.map +1 -1
- package/dist/alpha.d.ts +5 -0
- package/dist/api.d.ts +84 -17
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +83 -17
- package/dist/prompt.js.map +1 -1
- package/lib/agent.d.ts +30 -1
- package/lib/agent.d.ts.map +1 -1
- package/lib/agent.js +54 -32
- package/lib/agent.js.map +1 -1
- package/lib/alpha.d.ts +5 -0
- package/lib/api.d.ts +84 -17
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/prompt.d.ts.map +1 -1
- package/lib/prompt.js +82 -16
- package/lib/prompt.js.map +1 -1
- package/package.json +13 -15
- package/src/agent.ts +94 -41
- package/src/api.ts +98 -24
- package/src/index.ts +8 -1
- package/src/prompt.ts +89 -18
|
@@ -10,9 +10,21 @@ export type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string,
|
|
|
10
10
|
// @alpha
|
|
11
11
|
export type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg] ? [Single[1]] : T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]] ? [Head[1], ...ArgsTuple<Tail>] : never;
|
|
12
12
|
|
|
13
|
+
// @alpha
|
|
14
|
+
export type AsynchronousEditor = (context: Record<string, unknown>, code: string) => Promise<void>;
|
|
15
|
+
|
|
13
16
|
// @alpha
|
|
14
17
|
export type BindableSchema = TreeNodeSchema<string, NodeKind.Object> | TreeNodeSchema<string, NodeKind.Record> | TreeNodeSchema<string, NodeKind.Array> | TreeNodeSchema<string, NodeKind.Map>;
|
|
15
18
|
|
|
19
|
+
// @alpha
|
|
20
|
+
export const bindEditor: typeof bindEditorImpl;
|
|
21
|
+
|
|
22
|
+
// @alpha
|
|
23
|
+
export function bindEditorImpl<TSchema extends ImplicitFieldSchema>(tree: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), editor: AsynchronousEditor): (code: string) => Promise<void>;
|
|
24
|
+
|
|
25
|
+
// @alpha
|
|
26
|
+
export function bindEditorImpl<TSchema extends ImplicitFieldSchema>(tree: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), editor: SynchronousEditor): (code: string) => void;
|
|
27
|
+
|
|
16
28
|
// @alpha
|
|
17
29
|
export function buildFunc<const Return extends z.ZodTypeAny, const Args extends readonly Arg[], const Rest extends z.ZodTypeAny | null = null>(def: {
|
|
18
30
|
description?: string;
|
|
@@ -23,10 +35,13 @@ export function buildFunc<const Return extends z.ZodTypeAny, const Args extends
|
|
|
23
35
|
// @alpha
|
|
24
36
|
export type Ctor<T = any> = new (...args: any[]) => T;
|
|
25
37
|
|
|
38
|
+
// @alpha
|
|
39
|
+
export const defaultEditor: AsynchronousEditor;
|
|
40
|
+
|
|
26
41
|
// @alpha
|
|
27
42
|
export interface EditResult {
|
|
28
43
|
message: string;
|
|
29
|
-
type: "success" | "disabledError" | "
|
|
44
|
+
type: "success" | "disabledError" | "editingError" | "tooManyEditsError" | "expiredError";
|
|
30
45
|
}
|
|
31
46
|
|
|
32
47
|
// @alpha
|
|
@@ -78,10 +93,9 @@ export type MethodKeys<T> = {
|
|
|
78
93
|
// @alpha
|
|
79
94
|
export interface SemanticAgentOptions {
|
|
80
95
|
domainHints?: string;
|
|
81
|
-
|
|
96
|
+
editor?: SynchronousEditor | AsynchronousEditor;
|
|
82
97
|
logger?: Logger;
|
|
83
98
|
maximumSequentialEdits?: number;
|
|
84
|
-
validateEdit?: (code: string) => void | Promise<void>;
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
// @alpha
|
|
@@ -104,6 +118,9 @@ export class SharedTreeSemanticAgent<TSchema extends ImplicitFieldSchema> {
|
|
|
104
118
|
query(userPrompt: string): Promise<string>;
|
|
105
119
|
}
|
|
106
120
|
|
|
121
|
+
// @alpha
|
|
122
|
+
export type SynchronousEditor = (context: Record<string, unknown>, code: string) => void;
|
|
123
|
+
|
|
107
124
|
// @alpha
|
|
108
125
|
export type TreeView<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> = Pick<TreeViewAlpha<TRoot>, "root" | "fork" | "merge" | "rebaseOnto" | "schema" | "events"> & TreeBranch;
|
|
109
126
|
|
package/dist/agent.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { ImplicitFieldSchema } from "@fluidframework/tree";
|
|
6
6
|
import { TreeNode } from "@fluidframework/tree";
|
|
7
7
|
import type { ReadableField } from "@fluidframework/tree/alpha";
|
|
8
|
-
import type { SharedTreeChatModel, SemanticAgentOptions } from "./api.js";
|
|
8
|
+
import type { SharedTreeChatModel, SemanticAgentOptions, SynchronousEditor, AsynchronousEditor } from "./api.js";
|
|
9
9
|
import { type TreeView } from "./utils.js";
|
|
10
10
|
/**
|
|
11
11
|
* An agent that uses a {@link SharedTreeChatModel} to interact with a SharedTree.
|
|
@@ -29,4 +29,33 @@ export declare class SharedTreeSemanticAgent<TSchema extends ImplicitFieldSchema
|
|
|
29
29
|
*/
|
|
30
30
|
query(userPrompt: string): Promise<string>;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* The default {@link AsynchronousEditor | editor} implementation that simply uses `new Function` to run the provided code.
|
|
34
|
+
* @remarks This editor allows both synchronous and asynchronous code (i.e. the provided code may return a Promise).
|
|
35
|
+
* @example `await new Function("context", code)(context);`
|
|
36
|
+
* @alpha
|
|
37
|
+
*/
|
|
38
|
+
export declare const defaultEditor: AsynchronousEditor;
|
|
39
|
+
/**
|
|
40
|
+
* Binds the given {@link AsynchronousEditor | editor} to the given view or tree.
|
|
41
|
+
* @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor function.
|
|
42
|
+
* @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.
|
|
43
|
+
* @alpha
|
|
44
|
+
*/
|
|
45
|
+
export declare function bindEditorImpl<TSchema extends ImplicitFieldSchema>(tree: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), editor: AsynchronousEditor): (code: string) => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Binds the given {@link SynchronousEditor | editor} to the given view or tree.
|
|
48
|
+
* @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor function.
|
|
49
|
+
* @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.
|
|
50
|
+
* @alpha
|
|
51
|
+
*/
|
|
52
|
+
export declare function bindEditorImpl<TSchema extends ImplicitFieldSchema>(tree: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), editor: SynchronousEditor): (code: string) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Binds the given {@link SynchronousEditor | synchronous} or {@link AsynchronousEditor | asynchronous} editor to the given view or tree.
|
|
55
|
+
* @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor.
|
|
56
|
+
* @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.
|
|
57
|
+
* @alpha
|
|
58
|
+
* @privateRemarks This exists (as opposed to just exporting bindEditorImpl directly) so that API documentation links work correctly.
|
|
59
|
+
*/
|
|
60
|
+
export declare const bindEditor: typeof bindEditorImpl;
|
|
32
61
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.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gB,cAAc,CAAC,OAAO,SAAS,mBAAmB,EACjE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,EAC7D,MAAM,EAAE,kBAAkB,GACxB,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AACnC;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,mBAAmB,EACjE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,EAC7D,MAAM,EAAE,iBAAiB,GACvB,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAe1B;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,uBAAiB,CAAC"}
|
package/dist/agent.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.SharedTreeSemanticAgent = void 0;
|
|
7
|
+
exports.bindEditor = exports.bindEditorImpl = exports.defaultEditor = exports.SharedTreeSemanticAgent = void 0;
|
|
8
8
|
const tree_1 = require("@fluidframework/tree");
|
|
9
9
|
const alpha_1 = require("@fluidframework/tree/alpha");
|
|
10
10
|
const prompt_js_1 = require("./prompt.js");
|
|
@@ -100,7 +100,7 @@ class SharedTreeSemanticAgent {
|
|
|
100
100
|
message: `The maximum number of edits (${maxEditCount}) for this query has been exceeded.`,
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
const editResult = await applyTreeFunction(queryTree, editCode, this.options?.
|
|
103
|
+
const editResult = await applyTreeFunction(queryTree, editCode, this.options?.editor ?? exports.defaultEditor, this.options?.logger);
|
|
104
104
|
rollbackEdits = editResult.type !== "success";
|
|
105
105
|
return editResult;
|
|
106
106
|
};
|
|
@@ -151,46 +151,21 @@ function constructTreeNode(schema, value) {
|
|
|
151
151
|
/**
|
|
152
152
|
* Applies the given function (as a string of JavaScript code or an actual function) to the given tree.
|
|
153
153
|
*/
|
|
154
|
-
async function applyTreeFunction(tree, editCode,
|
|
154
|
+
async function applyTreeFunction(tree, editCode, editor, logger) {
|
|
155
155
|
logger?.log(`### Editing Tool Invoked\n\n`);
|
|
156
156
|
logger?.log(`#### Generated Code\n\n\`\`\`javascript\n${editCode}\n\`\`\`\n\n`);
|
|
157
|
-
try {
|
|
158
|
-
await validateEdit(editCode);
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
logger?.log(`#### Code Validation Failed\n\n`);
|
|
162
|
-
logger?.log(`\`\`\`JSON\n${(0, utils_js_1.toErrorString)(error)}\n\`\`\`\n\n`);
|
|
163
|
-
return {
|
|
164
|
-
type: "validationError",
|
|
165
|
-
message: `The generated code did not pass validation: ${(0, utils_js_1.toErrorString)(error)}`,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// Stick the tree schema constructors on an object passed to the function so that the LLM can create new nodes.
|
|
169
|
-
const create = {};
|
|
170
|
-
for (const schema of (0, utils_js_1.findNamedSchemas)(tree.schema)) {
|
|
171
|
-
const name = (0, utils_js_1.getFriendlyName)(schema);
|
|
172
|
-
create[name] = (input) => constructTreeNode(schema, input);
|
|
173
|
-
}
|
|
174
157
|
// Fork a branch to edit. If the edit fails or produces an error, we discard this branch, otherwise we merge it.
|
|
175
158
|
const editTree = tree.fork();
|
|
176
|
-
const
|
|
177
|
-
get root() {
|
|
178
|
-
return editTree.field;
|
|
179
|
-
},
|
|
180
|
-
set root(value) {
|
|
181
|
-
editTree.field = value;
|
|
182
|
-
},
|
|
183
|
-
create,
|
|
184
|
-
};
|
|
159
|
+
const boundEditor = bindEditorToSubtree(editTree, editor);
|
|
185
160
|
try {
|
|
186
|
-
await
|
|
161
|
+
await boundEditor(editCode);
|
|
187
162
|
}
|
|
188
163
|
catch (error) {
|
|
189
164
|
logger?.log(`#### Error\n\n`);
|
|
190
165
|
logger?.log(`\`\`\`JSON\n${(0, utils_js_1.toErrorString)(error)}\n\`\`\`\n\n`);
|
|
191
166
|
editTree.branch.dispose();
|
|
192
167
|
return {
|
|
193
|
-
type: "
|
|
168
|
+
type: "editingError",
|
|
194
169
|
message: `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: ${(0, utils_js_1.toErrorString)(error)}`,
|
|
195
170
|
};
|
|
196
171
|
}
|
|
@@ -202,10 +177,59 @@ async function applyTreeFunction(tree, editCode, validateEdit, executeEdit, logg
|
|
|
202
177
|
message: `After running the code, the new state of the tree is:\n\n\`\`\`JSON\n${(0, prompt_js_1.stringifyTree)(tree.field)}\n\`\`\``,
|
|
203
178
|
};
|
|
204
179
|
}
|
|
205
|
-
|
|
206
|
-
|
|
180
|
+
/**
|
|
181
|
+
* The default {@link AsynchronousEditor | editor} implementation that simply uses `new Function` to run the provided code.
|
|
182
|
+
* @remarks This editor allows both synchronous and asynchronous code (i.e. the provided code may return a Promise).
|
|
183
|
+
* @example `await new Function("context", code)(context);`
|
|
184
|
+
* @alpha
|
|
185
|
+
*/
|
|
186
|
+
const defaultEditor = async (context, code) => {
|
|
207
187
|
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
|
|
208
188
|
const fn = new Function("context", code);
|
|
209
189
|
await fn(context);
|
|
210
190
|
};
|
|
191
|
+
exports.defaultEditor = defaultEditor;
|
|
192
|
+
/**
|
|
193
|
+
* Binds the given {@link SynchronousEditor | editor} or {@link AsynchronousEditor | editor} to the given view or tree.
|
|
194
|
+
* @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor function.
|
|
195
|
+
* @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.
|
|
196
|
+
* @alpha
|
|
197
|
+
*/
|
|
198
|
+
function bindEditorImpl(tree, editor) {
|
|
199
|
+
const subtree = new subtree_js_1.Subtree(tree);
|
|
200
|
+
return bindEditorToSubtree(subtree, editor);
|
|
201
|
+
}
|
|
202
|
+
exports.bindEditorImpl = bindEditorImpl;
|
|
203
|
+
/**
|
|
204
|
+
* Binds the given {@link SynchronousEditor | synchronous} or {@link AsynchronousEditor | asynchronous} editor to the given view or tree.
|
|
205
|
+
* @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor.
|
|
206
|
+
* @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.
|
|
207
|
+
* @alpha
|
|
208
|
+
* @privateRemarks This exists (as opposed to just exporting bindEditorImpl directly) so that API documentation links work correctly.
|
|
209
|
+
*/
|
|
210
|
+
exports.bindEditor = bindEditorImpl;
|
|
211
|
+
function bindEditorToSubtree(tree, executeEdit) {
|
|
212
|
+
// Stick the tree schema constructors on an object passed to the function so that the LLM can create new nodes.
|
|
213
|
+
const create = {};
|
|
214
|
+
const is = {};
|
|
215
|
+
for (const schema of (0, utils_js_1.findNamedSchemas)(tree.schema)) {
|
|
216
|
+
const name = (0, utils_js_1.getFriendlyName)(schema);
|
|
217
|
+
create[name] = (input) => constructTreeNode(schema, input);
|
|
218
|
+
is[name] = (input) => alpha_1.Tree.is(input, schema);
|
|
219
|
+
}
|
|
220
|
+
const context = {
|
|
221
|
+
get root() {
|
|
222
|
+
return tree.field;
|
|
223
|
+
},
|
|
224
|
+
set root(value) {
|
|
225
|
+
tree.field = value;
|
|
226
|
+
},
|
|
227
|
+
create,
|
|
228
|
+
is,
|
|
229
|
+
parent: (child) => alpha_1.Tree.parent(child),
|
|
230
|
+
key: (child) => alpha_1.Tree.key(child),
|
|
231
|
+
};
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
233
|
+
return (code) => executeEdit(context, code);
|
|
234
|
+
}
|
|
211
235
|
//# sourceMappingURL=agent.js.map
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],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AM,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC9B,MAAM,EAAE,GAAG,CAAC,eAAe,IAAA,wBAAa,EAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC/D,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAC1B,OAAO;YACN,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,+KAA+K,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE;SAC9M,CAAC;IACH,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,MAAM,EAAE,GAAG,CAAC,GAAG,eAAe,IAAA,yBAAa,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU,MAAM,CAAC,CAAC;IACzE,OAAO;QACN,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,wEAAwE,IAAA,yBAAa,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU;KACpH,CAAC;AACH,CAAC;AAED,MAAM,mBAAmB,GAAmD,GAAG,EAAE,GAAE,CAAC,CAAC;AAErF,MAAM,kBAAkB,GAAkD,KAAK,EAC9E,OAAO,EACP,IAAI,EACH,EAAE;IACH,2EAA2E;IAC3E,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACzC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;AACnB,CAAC,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 { TreeNode } from \"@fluidframework/tree\";\nimport type {\n\tReadableField,\n\tFactoryContentObject,\n\tInsertableContent,\n\tReadSchema,\n} from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema, Tree } from \"@fluidframework/tree/alpha\";\n\nimport type { SharedTreeChatModel, EditResult, SemanticAgentOptions, Logger } from \"./api.js\";\nimport { getPrompt, stringifyTree } from \"./prompt.js\";\nimport { Subtree } from \"./subtree.js\";\nimport {\n\tconstructNode,\n\tgetFriendlyName,\n\tllmDefault,\n\ttype TreeView,\n\tfindNamedSchemas,\n\ttoErrorString,\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\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: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),\n\t\tprivate readonly options?: Readonly<SemanticAgentOptions>,\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\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.options?.validateEdit ?? defaultValidateEdit,\n\t\t\t\tthis.options?.executeEdit ?? defaultExecuteEdit,\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, value: FactoryContentObject): TreeNode {\n\tif (schema instanceof ObjectNodeSchema) {\n\t\tconst inputWithDefaults: Record<string, InsertableContent | undefined> = {};\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (value[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\tinputWithDefaults[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\tinputWithDefaults[key] = value[key];\n\t\t\t}\n\t\t}\n\t\treturn constructNode(schema, inputWithDefaults);\n\t}\n\treturn constructNode(schema, value);\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\tvalidateEdit: Required<SemanticAgentOptions>[\"validateEdit\"],\n\texecuteEdit: Required<SemanticAgentOptions>[\"executeEdit\"],\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\ttry {\n\t\tawait validateEdit(editCode);\n\t} catch (error: unknown) {\n\t\tlogger?.log(`#### Code Validation Failed\\n\\n`);\n\t\tlogger?.log(`\\`\\`\\`JSON\\n${toErrorString(error)}\\n\\`\\`\\`\\n\\n`);\n\t\treturn {\n\t\t\ttype: \"validationError\",\n\t\t\tmessage: `The generated code did not pass validation: ${toErrorString(error)}`,\n\t\t};\n\t}\n\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\tfor (const schema of findNamedSchemas(tree.schema)) {\n\t\tconst name = getFriendlyName(schema);\n\t\tcreate[name] = (input: FactoryContentObject) => constructTreeNode(schema, input);\n\t}\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\tconst context = {\n\t\tget root(): ReadableField<TSchema> {\n\t\t\treturn editTree.field;\n\t\t},\n\t\tset root(value: TreeFieldFromImplicitField<ReadSchema<TSchema>>) {\n\t\t\teditTree.field = value;\n\t\t},\n\t\tcreate,\n\t};\n\n\ttry {\n\t\tawait executeEdit(context, 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: \"executionError\",\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\nconst defaultValidateEdit: Required<SemanticAgentOptions>[\"validateEdit\"] = () => {};\n\nconst defaultExecuteEdit: Required<SemanticAgentOptions>[\"executeEdit\"] = async (\n\tcontext,\n\tcode,\n) => {\n\t// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval\n\tconst fn = new Function(\"context\", code);\n\tawait fn(context);\n};\n"]}
|
|
1
|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AAC,KAAK,CAAC;QACrE,GAAG,EAAE,CAAC,KAAe,EAAmB,EAAE,CAAC,YAAI,CAAC,GAAG,CAAC,KAAK,CAAC;KAC/B,CAAC;IAE7B,qEAAqE;IACrE,OAAO,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACrD,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 { TreeNode } from \"@fluidframework/tree\";\nimport type {\n\tReadableField,\n\tFactoryContentObject,\n\tInsertableContent,\n\tReadSchema,\n} from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema, Tree } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tSharedTreeChatModel,\n\tEditResult,\n\tSemanticAgentOptions,\n\tLogger,\n\tSynchronousEditor,\n\tAsynchronousEditor,\n\tContext,\n} from \"./api.js\";\nimport { getPrompt, stringifyTree } from \"./prompt.js\";\nimport { Subtree } from \"./subtree.js\";\nimport {\n\tconstructNode,\n\tgetFriendlyName,\n\tllmDefault,\n\ttype TreeView,\n\tfindNamedSchemas,\n\ttoErrorString,\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\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: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),\n\t\tprivate readonly options?: Readonly<SemanticAgentOptions>,\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\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.options?.editor ?? defaultEditor,\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, value: FactoryContentObject): TreeNode {\n\tif (schema instanceof ObjectNodeSchema) {\n\t\tconst inputWithDefaults: Record<string, InsertableContent | undefined> = {};\n\t\tfor (const [key, field] of schema.fields) {\n\t\t\tif (value[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\tinputWithDefaults[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\tinputWithDefaults[key] = value[key];\n\t\t\t}\n\t\t}\n\t\treturn constructNode(schema, inputWithDefaults);\n\t}\n\treturn constructNode(schema, value);\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: Required<SemanticAgentOptions>[\"editor\"],\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\tconst boundEditor = bindEditorToSubtree(editTree, editor);\n\ttry {\n\t\tawait boundEditor(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\n/**\n * The default {@link AsynchronousEditor | editor} implementation that simply uses `new Function` to run the provided code.\n * @remarks This editor allows both synchronous and asynchronous code (i.e. the provided code may return a Promise).\n * @example `await new Function(\"context\", code)(context);`\n * @alpha\n */\nexport const defaultEditor: AsynchronousEditor = async (context, code) => {\n\t// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval\n\tconst fn = new Function(\"context\", code);\n\tawait fn(context);\n};\n\n/**\n * Binds the given {@link AsynchronousEditor | editor} to the given view or tree.\n * @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor function.\n * @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.\n * @alpha\n */\nexport function bindEditorImpl<TSchema extends ImplicitFieldSchema>(\n\ttree: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),\n\teditor: AsynchronousEditor,\n): (code: string) => Promise<void>;\n/**\n * Binds the given {@link SynchronousEditor | editor} to the given view or tree.\n * @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor function.\n * @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.\n * @alpha\n */\nexport function bindEditorImpl<TSchema extends ImplicitFieldSchema>(\n\ttree: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),\n\teditor: SynchronousEditor,\n): (code: string) => void;\n/**\n * Binds the given {@link SynchronousEditor | editor} or {@link AsynchronousEditor | editor} to the given view or tree.\n * @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor function.\n * @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.\n * @alpha\n */\nexport function bindEditorImpl<TSchema extends ImplicitFieldSchema>(\n\ttree: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),\n\teditor: SynchronousEditor | AsynchronousEditor,\n): ((code: string) => void) | ((code: string) => Promise<void>) {\n\tconst subtree = new Subtree(tree);\n\treturn bindEditorToSubtree(subtree, editor);\n}\n\n/**\n * Binds the given {@link SynchronousEditor | synchronous} or {@link AsynchronousEditor | asynchronous} editor to the given view or tree.\n * @returns A function that takes a string of JavaScript code and executes it on the given view or tree using the given editor.\n * @remarks This is useful for testing/debugging code execution without needing to set up a full {@link SharedTreeSemanticAgent | agent}.\n * @alpha\n * @privateRemarks This exists (as opposed to just exporting bindEditorImpl directly) so that API documentation links work correctly.\n */\nexport const bindEditor = bindEditorImpl;\n\nfunction bindEditorToSubtree<TSchema extends ImplicitFieldSchema>(\n\ttree: Subtree<TSchema>,\n\texecuteEdit: SynchronousEditor | AsynchronousEditor,\n): (code: string) => void | Promise<void> {\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 findNamedSchemas(tree.schema)) {\n\t\tconst name = getFriendlyName(schema);\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\tconst context = {\n\t\tget root(): ReadableField<TSchema> {\n\t\t\treturn tree.field;\n\t\t},\n\t\tset root(value: TreeFieldFromImplicitField<ReadSchema<TSchema>>) {\n\t\t\ttree.field = value;\n\t\t},\n\t\tcreate,\n\t\tis,\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\t// eslint-disable-next-line @typescript-eslint/promise-function-async\n\treturn (code: string) => executeEdit(context, code);\n}\n"]}
|
package/dist/alpha.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export {
|
|
|
18
18
|
// #region @alpha APIs
|
|
19
19
|
Arg,
|
|
20
20
|
ArgsTuple,
|
|
21
|
+
AsynchronousEditor,
|
|
21
22
|
BindableSchema,
|
|
22
23
|
Ctor,
|
|
23
24
|
EditResult,
|
|
@@ -31,8 +32,12 @@ export {
|
|
|
31
32
|
SharedTreeChatModel,
|
|
32
33
|
SharedTreeChatQuery,
|
|
33
34
|
SharedTreeSemanticAgent,
|
|
35
|
+
SynchronousEditor,
|
|
34
36
|
TreeView,
|
|
37
|
+
bindEditor,
|
|
38
|
+
bindEditorImpl,
|
|
35
39
|
buildFunc,
|
|
40
|
+
defaultEditor,
|
|
36
41
|
exposeMethodsSymbol,
|
|
37
42
|
llmDefault
|
|
38
43
|
// #endregion
|
package/dist/api.d.ts
CHANGED
|
@@ -14,6 +14,82 @@ export interface Logger {
|
|
|
14
14
|
*/
|
|
15
15
|
log(message: string): void;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The context object available to generated code when editing a tree.
|
|
19
|
+
* @remarks This object is provided to JavaScript code executed by the {@link SynchronousEditor | editor} as a variable named `context`.
|
|
20
|
+
* It contains the current state of the tree and utilities for creating and inspecting tree nodes.
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
export interface Context<TSchema extends ImplicitFieldSchema> {
|
|
24
|
+
/**
|
|
25
|
+
* The root of the tree that can be read or modified.
|
|
26
|
+
* @remarks
|
|
27
|
+
* You can read properties and navigate through the tree starting from this root.
|
|
28
|
+
* You can also assign a new value to this property to replace the entire tree, as long as the new value is one of the types allowed at the root.
|
|
29
|
+
*
|
|
30
|
+
* Example: Read the current root with `const currentRoot = context.root;`
|
|
31
|
+
*
|
|
32
|
+
* Example: Replace the entire root with `context.root = context.create.MyRootType({ });`
|
|
33
|
+
*/
|
|
34
|
+
root: ReadableField<TSchema>;
|
|
35
|
+
/**
|
|
36
|
+
* A collection of builder functions for creating new tree nodes.
|
|
37
|
+
* @remarks
|
|
38
|
+
* Each property on this object is named after a type in the tree schema.
|
|
39
|
+
* Call the corresponding function to create a new node of that type.
|
|
40
|
+
* Always use these builder functions when creating new nodes rather than plain JavaScript objects.
|
|
41
|
+
*
|
|
42
|
+
* Example: Create a new Person node with `context.create.Person({ name: "Alice", age: 30 })`
|
|
43
|
+
*
|
|
44
|
+
* Example: Create a new Task node with `context.create.Task({ title: "Buy groceries", completed: false })`
|
|
45
|
+
*/
|
|
46
|
+
create: Record<string, (input: FactoryContentObject) => TreeNode>;
|
|
47
|
+
/**
|
|
48
|
+
* A collection of type-checking functions for tree nodes.
|
|
49
|
+
* @remarks
|
|
50
|
+
* Each property on this object is named after a type in the tree schema.
|
|
51
|
+
* Call the corresponding function to check if a node is of that specific type.
|
|
52
|
+
* This is useful when working with nodes that could be one of multiple types.
|
|
53
|
+
*
|
|
54
|
+
* Example: Check if a node is a Person with `if (context.is.Person(node)) { console.log(node.name); }`
|
|
55
|
+
*/
|
|
56
|
+
is: Record<string, <T extends TreeNode>(input: T) => input is T>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the parent node of the given child node.
|
|
59
|
+
* @param child - The node whose parent you want to find.
|
|
60
|
+
* @returns The parent node, or `undefined` if the node is the root or is not in the tree.
|
|
61
|
+
* @remarks
|
|
62
|
+
* Example: Get the parent with `const parent = context.parent(childNode);`
|
|
63
|
+
*/
|
|
64
|
+
parent(child: TreeNode): TreeNode | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the key or index of the given node within its parent.
|
|
67
|
+
* @param child - The node whose key you want to find.
|
|
68
|
+
* @returns A string key if the node is in an object or map, or a numeric index if the node is in an array.
|
|
69
|
+
* @remarks
|
|
70
|
+
* For a node in an object, this might return a string like "firstName".
|
|
71
|
+
* For a node in an array, this might return a number like 0, 1, 2, etc.
|
|
72
|
+
*
|
|
73
|
+
* Example: `const key = context.key(childNode);`
|
|
74
|
+
*/
|
|
75
|
+
key(child: TreeNode): string | number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A synchronous function that executes a string of JavaScript code to perform an edit within a {@link SharedTreeSemanticAgent}.
|
|
79
|
+
* @param context - An object that must be provided to the generated code as a variable named "context" in its top-level scope.
|
|
80
|
+
* @param code - The JavaScript code that should be executed.
|
|
81
|
+
* @remarks To simulate the execution of an editor outside of an {@link SharedTreeSemanticAgent | agent}, you can use {@link bindEditor | bindEditor} to bind an editor to a specific subtree.
|
|
82
|
+
* @alpha
|
|
83
|
+
*/
|
|
84
|
+
export type SynchronousEditor = (context: Record<string, unknown>, code: string) => void;
|
|
85
|
+
/**
|
|
86
|
+
* An asynchronous function that executes a string of JavaScript code to perform an edit within a {@link SharedTreeSemanticAgent}.
|
|
87
|
+
* @param context - An object that must be provided to the generated code as a variable named "context" in its top-level scope.
|
|
88
|
+
* @param code - The JavaScript code that should be executed.
|
|
89
|
+
* @remarks To simulate the execution of an editor outside of an {@link SharedTreeSemanticAgent | agent}, you can use {@link bindEditor | bindEditor} to bind an editor to a specific subtree.
|
|
90
|
+
* @alpha
|
|
91
|
+
*/
|
|
92
|
+
export type AsynchronousEditor = (context: Record<string, unknown>, code: string) => Promise<void>;
|
|
17
93
|
/**
|
|
18
94
|
* Options used to parameterize the creation of a {@link SharedTreeSemanticAgent}.
|
|
19
95
|
* @alpha
|
|
@@ -24,22 +100,14 @@ export interface SemanticAgentOptions {
|
|
|
24
100
|
*/
|
|
25
101
|
domainHints?: string;
|
|
26
102
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* @
|
|
30
|
-
* @throws If the code is invalid, this function should throw an error with a human-readable message describing why it is invalid.
|
|
31
|
-
*/
|
|
32
|
-
validateEdit?: (code: string) => void | Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Evaluates/runs any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.
|
|
35
|
-
* @remarks This happens only after the code has been successfully validated by the optional {@link SemanticAgentOptions.validateEdit | validateEdit} function.
|
|
36
|
-
* @param context - An object that must be provided to the generated code as a variable named "context" in its top-level scope.
|
|
37
|
-
* @param code - The generated JavaScript code as a string.
|
|
38
|
-
* @throws If an error is thrown while executing the code, it will be caught and the message will be forwarded to the model for debugging.
|
|
39
|
-
* @remarks If this function is not provided, the generated code will be executed using a simple `eval` call, which may not provide sufficient security guarantees for some environments.
|
|
103
|
+
* Executes any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.
|
|
104
|
+
* @remarks If an error is thrown while executing the code, it will be caught and the message will be forwarded to the {@link SharedTreeChatModel | model} for debugging.
|
|
105
|
+
* @remarks If this function is not provided, the generated code will be executed using a {@link defaultEditor | simple default} which may not provide sufficient security guarantees for some environments.
|
|
40
106
|
* Use a library such as SES to provide a more secure implementation - see `@fluidframework/tree-agent-ses` for a drop-in implementation.
|
|
107
|
+
*
|
|
108
|
+
* To simulate the execution of an editor outside of an {@link SharedTreeSemanticAgent | agent}, you can use {@link bindEditor | bindEditor} to bind an editor to a specific subtree.
|
|
41
109
|
*/
|
|
42
|
-
|
|
110
|
+
editor?: SynchronousEditor | AsynchronousEditor;
|
|
43
111
|
/**
|
|
44
112
|
* The maximum number of sequential edits the LLM can make before we assume it's stuck in a loop.
|
|
45
113
|
*/
|
|
@@ -59,12 +127,11 @@ export interface EditResult {
|
|
|
59
127
|
* @remarks
|
|
60
128
|
* - `success`: The edit was successfully applied.
|
|
61
129
|
* - `disabledError`: The model is not allowed to edit the tree (i.e. {@link SharedTreeChatModel.editToolName} was not provided).
|
|
62
|
-
* - `
|
|
63
|
-
* - `executionError`: An error was thrown while parsing or executing the provided JavaScript.
|
|
130
|
+
* - `editingError`: An error was thrown while parsing or executing the provided JavaScript.
|
|
64
131
|
* - `tooManyEditsError`: The {@link SharedTreeChatQuery.edit} function has been called more than the number of times specified by {@link SemanticAgentOptions.maximumSequentialEdits} for the same message.
|
|
65
132
|
* - `expiredError`: The {@link SharedTreeChatQuery.edit} function was called after the issuing query has already completed.
|
|
66
133
|
*/
|
|
67
|
-
type: "success" | "disabledError" | "
|
|
134
|
+
type: "success" | "disabledError" | "editingError" | "tooManyEditsError" | "expiredError";
|
|
68
135
|
/**
|
|
69
136
|
* A human-readable message describing the result of the edit attempt.
|
|
70
137
|
* @remarks In the case of an error, this message is appropriate to include in a model's chat history.
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC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3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmFH;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CACN,OAAQ,KAAoB,CAAC,IAAI,KAAK,QAAQ;QAC9C,OAAQ,KAAoB,CAAC,OAAO,KAAK,QAAQ,CACjD,CAAC;AACH,CAAC;AARD,oCAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ImplicitFieldSchema, TreeNode } from \"@fluidframework/tree\";\n// This is used for doc links\nimport type { FactoryContentObject, ReadableField } from \"@fluidframework/tree/alpha\";\n\n/**\n * Logger interface for logging events from a {@link SharedTreeSemanticAgent}.\n * @alpha\n */\nexport interface Logger {\n\t/**\n\t * Log a message.\n\t */\n\tlog(message: string): void;\n}\n\n/**\n * Options used to parameterize the creation of a {@link SharedTreeSemanticAgent}.\n * @alpha\n */\nexport interface SemanticAgentOptions {\n\t/**\n\t * Additional information about the application domain that will be included in the context provided to the {@link SharedTreeChatModel | model}.\n\t */\n\tdomainHints?: string;\n\t/**\n\t * Validates any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.\n\t * @remarks This happens before the code is executed - execution can be intercepted by using the {@link SemanticAgentOptions.executeEdit | executeEdit} callback.\n\t * @param code - The generated JavaScript code as a string.\n\t * @throws If the code is invalid, this function should throw an error with a human-readable message describing why it is invalid.\n\t */\n\tvalidateEdit?: (code: string) => void | Promise<void>;\n\t/**\n\t * Evaluates/runs any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.\n\t * @remarks This happens only after the code has been successfully validated by the optional {@link SemanticAgentOptions.validateEdit | validateEdit} function.\n\t * @param context - An object that must be provided to the generated code as a variable named \"context\" in its top-level scope.\n\t * @param code - The generated JavaScript code as a string.\n\t * @throws If an error is thrown while executing the code, it will be caught and the message will be forwarded to the model for debugging.\n\t * @remarks If this function is not provided, the generated code will be executed using a simple `eval` call, which may not provide sufficient security guarantees for some environments.\n\t * Use a library such as SES to provide a more secure implementation - see `@fluidframework/tree-agent-ses` for a drop-in implementation.\n\t */\n\texecuteEdit?: (context: Record<string, unknown>, code: string) => void | Promise<void>;\n\t/**\n\t * The maximum number of sequential edits the LLM can make before we assume it's stuck in a loop.\n\t */\n\tmaximumSequentialEdits?: number;\n\t/**\n\t * If supplied, generates human-readable markdown text describing the actions taken by the {@link SharedTreeSemanticAgent | agent} as it performs queries.\n\t */\n\tlogger?: Logger;\n}\n\n/**\n * A result from an edit attempt via the {@link SharedTreeChatQuery.edit} function.\n * @alpha\n */\nexport interface EditResult {\n\t/**\n\t * The type of the edit result.\n\t * @remarks\n\t * - `success`: The edit was successfully applied.\n\t * - `disabledError`: The model is not allowed to edit the tree (i.e. {@link SharedTreeChatModel.editToolName} was not provided).\n\t * - `validationError`: The provided JavaScript did not pass the optional {@link SemanticAgentOptions.validateEdit} function.\n\t * - `executionError`: An error was thrown while parsing or executing the provided JavaScript.\n\t * - `tooManyEditsError`: The {@link SharedTreeChatQuery.edit} function has been called more than the number of times specified by {@link SemanticAgentOptions.maximumSequentialEdits} for the same message.\n\t * - `expiredError`: The {@link SharedTreeChatQuery.edit} function was called after the issuing query has already completed.\n\t */\n\ttype:\n\t\t| \"success\"\n\t\t| \"disabledError\"\n\t\t| \"validationError\"\n\t\t| \"executionError\"\n\t\t| \"tooManyEditsError\"\n\t\t| \"expiredError\";\n\n\t/**\n\t * A human-readable message describing the result of the edit attempt.\n\t * @remarks In the case of an error, this message is appropriate to include in a model's chat history.\n\t */\n\tmessage: string;\n}\n\n/**\n * Type guard for {@link EditResult}.\n */\nexport function isEditResult(value: unknown): value is EditResult {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn false;\n\t}\n\treturn (\n\t\ttypeof (value as EditResult).type === \"string\" &&\n\t\ttypeof (value as EditResult).message === \"string\"\n\t);\n}\n\n/**\n * A query from a user to a {@link SharedTreeSemanticAgent}.\n * @remarks Processing a query may involve editing the SharedTree via the provided {@link SharedTreeChatQuery.edit} function.\n * @alpha\n */\nexport interface SharedTreeChatQuery {\n\t/**\n\t * The user's query.\n\t */\n\ttext: string;\n\t/**\n\t * Edit the tree with the provided JavaScript function code.\n\t * @remarks Attempting an edit may fail for a variety of reasons which are captured in the {@link EditResult | returned object}.\n\t * If an edit fails, the tree will not be modified and the model may attempt another edit if desired.\n\t * When the query ends, if the last edit attempt was successful, all edits made during the query will be merged into the agent's SharedTree.\n\t * Otherwise, all edits made during the query will be discarded.\n\t */\n\tedit(js: string): Promise<EditResult>;\n}\n\n/**\n * A plugin interface that handles queries from a {@link SharedTreeSemanticAgent}.\n * @remarks This wraps an underlying communication with an LLM and receives all necessary {@link SharedTreeChatModel.appendContext | context} from the {@link SharedTreeSemanticAgent | agent} for the LLM to properly analyze and edit the tree.\n * See `@fluidframework/tree-agent-langchain` for a drop-in implementation based on the LangChain library.\n * @alpha\n */\nexport interface SharedTreeChatModel {\n\t/**\n\t * A optional name of this chat model.\n\t * @remarks If supplied, this may be used in logging or debugging information.\n\t * @example \"gpt-5\"\n\t */\n\tname?: string;\n\t/**\n\t * The name of the tool that the model should use to edit the tree.\n\t * @remarks If supplied, this will be mentioned in the context provided to the model so that the underlying LLM will be encouraged to use it when a user query requires an edit.\n\t * The model should \"implement\" the tool by registering it with the underlying LLM API.\n\t * The tool should take an LLM-generated JavaScript function as input and supply it to the {@link SharedTreeChatQuery.edit | edit} function.\n\t * Instructions for generating the proper function signature and implementation will be provided by the {@link SharedTreeSemanticAgent | agent} via {@link SharedTreeChatModel.appendContext | context}.\n\t * If not supplied, the model will not be able to edit the tree (running the {@link SharedTreeChatQuery.edit | edit} function will fail).\n\t */\n\teditToolName?: string;\n\t/**\n\t * Add contextual information to the model that may be relevant to future queries.\n\t * @remarks In practice, this may be implemented by e.g. appending a \"system\" message to an LLM's chat/message history.\n\t * This context must be present in the context window of every {@link SharedTreeChatModel.query | query} for e.g. {@link SharedTreeChatModel.editToolName | editing} to work.\n\t * @param text - The message or context to append.\n\t */\n\tappendContext?(text: string): void;\n\t/**\n\t * Queries the chat model with a request from the user.\n\t * @remarks This model may simply return a text response to the query, or it may first call the {@link SharedTreeChatQuery.edit} function (potentially multiple times) to modify the tree in response to the query.\n\t */\n\tquery(message: SharedTreeChatQuery): Promise<string>;\n}\n\n/**\n * A function that edits a SharedTree.\n */\nexport type EditFunction<TSchema extends ImplicitFieldSchema> = ({\n\troot,\n\tcreate,\n}: {\n\troot: ReadableField<TSchema>;\n\tcreate: Record<string, (input: FactoryContentObject) => TreeNode>;\n}) => void | Promise<void>;\n"]}
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA6JH;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CACN,OAAQ,KAAoB,CAAC,IAAI,KAAK,QAAQ;QAC9C,OAAQ,KAAoB,CAAC,OAAO,KAAK,QAAQ,CACjD,CAAC;AACH,CAAC;AARD,oCAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ImplicitFieldSchema, TreeNode } from \"@fluidframework/tree\";\n// These are used for doc links\nimport type { FactoryContentObject, ReadableField } from \"@fluidframework/tree/alpha\";\n\n// This is used for doc links\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport type { bindEditor, defaultEditor } from \"./agent.js\";\n\n/**\n * Logger interface for logging events from a {@link SharedTreeSemanticAgent}.\n * @alpha\n */\nexport interface Logger {\n\t/**\n\t * Log a message.\n\t */\n\tlog(message: string): void;\n}\n\n/**\n * The context object available to generated code when editing a tree.\n * @remarks This object is provided to JavaScript code executed by the {@link SynchronousEditor | editor} as a variable named `context`.\n * It contains the current state of the tree and utilities for creating and inspecting tree nodes.\n * @alpha\n */\nexport interface Context<TSchema extends ImplicitFieldSchema> {\n\t/**\n\t * The root of the tree that can be read or modified.\n\t * @remarks\n\t * You can read properties and navigate through the tree starting from this root.\n\t * You can also assign a new value to this property to replace the entire tree, as long as the new value is one of the types allowed at the root.\n\t *\n\t * Example: Read the current root with `const currentRoot = context.root;`\n\t *\n\t * Example: Replace the entire root with `context.root = context.create.MyRootType({ });`\n\t */\n\troot: ReadableField<TSchema>;\n\n\t/**\n\t * A collection of builder functions for creating new tree nodes.\n\t * @remarks\n\t * Each property on this object is named after a type in the tree schema.\n\t * Call the corresponding function to create a new node of that type.\n\t * Always use these builder functions when creating new nodes rather than plain JavaScript objects.\n\t *\n\t * Example: Create a new Person node with `context.create.Person({ name: \"Alice\", age: 30 })`\n\t *\n\t * Example: Create a new Task node with `context.create.Task({ title: \"Buy groceries\", completed: false })`\n\t */\n\tcreate: Record<string, (input: FactoryContentObject) => TreeNode>;\n\n\t/**\n\t * A collection of type-checking functions for tree nodes.\n\t * @remarks\n\t * Each property on this object is named after a type in the tree schema.\n\t * Call the corresponding function to check if a node is of that specific type.\n\t * This is useful when working with nodes that could be one of multiple types.\n\t *\n\t * Example: Check if a node is a Person with `if (context.is.Person(node)) { console.log(node.name); }`\n\t */\n\tis: Record<string, <T extends TreeNode>(input: T) => input is T>;\n\n\t/**\n\t * Returns the parent node of the given child node.\n\t * @param child - The node whose parent you want to find.\n\t * @returns The parent node, or `undefined` if the node is the root or is not in the tree.\n\t * @remarks\n\t * Example: Get the parent with `const parent = context.parent(childNode);`\n\t */\n\tparent(child: TreeNode): TreeNode | undefined;\n\n\t/**\n\t * Returns the key or index of the given node within its parent.\n\t * @param child - The node whose key you want to find.\n\t * @returns A string key if the node is in an object or map, or a numeric index if the node is in an array.\n\t * @remarks\n\t * For a node in an object, this might return a string like \"firstName\".\n\t * For a node in an array, this might return a number like 0, 1, 2, etc.\n\t *\n\t * Example: `const key = context.key(childNode);`\n\t */\n\tkey(child: TreeNode): string | number;\n}\n\n/**\n * A synchronous function that executes a string of JavaScript code to perform an edit within a {@link SharedTreeSemanticAgent}.\n * @param context - An object that must be provided to the generated code as a variable named \"context\" in its top-level scope.\n * @param code - The JavaScript code that should be executed.\n * @remarks To simulate the execution of an editor outside of an {@link SharedTreeSemanticAgent | agent}, you can use {@link bindEditor | bindEditor} to bind an editor to a specific subtree.\n * @alpha\n */\nexport type SynchronousEditor = (context: Record<string, unknown>, code: string) => void;\n/**\n * An asynchronous function that executes a string of JavaScript code to perform an edit within a {@link SharedTreeSemanticAgent}.\n * @param context - An object that must be provided to the generated code as a variable named \"context\" in its top-level scope.\n * @param code - The JavaScript code that should be executed.\n * @remarks To simulate the execution of an editor outside of an {@link SharedTreeSemanticAgent | agent}, you can use {@link bindEditor | bindEditor} to bind an editor to a specific subtree.\n * @alpha\n */\nexport type AsynchronousEditor = (\n\tcontext: Record<string, unknown>,\n\tcode: string,\n) => Promise<void>;\n\n/**\n * Options used to parameterize the creation of a {@link SharedTreeSemanticAgent}.\n * @alpha\n */\nexport interface SemanticAgentOptions {\n\t/**\n\t * Additional information about the application domain that will be included in the context provided to the {@link SharedTreeChatModel | model}.\n\t */\n\tdomainHints?: string;\n\t/**\n\t * Executes any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.\n\t * @remarks If an error is thrown while executing the code, it will be caught and the message will be forwarded to the {@link SharedTreeChatModel | model} for debugging.\n\t * @remarks If this function is not provided, the generated code will be executed using a {@link defaultEditor | simple default} which may not provide sufficient security guarantees for some environments.\n\t * Use a library such as SES to provide a more secure implementation - see `@fluidframework/tree-agent-ses` for a drop-in implementation.\n\t *\n\t * To simulate the execution of an editor outside of an {@link SharedTreeSemanticAgent | agent}, you can use {@link bindEditor | bindEditor} to bind an editor to a specific subtree.\n\t */\n\teditor?: SynchronousEditor | AsynchronousEditor;\n\t/**\n\t * The maximum number of sequential edits the LLM can make before we assume it's stuck in a loop.\n\t */\n\tmaximumSequentialEdits?: number;\n\t/**\n\t * If supplied, generates human-readable markdown text describing the actions taken by the {@link SharedTreeSemanticAgent | agent} as it performs queries.\n\t */\n\tlogger?: Logger;\n}\n\n/**\n * A result from an edit attempt via the {@link SharedTreeChatQuery.edit} function.\n * @alpha\n */\nexport interface EditResult {\n\t/**\n\t * The type of the edit result.\n\t * @remarks\n\t * - `success`: The edit was successfully applied.\n\t * - `disabledError`: The model is not allowed to edit the tree (i.e. {@link SharedTreeChatModel.editToolName} was not provided).\n\t * - `editingError`: An error was thrown while parsing or executing the provided JavaScript.\n\t * - `tooManyEditsError`: The {@link SharedTreeChatQuery.edit} function has been called more than the number of times specified by {@link SemanticAgentOptions.maximumSequentialEdits} for the same message.\n\t * - `expiredError`: The {@link SharedTreeChatQuery.edit} function was called after the issuing query has already completed.\n\t */\n\ttype: \"success\" | \"disabledError\" | \"editingError\" | \"tooManyEditsError\" | \"expiredError\";\n\n\t/**\n\t * A human-readable message describing the result of the edit attempt.\n\t * @remarks In the case of an error, this message is appropriate to include in a model's chat history.\n\t */\n\tmessage: string;\n}\n\n/**\n * Type guard for {@link EditResult}.\n */\nexport function isEditResult(value: unknown): value is EditResult {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn false;\n\t}\n\treturn (\n\t\ttypeof (value as EditResult).type === \"string\" &&\n\t\ttypeof (value as EditResult).message === \"string\"\n\t);\n}\n\n/**\n * A query from a user to a {@link SharedTreeSemanticAgent}.\n * @remarks Processing a query may involve editing the SharedTree via the provided {@link SharedTreeChatQuery.edit} function.\n * @alpha\n */\nexport interface SharedTreeChatQuery {\n\t/**\n\t * The user's query.\n\t */\n\ttext: string;\n\t/**\n\t * Edit the tree with the provided JavaScript function code.\n\t * @remarks Attempting an edit may fail for a variety of reasons which are captured in the {@link EditResult | returned object}.\n\t * If an edit fails, the tree will not be modified and the model may attempt another edit if desired.\n\t * When the query ends, if the last edit attempt was successful, all edits made during the query will be merged into the agent's SharedTree.\n\t * Otherwise, all edits made during the query will be discarded.\n\t */\n\tedit(js: string): Promise<EditResult>;\n}\n\n/**\n * A plugin interface that handles queries from a {@link SharedTreeSemanticAgent}.\n * @remarks This wraps an underlying communication with an LLM and receives all necessary {@link SharedTreeChatModel.appendContext | context} from the {@link SharedTreeSemanticAgent | agent} for the LLM to properly analyze and edit the tree.\n * See `@fluidframework/tree-agent-langchain` for a drop-in implementation based on the LangChain library.\n * @alpha\n */\nexport interface SharedTreeChatModel {\n\t/**\n\t * A optional name of this chat model.\n\t * @remarks If supplied, this may be used in logging or debugging information.\n\t * @example \"gpt-5\"\n\t */\n\tname?: string;\n\t/**\n\t * The name of the tool that the model should use to edit the tree.\n\t * @remarks If supplied, this will be mentioned in the context provided to the model so that the underlying LLM will be encouraged to use it when a user query requires an edit.\n\t * The model should \"implement\" the tool by registering it with the underlying LLM API.\n\t * The tool should take an LLM-generated JavaScript function as input and supply it to the {@link SharedTreeChatQuery.edit | edit} function.\n\t * Instructions for generating the proper function signature and implementation will be provided by the {@link SharedTreeSemanticAgent | agent} via {@link SharedTreeChatModel.appendContext | context}.\n\t * If not supplied, the model will not be able to edit the tree (running the {@link SharedTreeChatQuery.edit | edit} function will fail).\n\t */\n\teditToolName?: string;\n\t/**\n\t * Add contextual information to the model that may be relevant to future queries.\n\t * @remarks In practice, this may be implemented by e.g. appending a \"system\" message to an LLM's chat/message history.\n\t * This context must be present in the context window of every {@link SharedTreeChatModel.query | query} for e.g. {@link SharedTreeChatModel.editToolName | editing} to work.\n\t * @param text - The message or context to append.\n\t */\n\tappendContext?(text: string): void;\n\t/**\n\t * Queries the chat model with a request from the user.\n\t * @remarks This model may simply return a text response to the query, or it may first call the {@link SharedTreeChatQuery.edit} function (potentially multiple times) to modify the tree in response to the query.\n\t */\n\tquery(message: SharedTreeChatQuery): Promise<string>;\n}\n\n/**\n * A function that edits a SharedTree.\n */\nexport type EditFunction<TSchema extends ImplicitFieldSchema> = ({\n\troot,\n\tcreate,\n}: {\n\troot: ReadableField<TSchema>;\n\tcreate: Record<string, (input: FactoryContentObject) => TreeNode>;\n}) => void | Promise<void>;\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
|
-
export { SharedTreeSemanticAgent } from "./agent.js";
|
|
11
|
-
export type { EditResult, SharedTreeChatModel, SharedTreeChatQuery, Logger, SemanticAgentOptions, } from "./api.js";
|
|
10
|
+
export { SharedTreeSemanticAgent, bindEditor, bindEditorImpl, defaultEditor, } from "./agent.js";
|
|
11
|
+
export type { EditResult, SharedTreeChatModel, SharedTreeChatQuery, Logger, SemanticAgentOptions, SynchronousEditor, AsynchronousEditor, } from "./api.js";
|
|
12
12
|
export { type TreeView, llmDefault } from "./utils.js";
|
|
13
13
|
export { buildFunc, exposeMethodsSymbol, type ArgsTuple, type ExposedMethods, type Arg, type FunctionDef, type MethodKeys, type BindableSchema, type Ctor, type Infer, type IExposedMethods, } from "./methodBinding.js";
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EACN,uBAAuB,EACvB,UAAU,EACV,cAAc,EACd,aAAa,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,EACN,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACN,SAAS,EACT,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,GAAG,EACR,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,IAAI,EACT,KAAK,KAAK,EACV,KAAK,eAAe,GACpB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.exposeMethodsSymbol = exports.buildFunc = exports.llmDefault = exports.SharedTreeSemanticAgent = void 0;
|
|
7
|
+
exports.exposeMethodsSymbol = exports.buildFunc = exports.llmDefault = exports.defaultEditor = exports.bindEditorImpl = exports.bindEditor = exports.SharedTreeSemanticAgent = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* A library for creating AI agents to interact with a {@link SharedTree | https://fluidframework.com/docs/data-structures/tree/}.
|
|
10
10
|
*
|
|
@@ -12,6 +12,9 @@ exports.exposeMethodsSymbol = exports.buildFunc = exports.llmDefault = exports.S
|
|
|
12
12
|
*/
|
|
13
13
|
var agent_js_1 = require("./agent.js");
|
|
14
14
|
Object.defineProperty(exports, "SharedTreeSemanticAgent", { enumerable: true, get: function () { return agent_js_1.SharedTreeSemanticAgent; } });
|
|
15
|
+
Object.defineProperty(exports, "bindEditor", { enumerable: true, get: function () { return agent_js_1.bindEditor; } });
|
|
16
|
+
Object.defineProperty(exports, "bindEditorImpl", { enumerable: true, get: function () { return agent_js_1.bindEditorImpl; } });
|
|
17
|
+
Object.defineProperty(exports, "defaultEditor", { enumerable: true, get: function () { return agent_js_1.defaultEditor; } });
|
|
15
18
|
var utils_js_1 = require("./utils.js");
|
|
16
19
|
Object.defineProperty(exports, "llmDefault", { enumerable: true, get: function () { return utils_js_1.llmDefault; } });
|
|
17
20
|
var methodBinding_js_1 = require("./methodBinding.js");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH,uCAKoB;AAJnB,mHAAA,uBAAuB,OAAA;AACvB,sGAAA,UAAU,OAAA;AACV,0GAAA,cAAc,OAAA;AACd,yGAAA,aAAa,OAAA;AAWd,uCAAuD;AAA/B,sGAAA,UAAU,OAAA;AAClC,uDAY4B;AAX3B,6GAAA,SAAS,OAAA;AACT,uHAAA,mBAAmB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A library for creating AI agents to interact with a {@link SharedTree | https://fluidframework.com/docs/data-structures/tree/}.\n *\n * @packageDocumentation\n */\n\nexport {\n\tSharedTreeSemanticAgent,\n\tbindEditor,\n\tbindEditorImpl,\n\tdefaultEditor,\n} from \"./agent.js\";\nexport type {\n\tEditResult,\n\tSharedTreeChatModel,\n\tSharedTreeChatQuery,\n\tLogger,\n\tSemanticAgentOptions,\n\tSynchronousEditor,\n\tAsynchronousEditor,\n} from \"./api.js\";\nexport { type TreeView, llmDefault } from \"./utils.js\";\nexport {\n\tbuildFunc,\n\texposeMethodsSymbol,\n\ttype ArgsTuple,\n\ttype ExposedMethods,\n\ttype Arg,\n\ttype FunctionDef,\n\ttype MethodKeys,\n\ttype BindableSchema,\n\ttype Ctor,\n\ttype Infer,\n\ttype IExposedMethods,\n} from \"./methodBinding.js\";\n"]}
|
package/dist/prompt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAe,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAIhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAW5C;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,SAAS,mBAAmB,EAAE,IAAI,EAAE;IAClE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,MAAM,CA4PT;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAAG,MAAM,CA8C9E"}
|