@fluidframework/tree-agent 2.63.0-359734 → 2.63.0-359962
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 +0 -28
- package/dist/alpha.d.ts +0 -3
- package/dist/api.d.ts +4 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/lib/alpha.d.ts +0 -3
- package/lib/api.d.ts +4 -3
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js.map +1 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/package.json +11 -12
- package/src/api.ts +4 -3
- package/src/index.ts +0 -2
- package/dist/langchain.d.ts +0 -43
- package/dist/langchain.d.ts.map +0 -1
- package/dist/langchain.js +0 -89
- package/dist/langchain.js.map +0 -1
- package/dist/ses.d.ts +0 -21
- package/dist/ses.d.ts.map +0 -1
- package/dist/ses.js +0 -64
- package/dist/ses.js.map +0 -1
- package/lib/langchain.d.ts +0 -43
- package/lib/langchain.d.ts.map +0 -1
- package/lib/langchain.js +0 -83
- package/lib/langchain.js.map +0 -1
- package/lib/ses.d.ts +0 -21
- package/lib/ses.d.ts.map +0 -1
- package/lib/ses.js +0 -60
- package/lib/ses.js.map +0 -1
- package/src/langchain.ts +0 -145
- package/src/ses.ts +0 -73
|
@@ -20,21 +20,6 @@ export function buildFunc<const Return extends z.ZodTypeAny, const Args extends
|
|
|
20
20
|
rest?: Rest;
|
|
21
21
|
}, ...args: Args): FunctionDef<Args, Return, Rest>;
|
|
22
22
|
|
|
23
|
-
// @alpha @deprecated
|
|
24
|
-
export function createSemanticAgent<TSchema extends ImplicitFieldSchema_2>(client: BaseChatModel, treeView: TreeView<TSchema>, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
25
|
-
|
|
26
|
-
// @alpha @deprecated
|
|
27
|
-
export function createSemanticAgent<TSchema extends ImplicitFieldSchema_2>(client: BaseChatModel, node: ReadableField<TSchema> & TreeNode_2, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
28
|
-
|
|
29
|
-
// @alpha @deprecated
|
|
30
|
-
export function createSemanticAgent<TSchema extends ImplicitFieldSchema_2>(client: BaseChatModel, treeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode_2), options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
31
|
-
|
|
32
|
-
// @alpha
|
|
33
|
-
export function createSesEditEvaluator(options?: {
|
|
34
|
-
compartmentOptions?: CompartmentOptions;
|
|
35
|
-
lockdownOptions?: LockdownOptions;
|
|
36
|
-
}): Promise<SemanticAgentOptions["executeEdit"]>;
|
|
37
|
-
|
|
38
23
|
// @alpha
|
|
39
24
|
export type Ctor<T = any> = new (...args: any[]) => T;
|
|
40
25
|
|
|
@@ -78,19 +63,6 @@ export interface IExposedMethods {
|
|
|
78
63
|
// @alpha
|
|
79
64
|
export type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest> ? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>> : never;
|
|
80
65
|
|
|
81
|
-
// @alpha
|
|
82
|
-
export class LangchainChatModel implements SharedTreeChatModel {
|
|
83
|
-
constructor(model: BaseChatModel);
|
|
84
|
-
// (undocumented)
|
|
85
|
-
appendContext(text: string): void;
|
|
86
|
-
// (undocumented)
|
|
87
|
-
readonly editToolName = "GenerateTreeEditingCode";
|
|
88
|
-
// (undocumented)
|
|
89
|
-
get name(): string | undefined;
|
|
90
|
-
// (undocumented)
|
|
91
|
-
query(query: SharedTreeChatQuery): Promise<string>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
66
|
// @alpha
|
|
95
67
|
export const llmDefault: unique symbol;
|
|
96
68
|
|
package/dist/alpha.d.ts
CHANGED
|
@@ -25,7 +25,6 @@ export {
|
|
|
25
25
|
FunctionDef,
|
|
26
26
|
IExposedMethods,
|
|
27
27
|
Infer,
|
|
28
|
-
LangchainChatModel,
|
|
29
28
|
Logger,
|
|
30
29
|
MethodKeys,
|
|
31
30
|
SemanticAgentOptions,
|
|
@@ -34,8 +33,6 @@ export {
|
|
|
34
33
|
SharedTreeSemanticAgent,
|
|
35
34
|
TreeView,
|
|
36
35
|
buildFunc,
|
|
37
|
-
createSemanticAgent,
|
|
38
|
-
createSesEditEvaluator,
|
|
39
36
|
exposeMethodsSymbol,
|
|
40
37
|
llmDefault
|
|
41
38
|
// #endregion
|
package/dist/api.d.ts
CHANGED
|
@@ -31,13 +31,13 @@ export interface SemanticAgentOptions {
|
|
|
31
31
|
*/
|
|
32
32
|
validateEdit?: (code: string) => void | Promise<void>;
|
|
33
33
|
/**
|
|
34
|
-
* Evaluates
|
|
34
|
+
* Evaluates/runs any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.
|
|
35
35
|
* @remarks This happens only after the code has been successfully validated by the optional {@link SemanticAgentOptions.validateEdit | validateEdit} function.
|
|
36
36
|
* @param context - An object that must be provided to the generated code as a variable named "context" in its top-level scope.
|
|
37
37
|
* @param code - The generated JavaScript code as a string.
|
|
38
|
-
* @throws If an error is thrown while
|
|
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
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.
|
|
40
|
-
* Use a library such as SES to provide a more secure implementation - see
|
|
40
|
+
* Use a library such as SES to provide a more secure implementation - see `@fluidframework/tree-agent-ses` for a drop-in implementation.
|
|
41
41
|
*/
|
|
42
42
|
executeEdit?: (context: Record<string, unknown>, code: string) => void | Promise<void>;
|
|
43
43
|
/**
|
|
@@ -91,6 +91,7 @@ export interface SharedTreeChatQuery {
|
|
|
91
91
|
/**
|
|
92
92
|
* A plugin interface that handles queries from a {@link SharedTreeSemanticAgent}.
|
|
93
93
|
* @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.
|
|
94
|
+
* See `@fluidframework/tree-agent-langchain` for a drop-in implementation based on the LangChain library.
|
|
94
95
|
* @alpha
|
|
95
96
|
*/
|
|
96
97
|
export interface SharedTreeChatModel {
|
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;AAEtF;;;GAGG;AACH,MAAM,WAAW,MAAM;IACtB;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvF;;OAEG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,UAAU;IAC1B,IAAI,EACD,SAAS,GAC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AAI,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
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAgFH;;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 * @remarks\n * - `success`: The edit was successfully applied.\n * - `disabledError`: The model is not allowed to edit the tree (i.e. {@link SharedTreeChatModel.editToolName} was not provided).\n * - `validationError`: The provided JavaScript did not pass the optional {@link SemanticAgentOptions.validateEdit} function.\n * - `executionError`: An error was thrown while parsing or executing the provided JavaScript.\n * - `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 * - `expiredError`: The {@link SharedTreeChatQuery.edit} function was called after the issuing query has already completed.\n * @alpha\n */\nexport interface EditResult {\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 */\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
|
@@ -11,6 +11,4 @@ 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
|
-
export { LangchainChatModel, createSemanticAgent } from "./langchain.js";
|
|
15
|
-
export { createSesEditEvaluator } from "./ses.js";
|
|
16
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,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
|
|
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"}
|
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.
|
|
7
|
+
exports.exposeMethodsSymbol = exports.buildFunc = exports.llmDefault = 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
|
*
|
|
@@ -17,9 +17,4 @@ Object.defineProperty(exports, "llmDefault", { enumerable: true, get: function (
|
|
|
17
17
|
var methodBinding_js_1 = require("./methodBinding.js");
|
|
18
18
|
Object.defineProperty(exports, "buildFunc", { enumerable: true, get: function () { return methodBinding_js_1.buildFunc; } });
|
|
19
19
|
Object.defineProperty(exports, "exposeMethodsSymbol", { enumerable: true, get: function () { return methodBinding_js_1.exposeMethodsSymbol; } });
|
|
20
|
-
var langchain_js_1 = require("./langchain.js");
|
|
21
|
-
Object.defineProperty(exports, "LangchainChatModel", { enumerable: true, get: function () { return langchain_js_1.LangchainChatModel; } });
|
|
22
|
-
Object.defineProperty(exports, "createSemanticAgent", { enumerable: true, get: function () { return langchain_js_1.createSemanticAgent; } });
|
|
23
|
-
var ses_js_1 = require("./ses.js");
|
|
24
|
-
Object.defineProperty(exports, "createSesEditEvaluator", { enumerable: true, get: function () { return ses_js_1.createSesEditEvaluator; } });
|
|
25
20
|
//# sourceMappingURL=index.js.map
|
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,uCAAqD;AAA5C,mHAAA,uBAAuB,OAAA;AAQhC,uCAAuD;AAA/B,sGAAA,UAAU,OAAA;AAClC,uDAY4B;AAX3B,6GAAA,SAAS,OAAA;AACT,uHAAA,mBAAmB,OAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH,uCAAqD;AAA5C,mHAAA,uBAAuB,OAAA;AAQhC,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 { 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\";\n"]}
|
package/lib/alpha.d.ts
CHANGED
|
@@ -25,7 +25,6 @@ export {
|
|
|
25
25
|
FunctionDef,
|
|
26
26
|
IExposedMethods,
|
|
27
27
|
Infer,
|
|
28
|
-
LangchainChatModel,
|
|
29
28
|
Logger,
|
|
30
29
|
MethodKeys,
|
|
31
30
|
SemanticAgentOptions,
|
|
@@ -34,8 +33,6 @@ export {
|
|
|
34
33
|
SharedTreeSemanticAgent,
|
|
35
34
|
TreeView,
|
|
36
35
|
buildFunc,
|
|
37
|
-
createSemanticAgent,
|
|
38
|
-
createSesEditEvaluator,
|
|
39
36
|
exposeMethodsSymbol,
|
|
40
37
|
llmDefault
|
|
41
38
|
// #endregion
|
package/lib/api.d.ts
CHANGED
|
@@ -31,13 +31,13 @@ export interface SemanticAgentOptions {
|
|
|
31
31
|
*/
|
|
32
32
|
validateEdit?: (code: string) => void | Promise<void>;
|
|
33
33
|
/**
|
|
34
|
-
* Evaluates
|
|
34
|
+
* Evaluates/runs any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.
|
|
35
35
|
* @remarks This happens only after the code has been successfully validated by the optional {@link SemanticAgentOptions.validateEdit | validateEdit} function.
|
|
36
36
|
* @param context - An object that must be provided to the generated code as a variable named "context" in its top-level scope.
|
|
37
37
|
* @param code - The generated JavaScript code as a string.
|
|
38
|
-
* @throws If an error is thrown while
|
|
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
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.
|
|
40
|
-
* Use a library such as SES to provide a more secure implementation - see
|
|
40
|
+
* Use a library such as SES to provide a more secure implementation - see `@fluidframework/tree-agent-ses` for a drop-in implementation.
|
|
41
41
|
*/
|
|
42
42
|
executeEdit?: (context: Record<string, unknown>, code: string) => void | Promise<void>;
|
|
43
43
|
/**
|
|
@@ -91,6 +91,7 @@ export interface SharedTreeChatQuery {
|
|
|
91
91
|
/**
|
|
92
92
|
* A plugin interface that handles queries from a {@link SharedTreeSemanticAgent}.
|
|
93
93
|
* @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.
|
|
94
|
+
* See `@fluidframework/tree-agent-langchain` for a drop-in implementation based on the LangChain library.
|
|
94
95
|
* @alpha
|
|
95
96
|
*/
|
|
96
97
|
export interface SharedTreeChatModel {
|
package/lib/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;AAEtF;;;GAGG;AACH,MAAM,WAAW,MAAM;IACtB;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvF;;OAEG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,UAAU;IAC1B,IAAI,EACD,SAAS,GACT,eAAe,GACf,iBAAiB,GACjB,gBAAgB,GAChB,mBAAmB,GACnB,cA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AO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CACN,OAAQ,KAAoB,CAAC,IAAI,KAAK,QAAQ;QAC9C,OAAQ,KAAoB,CAAC,OAAO,KAAK,QAAQ,CACjD,CAAC;AACH,CAAC","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
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgFH;;GAEG;AACH,MAAM,UAAU,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","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 * @remarks\n * - `success`: The edit was successfully applied.\n * - `disabledError`: The model is not allowed to edit the tree (i.e. {@link SharedTreeChatModel.editToolName} was not provided).\n * - `validationError`: The provided JavaScript did not pass the optional {@link SemanticAgentOptions.validateEdit} function.\n * - `executionError`: An error was thrown while parsing or executing the provided JavaScript.\n * - `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 * - `expiredError`: The {@link SharedTreeChatQuery.edit} function was called after the issuing query has already completed.\n * @alpha\n */\nexport interface EditResult {\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 */\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/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,4 @@ 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
|
-
export { LangchainChatModel, createSemanticAgent } from "./langchain.js";
|
|
15
|
-
export { createSesEditEvaluator } from "./ses.js";
|
|
16
14
|
//# 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,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
|
|
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"}
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,4 @@
|
|
|
10
10
|
export { SharedTreeSemanticAgent } from "./agent.js";
|
|
11
11
|
export { llmDefault } from "./utils.js";
|
|
12
12
|
export { buildFunc, exposeMethodsSymbol, } from "./methodBinding.js";
|
|
13
|
-
export { LangchainChatModel, createSemanticAgent } from "./langchain.js";
|
|
14
|
-
export { createSesEditEvaluator } from "./ses.js";
|
|
15
13
|
//# 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;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
|
|
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","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\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/tree-agent",
|
|
3
|
-
"version": "2.63.0-
|
|
3
|
+
"version": "2.63.0-359962",
|
|
4
4
|
"description": "Experimental package to simplify integrating AI into Fluid-based applications",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -70,28 +70,26 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
73
|
-
"@fluidframework/core-utils": "2.63.0-
|
|
74
|
-
"@fluidframework/runtime-utils": "2.63.0-
|
|
75
|
-
"@fluidframework/telemetry-utils": "2.63.0-
|
|
76
|
-
"@fluidframework/tree": "2.63.0-
|
|
77
|
-
"@langchain/core": "^0.3.66",
|
|
78
|
-
"langchain": "^0.3.30",
|
|
79
|
-
"ses": "^1.14.0",
|
|
73
|
+
"@fluidframework/core-utils": "2.63.0-359962",
|
|
74
|
+
"@fluidframework/runtime-utils": "2.63.0-359962",
|
|
75
|
+
"@fluidframework/telemetry-utils": "2.63.0-359962",
|
|
76
|
+
"@fluidframework/tree": "2.63.0-359962",
|
|
80
77
|
"uuid": "^11.1.0",
|
|
81
78
|
"zod": "^3.25.32"
|
|
82
79
|
},
|
|
83
80
|
"devDependencies": {
|
|
84
81
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
85
82
|
"@biomejs/biome": "~1.9.3",
|
|
86
|
-
"@fluid-internal/mocha-test-setup": "2.63.0-
|
|
83
|
+
"@fluid-internal/mocha-test-setup": "2.63.0-359962",
|
|
87
84
|
"@fluid-tools/build-cli": "^0.58.3",
|
|
88
85
|
"@fluidframework/build-common": "^2.0.3",
|
|
89
86
|
"@fluidframework/build-tools": "^0.58.3",
|
|
90
87
|
"@fluidframework/eslint-config-fluid": "^6.0.0",
|
|
91
|
-
"@fluidframework/id-compressor": "2.63.0-
|
|
92
|
-
"@fluidframework/runtime-utils": "2.63.0-
|
|
93
|
-
"@fluidframework/test-runtime-utils": "2.63.0-
|
|
88
|
+
"@fluidframework/id-compressor": "2.63.0-359962",
|
|
89
|
+
"@fluidframework/runtime-utils": "2.63.0-359962",
|
|
90
|
+
"@fluidframework/test-runtime-utils": "2.63.0-359962",
|
|
94
91
|
"@langchain/anthropic": "^0.3.24",
|
|
92
|
+
"@langchain/core": "^0.3.78",
|
|
95
93
|
"@langchain/google-genai": "^0.2.16",
|
|
96
94
|
"@langchain/openai": "^0.6.12",
|
|
97
95
|
"@microsoft/api-extractor": "7.52.11",
|
|
@@ -108,6 +106,7 @@
|
|
|
108
106
|
"mocha-multi-reporters": "^1.5.1",
|
|
109
107
|
"prettier": "~3.0.3",
|
|
110
108
|
"rimraf": "^4.4.0",
|
|
109
|
+
"ses": "^1.14.0",
|
|
111
110
|
"typescript": "~5.4.5"
|
|
112
111
|
},
|
|
113
112
|
"fluidBuild": {
|
package/src/api.ts
CHANGED
|
@@ -35,13 +35,13 @@ export interface SemanticAgentOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
validateEdit?: (code: string) => void | Promise<void>;
|
|
37
37
|
/**
|
|
38
|
-
* Evaluates
|
|
38
|
+
* Evaluates/runs any generated JavaScript created by the {@link SharedTreeChatModel.editToolName | model's editing tool}.
|
|
39
39
|
* @remarks This happens only after the code has been successfully validated by the optional {@link SemanticAgentOptions.validateEdit | validateEdit} function.
|
|
40
40
|
* @param context - An object that must be provided to the generated code as a variable named "context" in its top-level scope.
|
|
41
41
|
* @param code - The generated JavaScript code as a string.
|
|
42
|
-
* @throws If an error is thrown while
|
|
42
|
+
* @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.
|
|
43
43
|
* @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.
|
|
44
|
-
* Use a library such as SES to provide a more secure implementation - see
|
|
44
|
+
* Use a library such as SES to provide a more secure implementation - see `@fluidframework/tree-agent-ses` for a drop-in implementation.
|
|
45
45
|
*/
|
|
46
46
|
executeEdit?: (context: Record<string, unknown>, code: string) => void | Promise<void>;
|
|
47
47
|
/**
|
|
@@ -114,6 +114,7 @@ export interface SharedTreeChatQuery {
|
|
|
114
114
|
/**
|
|
115
115
|
* A plugin interface that handles queries from a {@link SharedTreeSemanticAgent}.
|
|
116
116
|
* @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.
|
|
117
|
+
* See `@fluidframework/tree-agent-langchain` for a drop-in implementation based on the LangChain library.
|
|
117
118
|
* @alpha
|
|
118
119
|
*/
|
|
119
120
|
export interface SharedTreeChatModel {
|
package/src/index.ts
CHANGED
package/dist/langchain.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import type { ImplicitFieldSchema, ReadableField, TreeNode } from "@fluidframework/tree/alpha";
|
|
6
|
-
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
7
|
-
import { SharedTreeSemanticAgent } from "./agent.js";
|
|
8
|
-
import { type SemanticAgentOptions, type SharedTreeChatModel, type SharedTreeChatQuery } from "./api.js";
|
|
9
|
-
import type { TreeView } from "./utils.js";
|
|
10
|
-
/**
|
|
11
|
-
* An implementation of {@link SharedTreeChatModel} that wraps a Langchain chat model.
|
|
12
|
-
* @remarks This class is responsible for managing the conversation history and interacting with the Langchain model (e.g. via Tool use for editing).
|
|
13
|
-
* @alpha
|
|
14
|
-
*/
|
|
15
|
-
export declare class LangchainChatModel implements SharedTreeChatModel {
|
|
16
|
-
private readonly model;
|
|
17
|
-
private readonly messages;
|
|
18
|
-
constructor(model: BaseChatModel);
|
|
19
|
-
readonly editToolName = "GenerateTreeEditingCode";
|
|
20
|
-
get name(): string | undefined;
|
|
21
|
-
appendContext(text: string): void;
|
|
22
|
-
query(query: SharedTreeChatQuery): Promise<string>;
|
|
23
|
-
private queryEdit;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
27
|
-
* @alpha
|
|
28
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
29
|
-
*/
|
|
30
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema>, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
31
|
-
/**
|
|
32
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
33
|
-
* @alpha
|
|
34
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
35
|
-
*/
|
|
36
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, node: ReadableField<TSchema> & TreeNode, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
37
|
-
/**
|
|
38
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
39
|
-
* @alpha
|
|
40
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
41
|
-
*/
|
|
42
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
43
|
-
//# sourceMappingURL=langchain.d.ts.map
|
package/dist/langchain.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/dist/langchain.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.createSemanticAgent = exports.LangchainChatModel = void 0;
|
|
11
|
-
const internal_1 = require("@fluidframework/telemetry-utils/internal");
|
|
12
|
-
const messages_1 = require("@langchain/core/messages");
|
|
13
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
14
|
-
const tools_1 = require("@langchain/core/tools");
|
|
15
|
-
const zod_1 = __importDefault(require("zod"));
|
|
16
|
-
const agent_js_1 = require("./agent.js");
|
|
17
|
-
const api_js_1 = require("./api.js");
|
|
18
|
-
/**
|
|
19
|
-
* An implementation of {@link SharedTreeChatModel} that wraps a Langchain chat model.
|
|
20
|
-
* @remarks This class is responsible for managing the conversation history and interacting with the Langchain model (e.g. via Tool use for editing).
|
|
21
|
-
* @alpha
|
|
22
|
-
*/
|
|
23
|
-
class LangchainChatModel {
|
|
24
|
-
constructor(model) {
|
|
25
|
-
this.model = model;
|
|
26
|
-
this.messages = [];
|
|
27
|
-
this.editToolName = "GenerateTreeEditingCode";
|
|
28
|
-
}
|
|
29
|
-
get name() {
|
|
30
|
-
const name = this.model.metadata?.modelName;
|
|
31
|
-
return typeof name === "string" ? name : undefined;
|
|
32
|
-
}
|
|
33
|
-
appendContext(text) {
|
|
34
|
-
this.messages.push(new messages_1.SystemMessage(text));
|
|
35
|
-
}
|
|
36
|
-
async query(query) {
|
|
37
|
-
this.messages.push(new messages_1.HumanMessage(query.text));
|
|
38
|
-
return this.queryEdit(async (js) => query.edit(js));
|
|
39
|
-
}
|
|
40
|
-
async queryEdit(edit) {
|
|
41
|
-
const editingTool = (0, tools_1.tool)(async ({ functionCode }) => {
|
|
42
|
-
return edit(functionCode);
|
|
43
|
-
}, {
|
|
44
|
-
name: this.editToolName,
|
|
45
|
-
description: `Invokes a JavaScript code snippet to edit a tree of application data.`,
|
|
46
|
-
schema: zod_1.default.object({
|
|
47
|
-
functionCode: zod_1.default.string().describe(`The JavaScript snippet code.`),
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
const runnable = this.model.bindTools?.([editingTool], { tool_choice: "auto" });
|
|
51
|
-
if (runnable === undefined) {
|
|
52
|
-
throw new internal_1.UsageError("LLM client must support function calling or tool use.");
|
|
53
|
-
}
|
|
54
|
-
const responseMessage = await runnable.invoke(this.messages);
|
|
55
|
-
this.messages.push(responseMessage);
|
|
56
|
-
if (responseMessage.tool_calls !== undefined && responseMessage.tool_calls.length > 0) {
|
|
57
|
-
for (const toolCall of responseMessage.tool_calls) {
|
|
58
|
-
switch (toolCall.name) {
|
|
59
|
-
case editingTool.name: {
|
|
60
|
-
const toolResult = await editingTool.invoke(toolCall);
|
|
61
|
-
this.messages.push(toolResult);
|
|
62
|
-
const editResult = JSON.parse(toolResult.text);
|
|
63
|
-
if ((0, api_js_1.isEditResult)(editResult) && editResult.type === "tooManyEditsError") {
|
|
64
|
-
return editResult.message;
|
|
65
|
-
}
|
|
66
|
-
// This call will either terminate the edit chain (if the LLM decides not to edit further) or continue it if more edits are required.
|
|
67
|
-
return this.queryEdit(edit);
|
|
68
|
-
}
|
|
69
|
-
default: {
|
|
70
|
-
this.messages.push(new messages_1.HumanMessage(`Unrecognized tool call: ${toolCall.name}`));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return responseMessage.text;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.LangchainChatModel = LangchainChatModel;
|
|
79
|
-
/**
|
|
80
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
81
|
-
* @alpha
|
|
82
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
83
|
-
*/
|
|
84
|
-
function createSemanticAgent(client, treeView, options) {
|
|
85
|
-
return new agent_js_1.SharedTreeSemanticAgent(new LangchainChatModel(client), treeView, options);
|
|
86
|
-
}
|
|
87
|
-
exports.createSemanticAgent = createSemanticAgent;
|
|
88
|
-
// #endregion Legacy APIs
|
|
89
|
-
//# sourceMappingURL=langchain.js.map
|
package/dist/langchain.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"langchain.js","sourceRoot":"","sources":["../src/langchain.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,uEAAsE;AAMtE,uDAIkC;AAClC,sDAAsD;AACtD,iDAA6C;AAC7C,8CAAoB;AAEpB,yCAAqD;AACrD,qCAKkB;A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,CAAC;IAC7B,CAAC;CACD;AA/DD,gDA+DC;AAkCD;;;;GAIG;AACH,SAAgB,mBAAmB,CAClC,MAAqB,EACrB,QAAiE,EACjE,OAAwC;IAExC,OAAO,IAAI,kCAAuB,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC;AAND,kDAMC;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/dist/ses.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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/dist/ses.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/dist/ses.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.createSesEditEvaluator = void 0;
|
|
8
|
-
const utils_js_1 = require("./utils.js");
|
|
9
|
-
const lockdownSymbol = Symbol.for("tree-agent.ses.locked");
|
|
10
|
-
/**
|
|
11
|
-
* Create an implementation of {@link SemanticAgentOptions.executeEdit} that uses the SES library to run the provided code in a secure environment.
|
|
12
|
-
* @param createCompartment - This function can be used to optionally configure the SES Compartment used to execute the code.
|
|
13
|
-
* The provided globals must be included in the compartment's globals and must not conflict with any additional globals passed in.
|
|
14
|
-
* @param lockdownOptions - Optional configuration passed to the SES `lockdown` function.
|
|
15
|
-
* @returns A function that can be used as the {@link SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
16
|
-
* @remarks This function will both import the SES library and call its `lockdown` function the first time it is called.
|
|
17
|
-
* Therefore, this function should be called only once, early in an application's lifetime.
|
|
18
|
-
* @alpha
|
|
19
|
-
*/
|
|
20
|
-
async function createSesEditEvaluator(options) {
|
|
21
|
-
const optionsGlobals = options?.compartmentOptions?.globals ?? new Map();
|
|
22
|
-
if (optionsGlobals.has("context") === true) {
|
|
23
|
-
throw new Error("The 'context' global is reserved and cannot be overridden in the compartment options.");
|
|
24
|
-
}
|
|
25
|
-
// Importing 'ses' has side effects, so we do it lazily to avoid impacting environments that don't use this evaluator.
|
|
26
|
-
await import("ses");
|
|
27
|
-
if (!(lockdownSymbol in globalThis)) {
|
|
28
|
-
try {
|
|
29
|
-
lockdown(options?.lockdownOptions);
|
|
30
|
-
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
31
|
-
value: true,
|
|
32
|
-
writable: false,
|
|
33
|
-
configurable: false,
|
|
34
|
-
enumerable: false,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
if ((0, utils_js_1.toErrorString)(error).includes("SES_ALREADY_LOCKED_DOWN")) {
|
|
39
|
-
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
40
|
-
value: true,
|
|
41
|
-
writable: false,
|
|
42
|
-
configurable: false,
|
|
43
|
-
enumerable: false,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return async (context, code) => {
|
|
52
|
-
const compartmentOptions = {
|
|
53
|
-
...options?.compartmentOptions,
|
|
54
|
-
globals: {
|
|
55
|
-
...Object.fromEntries(optionsGlobals),
|
|
56
|
-
context,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
const compartment = new Compartment({ ...compartmentOptions, __options__: true });
|
|
60
|
-
await compartment.evaluate(code);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
exports.createSesEditEvaluator = createSesEditEvaluator;
|
|
64
|
-
//# sourceMappingURL=ses.js.map
|
package/dist/ses.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ses.js","sourceRoot":"","sources":["../src/ses.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,yCAA2C;AAE3C,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAE3D;;;;;;;;;GASG;AACI,KAAK,UAAU,sBAAsB,CAAC,OAG5C;IACA,MAAM,cAAc,GACnB,OAAO,EAAE,kBAAkB,EAAE,OAAO,IAAI,IAAI,GAAG,EAAmB,CAAC;IACpE,IAAI,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,M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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/langchain.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import type { ImplicitFieldSchema, ReadableField, TreeNode } from "@fluidframework/tree/alpha";
|
|
6
|
-
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
7
|
-
import { SharedTreeSemanticAgent } from "./agent.js";
|
|
8
|
-
import { type SemanticAgentOptions, type SharedTreeChatModel, type SharedTreeChatQuery } from "./api.js";
|
|
9
|
-
import type { TreeView } from "./utils.js";
|
|
10
|
-
/**
|
|
11
|
-
* An implementation of {@link SharedTreeChatModel} that wraps a Langchain chat model.
|
|
12
|
-
* @remarks This class is responsible for managing the conversation history and interacting with the Langchain model (e.g. via Tool use for editing).
|
|
13
|
-
* @alpha
|
|
14
|
-
*/
|
|
15
|
-
export declare class LangchainChatModel implements SharedTreeChatModel {
|
|
16
|
-
private readonly model;
|
|
17
|
-
private readonly messages;
|
|
18
|
-
constructor(model: BaseChatModel);
|
|
19
|
-
readonly editToolName = "GenerateTreeEditingCode";
|
|
20
|
-
get name(): string | undefined;
|
|
21
|
-
appendContext(text: string): void;
|
|
22
|
-
query(query: SharedTreeChatQuery): Promise<string>;
|
|
23
|
-
private queryEdit;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
27
|
-
* @alpha
|
|
28
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
29
|
-
*/
|
|
30
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema>, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
31
|
-
/**
|
|
32
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
33
|
-
* @alpha
|
|
34
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
35
|
-
*/
|
|
36
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, node: ReadableField<TSchema> & TreeNode, options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
37
|
-
/**
|
|
38
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
39
|
-
* @alpha
|
|
40
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
41
|
-
*/
|
|
42
|
-
export declare function createSemanticAgent<TSchema extends ImplicitFieldSchema>(client: BaseChatModel, treeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode), options?: Readonly<SemanticAgentOptions>): SharedTreeSemanticAgent<TSchema>;
|
|
43
|
-
//# sourceMappingURL=langchain.d.ts.map
|
package/lib/langchain.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,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Q,CAAC,EACjE,OAAO,CAAC,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GACtC,uBAAuB,CAAC,OAAO,CAAC,CAAC"}
|
package/lib/langchain.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
6
|
-
import { HumanMessage, SystemMessage,
|
|
7
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
8
|
-
} from "@langchain/core/messages";
|
|
9
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
10
|
-
import { tool } from "@langchain/core/tools";
|
|
11
|
-
import z from "zod";
|
|
12
|
-
import { SharedTreeSemanticAgent } from "./agent.js";
|
|
13
|
-
import { isEditResult, } from "./api.js";
|
|
14
|
-
/**
|
|
15
|
-
* An implementation of {@link SharedTreeChatModel} that wraps a Langchain chat model.
|
|
16
|
-
* @remarks This class is responsible for managing the conversation history and interacting with the Langchain model (e.g. via Tool use for editing).
|
|
17
|
-
* @alpha
|
|
18
|
-
*/
|
|
19
|
-
export class LangchainChatModel {
|
|
20
|
-
constructor(model) {
|
|
21
|
-
this.model = model;
|
|
22
|
-
this.messages = [];
|
|
23
|
-
this.editToolName = "GenerateTreeEditingCode";
|
|
24
|
-
}
|
|
25
|
-
get name() {
|
|
26
|
-
const name = this.model.metadata?.modelName;
|
|
27
|
-
return typeof name === "string" ? name : undefined;
|
|
28
|
-
}
|
|
29
|
-
appendContext(text) {
|
|
30
|
-
this.messages.push(new SystemMessage(text));
|
|
31
|
-
}
|
|
32
|
-
async query(query) {
|
|
33
|
-
this.messages.push(new HumanMessage(query.text));
|
|
34
|
-
return this.queryEdit(async (js) => query.edit(js));
|
|
35
|
-
}
|
|
36
|
-
async queryEdit(edit) {
|
|
37
|
-
const editingTool = tool(async ({ functionCode }) => {
|
|
38
|
-
return edit(functionCode);
|
|
39
|
-
}, {
|
|
40
|
-
name: this.editToolName,
|
|
41
|
-
description: `Invokes a JavaScript code snippet to edit a tree of application data.`,
|
|
42
|
-
schema: z.object({
|
|
43
|
-
functionCode: z.string().describe(`The JavaScript snippet code.`),
|
|
44
|
-
}),
|
|
45
|
-
});
|
|
46
|
-
const runnable = this.model.bindTools?.([editingTool], { tool_choice: "auto" });
|
|
47
|
-
if (runnable === undefined) {
|
|
48
|
-
throw new UsageError("LLM client must support function calling or tool use.");
|
|
49
|
-
}
|
|
50
|
-
const responseMessage = await runnable.invoke(this.messages);
|
|
51
|
-
this.messages.push(responseMessage);
|
|
52
|
-
if (responseMessage.tool_calls !== undefined && responseMessage.tool_calls.length > 0) {
|
|
53
|
-
for (const toolCall of responseMessage.tool_calls) {
|
|
54
|
-
switch (toolCall.name) {
|
|
55
|
-
case editingTool.name: {
|
|
56
|
-
const toolResult = await editingTool.invoke(toolCall);
|
|
57
|
-
this.messages.push(toolResult);
|
|
58
|
-
const editResult = JSON.parse(toolResult.text);
|
|
59
|
-
if (isEditResult(editResult) && editResult.type === "tooManyEditsError") {
|
|
60
|
-
return editResult.message;
|
|
61
|
-
}
|
|
62
|
-
// This call will either terminate the edit chain (if the LLM decides not to edit further) or continue it if more edits are required.
|
|
63
|
-
return this.queryEdit(edit);
|
|
64
|
-
}
|
|
65
|
-
default: {
|
|
66
|
-
this.messages.push(new HumanMessage(`Unrecognized tool call: ${toolCall.name}`));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return responseMessage.text;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
76
|
-
* @alpha
|
|
77
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
78
|
-
*/
|
|
79
|
-
export function createSemanticAgent(client, treeView, options) {
|
|
80
|
-
return new SharedTreeSemanticAgent(new LangchainChatModel(client), treeView, options);
|
|
81
|
-
}
|
|
82
|
-
// #endregion Legacy APIs
|
|
83
|
-
//# sourceMappingURL=langchain.js.map
|
package/lib/langchain.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;IAFE,CAAC;IAI5D,IAAW,IAAI;QACd,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC;QAC5C,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC;IAEM,aAAa,CAAC,IAAY;QAChC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,KAA0B;QAC5C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,OAAO,IAA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IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;wBAC/B,MAAM,UAAU,GAAY,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;wBACxD,IAAI,YAAY,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;4BACzE,OAAO,UAAU,CAAC,OAAO,CAAC;wBAC3B,CAAC;wBACD,qIAAqI;wBACrI,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;oBAC7B,CAAC;oBACD,OAAO,CAAC,CAAC,CAAC;wBACT,IAAI,CAAC,QAAQ,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/ses.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=ses.js.map
|
package/lib/ses.js.map
DELETED
|
@@ -1 +0,0 @@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AAC;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/src/langchain.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
7
|
-
import type { ImplicitFieldSchema, ReadableField, TreeNode } from "@fluidframework/tree/alpha";
|
|
8
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
9
|
-
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
10
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
11
|
-
import type { AIMessage, ToolMessage } from "@langchain/core/messages";
|
|
12
|
-
import {
|
|
13
|
-
HumanMessage,
|
|
14
|
-
SystemMessage,
|
|
15
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
16
|
-
} from "@langchain/core/messages";
|
|
17
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
18
|
-
import { tool } from "@langchain/core/tools";
|
|
19
|
-
import z from "zod";
|
|
20
|
-
|
|
21
|
-
import { SharedTreeSemanticAgent } from "./agent.js";
|
|
22
|
-
import {
|
|
23
|
-
isEditResult,
|
|
24
|
-
type SemanticAgentOptions,
|
|
25
|
-
type SharedTreeChatModel,
|
|
26
|
-
type SharedTreeChatQuery,
|
|
27
|
-
} from "./api.js";
|
|
28
|
-
import type { TreeView } from "./utils.js";
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* An implementation of {@link SharedTreeChatModel} that wraps a Langchain chat model.
|
|
32
|
-
* @remarks This class is responsible for managing the conversation history and interacting with the Langchain model (e.g. via Tool use for editing).
|
|
33
|
-
* @alpha
|
|
34
|
-
*/
|
|
35
|
-
export class LangchainChatModel implements SharedTreeChatModel {
|
|
36
|
-
private readonly messages: (HumanMessage | AIMessage | ToolMessage)[] = [];
|
|
37
|
-
public constructor(private readonly model: BaseChatModel) {}
|
|
38
|
-
|
|
39
|
-
public readonly editToolName = "GenerateTreeEditingCode";
|
|
40
|
-
|
|
41
|
-
public get name(): string | undefined {
|
|
42
|
-
const name = this.model.metadata?.modelName;
|
|
43
|
-
return typeof name === "string" ? name : undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public appendContext(text: string): void {
|
|
47
|
-
this.messages.push(new SystemMessage(text));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public async query(query: SharedTreeChatQuery): Promise<string> {
|
|
51
|
-
this.messages.push(new HumanMessage(query.text));
|
|
52
|
-
return this.queryEdit(async (js) => query.edit(js));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private async queryEdit(edit: SharedTreeChatQuery["edit"]): Promise<string> {
|
|
56
|
-
const editingTool = tool(
|
|
57
|
-
async ({ functionCode }) => {
|
|
58
|
-
return edit(functionCode);
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: this.editToolName,
|
|
62
|
-
description: `Invokes a JavaScript code snippet to edit a tree of application data.`,
|
|
63
|
-
schema: z.object({
|
|
64
|
-
functionCode: z.string().describe(`The JavaScript snippet code.`),
|
|
65
|
-
}),
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
const runnable = this.model.bindTools?.([editingTool], { tool_choice: "auto" });
|
|
69
|
-
if (runnable === undefined) {
|
|
70
|
-
throw new UsageError("LLM client must support function calling or tool use.");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const responseMessage = await runnable.invoke(this.messages);
|
|
74
|
-
this.messages.push(responseMessage);
|
|
75
|
-
|
|
76
|
-
if (responseMessage.tool_calls !== undefined && responseMessage.tool_calls.length > 0) {
|
|
77
|
-
for (const toolCall of responseMessage.tool_calls) {
|
|
78
|
-
switch (toolCall.name) {
|
|
79
|
-
case editingTool.name: {
|
|
80
|
-
const toolResult = await editingTool.invoke(toolCall);
|
|
81
|
-
this.messages.push(toolResult);
|
|
82
|
-
const editResult: unknown = JSON.parse(toolResult.text);
|
|
83
|
-
if (isEditResult(editResult) && editResult.type === "tooManyEditsError") {
|
|
84
|
-
return editResult.message;
|
|
85
|
-
}
|
|
86
|
-
// This call will either terminate the edit chain (if the LLM decides not to edit further) or continue it if more edits are required.
|
|
87
|
-
return this.queryEdit(edit);
|
|
88
|
-
}
|
|
89
|
-
default: {
|
|
90
|
-
this.messages.push(new HumanMessage(`Unrecognized tool call: ${toolCall.name}`));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return responseMessage.text;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// #region Legacy APIs
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
104
|
-
* @alpha
|
|
105
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
106
|
-
*/
|
|
107
|
-
export function createSemanticAgent<TSchema extends ImplicitFieldSchema>(
|
|
108
|
-
client: BaseChatModel,
|
|
109
|
-
treeView: TreeView<TSchema>,
|
|
110
|
-
options?: Readonly<SemanticAgentOptions>,
|
|
111
|
-
): SharedTreeSemanticAgent<TSchema>;
|
|
112
|
-
/**
|
|
113
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
114
|
-
* @alpha
|
|
115
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
116
|
-
*/
|
|
117
|
-
export function createSemanticAgent<TSchema extends ImplicitFieldSchema>(
|
|
118
|
-
client: BaseChatModel,
|
|
119
|
-
node: ReadableField<TSchema> & TreeNode,
|
|
120
|
-
options?: Readonly<SemanticAgentOptions>,
|
|
121
|
-
): SharedTreeSemanticAgent<TSchema>;
|
|
122
|
-
/**
|
|
123
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
124
|
-
* @alpha
|
|
125
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
126
|
-
*/
|
|
127
|
-
export function createSemanticAgent<TSchema extends ImplicitFieldSchema>(
|
|
128
|
-
client: BaseChatModel,
|
|
129
|
-
treeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),
|
|
130
|
-
options?: Readonly<SemanticAgentOptions>,
|
|
131
|
-
): SharedTreeSemanticAgent<TSchema>;
|
|
132
|
-
/**
|
|
133
|
-
* Create a {@link SharedTreeSemanticAgent} using a Langchain chat model.
|
|
134
|
-
* @alpha
|
|
135
|
-
* @deprecated Use {@link SharedTreeSemanticAgent} with a {@link LangchainChatModel} instead.
|
|
136
|
-
*/
|
|
137
|
-
export function createSemanticAgent<TSchema extends ImplicitFieldSchema>(
|
|
138
|
-
client: BaseChatModel,
|
|
139
|
-
treeView: TreeView<TSchema> | (ReadableField<TSchema> & TreeNode),
|
|
140
|
-
options?: Readonly<SemanticAgentOptions>,
|
|
141
|
-
): SharedTreeSemanticAgent<TSchema> {
|
|
142
|
-
return new SharedTreeSemanticAgent(new LangchainChatModel(client), treeView, options);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// #endregion Legacy APIs
|
package/src/ses.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { CompartmentOptions, LockdownOptions } from "ses";
|
|
7
|
-
|
|
8
|
-
import type { SemanticAgentOptions } from "./api.js";
|
|
9
|
-
import { toErrorString } from "./utils.js";
|
|
10
|
-
|
|
11
|
-
const lockdownSymbol = Symbol.for("tree-agent.ses.locked");
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Create an implementation of {@link SemanticAgentOptions.executeEdit} that uses the SES library to run the provided code in a secure environment.
|
|
15
|
-
* @param createCompartment - This function can be used to optionally configure the SES Compartment used to execute the code.
|
|
16
|
-
* The provided globals must be included in the compartment's globals and must not conflict with any additional globals passed in.
|
|
17
|
-
* @param lockdownOptions - Optional configuration passed to the SES `lockdown` function.
|
|
18
|
-
* @returns A function that can be used as the {@link SemanticAgentOptions.executeEdit | executeEdit} callback.
|
|
19
|
-
* @remarks This function will both import the SES library and call its `lockdown` function the first time it is called.
|
|
20
|
-
* Therefore, this function should be called only once, early in an application's lifetime.
|
|
21
|
-
* @alpha
|
|
22
|
-
*/
|
|
23
|
-
export async function createSesEditEvaluator(options?: {
|
|
24
|
-
compartmentOptions?: CompartmentOptions;
|
|
25
|
-
lockdownOptions?: LockdownOptions;
|
|
26
|
-
}): Promise<SemanticAgentOptions["executeEdit"]> {
|
|
27
|
-
const optionsGlobals: Map<string, unknown> =
|
|
28
|
-
options?.compartmentOptions?.globals ?? new Map<string, unknown>();
|
|
29
|
-
if (optionsGlobals.has("context") === true) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
"The 'context' global is reserved and cannot be overridden in the compartment options.",
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Importing 'ses' has side effects, so we do it lazily to avoid impacting environments that don't use this evaluator.
|
|
36
|
-
await import("ses");
|
|
37
|
-
|
|
38
|
-
if (!(lockdownSymbol in globalThis)) {
|
|
39
|
-
try {
|
|
40
|
-
lockdown(options?.lockdownOptions);
|
|
41
|
-
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
42
|
-
value: true,
|
|
43
|
-
writable: false,
|
|
44
|
-
configurable: false,
|
|
45
|
-
enumerable: false,
|
|
46
|
-
});
|
|
47
|
-
} catch (error: unknown) {
|
|
48
|
-
if (toErrorString(error).includes("SES_ALREADY_LOCKED_DOWN")) {
|
|
49
|
-
Object.defineProperty(globalThis, lockdownSymbol, {
|
|
50
|
-
value: true,
|
|
51
|
-
writable: false,
|
|
52
|
-
configurable: false,
|
|
53
|
-
enumerable: false,
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return async (context: Record<string, unknown>, code: string) => {
|
|
62
|
-
const compartmentOptions = {
|
|
63
|
-
...options?.compartmentOptions,
|
|
64
|
-
globals: {
|
|
65
|
-
...Object.fromEntries(optionsGlobals),
|
|
66
|
-
context,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const compartment = new Compartment({ ...compartmentOptions, __options__: true });
|
|
71
|
-
await compartment.evaluate(code);
|
|
72
|
-
};
|
|
73
|
-
}
|