@langchain/core 0.3.50 → 0.3.52

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tool = exports.BaseToolkit = exports.DynamicStructuredTool = exports.DynamicTool = exports.Tool = exports.StructuredTool = exports.ToolInputParsingException = void 0;
3
+ exports.tool = exports.BaseToolkit = exports.DynamicStructuredTool = exports.DynamicTool = exports.Tool = exports.StructuredTool = exports.ToolInputParsingException = exports.isStructuredToolParams = exports.isStructuredTool = exports.isRunnableToolLike = exports.isLangChainTool = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const json_schema_1 = require("@cfworker/json-schema");
6
6
  const manager_js_1 = require("../callbacks/manager.cjs");
@@ -12,6 +12,11 @@ const utils_js_1 = require("./utils.cjs");
12
12
  Object.defineProperty(exports, "ToolInputParsingException", { enumerable: true, get: function () { return utils_js_1.ToolInputParsingException; } });
13
13
  const is_zod_schema_js_1 = require("../utils/types/is_zod_schema.cjs");
14
14
  const json_schema_js_1 = require("../utils/json_schema.cjs");
15
+ var types_js_1 = require("./types.cjs");
16
+ Object.defineProperty(exports, "isLangChainTool", { enumerable: true, get: function () { return types_js_1.isLangChainTool; } });
17
+ Object.defineProperty(exports, "isRunnableToolLike", { enumerable: true, get: function () { return types_js_1.isRunnableToolLike; } });
18
+ Object.defineProperty(exports, "isStructuredTool", { enumerable: true, get: function () { return types_js_1.isStructuredTool; } });
19
+ Object.defineProperty(exports, "isStructuredToolParams", { enumerable: true, get: function () { return types_js_1.isStructuredToolParams; } });
15
20
  /**
16
21
  * Base class for Tools that accept input of any shape defined by a Zod schema.
17
22
  */
@@ -7,7 +7,8 @@ import { ToolCall } from "../messages/tool.js";
7
7
  import { ToolInputParsingException } from "./utils.js";
8
8
  import type { StructuredToolCallInput, ToolInputSchemaBase, ToolReturnType, ResponseFormat, ToolInputSchemaInputType, ToolInputSchemaOutputType, ToolParams, ToolRunnableConfig, StructuredToolInterface, DynamicToolInput, DynamicStructuredToolInput, ZodObjectAny } from "./types.js";
9
9
  import { type JSONSchema } from "../utils/json_schema.js";
10
- export type { BaseDynamicToolInput, ContentAndArtifact, DynamicToolInput, DynamicStructuredToolInput, isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams, ResponseFormat, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInterface, ToolParams, ToolReturnType, ToolRunnableConfig, ToolInputSchemaBase as ToolSchemaBase, } from "./types.js";
10
+ export type { BaseDynamicToolInput, ContentAndArtifact, DynamicToolInput, DynamicStructuredToolInput, ResponseFormat, StructuredToolCallInput, StructuredToolInterface, StructuredToolParams, ToolInterface, ToolParams, ToolReturnType, ToolRunnableConfig, ToolInputSchemaBase as ToolSchemaBase, } from "./types.js";
11
+ export { isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams, } from "./types.js";
11
12
  export { ToolInputParsingException };
12
13
  /**
13
14
  * Base class for Tools that accept input of any shape defined by a Zod schema.
@@ -8,6 +8,7 @@ import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js";
8
8
  import { _isToolCall, ToolInputParsingException } from "./utils.js";
9
9
  import { isZodSchema } from "../utils/types/is_zod_schema.js";
10
10
  import { validatesOnlyStrings } from "../utils/json_schema.js";
11
+ export { isLangChainTool, isRunnableToolLike, isStructuredTool, isStructuredToolParams, } from "./types.js";
11
12
  export { ToolInputParsingException };
12
13
  /**
13
14
  * Base class for Tools that accept input of any shape defined by a Zod schema.
@@ -40,7 +40,12 @@ function isStructuredToolParams(tool) {
40
40
  "name" in tool &&
41
41
  "schema" in tool &&
42
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- (0, is_zod_schema_js_1.isZodSchema)(tool.schema));
43
+ ((0, is_zod_schema_js_1.isZodSchema)(tool.schema) ||
44
+ (tool.schema != null &&
45
+ typeof tool.schema === "object" &&
46
+ "type" in tool.schema &&
47
+ typeof tool.schema.type === "string" &&
48
+ ["null", "boolean", "object", "array", "number", "string"].includes(tool.schema.type))));
44
49
  }
45
50
  exports.isStructuredToolParams = isStructuredToolParams;
46
51
  /**
@@ -35,7 +35,12 @@ export function isStructuredToolParams(tool) {
35
35
  "name" in tool &&
36
36
  "schema" in tool &&
37
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- isZodSchema(tool.schema));
38
+ (isZodSchema(tool.schema) ||
39
+ (tool.schema != null &&
40
+ typeof tool.schema === "object" &&
41
+ "type" in tool.schema &&
42
+ typeof tool.schema.type === "string" &&
43
+ ["null", "boolean", "object", "array", "number", "string"].includes(tool.schema.type))));
39
44
  }
40
45
  /**
41
46
  * Whether or not the tool is one of StructuredTool, RunnableTool or StructuredToolParams.
@@ -4,13 +4,26 @@ exports.parsePartialJson = exports.parseJsonMarkdown = void 0;
4
4
  function parseJsonMarkdown(s, parser = parsePartialJson) {
5
5
  // eslint-disable-next-line no-param-reassign
6
6
  s = s.trim();
7
- const match = /```(json)?(.*)```/s.exec(s);
8
- if (!match) {
7
+ const firstFenceIndex = s.indexOf("```");
8
+ if (firstFenceIndex === -1) {
9
9
  return parser(s);
10
10
  }
11
- else {
12
- return parser(match[2]);
11
+ let contentAfterFence = s.substring(firstFenceIndex + 3);
12
+ if (contentAfterFence.startsWith("json\n")) {
13
+ contentAfterFence = contentAfterFence.substring(5);
13
14
  }
15
+ else if (contentAfterFence.startsWith("json")) {
16
+ contentAfterFence = contentAfterFence.substring(4);
17
+ }
18
+ else if (contentAfterFence.startsWith("\n")) {
19
+ contentAfterFence = contentAfterFence.substring(1);
20
+ }
21
+ const closingFenceIndex = contentAfterFence.indexOf("```");
22
+ let finalContent = contentAfterFence;
23
+ if (closingFenceIndex !== -1) {
24
+ finalContent = contentAfterFence.substring(0, closingFenceIndex);
25
+ }
26
+ return parser(finalContent.trim());
14
27
  }
15
28
  exports.parseJsonMarkdown = parseJsonMarkdown;
16
29
  // Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py
@@ -1,13 +1,26 @@
1
1
  export function parseJsonMarkdown(s, parser = parsePartialJson) {
2
2
  // eslint-disable-next-line no-param-reassign
3
3
  s = s.trim();
4
- const match = /```(json)?(.*)```/s.exec(s);
5
- if (!match) {
4
+ const firstFenceIndex = s.indexOf("```");
5
+ if (firstFenceIndex === -1) {
6
6
  return parser(s);
7
7
  }
8
- else {
9
- return parser(match[2]);
8
+ let contentAfterFence = s.substring(firstFenceIndex + 3);
9
+ if (contentAfterFence.startsWith("json\n")) {
10
+ contentAfterFence = contentAfterFence.substring(5);
10
11
  }
12
+ else if (contentAfterFence.startsWith("json")) {
13
+ contentAfterFence = contentAfterFence.substring(4);
14
+ }
15
+ else if (contentAfterFence.startsWith("\n")) {
16
+ contentAfterFence = contentAfterFence.substring(1);
17
+ }
18
+ const closingFenceIndex = contentAfterFence.indexOf("```");
19
+ let finalContent = contentAfterFence;
20
+ if (closingFenceIndex !== -1) {
21
+ finalContent = contentAfterFence.substring(0, closingFenceIndex);
22
+ }
23
+ return parser(finalContent.trim());
11
24
  }
12
25
  // Adapted from https://github.com/KillianLucas/open-interpreter/blob/main/interpreter/core/llm/utils/parse_partial_json.py
13
26
  // MIT License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.50",
3
+ "version": "0.3.52",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {