@langchain/core 0.2.29 → 0.2.30

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({
@@ -17,6 +17,15 @@ function tryJsonStringify(obj, fallback) {
17
17
  return fallback;
18
18
  }
19
19
  }
20
+ function formatKVMapItem(value) {
21
+ if (typeof value === "string") {
22
+ return value.trim();
23
+ }
24
+ if (value === null || value === undefined) {
25
+ return value;
26
+ }
27
+ return tryJsonStringify(value, value.toString());
28
+ }
20
29
  function elapsed(run) {
21
30
  if (!run.end_time)
22
31
  return "";
@@ -163,7 +172,7 @@ class ConsoleCallbackHandler extends base_js_1.BaseTracer {
163
172
  */
164
173
  onToolStart(run) {
165
174
  const crumbs = this.getBreadcrumbs(run);
166
- console.log(`${wrap(color.green, "[tool/start]")} [${crumbs}] Entering Tool run with input: "${run.inputs.input?.trim()}"`);
175
+ console.log(`${wrap(color.green, "[tool/start]")} [${crumbs}] Entering Tool run with input: "${formatKVMapItem(run.inputs.input)}"`);
167
176
  }
168
177
  /**
169
178
  * Method used to log the end of a tool run.
@@ -172,7 +181,7 @@ class ConsoleCallbackHandler extends base_js_1.BaseTracer {
172
181
  */
173
182
  onToolEnd(run) {
174
183
  const crumbs = this.getBreadcrumbs(run);
175
- console.log(`${wrap(color.cyan, "[tool/end]")} [${crumbs}] [${elapsed(run)}] Exiting Tool run with output: "${run.outputs?.output?.trim()}"`);
184
+ console.log(`${wrap(color.cyan, "[tool/end]")} [${crumbs}] [${elapsed(run)}] Exiting Tool run with output: "${formatKVMapItem(run.outputs?.output)}"`);
176
185
  }
177
186
  /**
178
187
  * Method used to log any errors of a tool run.
@@ -11,6 +11,15 @@ function tryJsonStringify(obj, fallback) {
11
11
  return fallback;
12
12
  }
13
13
  }
14
+ function formatKVMapItem(value) {
15
+ if (typeof value === "string") {
16
+ return value.trim();
17
+ }
18
+ if (value === null || value === undefined) {
19
+ return value;
20
+ }
21
+ return tryJsonStringify(value, value.toString());
22
+ }
14
23
  function elapsed(run) {
15
24
  if (!run.end_time)
16
25
  return "";
@@ -157,7 +166,7 @@ export class ConsoleCallbackHandler extends BaseTracer {
157
166
  */
158
167
  onToolStart(run) {
159
168
  const crumbs = this.getBreadcrumbs(run);
160
- console.log(`${wrap(color.green, "[tool/start]")} [${crumbs}] Entering Tool run with input: "${run.inputs.input?.trim()}"`);
169
+ console.log(`${wrap(color.green, "[tool/start]")} [${crumbs}] Entering Tool run with input: "${formatKVMapItem(run.inputs.input)}"`);
161
170
  }
162
171
  /**
163
172
  * Method used to log the end of a tool run.
@@ -166,7 +175,7 @@ export class ConsoleCallbackHandler extends BaseTracer {
166
175
  */
167
176
  onToolEnd(run) {
168
177
  const crumbs = this.getBreadcrumbs(run);
169
- console.log(`${wrap(color.cyan, "[tool/end]")} [${crumbs}] [${elapsed(run)}] Exiting Tool run with output: "${run.outputs?.output?.trim()}"`);
178
+ console.log(`${wrap(color.cyan, "[tool/end]")} [${crumbs}] [${elapsed(run)}] Exiting Tool run with output: "${formatKVMapItem(run.outputs?.output)}"`);
170
179
  }
171
180
  /**
172
181
  * Method used to log any errors of a tool run.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.2.29",
3
+ "version": "0.2.30",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {