@langchain/core 0.2.28 → 0.2.30-rc.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.
@@ -141,8 +141,10 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
141
141
  for (const toolCallChunk of fields.tool_call_chunks) {
142
142
  let parsedArgs = {};
143
143
  try {
144
- parsedArgs = (0, json_js_1.parsePartialJson)(toolCallChunk.args ?? "{}") ?? {};
145
- if (typeof parsedArgs !== "object" || Array.isArray(parsedArgs)) {
144
+ parsedArgs = (0, json_js_1.parsePartialJson)(toolCallChunk.args || "{}");
145
+ if (parsedArgs === null ||
146
+ typeof parsedArgs !== "object" ||
147
+ Array.isArray(parsedArgs)) {
146
148
  throw new Error("Malformed tool call chunk args.");
147
149
  }
148
150
  toolCalls.push({
@@ -136,8 +136,10 @@ export class AIMessageChunk extends BaseMessageChunk {
136
136
  for (const toolCallChunk of fields.tool_call_chunks) {
137
137
  let parsedArgs = {};
138
138
  try {
139
- parsedArgs = parsePartialJson(toolCallChunk.args ?? "{}") ?? {};
140
- if (typeof parsedArgs !== "object" || Array.isArray(parsedArgs)) {
139
+ parsedArgs = parsePartialJson(toolCallChunk.args || "{}");
140
+ if (parsedArgs === null ||
141
+ typeof parsedArgs !== "object" ||
142
+ Array.isArray(parsedArgs)) {
141
143
  throw new Error("Malformed tool call chunk args.");
142
144
  }
143
145
  toolCalls.push({
@@ -72,16 +72,19 @@ class Graph {
72
72
  id: stableNodeIds[node.id],
73
73
  ...nodeDataJson(node),
74
74
  })),
75
- edges: this.edges.map((edge) => edge.data
76
- ? {
75
+ edges: this.edges.map((edge) => {
76
+ const item = {
77
77
  source: stableNodeIds[edge.source],
78
78
  target: stableNodeIds[edge.target],
79
- data: edge.data,
79
+ };
80
+ if (typeof edge.data !== "undefined") {
81
+ item.data = edge.data;
80
82
  }
81
- : {
82
- source: stableNodeIds[edge.source],
83
- target: stableNodeIds[edge.target],
84
- }),
83
+ if (typeof edge.conditional !== "undefined") {
84
+ item.conditional = edge.conditional;
85
+ }
86
+ return item;
87
+ }),
85
88
  };
86
89
  }
87
90
  addNode(data, id) {
@@ -69,16 +69,19 @@ export class Graph {
69
69
  id: stableNodeIds[node.id],
70
70
  ...nodeDataJson(node),
71
71
  })),
72
- edges: this.edges.map((edge) => edge.data
73
- ? {
72
+ edges: this.edges.map((edge) => {
73
+ const item = {
74
74
  source: stableNodeIds[edge.source],
75
75
  target: stableNodeIds[edge.target],
76
- data: edge.data,
76
+ };
77
+ if (typeof edge.data !== "undefined") {
78
+ item.data = edge.data;
77
79
  }
78
- : {
79
- source: stableNodeIds[edge.source],
80
- target: stableNodeIds[edge.target],
81
- }),
80
+ if (typeof edge.conditional !== "undefined") {
81
+ item.conditional = edge.conditional;
82
+ }
83
+ return item;
84
+ }),
82
85
  };
83
86
  }
84
87
  addNode(data, id) {
@@ -25,6 +25,13 @@ class StructuredTool extends base_js_1.BaseLangChain {
25
25
  writable: true,
26
26
  value: false
27
27
  });
28
+ // TODO: Make default in 0.3
29
+ Object.defineProperty(this, "verboseParsingErrors", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: false
34
+ });
28
35
  /**
29
36
  * The tool response format.
30
37
  *
@@ -40,6 +47,8 @@ class StructuredTool extends base_js_1.BaseLangChain {
40
47
  writable: true,
41
48
  value: "content"
42
49
  });
50
+ this.verboseParsingErrors =
51
+ fields?.verboseParsingErrors ?? this.verboseParsingErrors;
43
52
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
44
53
  }
45
54
  /**
@@ -84,9 +93,14 @@ class StructuredTool extends base_js_1.BaseLangChain {
84
93
  let parsed;
85
94
  try {
86
95
  parsed = await this.schema.parseAsync(arg);
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
97
  }
88
98
  catch (e) {
89
- throw new utils_js_1.ToolInputParsingException(`Received tool input did not match expected schema`, JSON.stringify(arg));
99
+ let message = `Received tool input did not match expected schema`;
100
+ if (this.verboseParsingErrors) {
101
+ message = `${message}\nDetails: ${e.message}`;
102
+ }
103
+ throw new utils_js_1.ToolInputParsingException(message, JSON.stringify(arg));
90
104
  }
91
105
  const config = (0, manager_js_1.parseCallbackConfigArg)(configArg);
92
106
  const callbackManager_ = await manager_js_1.CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
@@ -25,6 +25,12 @@ export interface ToolParams extends BaseLangChainParams {
25
25
  * @default "content"
26
26
  */
27
27
  responseFormat?: ResponseFormat;
28
+ /**
29
+ * Whether to show full details in the thrown parsing errors.
30
+ *
31
+ * @default false
32
+ */
33
+ verboseParsingErrors?: boolean;
28
34
  }
29
35
  /**
30
36
  * Schema for defining tools.
@@ -75,6 +81,7 @@ export declare abstract class StructuredTool<T extends ZodObjectAny = ZodObjectA
75
81
  abstract description: string;
76
82
  abstract schema: T | z.ZodEffects<T>;
77
83
  returnDirect: boolean;
84
+ verboseParsingErrors: boolean;
78
85
  get lc_namespace(): string[];
79
86
  /**
80
87
  * The tool response format.
@@ -22,6 +22,13 @@ export class StructuredTool extends BaseLangChain {
22
22
  writable: true,
23
23
  value: false
24
24
  });
25
+ // TODO: Make default in 0.3
26
+ Object.defineProperty(this, "verboseParsingErrors", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: false
31
+ });
25
32
  /**
26
33
  * The tool response format.
27
34
  *
@@ -37,6 +44,8 @@ export class StructuredTool extends BaseLangChain {
37
44
  writable: true,
38
45
  value: "content"
39
46
  });
47
+ this.verboseParsingErrors =
48
+ fields?.verboseParsingErrors ?? this.verboseParsingErrors;
40
49
  this.responseFormat = fields?.responseFormat ?? this.responseFormat;
41
50
  }
42
51
  /**
@@ -81,9 +90,14 @@ export class StructuredTool extends BaseLangChain {
81
90
  let parsed;
82
91
  try {
83
92
  parsed = await this.schema.parseAsync(arg);
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
94
  }
85
95
  catch (e) {
86
- throw new ToolInputParsingException(`Received tool input did not match expected schema`, JSON.stringify(arg));
96
+ let message = `Received tool input did not match expected schema`;
97
+ if (this.verboseParsingErrors) {
98
+ message = `${message}\nDetails: ${e.message}`;
99
+ }
100
+ throw new ToolInputParsingException(message, JSON.stringify(arg));
87
101
  }
88
102
  const config = parseCallbackConfigArg(configArg);
89
103
  const callbackManager_ = await CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.2.28",
3
+ "version": "0.2.30-rc.0",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -15,13 +15,8 @@
15
15
  "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/langchain-core/",
16
16
  "scripts": {
17
17
  "build": "yarn turbo:command build:internal --filter=@langchain/core",
18
- "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking",
18
+ "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking",
19
19
  "clean": "rm -rf .turbo dist/",
20
- "build:deps": "yarn turbo build",
21
- "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests",
22
- "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs",
23
- "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
24
- "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
25
20
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
26
21
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
27
22
  "lint": "yarn lint:eslint && yarn lint:dpdm",
@@ -33,10 +28,7 @@
33
28
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
34
29
  "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
35
30
  "format": "prettier --config .prettierrc --write \"src\"",
36
- "format:check": "prettier --config .prettierrc --check \"src\"",
37
- "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
38
- "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
39
- "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
31
+ "format:check": "prettier --config .prettierrc --check \"src\""
40
32
  },
41
33
  "author": "LangChain",
42
34
  "license": "MIT",
@@ -55,7 +47,7 @@
55
47
  },
56
48
  "devDependencies": {
57
49
  "@jest/globals": "^29.5.0",
58
- "@langchain/scripts": "^0.0.21",
50
+ "@langchain/scripts": ">=0.1.0 <0.2.0",
59
51
  "@swc/core": "^1.3.90",
60
52
  "@swc/jest": "^0.2.29",
61
53
  "@types/decamelize": "^1.2.0",