@langchain/core 0.3.62 → 0.3.63

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.
@@ -143,29 +143,38 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
143
143
  };
144
144
  }
145
145
  else {
146
+ const groupedToolCallChunk = fields.tool_call_chunks.reduce((acc, chunk) => {
147
+ if (!chunk.id)
148
+ return acc;
149
+ acc[chunk.id] = acc[chunk.id] ?? [];
150
+ acc[chunk.id].push(chunk);
151
+ return acc;
152
+ }, {});
146
153
  const toolCalls = [];
147
154
  const invalidToolCalls = [];
148
- for (const toolCallChunk of fields.tool_call_chunks) {
155
+ for (const [id, chunks] of Object.entries(groupedToolCallChunk)) {
149
156
  let parsedArgs = {};
157
+ const name = chunks[0]?.name ?? "";
158
+ const argStr = chunks.map((c) => c.args || "").join("");
150
159
  try {
151
- parsedArgs = (0, json_js_1.parsePartialJson)(toolCallChunk.args || "{}");
160
+ parsedArgs = (0, json_js_1.parsePartialJson)(argStr);
152
161
  if (parsedArgs === null ||
153
162
  typeof parsedArgs !== "object" ||
154
163
  Array.isArray(parsedArgs)) {
155
164
  throw new Error("Malformed tool call chunk args.");
156
165
  }
157
166
  toolCalls.push({
158
- name: toolCallChunk.name ?? "",
167
+ name,
159
168
  args: parsedArgs,
160
- id: toolCallChunk.id,
169
+ id,
161
170
  type: "tool_call",
162
171
  });
163
172
  }
164
173
  catch (e) {
165
174
  invalidToolCalls.push({
166
- name: toolCallChunk.name,
167
- args: toolCallChunk.args,
168
- id: toolCallChunk.id,
175
+ name,
176
+ args: argStr,
177
+ id,
169
178
  error: "Malformed args.",
170
179
  type: "invalid_tool_call",
171
180
  });
@@ -137,29 +137,38 @@ export class AIMessageChunk extends BaseMessageChunk {
137
137
  };
138
138
  }
139
139
  else {
140
+ const groupedToolCallChunk = fields.tool_call_chunks.reduce((acc, chunk) => {
141
+ if (!chunk.id)
142
+ return acc;
143
+ acc[chunk.id] = acc[chunk.id] ?? [];
144
+ acc[chunk.id].push(chunk);
145
+ return acc;
146
+ }, {});
140
147
  const toolCalls = [];
141
148
  const invalidToolCalls = [];
142
- for (const toolCallChunk of fields.tool_call_chunks) {
149
+ for (const [id, chunks] of Object.entries(groupedToolCallChunk)) {
143
150
  let parsedArgs = {};
151
+ const name = chunks[0]?.name ?? "";
152
+ const argStr = chunks.map((c) => c.args || "").join("");
144
153
  try {
145
- parsedArgs = parsePartialJson(toolCallChunk.args || "{}");
154
+ parsedArgs = parsePartialJson(argStr);
146
155
  if (parsedArgs === null ||
147
156
  typeof parsedArgs !== "object" ||
148
157
  Array.isArray(parsedArgs)) {
149
158
  throw new Error("Malformed tool call chunk args.");
150
159
  }
151
160
  toolCalls.push({
152
- name: toolCallChunk.name ?? "",
161
+ name,
153
162
  args: parsedArgs,
154
- id: toolCallChunk.id,
163
+ id,
155
164
  type: "tool_call",
156
165
  });
157
166
  }
158
167
  catch (e) {
159
168
  invalidToolCalls.push({
160
- name: toolCallChunk.name,
161
- args: toolCallChunk.args,
162
- id: toolCallChunk.id,
169
+ name,
170
+ args: argStr,
171
+ id,
163
172
  error: "Malformed args.",
164
173
  type: "invalid_tool_call",
165
174
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.62",
3
+ "version": "0.3.63",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {