@fluidframework/tree-agent-langchain 2.81.1 → 2.83.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/chatModel.d.ts.map +1 -1
- package/dist/chatModel.js +1 -10
- package/dist/chatModel.js.map +1 -1
- package/eslint.config.mts +0 -6
- package/lib/chatModel.d.ts.map +1 -1
- package/lib/chatModel.js +1 -7
- package/lib/chatModel.js.map +1 -1
- package/package.json +10 -11
- package/src/chatModel.ts +4 -13
- package/api-extractor-lint.json +0 -4
- package/biome.jsonc +0 -4
package/CHANGELOG.md
CHANGED
package/dist/chatModel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatModel.d.ts","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAEX,mBAAmB,EAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"chatModel.d.ts","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAEX,mBAAmB,EAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAKjF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,aAAa,GAAG,mBAAmB,CAE3F"}
|
package/dist/chatModel.js
CHANGED
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
7
|
exports.createLangchainChatModel = void 0;
|
|
11
8
|
/* eslint-disable import-x/no-internal-modules */
|
|
12
9
|
const internal_1 = require("@fluidframework/telemetry-utils/internal");
|
|
13
10
|
const messages_1 = require("@langchain/core/messages");
|
|
14
11
|
const tools_1 = require("@langchain/core/tools");
|
|
15
|
-
const zod_1 = __importDefault(require("zod"));
|
|
16
12
|
/**
|
|
17
13
|
* Creates a `SharedTreeChatModel` that uses the LangChain library to connect to the underlying LLM.
|
|
18
14
|
* @param langchainModel - The LangChain chat model to use.
|
|
@@ -40,14 +36,9 @@ class LangchainChatModel {
|
|
|
40
36
|
return this.queryEdit(async (js) => query.edit(js));
|
|
41
37
|
}
|
|
42
38
|
async queryEdit(edit) {
|
|
43
|
-
const editingTool = (0, tools_1.tool)(
|
|
44
|
-
return edit(functionCode);
|
|
45
|
-
}, {
|
|
39
|
+
const editingTool = (0, tools_1.tool)(edit, {
|
|
46
40
|
name: this.editToolName,
|
|
47
41
|
description: "Invokes a JavaScript code snippet to edit a tree of application data.",
|
|
48
|
-
schema: zod_1.default.object({
|
|
49
|
-
functionCode: zod_1.default.string().describe("The JavaScript snippet code."),
|
|
50
|
-
}),
|
|
51
42
|
});
|
|
52
43
|
const runnable = this.model.bindTools?.([editingTool], { tool_choice: "auto" });
|
|
53
44
|
if (runnable === undefined) {
|
package/dist/chatModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatModel.js","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"chatModel.js","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iDAAiD;AAEjD,uEAAsE;AAQtE,uDAAuE;AACvE,iDAA6C;AAE7C;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,cAA6B;IACrE,OAAO,IAAI,kBAAkB,CAAC,cAAc,CAAC,CAA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AQ;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\n/* eslint-disable import-x/no-internal-modules */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type {\n\tEditResult,\n\tSharedTreeChatModel,\n\tSharedTreeChatQuery,\n} from \"@fluidframework/tree-agent/alpha\";\nimport type { BaseChatModel } from \"@langchain/core/language_models/chat_models\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport { HumanMessage, SystemMessage } from \"@langchain/core/messages\";\nimport { tool } from \"@langchain/core/tools\";\n\n/**\n * Creates a `SharedTreeChatModel` that uses the LangChain library to connect to the underlying LLM.\n * @param langchainModel - The LangChain chat model to use.\n * @alpha\n */\nexport function createLangchainChatModel(langchainModel: BaseChatModel): SharedTreeChatModel {\n\treturn new LangchainChatModel(langchainModel);\n}\n\nclass LangchainChatModel implements SharedTreeChatModel {\n\tprivate readonly messages: BaseMessage[] = [];\n\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: string) => query.edit(js));\n\t}\n\n\tprivate async queryEdit(edit: SharedTreeChatQuery[\"edit\"]): Promise<string> {\n\t\tconst editingTool = tool(edit, {\n\t\t\tname: this.editToolName,\n\t\t\tdescription: \"Invokes a JavaScript code snippet to edit a tree of application data.\",\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\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/**\n * Type guard for {@link EditResult}.\n */\nfunction 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"]}
|
package/eslint.config.mts
CHANGED
|
@@ -25,12 +25,6 @@ const config: Linter.Config[] = [
|
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
files: ["src/test/**/*"],
|
|
28
|
-
languageOptions: {
|
|
29
|
-
parserOptions: {
|
|
30
|
-
projectService: false,
|
|
31
|
-
project: ["./src/test/tsconfig.json"],
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
28
|
rules: {
|
|
35
29
|
"import-x/no-internal-modules": [
|
|
36
30
|
"error",
|
package/lib/chatModel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatModel.d.ts","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAEX,mBAAmB,EAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"chatModel.d.ts","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAEX,mBAAmB,EAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAKjF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,aAAa,GAAG,mBAAmB,CAE3F"}
|
package/lib/chatModel.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
7
7
|
import { HumanMessage, SystemMessage } from "@langchain/core/messages";
|
|
8
8
|
import { tool } from "@langchain/core/tools";
|
|
9
|
-
import z from "zod";
|
|
10
9
|
/**
|
|
11
10
|
* Creates a `SharedTreeChatModel` that uses the LangChain library to connect to the underlying LLM.
|
|
12
11
|
* @param langchainModel - The LangChain chat model to use.
|
|
@@ -33,14 +32,9 @@ class LangchainChatModel {
|
|
|
33
32
|
return this.queryEdit(async (js) => query.edit(js));
|
|
34
33
|
}
|
|
35
34
|
async queryEdit(edit) {
|
|
36
|
-
const editingTool = tool(
|
|
37
|
-
return edit(functionCode);
|
|
38
|
-
}, {
|
|
35
|
+
const editingTool = tool(edit, {
|
|
39
36
|
name: this.editToolName,
|
|
40
37
|
description: "Invokes a JavaScript code snippet to edit a tree of application data.",
|
|
41
|
-
schema: z.object({
|
|
42
|
-
functionCode: z.string().describe("The JavaScript snippet code."),
|
|
43
|
-
}),
|
|
44
38
|
});
|
|
45
39
|
const runnable = this.model.bindTools?.([editingTool], { tool_choice: "auto" });
|
|
46
40
|
if (runnable === undefined) {
|
package/lib/chatModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatModel.js","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iDAAiD;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAQtE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"chatModel.js","sourceRoot":"","sources":["../src/chatModel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iDAAiD;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAQtE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,cAA6B;IACrE,OAAO,IAAI,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,kBAAkB;IAGvB,YAAoC,KAAoB;QAApB,UAAK,GAAL,KAAK,CAAe;QAFvC,aAAQ,GAAkB,EAAE,CAAC;QAI9B,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,C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/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,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;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,KAAc;IACnC,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\n/* eslint-disable import-x/no-internal-modules */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type {\n\tEditResult,\n\tSharedTreeChatModel,\n\tSharedTreeChatQuery,\n} from \"@fluidframework/tree-agent/alpha\";\nimport type { BaseChatModel } from \"@langchain/core/language_models/chat_models\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport { HumanMessage, SystemMessage } from \"@langchain/core/messages\";\nimport { tool } from \"@langchain/core/tools\";\n\n/**\n * Creates a `SharedTreeChatModel` that uses the LangChain library to connect to the underlying LLM.\n * @param langchainModel - The LangChain chat model to use.\n * @alpha\n */\nexport function createLangchainChatModel(langchainModel: BaseChatModel): SharedTreeChatModel {\n\treturn new LangchainChatModel(langchainModel);\n}\n\nclass LangchainChatModel implements SharedTreeChatModel {\n\tprivate readonly messages: BaseMessage[] = [];\n\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: string) => query.edit(js));\n\t}\n\n\tprivate async queryEdit(edit: SharedTreeChatQuery[\"edit\"]): Promise<string> {\n\t\tconst editingTool = tool(edit, {\n\t\t\tname: this.editToolName,\n\t\t\tdescription: \"Invokes a JavaScript code snippet to edit a tree of application data.\",\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\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/**\n * Type guard for {@link EditResult}.\n */\nfunction 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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/tree-agent-langchain",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.83.0",
|
|
4
4
|
"description": "LangChain integration helpers for @fluidframework/tree-agent",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,28 +69,27 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluidframework/telemetry-utils": "~2.
|
|
73
|
-
"@fluidframework/tree-agent": "~2.
|
|
74
|
-
"@langchain/core": "^0.3.
|
|
75
|
-
"zod": "^3.25.32"
|
|
72
|
+
"@fluidframework/telemetry-utils": "~2.83.0",
|
|
73
|
+
"@fluidframework/tree-agent": "~2.83.0",
|
|
74
|
+
"@langchain/core": "^0.3.80"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
77
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
79
78
|
"@biomejs/biome": "~1.9.3",
|
|
80
|
-
"@fluid-internal/mocha-test-setup": "~2.
|
|
79
|
+
"@fluid-internal/mocha-test-setup": "~2.83.0",
|
|
81
80
|
"@fluid-tools/build-cli": "^0.63.0",
|
|
82
81
|
"@fluidframework/build-common": "^2.0.3",
|
|
83
82
|
"@fluidframework/build-tools": "^0.63.0",
|
|
84
|
-
"@fluidframework/core-utils": "~2.
|
|
85
|
-
"@fluidframework/eslint-config-fluid": "~2.
|
|
86
|
-
"@fluidframework/runtime-utils": "~2.
|
|
87
|
-
"@fluidframework/tree": "~2.
|
|
83
|
+
"@fluidframework/core-utils": "~2.83.0",
|
|
84
|
+
"@fluidframework/eslint-config-fluid": "~2.83.0",
|
|
85
|
+
"@fluidframework/runtime-utils": "~2.83.0",
|
|
86
|
+
"@fluidframework/tree": "~2.83.0",
|
|
88
87
|
"@langchain/anthropic": "^0.3.24",
|
|
89
88
|
"@langchain/google-genai": "^0.2.16",
|
|
90
89
|
"@langchain/openai": "^0.6.12",
|
|
91
90
|
"@microsoft/api-extractor": "7.52.11",
|
|
92
91
|
"@types/mocha": "^10.0.10",
|
|
93
|
-
"@types/node": "
|
|
92
|
+
"@types/node": "~20.19.30",
|
|
94
93
|
"c8": "^10.1.3",
|
|
95
94
|
"concurrently": "^9.2.1",
|
|
96
95
|
"copyfiles": "^2.4.1",
|
package/src/chatModel.ts
CHANGED
|
@@ -15,7 +15,6 @@ import type { BaseChatModel } from "@langchain/core/language_models/chat_models"
|
|
|
15
15
|
import type { BaseMessage } from "@langchain/core/messages";
|
|
16
16
|
import { HumanMessage, SystemMessage } from "@langchain/core/messages";
|
|
17
17
|
import { tool } from "@langchain/core/tools";
|
|
18
|
-
import z from "zod";
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* Creates a `SharedTreeChatModel` that uses the LangChain library to connect to the underlying LLM.
|
|
@@ -48,18 +47,10 @@ class LangchainChatModel implements SharedTreeChatModel {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
private async queryEdit(edit: SharedTreeChatQuery["edit"]): Promise<string> {
|
|
51
|
-
const editingTool = tool(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
name: this.editToolName,
|
|
57
|
-
description: "Invokes a JavaScript code snippet to edit a tree of application data.",
|
|
58
|
-
schema: z.object({
|
|
59
|
-
functionCode: z.string().describe("The JavaScript snippet code."),
|
|
60
|
-
}),
|
|
61
|
-
},
|
|
62
|
-
);
|
|
50
|
+
const editingTool = tool(edit, {
|
|
51
|
+
name: this.editToolName,
|
|
52
|
+
description: "Invokes a JavaScript code snippet to edit a tree of application data.",
|
|
53
|
+
});
|
|
63
54
|
const runnable = this.model.bindTools?.([editingTool], { tool_choice: "auto" });
|
|
64
55
|
if (runnable === undefined) {
|
|
65
56
|
throw new UsageError("LLM client must support function calling or tool use.");
|
package/api-extractor-lint.json
DELETED
package/biome.jsonc
DELETED