@fluidframework/tree-agent 2.63.0-359286 → 2.63.0-359734
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-report/tree-agent.alpha.api.md +16 -18
- package/dist/agent.d.ts +1 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +24 -51
- package/dist/agent.js.map +1 -1
- package/dist/alpha.d.ts +1 -0
- package/dist/api.d.ts +38 -20
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/langchain.d.ts +3 -4
- package/dist/langchain.d.ts.map +1 -1
- package/dist/langchain.js +2 -4
- package/dist/langchain.js.map +1 -1
- package/dist/prompt.d.ts +1 -2
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +18 -21
- package/dist/prompt.js.map +1 -1
- package/dist/ses.d.ts +21 -0
- package/dist/ses.d.ts.map +1 -0
- package/dist/ses.js +64 -0
- package/dist/ses.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -1
- package/dist/utils.js.map +1 -1
- package/lib/agent.d.ts +1 -2
- package/lib/agent.d.ts.map +1 -1
- package/lib/agent.js +25 -52
- package/lib/agent.js.map +1 -1
- package/lib/alpha.d.ts +1 -0
- package/lib/api.d.ts +38 -20
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib/langchain.d.ts +3 -4
- package/lib/langchain.d.ts.map +1 -1
- package/lib/langchain.js +2 -4
- package/lib/langchain.js.map +1 -1
- package/lib/prompt.d.ts +1 -2
- package/lib/prompt.d.ts.map +1 -1
- package/lib/prompt.js +18 -21
- package/lib/prompt.js.map +1 -1
- package/lib/ses.d.ts +21 -0
- package/lib/ses.d.ts.map +1 -0
- package/lib/ses.js +60 -0
- package/lib/ses.js.map +1 -0
- package/lib/utils.d.ts +4 -0
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +14 -0
- package/lib/utils.js.map +1 -1
- package/package.json +10 -9
- package/src/agent.ts +34 -74
- package/src/api.ts +39 -23
- package/src/index.ts +2 -1
- package/src/langchain.ts +6 -8
- package/src/prompt.ts +19 -23
- package/src/ses.ts +73 -0
- package/src/utils.ts +14 -0
package/lib/index.d.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export { SharedTreeSemanticAgent } from "./agent.js";
|
|
11
11
|
export type { EditResult, SharedTreeChatModel, SharedTreeChatQuery, Logger, SemanticAgentOptions, } 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
|
export { LangchainChatModel, createSemanticAgent } from "./langchain.js";
|
|
15
|
+
export { createSesEditEvaluator } from "./ses.js";
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,YAAY,EACX,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,EACN,oBAAoB,GACpB,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;AAC5B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* A library for creating AI agents to interact with a {@link SharedTree | https://fluidframework.com/docs/data-structures/tree/}.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { SharedTreeSemanticAgent } from "./agent.js";
|
|
5
11
|
export { llmDefault } from "./utils.js";
|
|
6
12
|
export { buildFunc, exposeMethodsSymbol, } from "./methodBinding.js";
|
|
7
13
|
export { LangchainChatModel, createSemanticAgent } from "./langchain.js";
|
|
14
|
+
export { createSesEditEvaluator } from "./ses.js";
|
|
8
15
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAQrD,OAAO,EAAiB,UAAU,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACN,SAAS,EACT,mBAAmB,GAUnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC","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 { SharedTreeSemanticAgent } from \"./agent.js\";\nexport type {\n\tEditResult,\n\tSharedTreeChatModel,\n\tSharedTreeChatQuery,\n\tLogger,\n\tSemanticAgentOptions,\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\";\nexport { LangchainChatModel, createSemanticAgent } from \"./langchain.js\";\nexport { createSesEditEvaluator } from \"./ses.js\";\n"]}
|
package/lib/langchain.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export declare class LangchainChatModel implements SharedTreeChatModel {
|
|
|
17
17
|
private readonly messages;
|
|
18
18
|
constructor(model: BaseChatModel);
|
|
19
19
|
readonly editToolName = "GenerateTreeEditingCode";
|
|
20
|
-
readonly editFunctionName = "editTree";
|
|
21
20
|
get name(): string | undefined;
|
|
22
21
|
appendContext(text: string): void;
|
|
23
22
|
query(query: SharedTreeChatQuery): Promise<string>;
|
|
@@ -28,17 +27,17 @@ export declare class LangchainChatModel implements SharedTreeChatModel {
|
|
|
28
27
|
* @alpha
|
|
29
28
|
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
30
29
|
*/
|
|
31
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema>, options?: Readonly<SemanticAgentOptions
|
|
30
|
+
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema>, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
32
31
|
/**
|
|
33
32
|
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
34
33
|
* @alpha
|
|
35
34
|
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
36
35
|
*/
|
|
37
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, node: ReadableField<TSchema> & TreeNode, options?: Readonly<SemanticAgentOptions
|
|
36
|
+
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, node: ReadableField<TSchema> & TreeNode, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
38
37
|
/**
|
|
39
38
|
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
40
39
|
* @alpha
|
|
41
40
|
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
42
41
|
*/
|
|
43
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), options?: Readonly<SemanticAgentOptions
|
|
42
|
+
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
44
43
|
//# sourceMappingURL=langchain.d.ts.map
|
package/lib/langchain.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langchain.d.ts","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE/F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAYjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAEN,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,mBAAmB;IAE1C,OAAO,CAAC,QAAQ,CAAC,KAAK;IADzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkD;gBACvC,KAAK,EAAE,aAAa;IAExD,SAAgB,YAAY,6BAA6B;
|
|
1
|
+
{"version":3,"file":"langchain.d.ts","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE/F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAYjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAEN,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,mBAAmB;IAE1C,OAAO,CAAC,QAAQ,CAAC,KAAK;IADzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkD;gBACvC,KAAK,EAAE,aAAa;IAExD,SAAgB,YAAY,6BAA6B;IAEzD,IAAW,IAAI,IAAI,MAAM,GAAG,SAAS,CAGpC;IAEM,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI3B,KAAK,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;YAKjD,SAAS;CA2CvB;AAID;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,mBAAmB,EACtE,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAC3B,OAAO,CAAC,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GACtC,uBAAuB,CAAC,OAAO,CAAC,CAAC;AACpC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,mBAAmB,EACtE,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,EACvC,OAAO,CAAC,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GACtC,uBAAuB,CAAC,OAAO,CAAC,CAAC;AACpC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,mBAAmB,EACtE,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,EACjE,OAAO,CAAC,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GACtC,uBAAuB,CAAC,OAAO,CAAC,CAAC"}
|
package/lib/langchain.js
CHANGED
|
@@ -21,7 +21,6 @@ export class LangchainChatModel {
|
|
|
21
21
|
this.model = model;
|
|
22
22
|
this.messages = [];
|
|
23
23
|
this.editToolName = "GenerateTreeEditingCode";
|
|
24
|
-
this.editFunctionName = "editTree";
|
|
25
24
|
}
|
|
26
25
|
get name() {
|
|
27
26
|
const name = this.model.metadata?.modelName;
|
|
@@ -39,10 +38,9 @@ export class LangchainChatModel {
|
|
|
39
38
|
return edit(functionCode);
|
|
40
39
|
}, {
|
|
41
40
|
name: this.editToolName,
|
|
42
|
-
description: `Invokes a JavaScript
|
|
41
|
+
description: `Invokes a JavaScript code snippet to edit a tree of application data.`,
|
|
43
42
|
schema: z.object({
|
|
44
|
-
functionCode: z.string().describe(`The
|
|
45
|
-
For example: "function ${this.editFunctionName}({ root, create }) { /* your code here */ }"`),
|
|
43
|
+
functionCode: z.string().describe(`The JavaScript snippet code.`),
|
|
46
44
|
}),
|
|
47
45
|
});
|
|
48
46
|
const runnable = this.model.bindTools?.([editingTool], { tool_choice: "auto" });
|
package/lib/langchain.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langchain.js","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAMtE,OAAO,EACN,YAAY,EACZ,aAAa;AACb,sDAAsD;EACtD,MAAM,0BAA0B,CAAC;AAClC,sDAAsD;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EACN,YAAY,GAIZ,MAAM,UAAU,CAAC;AAGlB;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAE9B,YAAoC,KAAoB;QAApB,UAAK,GAAL,KAAK,CAAe;QADvC,aAAQ,GAA+C,EAAE,CAAC;QAG3D,iBAAY,GAAG,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"langchain.js","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAMtE,OAAO,EACN,YAAY,EACZ,aAAa;AACb,sDAAsD;EACtD,MAAM,0BAA0B,CAAC;AAClC,sDAAsD;AACtD,OA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AAQ,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,2BAA2B,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;oBAClF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,eAAe,CAAC,IAAI,CAAC;IAC7B,CAAC;CACD;AAkCD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAClC,MAAqB,EACrB,QAAiE,EACjE,OAAwC;IAExC,OAAO,IAAI,uBAAuB,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC;AAED,yBAAyB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema, ReadableField, TreeNode } from \"@fluidframework/tree/alpha\";\n// eslint-disable-next-line import/no-internal-modules\nimport type { BaseChatModel } from \"@langchain/core/language_models/chat_models\";\n// eslint-disable-next-line import/no-internal-modules\nimport type { AIMessage, ToolMessage } from \"@langchain/core/messages\";\nimport {\n\tHumanMessage,\n\tSystemMessage,\n\t// eslint-disable-next-line import/no-internal-modules\n} from \"@langchain/core/messages\";\n// eslint-disable-next-line import/no-internal-modules\nimport { tool } from \"@langchain/core/tools\";\nimport z from \"zod\";\n\nimport { SharedTreeSemanticAgent } from \"./agent.js\";\nimport {\n\tisEditResult,\n\ttype SemanticAgentOptions,\n\ttype SharedTreeChatModel,\n\ttype SharedTreeChatQuery,\n} from \"./api.js\";\nimport type { TreeView } from \"./utils.js\";\n\n/**\n * An implementation of {@link SharedTreeChatModel} that wraps a Langchain chat model.\n * @remarks This class is responsible for managing the conversation history and interacting with the Langchain model (e.g. via Tool use for editing).\n * @alpha\n */\nexport class LangchainChatModel implements SharedTreeChatModel {\n\tprivate readonly messages: (HumanMessage | AIMessage | ToolMessage)[] = [];\n\tpublic constructor(private readonly model: BaseChatModel) {}\n\n\tpublic readonly editToolName = \"GenerateTreeEditingCode\";\n\n\tpublic get name(): string | undefined {\n\t\tconst name = this.model.metadata?.modelName;\n\t\treturn typeof name === \"string\" ? name : undefined;\n\t}\n\n\tpublic appendContext(text: string): void {\n\t\tthis.messages.push(new SystemMessage(text));\n\t}\n\n\tpublic async query(query: SharedTreeChatQuery): Promise<string> {\n\t\tthis.messages.push(new HumanMessage(query.text));\n\t\treturn this.queryEdit(async (js) => query.edit(js));\n\t}\n\n\tprivate async queryEdit(edit: SharedTreeChatQuery[\"edit\"]): Promise<string> {\n\t\tconst editingTool = tool(\n\t\t\tasync ({ functionCode }) => {\n\t\t\t\treturn edit(functionCode);\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: this.editToolName,\n\t\t\t\tdescription: `Invokes a JavaScript code snippet to edit a tree of application data.`,\n\t\t\t\tschema: z.object({\n\t\t\t\t\tfunctionCode: z.string().describe(`The JavaScript snippet code.`),\n\t\t\t\t}),\n\t\t\t},\n\t\t);\n\t\tconst runnable = this.model.bindTools?.([editingTool], { tool_choice: \"auto\" });\n\t\tif (runnable === undefined) {\n\t\t\tthrow new UsageError(\"LLM client must support function calling or tool use.\");\n\t\t}\n\n\t\tconst responseMessage = await runnable.invoke(this.messages);\n\t\tthis.messages.push(responseMessage);\n\n\t\tif (responseMessage.tool_calls !== undefined && responseMessage.tool_calls.length > 0) {\n\t\t\tfor (const toolCall of responseMessage.tool_calls) {\n\t\t\t\tswitch (toolCall.name) {\n\t\t\t\t\tcase editingTool.name: {\n\t\t\t\t\t\tconst toolResult = await editingTool.invoke(toolCall);\n\t\t\t\t\t\tthis.messages.push(toolResult);\n\t\t\t\t\t\tconst editResult: unknown = JSON.parse(toolResult.text);\n\t\t\t\t\t\tif (isEditResult(editResult) && editResult.type === \"tooManyEditsError\") {\n\t\t\t\t\t\t\treturn editResult.message;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// This call will either terminate the edit chain (if the LLM decides not to edit further) or continue it if more edits are required.\n\t\t\t\t\t\treturn this.queryEdit(edit);\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthis.messages.push(new HumanMessage(`Unrecognized tool call: ${toolCall.name}`));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn responseMessage.text;\n\t}\n}\n\n// #region Legacy APIs\n\n/**\n * Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.\n * @alpha\n * @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.\n */\nexport function createSemanticAgent<TSchema extends ImplicitFieldSchema>(\n\tclient: BaseChatModel,\n\ttreeView: TreeView<TSchema>,\n\toptions?: Readonly<SemanticAgentOptions>,\n): SharedTreeSemanticAgent<TSchema>;\n/**\n * Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.\n * @alpha\n * @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.\n */\nexport function createSemanticAgent<TSchema extends ImplicitFieldSchema>(\n\tclient: BaseChatModel,\n\tnode: ReadableField<TSchema> & TreeNode,\n\toptions?: Readonly<SemanticAgentOptions>,\n): SharedTreeSemanticAgent<TSchema>;\n/**\n * Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.\n * @alpha\n * @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.\n */\nexport function createSemanticAgent<TSchema extends ImplicitFieldSchema>(\n\tclient: BaseChatModel,\n\ttreeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),\n\toptions?: Readonly<SemanticAgentOptions>,\n): SharedTreeSemanticAgent<TSchema>;\n/**\n * Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.\n * @alpha\n * @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.\n */\nexport function createSemanticAgent<TSchema extends ImplicitFieldSchema>(\n\tclient: BaseChatModel,\n\ttreeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),\n\toptions?: Readonly<SemanticAgentOptions>,\n): SharedTreeSemanticAgent<TSchema> {\n\treturn new SharedTreeSemanticAgent(new LangchainChatModel(client), treeView, options);\n}\n\n// #endregion Legacy APIs\n"]}
|
package/lib/prompt.d.ts
CHANGED
|
@@ -10,8 +10,7 @@ import type { Subtree } from "./subtree.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function getPrompt<TRoot extends ImplicitFieldSchema>(args: {
|
|
12
12
|
subtree: Subtree<TRoot>;
|
|
13
|
-
editToolName
|
|
14
|
-
editFunctionName?: string;
|
|
13
|
+
editToolName: string | undefined;
|
|
15
14
|
domainHints?: string;
|
|
16
15
|
}): string;
|
|
17
16
|
/**
|
package/lib/prompt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,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,
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,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,CA4IT;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,mBAAmB,CAAC,GAAG,MAAM,CA8C9E"}
|
package/lib/prompt.js
CHANGED
|
@@ -11,7 +11,7 @@ import { getFriendlyName, getZodSchemaAsTypeScript, isNamedSchema, communize, un
|
|
|
11
11
|
* Produces a "system" prompt for the tree agent, based on the provided subtree.
|
|
12
12
|
*/
|
|
13
13
|
export function getPrompt(args) {
|
|
14
|
-
const { subtree, editToolName,
|
|
14
|
+
const { subtree, editToolName, domainHints } = args;
|
|
15
15
|
const { field, schema } = subtree;
|
|
16
16
|
const arrayInterfaceName = "TreeArray";
|
|
17
17
|
const mapInterfaceName = "TreeMap";
|
|
@@ -50,22 +50,20 @@ export function getPrompt(args) {
|
|
|
50
50
|
const details = { hasHelperMethods: false };
|
|
51
51
|
const typescriptSchemaTypes = getZodSchemaAsTypeScript(domainTypes, details);
|
|
52
52
|
const helperMethodExplanation = details.hasHelperMethods
|
|
53
|
-
? `Manipulating the data using the APIs described below is allowed, but when possible ALWAYS prefer to use
|
|
53
|
+
? `Manipulating the data using the APIs described below is allowed, but when possible ALWAYS prefer to use any application helper methods exposed on the schema TypeScript types if the goal can be accomplished that way.
|
|
54
54
|
It will often not be possible to fully accomplish the goal using those helpers. When this is the case, mutate the objects as normal, taking into account the following guidance.`
|
|
55
55
|
: "";
|
|
56
56
|
const builderExplanation = exampleObjectName === undefined
|
|
57
57
|
? ""
|
|
58
58
|
: `When constructing new objects, you should wrap them in the appropriate builder function rather than simply making a javascript object.
|
|
59
|
-
The builders are available on the
|
|
59
|
+
The builders are available on the \`create\` property on the context object and are named according to the type that they create.
|
|
60
60
|
For example:
|
|
61
61
|
|
|
62
62
|
\`\`\`javascript
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// const ${communize(exampleObjectName)} = { /* ...properties... */ };
|
|
68
|
-
}
|
|
63
|
+
// This creates a new ${exampleObjectName} object:
|
|
64
|
+
const ${communize(exampleObjectName)} = context.create.${exampleObjectName}({ /* ...properties... */ });
|
|
65
|
+
// Don't do this:
|
|
66
|
+
// const ${communize(exampleObjectName)} = { /* ...properties... */ };
|
|
69
67
|
\`\`\`\n\n`;
|
|
70
68
|
const arrayEditing = `#### Editing Arrays
|
|
71
69
|
|
|
@@ -96,26 +94,25 @@ ${getTreeMapNodeDocumentation(mapInterfaceName)}
|
|
|
96
94
|
|
|
97
95
|
`;
|
|
98
96
|
const rootTypes = normalizeFieldSchema(schema).allowedTypeSet;
|
|
99
|
-
const editing = `If the user asks you to edit the tree, you should author a JavaScript
|
|
100
|
-
|
|
97
|
+
const editing = `If the user asks you to edit the tree, you should author a snippet of JavaScript code to accomplish the user-specified goal, following the instructions for editing detailed below.
|
|
98
|
+
You must use the "${editToolName}" tool to run the generated code.
|
|
101
99
|
After editing the tree, review the latest state of the tree to see if it satisfies the user's request.
|
|
102
100
|
If it does not, or if you receive an error, you may try again with a different approach.
|
|
103
101
|
Once the tree is in the desired state, you should inform the user that the request has been completed.
|
|
104
102
|
|
|
105
103
|
### Editing
|
|
106
104
|
|
|
107
|
-
If the user asks you to edit the document, you will write a JavaScript
|
|
108
|
-
The
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
You may
|
|
113
|
-
You may also set the \`root\` property to be an entirely new value as long as it is one of the types allowed at the root of the tree (\`${Array.from(rootTypes.values(), (t) => getFriendlyName(t)).join(" | ")}\`).
|
|
105
|
+
If the user asks you to edit the document, you will write a snippet of JavaScript code that mutates the data in-place to achieve the user's goal.
|
|
106
|
+
The snippet may be synchronous or asynchronous (i.e. it may \`await\` functions if necessary).
|
|
107
|
+
The snippet has a \`context\` variable in its scope.
|
|
108
|
+
This \`context\` variable holds the current state of the tree in the \`root\` property.
|
|
109
|
+
You may mutate any part of the root tree as necessary, taking into account the caveats around${hasArrays ? ` arrays${hasMaps ? " and" : ""}` : ""}${hasMaps ? " maps" : ""} detailed below.
|
|
110
|
+
You may also set the \`root\` property of the context to be an entirely new value as long as it is one of the types allowed at the root of the tree (\`${Array.from(rootTypes.values(), (t) => getFriendlyName(t)).join(" | ")}\`).
|
|
114
111
|
${helperMethodExplanation}
|
|
115
112
|
|
|
116
113
|
${hasArrays ? arrayEditing : ""}${hasMaps ? mapEditing : ""}#### Additional Notes
|
|
117
114
|
|
|
118
|
-
Before outputting the
|
|
115
|
+
Before outputting the edit function, you should check that it is valid according to both the application tree's schema and any restrictions of the editing APIs described above.
|
|
119
116
|
|
|
120
117
|
Once data has been removed from the tree (e.g. replaced via assignment, or removed from an array), that data cannot be re-inserted into the tree - instead, it must be deep cloned and recreated.
|
|
121
118
|
|
|
@@ -132,12 +129,12 @@ ${typescriptSchemaTypes}
|
|
|
132
129
|
If the user asks you a question about the tree, you should inspect the state of the tree and answer the question.
|
|
133
130
|
When answering such a question, DO NOT answer with information that is not part of the document unless requested to do so.
|
|
134
131
|
|
|
135
|
-
${
|
|
132
|
+
${editToolName === undefined ? "" : editing}### Application data
|
|
136
133
|
|
|
137
134
|
${domainHints === undefined
|
|
138
135
|
? ""
|
|
139
136
|
: `\nThe application supplied the following additional instructions: ${domainHints}`}
|
|
140
|
-
The current state of
|
|
137
|
+
The current state of \`context.root\` (a \`${field === undefined ? "undefined" : getFriendlyName(Tree.schema(field))}\`) is:
|
|
141
138
|
|
|
142
139
|
\`\`\`JSON
|
|
143
140
|
${stringified}
|
package/lib/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,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;;;;;;;;;;;;;;;;;;qEA0E0C,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAiDhE,QAAQ;;EAEnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,2BAA2B,CAAC,QAAgB;IACpD,OAAO;;;mBAGW,QAAQ;;;;;;;;kFAQuD,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDxF,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { NodeKind, Tree, TreeNode } from \"@fluidframework/tree\";\nimport type { ImplicitFieldSchema, TreeMapNode } from \"@fluidframework/tree\";\nimport type { ReadableField } from \"@fluidframework/tree/alpha\";\nimport { getSimpleSchema } from \"@fluidframework/tree/alpha\";\nimport { normalizeFieldSchema } from \"@fluidframework/tree/internal\";\n\nimport type { Subtree } from \"./subtree.js\";\nimport { generateEditTypesForPrompt } from \"./typeGeneration.js\";\nimport {\n\tgetFriendlyName,\n\tgetZodSchemaAsTypeScript,\n\tisNamedSchema,\n\tcommunize,\n\tunqualifySchema,\n\ttype SchemaDetails,\n} from \"./utils.js\";\n\n/**\n * Produces a \"system\" prompt for the tree agent, based on the provided subtree.\n */\nexport function getPrompt<TRoot extends ImplicitFieldSchema>(args: {\n\tsubtree: Subtree<TRoot>;\n\teditToolName?: string;\n\teditFunctionName?: string;\n\tdomainHints?: string;\n}): string {\n\tconst { subtree, editToolName, editFunctionName, domainHints } = args;\n\tconst { field, schema } = subtree;\n\tconst arrayInterfaceName = \"TreeArray\";\n\tconst mapInterfaceName = \"TreeMap\";\n\tconst simpleSchema = getSimpleSchema(schema);\n\t// Inspect the schema to determine what kinds of nodes are possible - this will affect how much information we need to include in the prompt.\n\tlet hasArrays = false;\n\tlet hasMaps = false;\n\tlet exampleObjectName: string | undefined;\n\tfor (const [definition, nodeSchema] of simpleSchema.definitions) {\n\t\tswitch (nodeSchema.kind) {\n\t\t\tcase NodeKind.Array: {\n\t\t\t\thasArrays = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\thasMaps = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Object: {\n\t\t\t\texampleObjectName ??= unqualifySchema(definition);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// No default\n\t\t}\n\t}\n\n\tconst { domainTypes } = generateEditTypesForPrompt(schema, simpleSchema);\n\tfor (const [key, value] of Object.entries(domainTypes)) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\tdelete domainTypes[key];\n\t\tif (isNamedSchema(key)) {\n\t\t\tconst friendlyKey = unqualifySchema(key);\n\t\t\tdomainTypes[friendlyKey] = value;\n\t\t}\n\t}\n\n\tconst stringified = stringifyTree(field);\n\tconst details: SchemaDetails = { hasHelperMethods: false };\n\tconst typescriptSchemaTypes = getZodSchemaAsTypeScript(domainTypes, details);\n\tconst helperMethodExplanation = details.hasHelperMethods\n\t\t? `Manipulating the data using the APIs described below is allowed, but when possible ALWAYS prefer to use the application helper methods exposed on the schema TypeScript types if the goal can be accomplished that way.\nIt will often not be possible to fully accomplish the goal using those helpers. When this is the case, mutate the objects as normal, taking into account the following guidance.`\n\t\t: \"\";\n\n\tconst builderExplanation =\n\t\texampleObjectName === undefined\n\t\t\t? \"\"\n\t\t\t: `When constructing new objects, you should wrap them in the appropriate builder function rather than simply making a javascript object.\nThe builders are available on the \"create\" property on the first argument of the \\`${editFunctionName}\\` function and are named according to the type that they create.\nFor example:\n\n\\`\\`\\`javascript\nfunction ${editFunctionName}({ root, create }) {\n\t// This creates a new ${exampleObjectName} object:\n\tconst ${communize(exampleObjectName)} = create.${exampleObjectName}({ /* ...properties... */ });\n\t// Don't do this:\n\t// const ${communize(exampleObjectName)} = { /* ...properties... */ };\n}\n\\`\\`\\`\\n\\n`;\n\n\tconst arrayEditing = `#### Editing Arrays\n\nThe arrays in the tree are somewhat different than normal JavaScript \\`Array\\`s.\nRead-only operations are generally the same - you can create them, read via index, and call non-mutating methods like \\`concat\\`, \\`map\\`, \\`filter\\`, \\`find\\`, \\`forEach\\`, \\`indexOf\\`, \\`slice\\`, \\`join\\`, etc.\nHowever, write operations (e.g. index assignment, \\`push\\`, \\`pop\\`, \\`splice\\`, etc.) are not supported.\nInstead, you must use the methods on the following interface to mutate the array:\n\n\\`\\`\\`typescript\n${getTreeArrayNodeDocumentation(arrayInterfaceName)}\n\\`\\`\\`\n\nWhen possible, ensure that the edits preserve the identity of objects already in the tree.\nFor example, prefer \\`array.moveToIndex\\` over \\`array.removeAt\\` + \\`array.insertAt\\` and prefer \\`array.moveRangeToIndex\\` over \\`array.removeRange\\` + \\`array.insertAt\\`.\n\n`;\n\n\tconst mapEditing = `#### Editing Maps\n\nThe maps in the tree are somewhat different than normal JavaScript \\`Map\\`s.\nMap keys are always strings.\nRead-only operations are generally the same - you can create them, read via \\`get\\`, and call non-mutating methods like \\`has\\`, \\`forEach\\`, \\`entries\\`, \\`keys\\`, \\`values\\`, etc. (note the subtle differences around return values and iteration order).\nHowever, write operations (e.g. \\`set\\`, \\`delete\\`, etc.) are not supported.\nInstead, you must use the methods on the following interface to mutate the map:\n\n\\`\\`\\`typescript\n${getTreeMapNodeDocumentation(mapInterfaceName)}\n\\`\\`\\`\n\n`;\n\n\tconst rootTypes = normalizeFieldSchema(schema).allowedTypeSet;\n\tconst editing = `If the user asks you to edit the tree, you should author a JavaScript function to accomplish the user-specified goal, following the instructions for editing detailed below.\n${editToolName === undefined ? \"Use an applicable tool to perform the edit (if one is available).\" : `You must use the \"${editToolName}\" tool to perform the edit.`}\nAfter editing the tree, review the latest state of the tree to see if it satisfies the user's request.\nIf it does not, or if you receive an error, you may try again with a different approach.\nOnce the tree is in the desired state, you should inform the user that the request has been completed.\n\n### Editing\n\nIf the user asks you to edit the document, you will write a JavaScript function that mutates the data in-place to achieve the user's goal.\nThe function must be named \"${editFunctionName}\".\nIt may be synchronous or asynchronous.\nThe ${editFunctionName} function must have a first parameter which has a \\`root\\` property.\nThis \\`root\\` property holds the current state of the tree as shown above.\nYou may mutate any part of the tree as necessary, taking into account the caveats around arrays and maps detailed below.\nYou may also set the \\`root\\` property to be an entirely new value as long as it is one of the types allowed at the root of the tree (\\`${Array.from(rootTypes.values(), (t) => getFriendlyName(t)).join(\" | \")}\\`).\n${helperMethodExplanation}\n\n${hasArrays ? arrayEditing : \"\"}${hasMaps ? mapEditing : \"\"}#### Additional Notes\n\nBefore outputting the ${editFunctionName} function, you should check that it is valid according to both the application tree's schema and any restrictions of the editing APIs described above.\n\nOnce data has been removed from the tree (e.g. replaced via assignment, or removed from an array), that data cannot be re-inserted into the tree - instead, it must be deep cloned and recreated.\n\n${builderExplanation}Finally, double check that the edits would accomplish the user's request (if it is possible).\n\n`;\n\n\tconst prompt = `You are a helpful assistant collaborating with the user on a document. The document state is a JSON tree, and you are able to analyze and edit it.\nThe JSON tree adheres to the following Typescript schema:\n\n\\`\\`\\`typescript\n${typescriptSchemaTypes}\n\\`\\`\\`\n\nIf the user asks you a question about the tree, you should inspect the state of the tree and answer the question.\nWhen answering such a question, DO NOT answer with information that is not part of the document unless requested to do so.\n\n${editFunctionName === undefined ? \"\" : editing}### Application data\n\n${\n\tdomainHints === undefined\n\t\t? \"\"\n\t\t: `\\nThe application supplied the following additional instructions: ${domainHints}`\n}\nThe current state of the application tree (a \\`${field === undefined ? \"undefined\" : getFriendlyName(Tree.schema(field))}\\`) is:\n\n\\`\\`\\`JSON\n${stringified}\n\\`\\`\\``;\n\treturn prompt;\n}\n\n/**\n * Serializes tree data e.g. to include in a prompt or message.\n * @remarks This includes some extra metadata to make it easier to understand the structure of the tree.\n */\nexport function stringifyTree(tree: ReadableField<ImplicitFieldSchema>): string {\n\tconst typeReplacementKey = \"_e944da5a5fd04ea2b8b2eb6109e089ed\";\n\tconst indexReplacementKey = \"_27bb216b474d45e6aaee14d1ec267b96\";\n\tconst mapReplacementKey = \"_a0d98d22a1c644539f07828d3f064d71\";\n\tconst stringified = JSON.stringify(\n\t\ttree,\n\t\t(_, node: unknown) => {\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst key = Tree.key(node);\n\t\t\t\tconst index = typeof key === \"number\" ? key : undefined;\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\tswitch (schema.kind) {\n\t\t\t\t\tcase NodeKind.Object: {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t[typeReplacementKey]: getFriendlyName(schema),\n\t\t\t\t\t\t\t[indexReplacementKey]: index,\n\t\t\t\t\t\t\t...node,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Map: {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t[indexReplacementKey]: index,\n\t\t\t\t\t\t\t[mapReplacementKey]: \"\",\n\t\t\t\t\t\t\t...Object.fromEntries(node as TreeMapNode),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t[indexReplacementKey]: index,\n\t\t\t\t\t\t\t...node,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn node;\n\t\t},\n\t\t2,\n\t);\n\n\treturn stringified\n\t\t.replace(new RegExp(`\"${typeReplacementKey}\":`, \"g\"), `// Type:`)\n\t\t.replace(new RegExp(`\"${indexReplacementKey}\":`, \"g\"), `// Index:`)\n\t\t.replace(\n\t\t\tnew RegExp(`\"${mapReplacementKey}\": \"\"`, \"g\"),\n\t\t\t`// Note: This is a map that has been serialized to JSON. It is not a key-value object/record but is being printed as such.`,\n\t\t);\n}\n\n/**\n * Retrieves the documentation for the `TreeArrayNode` interface to feed to the LLM.\n * @remarks The documentation has been simplified in various ways to make it easier for the LLM to understand.\n * @privateRemarks TODO: How do we keep this in sync with the actual `TreeArrayNode` docs if/when those docs change?\n */\nfunction getTreeArrayNodeDocumentation(typeName: string): string {\n\treturn `/** A special type of array which implements 'readonly T[]' (i.e. it supports all read-only JS array methods) and provides custom array mutation APIs. */\nexport interface ${typeName}<T> extends ReadonlyArray<T> {\n\t/**\n\t * Inserts new item(s) at a specified location.\n\t * @param index - The index at which to insert \\`value\\`.\n\t * @param value - The content to insert.\n\t * @throws Throws if \\`index\\` is not in the range [0, \\`array.length\\`).\n\t */\n\tinsertAt(index: number, ...value: readonly T[]): void;\n\n\t/**\n\t * Removes the item at the specified location.\n\t * @param index - The index at which to remove the item.\n\t * @throws Throws if \\`index\\` is not in the range [0, \\`array.length\\`).\n\t */\n\tremoveAt(index: number): void;\n\n\t/**\n\t * Removes all items between the specified indices.\n\t * @param start - The starting index of the range to remove (inclusive). Defaults to the start of the array.\n\t * @param end - The ending index of the range to remove (exclusive). Defaults to \\`array.length\\`.\n\t * @throws Throws if \\`start\\` is not in the range [0, \\`array.length\\`].\n\t * @throws Throws if \\`end\\` is less than \\`start\\`.\n\t * If \\`end\\` is not supplied or is greater than the length of the array, all items after \\`start\\` are removed.\n\t *\n\t * @remarks\n\t * The default values for start and end are computed when this is called,\n\t * and thus the behavior is the same as providing them explicitly, even with respect to merge resolution with concurrent edits.\n\t * For example, two concurrent transactions both emptying the array with \\`node.removeRange()\\` then inserting an item,\n\t * will merge to result in the array having both inserted items.\n\t */\n\tremoveRange(start?: number, end?: number): void;\n\n\t/**\n\t * Moves the specified item to the desired location in the array.\n\t *\n\t * WARNING - This API is easily misused.\n\t * Please read the documentation for the \\`destinationGap\\` parameter carefully.\n\t *\n\t * @param destinationGap - The location *between* existing items that the moved item should be moved to.\n\t *\n\t * WARNING - \\`destinationGap\\` describes a location between existing items *prior to applying the move operation*.\n\t *\n\t * For example, if the array contains items \\`[A, B, C]\\` before the move, the \\`destinationGap\\` must be one of the following:\n\t *\n\t * - \\`0\\` (between the start of the array and \\`A\\`'s original position)\n\t * - \\`1\\` (between \\`A\\`'s original position and \\`B\\`'s original position)\n\t * - \\`2\\` (between \\`B\\`'s original position and \\`C\\`'s original position)\n\t * - \\`3\\` (between \\`C\\`'s original position and the end of the array)\n\t *\n\t * So moving \\`A\\` between \\`B\\` and \\`C\\` would require \\`destinationGap\\` to be \\`2\\`.\n\t *\n\t * This interpretation of \\`destinationGap\\` makes it easy to specify the desired destination relative to a sibling item that is not being moved,\n\t * or relative to the start or end of the array:\n\t *\n\t * - Move to the start of the array: \\`array.moveToIndex(0, ...)\\` (see also \\`moveToStart\\`)\n\t * - Move to before some item X: \\`array.moveToIndex(indexOfX, ...)\\`\n\t * - Move to after some item X: \\`array.moveToIndex(indexOfX + 1\\`, ...)\n\t * - Move to the end of the array: \\`array.moveToIndex(array.length, ...)\\` (see also \\`moveToEnd\\`)\n\t *\n\t * This interpretation of \\`destinationGap\\` does however make it less obvious how to move an item relative to its current position:\n\t *\n\t * - Move item B before its predecessor: \\`array.moveToIndex(indexOfB - 1, ...)\\`\n\t * - Move item B after its successor: \\`array.moveToIndex(indexOfB + 2, ...)\\`\n\t *\n\t * Notice the asymmetry between \\`-1\\` and \\`+2\\` in the above examples.\n\t * In such scenarios, it can often be easier to approach such edits by swapping adjacent items:\n\t * If items A and B are adjacent, such that A precedes B,\n\t * then they can be swapped with \\`array.moveToIndex(indexOfA, indexOfB)\\`.\n\t *\n\t * @param sourceIndex - The index of the item to move.\n\t * @param source - The optional source array to move the item out of (defaults to this array).\n\t * @throws Throws if any of the source index is not in the range [0, \\`array.length\\`),\n\t * or if the index is not in the range [0, \\`array.length\\`].\n\t */\n\tmoveToIndex(destinationGap: number, sourceIndex: number, source?: ${typeName}<T>): void;\n\n\t/**\n\t * Moves the specified items to the desired location within the array.\n\t *\n\t * WARNING - This API is easily misused.\n\t * Please read the documentation for the \\`destinationGap\\` parameter carefully.\n\t *\n\t * @param destinationGap - The location *between* existing items that the moved item should be moved to.\n\t *\n\t * WARNING - \\`destinationGap\\` describes a location between existing items *prior to applying the move operation*.\n\t *\n\t * For example, if the array contains items \\`[A, B, C]\\` before the move, the \\`destinationGap\\` must be one of the following:\n\t *\n\t * - \\`0\\` (between the start of the array and \\`A\\`'s original position)\n\t * - \\`1\\` (between \\`A\\`'s original position and \\`B\\`'s original position)\n\t * - \\`2\\` (between \\`B\\`'s original position and \\`C\\`'s original position)\n\t * - \\`3\\` (between \\`C\\`'s original position and the end of the array)\n\t *\n\t * So moving \\`A\\` between \\`B\\` and \\`C\\` would require \\`destinationGap\\` to be \\`2\\`.\n\t *\n\t * This interpretation of \\`destinationGap\\` makes it easy to specify the desired destination relative to a sibling item that is not being moved,\n\t * or relative to the start or end of the array:\n\t *\n\t * - Move to the start of the array: \\`array.moveToIndex(0, ...)\\` (see also \\`moveToStart\\`)\n\t * - Move to before some item X: \\`array.moveToIndex(indexOfX, ...)\\`\n\t * - Move to after some item X: \\`array.moveToIndex(indexOfX + 1\\`, ...)\n\t * - Move to the end of the array: \\`array.moveToIndex(array.length, ...)\\` (see also \\`moveToEnd\\`)\n\t *\n\t * This interpretation of \\`destinationGap\\` does however make it less obvious how to move an item relative to its current position:\n\t *\n\t * - Move item B before its predecessor: \\`array.moveToIndex(indexOfB - 1, ...)\\`\n\t * - Move item B after its successor: \\`array.moveToIndex(indexOfB + 2, ...)\\`\n\t *\n\t * Notice the asymmetry between \\`-1\\` and \\`+2\\` in the above examples.\n\t * In such scenarios, it can often be easier to approach such edits by swapping adjacent items:\n\t * If items A and B are adjacent, such that A precedes B,\n\t * then they can be swapped with \\`array.moveToIndex(indexOfA, indexOfB)\\`.\n\t *\n\t * @param sourceStart - The starting index of the range to move (inclusive).\n\t * @param sourceEnd - The ending index of the range to move (exclusive)\n\t * @param source - The optional source array to move items out of (defaults to this array).\n\t * @throws Throws if the types of any of the items being moved are not allowed in the destination array,\n\t * if any of the input indices are not in the range [0, \\`array.length\\`], or if \\`sourceStart\\` is greater than \\`sourceEnd\\`.\n\t */\n\tmoveRangeToIndex(\n\t\tdestinationGap: number,\n\t\tsourceStart: number,\n\t\tsourceEnd: number,\n\t\tsource?: ${typeName}<T>,\n\t): void;\n}`;\n}\n\n/**\n * Retrieves the documentation for the `TreeMapNode` interface to feed to the LLM.\n * @remarks The documentation has been simplified in various ways to make it easier for the LLM to understand.\n * @privateRemarks TODO: How do we keep this in sync with the actual `TreeMapNode` docs if/when those docs change?\n */\nfunction getTreeMapNodeDocumentation(typeName: string): string {\n\treturn `/**\n * A map of string keys to tree objects.\n */\nexport interface ${typeName}<T> extends ReadonlyMap<string, T> {\n\t/**\n\t * Adds or updates an entry in the map with a specified \\`key\\` and a \\`value\\`.\n\t *\n\t * @param key - The key of the element to add to the map.\n\t * @param value - The value of the element to add to the map.\n\t *\n\t * @remarks\n\t * Setting the value at a key to \\`undefined\\` is equivalent to calling {@link ${typeName}.delete} with that key.\n\t */\n\tset(key: string, value: T | undefined): void;\n\n\t/**\n\t * Removes the specified element from this map by its \\`key\\`.\n\t *\n\t * @remarks\n\t * Note: unlike JavaScript's Map API, this method does not return a flag indicating whether or not the value was\n\t * deleted.\n\t *\n\t * @param key - The key of the element to remove from the map.\n\t */\n\tdelete(key: string): void;\n\n\t/**\n\t * Returns an iterable of keys in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the keys returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tkeys(): IterableIterator<string>;\n\n\t/**\n\t * Returns an iterable of values in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the values returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tvalues(): IterableIterator<T>;\n\n\t/**\n\t * Returns an iterable of key/value pairs for every entry in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the entries returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tentries(): IterableIterator<[string, T]>;\n\n\t/**\n\t * Executes the provided function once per each key/value pair in this map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order in which the function is called with respect to the map's entries.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tforEach(\n\t\tcallbackfn: (\n\t\t\tvalue: T,\n\t\t\tkey: string,\n\t\t\tmap: ReadonlyMap<string, T>,\n\t\t) => void,\n\t\tthisArg?: any,\n\t): void;\n}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAGrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EACN,eAAe,EACf,wBAAwB,EACxB,aAAa,EACb,SAAS,EACT,eAAe,GAEf,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,UAAU,SAAS,CAAoC,IAI5D;IACA,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IACpD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,kBAAkB,GAAG,WAAW,CAAC;IACvC,MAAM,gBAAgB,GAAG,SAAS,CAAC;IACnC,MAAM,YAAY,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAC7C,6IAA6I;IAC7I,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,iBAAqC,CAAC;IAC1C,KAAK,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;QACjE,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;YACzB,KAAK,QAAQ,CAAC,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AC,IAAI,MAAM,CAAC,IAAI,kBAAkB,IAAI,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC;SAChE,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,mBAAmB,IAAI,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC;SAClE,OAAO,CACP,IAAI,MAAM,CAAC,IAAI,iBAAiB,OAAO,EAAE,GAAG,CAAC,EAC7C,4HAA4H,CAC5H,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,6BAA6B,CAAC,QAAgB;IACtD,OAAO;mBACW,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEA0E0C,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAiDhE,QAAQ;;EAEnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,2BAA2B,CAAC,QAAgB;IACpD,OAAO;;;mBAGW,QAAQ;;;;;;;;kFAQuD,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDxF,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { NodeKind, Tree, TreeNode } from \"@fluidframework/tree\";\nimport type { ImplicitFieldSchema, TreeMapNode } from \"@fluidframework/tree\";\nimport type { ReadableField } from \"@fluidframework/tree/alpha\";\nimport { getSimpleSchema } from \"@fluidframework/tree/alpha\";\nimport { normalizeFieldSchema } from \"@fluidframework/tree/internal\";\n\nimport type { Subtree } from \"./subtree.js\";\nimport { generateEditTypesForPrompt } from \"./typeGeneration.js\";\nimport {\n\tgetFriendlyName,\n\tgetZodSchemaAsTypeScript,\n\tisNamedSchema,\n\tcommunize,\n\tunqualifySchema,\n\ttype SchemaDetails,\n} from \"./utils.js\";\n\n/**\n * Produces a \"system\" prompt for the tree agent, based on the provided subtree.\n */\nexport function getPrompt<TRoot extends ImplicitFieldSchema>(args: {\n\tsubtree: Subtree<TRoot>;\n\teditToolName: string | undefined;\n\tdomainHints?: string;\n}): string {\n\tconst { subtree, editToolName, domainHints } = args;\n\tconst { field, schema } = subtree;\n\tconst arrayInterfaceName = \"TreeArray\";\n\tconst mapInterfaceName = \"TreeMap\";\n\tconst simpleSchema = getSimpleSchema(schema);\n\t// Inspect the schema to determine what kinds of nodes are possible - this will affect how much information we need to include in the prompt.\n\tlet hasArrays = false;\n\tlet hasMaps = false;\n\tlet exampleObjectName: string | undefined;\n\tfor (const [definition, nodeSchema] of simpleSchema.definitions) {\n\t\tswitch (nodeSchema.kind) {\n\t\t\tcase NodeKind.Array: {\n\t\t\t\thasArrays = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\thasMaps = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase NodeKind.Object: {\n\t\t\t\texampleObjectName ??= unqualifySchema(definition);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// No default\n\t\t}\n\t}\n\n\tconst { domainTypes } = generateEditTypesForPrompt(schema, simpleSchema);\n\tfor (const [key, value] of Object.entries(domainTypes)) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\tdelete domainTypes[key];\n\t\tif (isNamedSchema(key)) {\n\t\t\tconst friendlyKey = unqualifySchema(key);\n\t\t\tdomainTypes[friendlyKey] = value;\n\t\t}\n\t}\n\n\tconst stringified = stringifyTree(field);\n\tconst details: SchemaDetails = { hasHelperMethods: false };\n\tconst typescriptSchemaTypes = getZodSchemaAsTypeScript(domainTypes, details);\n\tconst helperMethodExplanation = details.hasHelperMethods\n\t\t? `Manipulating the data using the APIs described below is allowed, but when possible ALWAYS prefer to use any application helper methods exposed on the schema TypeScript types if the goal can be accomplished that way.\nIt will often not be possible to fully accomplish the goal using those helpers. When this is the case, mutate the objects as normal, taking into account the following guidance.`\n\t\t: \"\";\n\n\tconst builderExplanation =\n\t\texampleObjectName === undefined\n\t\t\t? \"\"\n\t\t\t: `When constructing new objects, you should wrap them in the appropriate builder function rather than simply making a javascript object.\nThe builders are available on the \\`create\\` property on the context object and are named according to the type that they create.\nFor example:\n\n\\`\\`\\`javascript\n// This creates a new ${exampleObjectName} object:\nconst ${communize(exampleObjectName)} = context.create.${exampleObjectName}({ /* ...properties... */ });\n// Don't do this:\n// const ${communize(exampleObjectName)} = { /* ...properties... */ };\n\\`\\`\\`\\n\\n`;\n\n\tconst arrayEditing = `#### Editing Arrays\n\nThe arrays in the tree are somewhat different than normal JavaScript \\`Array\\`s.\nRead-only operations are generally the same - you can create them, read via index, and call non-mutating methods like \\`concat\\`, \\`map\\`, \\`filter\\`, \\`find\\`, \\`forEach\\`, \\`indexOf\\`, \\`slice\\`, \\`join\\`, etc.\nHowever, write operations (e.g. index assignment, \\`push\\`, \\`pop\\`, \\`splice\\`, etc.) are not supported.\nInstead, you must use the methods on the following interface to mutate the array:\n\n\\`\\`\\`typescript\n${getTreeArrayNodeDocumentation(arrayInterfaceName)}\n\\`\\`\\`\n\nWhen possible, ensure that the edits preserve the identity of objects already in the tree.\nFor example, prefer \\`array.moveToIndex\\` over \\`array.removeAt\\` + \\`array.insertAt\\` and prefer \\`array.moveRangeToIndex\\` over \\`array.removeRange\\` + \\`array.insertAt\\`.\n\n`;\n\n\tconst mapEditing = `#### Editing Maps\n\nThe maps in the tree are somewhat different than normal JavaScript \\`Map\\`s.\nMap keys are always strings.\nRead-only operations are generally the same - you can create them, read via \\`get\\`, and call non-mutating methods like \\`has\\`, \\`forEach\\`, \\`entries\\`, \\`keys\\`, \\`values\\`, etc. (note the subtle differences around return values and iteration order).\nHowever, write operations (e.g. \\`set\\`, \\`delete\\`, etc.) are not supported.\nInstead, you must use the methods on the following interface to mutate the map:\n\n\\`\\`\\`typescript\n${getTreeMapNodeDocumentation(mapInterfaceName)}\n\\`\\`\\`\n\n`;\n\n\tconst rootTypes = normalizeFieldSchema(schema).allowedTypeSet;\n\tconst editing = `If the user asks you to edit the tree, you should author a snippet of JavaScript code to accomplish the user-specified goal, following the instructions for editing detailed below.\nYou must use the \"${editToolName}\" tool to run the generated code.\nAfter editing the tree, review the latest state of the tree to see if it satisfies the user's request.\nIf it does not, or if you receive an error, you may try again with a different approach.\nOnce the tree is in the desired state, you should inform the user that the request has been completed.\n\n### Editing\n\nIf the user asks you to edit the document, you will write a snippet of JavaScript code that mutates the data in-place to achieve the user's goal.\nThe snippet may be synchronous or asynchronous (i.e. it may \\`await\\` functions if necessary).\nThe snippet has a \\`context\\` variable in its scope.\nThis \\`context\\` variable holds the current state of the tree in the \\`root\\` property.\nYou may mutate any part of the root tree as necessary, taking into account the caveats around${hasArrays ? ` arrays${hasMaps ? \" and\" : \"\"}` : \"\"}${hasMaps ? \" maps\" : \"\"} detailed below.\nYou may also set the \\`root\\` property of the context to be an entirely new value as long as it is one of the types allowed at the root of the tree (\\`${Array.from(rootTypes.values(), (t) => getFriendlyName(t)).join(\" | \")}\\`).\n${helperMethodExplanation}\n\n${hasArrays ? arrayEditing : \"\"}${hasMaps ? mapEditing : \"\"}#### Additional Notes\n\nBefore outputting the edit function, you should check that it is valid according to both the application tree's schema and any restrictions of the editing APIs described above.\n\nOnce data has been removed from the tree (e.g. replaced via assignment, or removed from an array), that data cannot be re-inserted into the tree - instead, it must be deep cloned and recreated.\n\n${builderExplanation}Finally, double check that the edits would accomplish the user's request (if it is possible).\n\n`;\n\n\tconst prompt = `You are a helpful assistant collaborating with the user on a document. The document state is a JSON tree, and you are able to analyze and edit it.\nThe JSON tree adheres to the following Typescript schema:\n\n\\`\\`\\`typescript\n${typescriptSchemaTypes}\n\\`\\`\\`\n\nIf the user asks you a question about the tree, you should inspect the state of the tree and answer the question.\nWhen answering such a question, DO NOT answer with information that is not part of the document unless requested to do so.\n\n${editToolName === undefined ? \"\" : editing}### Application data\n\n${\n\tdomainHints === undefined\n\t\t? \"\"\n\t\t: `\\nThe application supplied the following additional instructions: ${domainHints}`\n}\nThe current state of \\`context.root\\` (a \\`${field === undefined ? \"undefined\" : getFriendlyName(Tree.schema(field))}\\`) is:\n\n\\`\\`\\`JSON\n${stringified}\n\\`\\`\\``;\n\treturn prompt;\n}\n\n/**\n * Serializes tree data e.g. to include in a prompt or message.\n * @remarks This includes some extra metadata to make it easier to understand the structure of the tree.\n */\nexport function stringifyTree(tree: ReadableField<ImplicitFieldSchema>): string {\n\tconst typeReplacementKey = \"_e944da5a5fd04ea2b8b2eb6109e089ed\";\n\tconst indexReplacementKey = \"_27bb216b474d45e6aaee14d1ec267b96\";\n\tconst mapReplacementKey = \"_a0d98d22a1c644539f07828d3f064d71\";\n\tconst stringified = JSON.stringify(\n\t\ttree,\n\t\t(_, node: unknown) => {\n\t\t\tif (node instanceof TreeNode) {\n\t\t\t\tconst key = Tree.key(node);\n\t\t\t\tconst index = typeof key === \"number\" ? key : undefined;\n\t\t\t\tconst schema = Tree.schema(node);\n\t\t\t\tswitch (schema.kind) {\n\t\t\t\t\tcase NodeKind.Object: {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t[typeReplacementKey]: getFriendlyName(schema),\n\t\t\t\t\t\t\t[indexReplacementKey]: index,\n\t\t\t\t\t\t\t...node,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Map: {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t[indexReplacementKey]: index,\n\t\t\t\t\t\t\t[mapReplacementKey]: \"\",\n\t\t\t\t\t\t\t...Object.fromEntries(node as TreeMapNode),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t[indexReplacementKey]: index,\n\t\t\t\t\t\t\t...node,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn node;\n\t\t},\n\t\t2,\n\t);\n\n\treturn stringified\n\t\t.replace(new RegExp(`\"${typeReplacementKey}\":`, \"g\"), `// Type:`)\n\t\t.replace(new RegExp(`\"${indexReplacementKey}\":`, \"g\"), `// Index:`)\n\t\t.replace(\n\t\t\tnew RegExp(`\"${mapReplacementKey}\": \"\"`, \"g\"),\n\t\t\t`// Note: This is a map that has been serialized to JSON. It is not a key-value object/record but is being printed as such.`,\n\t\t);\n}\n\n/**\n * Retrieves the documentation for the `TreeArrayNode` interface to feed to the LLM.\n * @remarks The documentation has been simplified in various ways to make it easier for the LLM to understand.\n * @privateRemarks TODO: How do we keep this in sync with the actual `TreeArrayNode` docs if/when those docs change?\n */\nfunction getTreeArrayNodeDocumentation(typeName: string): string {\n\treturn `/** A special type of array which implements 'readonly T[]' (i.e. it supports all read-only JS array methods) and provides custom array mutation APIs. */\nexport interface ${typeName}<T> extends ReadonlyArray<T> {\n\t/**\n\t * Inserts new item(s) at a specified location.\n\t * @param index - The index at which to insert \\`value\\`.\n\t * @param value - The content to insert.\n\t * @throws Throws if \\`index\\` is not in the range [0, \\`array.length\\`).\n\t */\n\tinsertAt(index: number, ...value: readonly T[]): void;\n\n\t/**\n\t * Removes the item at the specified location.\n\t * @param index - The index at which to remove the item.\n\t * @throws Throws if \\`index\\` is not in the range [0, \\`array.length\\`).\n\t */\n\tremoveAt(index: number): void;\n\n\t/**\n\t * Removes all items between the specified indices.\n\t * @param start - The starting index of the range to remove (inclusive). Defaults to the start of the array.\n\t * @param end - The ending index of the range to remove (exclusive). Defaults to \\`array.length\\`.\n\t * @throws Throws if \\`start\\` is not in the range [0, \\`array.length\\`].\n\t * @throws Throws if \\`end\\` is less than \\`start\\`.\n\t * If \\`end\\` is not supplied or is greater than the length of the array, all items after \\`start\\` are removed.\n\t *\n\t * @remarks\n\t * The default values for start and end are computed when this is called,\n\t * and thus the behavior is the same as providing them explicitly, even with respect to merge resolution with concurrent edits.\n\t * For example, two concurrent transactions both emptying the array with \\`node.removeRange()\\` then inserting an item,\n\t * will merge to result in the array having both inserted items.\n\t */\n\tremoveRange(start?: number, end?: number): void;\n\n\t/**\n\t * Moves the specified item to the desired location in the array.\n\t *\n\t * WARNING - This API is easily misused.\n\t * Please read the documentation for the \\`destinationGap\\` parameter carefully.\n\t *\n\t * @param destinationGap - The location *between* existing items that the moved item should be moved to.\n\t *\n\t * WARNING - \\`destinationGap\\` describes a location between existing items *prior to applying the move operation*.\n\t *\n\t * For example, if the array contains items \\`[A, B, C]\\` before the move, the \\`destinationGap\\` must be one of the following:\n\t *\n\t * - \\`0\\` (between the start of the array and \\`A\\`'s original position)\n\t * - \\`1\\` (between \\`A\\`'s original position and \\`B\\`'s original position)\n\t * - \\`2\\` (between \\`B\\`'s original position and \\`C\\`'s original position)\n\t * - \\`3\\` (between \\`C\\`'s original position and the end of the array)\n\t *\n\t * So moving \\`A\\` between \\`B\\` and \\`C\\` would require \\`destinationGap\\` to be \\`2\\`.\n\t *\n\t * This interpretation of \\`destinationGap\\` makes it easy to specify the desired destination relative to a sibling item that is not being moved,\n\t * or relative to the start or end of the array:\n\t *\n\t * - Move to the start of the array: \\`array.moveToIndex(0, ...)\\` (see also \\`moveToStart\\`)\n\t * - Move to before some item X: \\`array.moveToIndex(indexOfX, ...)\\`\n\t * - Move to after some item X: \\`array.moveToIndex(indexOfX + 1\\`, ...)\n\t * - Move to the end of the array: \\`array.moveToIndex(array.length, ...)\\` (see also \\`moveToEnd\\`)\n\t *\n\t * This interpretation of \\`destinationGap\\` does however make it less obvious how to move an item relative to its current position:\n\t *\n\t * - Move item B before its predecessor: \\`array.moveToIndex(indexOfB - 1, ...)\\`\n\t * - Move item B after its successor: \\`array.moveToIndex(indexOfB + 2, ...)\\`\n\t *\n\t * Notice the asymmetry between \\`-1\\` and \\`+2\\` in the above examples.\n\t * In such scenarios, it can often be easier to approach such edits by swapping adjacent items:\n\t * If items A and B are adjacent, such that A precedes B,\n\t * then they can be swapped with \\`array.moveToIndex(indexOfA, indexOfB)\\`.\n\t *\n\t * @param sourceIndex - The index of the item to move.\n\t * @param source - The optional source array to move the item out of (defaults to this array).\n\t * @throws Throws if any of the source index is not in the range [0, \\`array.length\\`),\n\t * or if the index is not in the range [0, \\`array.length\\`].\n\t */\n\tmoveToIndex(destinationGap: number, sourceIndex: number, source?: ${typeName}<T>): void;\n\n\t/**\n\t * Moves the specified items to the desired location within the array.\n\t *\n\t * WARNING - This API is easily misused.\n\t * Please read the documentation for the \\`destinationGap\\` parameter carefully.\n\t *\n\t * @param destinationGap - The location *between* existing items that the moved item should be moved to.\n\t *\n\t * WARNING - \\`destinationGap\\` describes a location between existing items *prior to applying the move operation*.\n\t *\n\t * For example, if the array contains items \\`[A, B, C]\\` before the move, the \\`destinationGap\\` must be one of the following:\n\t *\n\t * - \\`0\\` (between the start of the array and \\`A\\`'s original position)\n\t * - \\`1\\` (between \\`A\\`'s original position and \\`B\\`'s original position)\n\t * - \\`2\\` (between \\`B\\`'s original position and \\`C\\`'s original position)\n\t * - \\`3\\` (between \\`C\\`'s original position and the end of the array)\n\t *\n\t * So moving \\`A\\` between \\`B\\` and \\`C\\` would require \\`destinationGap\\` to be \\`2\\`.\n\t *\n\t * This interpretation of \\`destinationGap\\` makes it easy to specify the desired destination relative to a sibling item that is not being moved,\n\t * or relative to the start or end of the array:\n\t *\n\t * - Move to the start of the array: \\`array.moveToIndex(0, ...)\\` (see also \\`moveToStart\\`)\n\t * - Move to before some item X: \\`array.moveToIndex(indexOfX, ...)\\`\n\t * - Move to after some item X: \\`array.moveToIndex(indexOfX + 1\\`, ...)\n\t * - Move to the end of the array: \\`array.moveToIndex(array.length, ...)\\` (see also \\`moveToEnd\\`)\n\t *\n\t * This interpretation of \\`destinationGap\\` does however make it less obvious how to move an item relative to its current position:\n\t *\n\t * - Move item B before its predecessor: \\`array.moveToIndex(indexOfB - 1, ...)\\`\n\t * - Move item B after its successor: \\`array.moveToIndex(indexOfB + 2, ...)\\`\n\t *\n\t * Notice the asymmetry between \\`-1\\` and \\`+2\\` in the above examples.\n\t * In such scenarios, it can often be easier to approach such edits by swapping adjacent items:\n\t * If items A and B are adjacent, such that A precedes B,\n\t * then they can be swapped with \\`array.moveToIndex(indexOfA, indexOfB)\\`.\n\t *\n\t * @param sourceStart - The starting index of the range to move (inclusive).\n\t * @param sourceEnd - The ending index of the range to move (exclusive)\n\t * @param source - The optional source array to move items out of (defaults to this array).\n\t * @throws Throws if the types of any of the items being moved are not allowed in the destination array,\n\t * if any of the input indices are not in the range [0, \\`array.length\\`], or if \\`sourceStart\\` is greater than \\`sourceEnd\\`.\n\t */\n\tmoveRangeToIndex(\n\t\tdestinationGap: number,\n\t\tsourceStart: number,\n\t\tsourceEnd: number,\n\t\tsource?: ${typeName}<T>,\n\t): void;\n}`;\n}\n\n/**\n * Retrieves the documentation for the `TreeMapNode` interface to feed to the LLM.\n * @remarks The documentation has been simplified in various ways to make it easier for the LLM to understand.\n * @privateRemarks TODO: How do we keep this in sync with the actual `TreeMapNode` docs if/when those docs change?\n */\nfunction getTreeMapNodeDocumentation(typeName: string): string {\n\treturn `/**\n * A map of string keys to tree objects.\n */\nexport interface ${typeName}<T> extends ReadonlyMap<string, T> {\n\t/**\n\t * Adds or updates an entry in the map with a specified \\`key\\` and a \\`value\\`.\n\t *\n\t * @param key - The key of the element to add to the map.\n\t * @param value - The value of the element to add to the map.\n\t *\n\t * @remarks\n\t * Setting the value at a key to \\`undefined\\` is equivalent to calling {@link ${typeName}.delete} with that key.\n\t */\n\tset(key: string, value: T | undefined): void;\n\n\t/**\n\t * Removes the specified element from this map by its \\`key\\`.\n\t *\n\t * @remarks\n\t * Note: unlike JavaScript's Map API, this method does not return a flag indicating whether or not the value was\n\t * deleted.\n\t *\n\t * @param key - The key of the element to remove from the map.\n\t */\n\tdelete(key: string): void;\n\n\t/**\n\t * Returns an iterable of keys in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the keys returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tkeys(): IterableIterator<string>;\n\n\t/**\n\t * Returns an iterable of values in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the values returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tvalues(): IterableIterator<T>;\n\n\t/**\n\t * Returns an iterable of key/value pairs for every entry in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the entries returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tentries(): IterableIterator<[string, T]>;\n\n\t/**\n\t * Executes the provided function once per each key/value pair in this map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order in which the function is called with respect to the map's entries.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tforEach(\n\t\tcallbackfn: (\n\t\t\tvalue: T,\n\t\t\tkey: string,\n\t\t\tmap: ReadonlyMap<string, T>,\n\t\t) => void,\n\t\tthisArg?: any,\n\t): void;\n}`;\n}\n"]}
|
package/lib/ses.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { CompartmentOptions, LockdownOptions } from "ses";
|
|
6
|
+
import type { SemanticAgentOptions } from "./api.js";
|
|
7
|
+
/**
|
|
8
|
+
* Create an implementation of {@link SemanticAgentOptions.executeEdit} that uses the SES library to run the provided code in a secure environment.
|
|
9
|
+
* @param createCompartment - This function can be used to optionally configure the SES Compartment used to execute the code.
|
|
10
|
+
* The provided globals must be included in the compartment's globals and must not conflict with any additional globals passed in.
|
|
11
|
+
* @param lockdownOptions - Optional configuration passed to the SES `lockdown` function.
|
|
12
|
+
* @returns A function that can be used as the {@link SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
13
|
+
* @remarks This function will both import the SES library and call its `lockdown` function the first time it is called.
|
|
14
|
+
* Therefore, this function should be called only once, early in an application's lifetime.
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSesEditEvaluator(options?: {
|
|
18
|
+
compartmentOptions?: CompartmentOptions;
|
|
19
|
+
lockdownOptions?: LockdownOptions;
|
|
20
|
+
}): Promise<SemanticAgentOptions["executeEdit"]>;
|
|
21
|
+
//# sourceMappingURL=ses.d.ts.map
|
package/lib/ses.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ses.d.ts","sourceRoot":"","sources":["../src/ses.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAE/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAKrD;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,CAAC,EAAE;IACtD,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,eAAe,CAAC,EAAE,eAAe,CAAC;CAClC,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC,CA+C/C"}
|
package/lib/ses.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { toErrorString } from "./utils.js";
|
|
6
|
+
const lockdownSymbol = Symbol.for("tree-agent.ses.locked");
|
|
7
|
+
/**
|
|
8
|
+
* Create an implementation of {@link SemanticAgentOptions.executeEdit} that uses the SES library to run the provided code in a secure environment.
|
|
9
|
+
* @param createCompartment - This function can be used to optionally configure the SES Compartment used to execute the code.
|
|
10
|
+
* The provided globals must be included in the compartment's globals and must not conflict with any additional globals passed in.
|
|
11
|
+
* @param lockdownOptions - Optional configuration passed to the SES `lockdown` function.
|
|
12
|
+
* @returns A function that can be used as the {@link SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
13
|
+
* @remarks This function will both import the SES library and call its `lockdown` function the first time it is called.
|
|
14
|
+
* Therefore, this function should be called only once, early in an application's lifetime.
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
export async function createSesEditEvaluator(options) {
|
|
18
|
+
const optionsGlobals = options?.compartmentOptions?.globals ?? new Map();
|
|
19
|
+
if (optionsGlobals.has("context") === true) {
|
|
20
|
+
throw new Error("The 'context' global is reserved and cannot be overridden in the compartment options.");
|
|
21
|
+
}
|
|
22
|
+
// Importing 'ses' has side effects, so we do it lazily to avoid impacting environments that don't use this evaluator.
|
|
23
|
+
await import("ses");
|
|
24
|
+
if (!(lockdownSymbol in globalThis)) {
|
|
25
|
+
try {
|
|
26
|
+
lockdown(options?.lockdownOptions);
|
|
27
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
28
|
+
value: true,
|
|
29
|
+
writable: false,
|
|
30
|
+
configurable: false,
|
|
31
|
+
enumerable: false,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (toErrorString(error).includes("SES_ALREADY_LOCKED_DOWN")) {
|
|
36
|
+
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
37
|
+
value: true,
|
|
38
|
+
writable: false,
|
|
39
|
+
configurable: false,
|
|
40
|
+
enumerable: false,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return async (context, code) => {
|
|
49
|
+
const compartmentOptions = {
|
|
50
|
+
...options?.compartmentOptions,
|
|
51
|
+
globals: {
|
|
52
|
+
...Object.fromEntries(optionsGlobals),
|
|
53
|
+
context,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const compartment = new Compartment({ ...compartmentOptions, __options__: true });
|
|
57
|
+
await compartment.evaluate(code);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|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;iBAAM,CAAC;gBACP,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,EAAE,OAAgC,EAAE,IAAY,EAAE,EAAE;QAC/D,MAAM,kBAAkB,GAAG;YAC1B,GAAG,OAAO,EAAE,kBAAkB;YAC9B,OAAO,EAAE;gBACR,GAAG,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC;gBACrC,OAAO;aACP;SACD,CAAC;QAEF,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,EAAE,GAAG,kBAAkB,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;QAClF,MAAM,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { CompartmentOptions, LockdownOptions } from \"ses\";\n\nimport type { SemanticAgentOptions } from \"./api.js\";\nimport { toErrorString } from \"./utils.js\";\n\nconst lockdownSymbol = Symbol.for(\"tree-agent.ses.locked\");\n\n/**\n * Create an implementation of {@link SemanticAgentOptions.executeEdit} that uses the SES library to run the provided code in a secure environment.\n * @param createCompartment - This function can be used to optionally configure the SES Compartment used to execute the code.\n * The provided globals must be included in the compartment's globals and must not conflict with any additional globals passed in.\n * @param lockdownOptions - Optional configuration passed to the SES `lockdown` function.\n * @returns A function that can be used as the {@link SemanticAgentOptions.executeEdit | executeEdit} callback.\n * @remarks This function will both import the SES library and call its `lockdown` function the first time it is called.\n * Therefore, this function should be called only once, early in an application's lifetime.\n * @alpha\n */\nexport async function createSesEditEvaluator(options?: {\n\tcompartmentOptions?: CompartmentOptions;\n\tlockdownOptions?: LockdownOptions;\n}): Promise<SemanticAgentOptions[\"executeEdit\"]> {\n\tconst optionsGlobals: Map<string, unknown> =\n\t\toptions?.compartmentOptions?.globals ?? new Map<string, unknown>();\n\tif (optionsGlobals.has(\"context\") === true) {\n\t\tthrow new Error(\n\t\t\t\"The 'context' global is reserved and cannot be overridden in the compartment options.\",\n\t\t);\n\t}\n\n\t// Importing 'ses' has side effects, so we do it lazily to avoid impacting environments that don't use this evaluator.\n\tawait import(\"ses\");\n\n\tif (!(lockdownSymbol in globalThis)) {\n\t\ttry {\n\t\t\tlockdown(options?.lockdownOptions);\n\t\t\tObject.defineProperty(globalThis, lockdownSymbol, {\n\t\t\t\tvalue: true,\n\t\t\t\twritable: false,\n\t\t\t\tconfigurable: false,\n\t\t\t\tenumerable: false,\n\t\t\t});\n\t\t} catch (error: unknown) {\n\t\t\tif (toErrorString(error).includes(\"SES_ALREADY_LOCKED_DOWN\")) {\n\t\t\t\tObject.defineProperty(globalThis, lockdownSymbol, {\n\t\t\t\t\tvalue: true,\n\t\t\t\t\twritable: false,\n\t\t\t\t\tconfigurable: false,\n\t\t\t\t\tenumerable: false,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn async (context: Record<string, unknown>, code: string) => {\n\t\tconst compartmentOptions = {\n\t\t\t...options?.compartmentOptions,\n\t\t\tglobals: {\n\t\t\t\t...Object.fromEntries(optionsGlobals),\n\t\t\t\tcontext,\n\t\t\t},\n\t\t};\n\n\t\tconst compartment = new Compartment({ ...compartmentOptions, __options__: true });\n\t\tawait compartment.evaluate(code);\n\t};\n}\n"]}
|
package/lib/utils.d.ts
CHANGED
|
@@ -124,4 +124,8 @@ export declare function findNamedSchemas(schema: ImplicitFieldSchema, schemas?:
|
|
|
124
124
|
* De-capitalize (the first letter of) a string.
|
|
125
125
|
*/
|
|
126
126
|
export declare function communize(str: string): string;
|
|
127
|
+
/**
|
|
128
|
+
* Stringify an unknown error value
|
|
129
|
+
*/
|
|
130
|
+
export declare function toErrorString(error: unknown): string;
|
|
127
131
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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AE,CAAC,GACP,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAO3D;AAID;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,mBAAmB,EAC3B,OAAO,sBAA4B,GACjC,GAAG,CAAC,cAAc,CAAC,CAWrB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD"}
|
package/lib/utils.js
CHANGED
|
@@ -501,4 +501,18 @@ export function findNamedSchemas(schema, schemas = new Set()) {
|
|
|
501
501
|
export function communize(str) {
|
|
502
502
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
503
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Stringify an unknown error value
|
|
506
|
+
*/
|
|
507
|
+
export function toErrorString(error) {
|
|
508
|
+
if (error instanceof Error) {
|
|
509
|
+
return error.message;
|
|
510
|
+
}
|
|
511
|
+
try {
|
|
512
|
+
return JSON.stringify(error);
|
|
513
|
+
}
|
|
514
|
+
catch {
|
|
515
|
+
return String(error);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
504
518
|
//# sourceMappingURL=utils.js.map
|