@langchain/core 0.3.66 → 0.3.67
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/dist/messages/ai.cjs +9 -6
- package/dist/messages/ai.js +9 -6
- package/dist/prompts/template.cjs +22 -13
- package/dist/prompts/template.js +22 -13
- package/dist/runnables/base.cjs +2 -2
- package/dist/runnables/base.d.ts +2 -2
- package/dist/runnables/base.js +2 -2
- package/package.json +1 -1
package/dist/messages/ai.cjs
CHANGED
|
@@ -144,10 +144,11 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
146
|
const groupedToolCallChunk = fields.tool_call_chunks.reduce((acc, chunk) => {
|
|
147
|
-
if
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
acc[
|
|
147
|
+
// Assign a fallback ID if the chunk doesn't have one
|
|
148
|
+
// This can happen with tools that have empty schemas
|
|
149
|
+
const chunkId = chunk.id || `fallback-${chunk.index || 0}`;
|
|
150
|
+
acc[chunkId] = acc[chunkId] ?? [];
|
|
151
|
+
acc[chunkId].push(chunk);
|
|
151
152
|
return acc;
|
|
152
153
|
}, {});
|
|
153
154
|
const toolCalls = [];
|
|
@@ -157,6 +158,8 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
157
158
|
const name = chunks[0]?.name ?? "";
|
|
158
159
|
const joinedArgs = chunks.map((c) => c.args || "").join("");
|
|
159
160
|
const argsStr = joinedArgs.length ? joinedArgs : "{}";
|
|
161
|
+
// Use the original ID from the first chunk if it exists, otherwise use the grouped ID
|
|
162
|
+
const originalId = chunks[0]?.id || id;
|
|
160
163
|
try {
|
|
161
164
|
parsedArgs = (0, json_js_1.parsePartialJson)(argsStr);
|
|
162
165
|
if (parsedArgs === null ||
|
|
@@ -167,7 +170,7 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
167
170
|
toolCalls.push({
|
|
168
171
|
name,
|
|
169
172
|
args: parsedArgs,
|
|
170
|
-
id,
|
|
173
|
+
id: originalId,
|
|
171
174
|
type: "tool_call",
|
|
172
175
|
});
|
|
173
176
|
}
|
|
@@ -175,7 +178,7 @@ class AIMessageChunk extends base_js_1.BaseMessageChunk {
|
|
|
175
178
|
invalidToolCalls.push({
|
|
176
179
|
name,
|
|
177
180
|
args: argsStr,
|
|
178
|
-
id,
|
|
181
|
+
id: originalId,
|
|
179
182
|
error: "Malformed args.",
|
|
180
183
|
type: "invalid_tool_call",
|
|
181
184
|
});
|
package/dist/messages/ai.js
CHANGED
|
@@ -138,10 +138,11 @@ export class AIMessageChunk extends BaseMessageChunk {
|
|
|
138
138
|
}
|
|
139
139
|
else {
|
|
140
140
|
const groupedToolCallChunk = fields.tool_call_chunks.reduce((acc, chunk) => {
|
|
141
|
-
if
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
acc[
|
|
141
|
+
// Assign a fallback ID if the chunk doesn't have one
|
|
142
|
+
// This can happen with tools that have empty schemas
|
|
143
|
+
const chunkId = chunk.id || `fallback-${chunk.index || 0}`;
|
|
144
|
+
acc[chunkId] = acc[chunkId] ?? [];
|
|
145
|
+
acc[chunkId].push(chunk);
|
|
145
146
|
return acc;
|
|
146
147
|
}, {});
|
|
147
148
|
const toolCalls = [];
|
|
@@ -151,6 +152,8 @@ export class AIMessageChunk extends BaseMessageChunk {
|
|
|
151
152
|
const name = chunks[0]?.name ?? "";
|
|
152
153
|
const joinedArgs = chunks.map((c) => c.args || "").join("");
|
|
153
154
|
const argsStr = joinedArgs.length ? joinedArgs : "{}";
|
|
155
|
+
// Use the original ID from the first chunk if it exists, otherwise use the grouped ID
|
|
156
|
+
const originalId = chunks[0]?.id || id;
|
|
154
157
|
try {
|
|
155
158
|
parsedArgs = parsePartialJson(argsStr);
|
|
156
159
|
if (parsedArgs === null ||
|
|
@@ -161,7 +164,7 @@ export class AIMessageChunk extends BaseMessageChunk {
|
|
|
161
164
|
toolCalls.push({
|
|
162
165
|
name,
|
|
163
166
|
args: parsedArgs,
|
|
164
|
-
id,
|
|
167
|
+
id: originalId,
|
|
165
168
|
type: "tool_call",
|
|
166
169
|
});
|
|
167
170
|
}
|
|
@@ -169,7 +172,7 @@ export class AIMessageChunk extends BaseMessageChunk {
|
|
|
169
172
|
invalidToolCalls.push({
|
|
170
173
|
name,
|
|
171
174
|
args: argsStr,
|
|
172
|
-
id,
|
|
175
|
+
id: originalId,
|
|
173
176
|
error: "Malformed args.",
|
|
174
177
|
type: "invalid_tool_call",
|
|
175
178
|
});
|
|
@@ -67,20 +67,29 @@ exports.parseFString = parseFString;
|
|
|
67
67
|
* @param {mustache.TemplateSpans} template The result of parsing a mustache template with the mustache.js library.
|
|
68
68
|
* @returns {ParsedTemplateNode[]}
|
|
69
69
|
*/
|
|
70
|
-
const mustacheTemplateToNodes = (template) =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
const mustacheTemplateToNodes = (template) => {
|
|
71
|
+
const nodes = [];
|
|
72
|
+
for (const temp of template) {
|
|
73
|
+
if (temp[0] === "name") {
|
|
74
|
+
const name = temp[1].includes(".") ? temp[1].split(".")[0] : temp[1];
|
|
75
|
+
nodes.push({ type: "variable", name });
|
|
76
|
+
}
|
|
77
|
+
else if (["#", "&", "^", ">"].includes(temp[0])) {
|
|
78
|
+
// # represents a section, "&" represents an unescaped variable.
|
|
79
|
+
// These should both be considered variables.
|
|
80
|
+
nodes.push({ type: "variable", name: temp[1] });
|
|
81
|
+
// If this is a section with nested content, recursively process it
|
|
82
|
+
if (temp[0] === "#" && temp.length > 4 && Array.isArray(temp[4])) {
|
|
83
|
+
const nestedNodes = mustacheTemplateToNodes(temp[4]);
|
|
84
|
+
nodes.push(...nestedNodes);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
nodes.push({ type: "literal", text: temp[1] });
|
|
89
|
+
}
|
|
82
90
|
}
|
|
83
|
-
|
|
91
|
+
return nodes;
|
|
92
|
+
};
|
|
84
93
|
const parseMustache = (template) => {
|
|
85
94
|
configureMustache();
|
|
86
95
|
const parsed = mustache_1.default.parse(template);
|
package/dist/prompts/template.js
CHANGED
|
@@ -60,20 +60,29 @@ export const parseFString = (template) => {
|
|
|
60
60
|
* @param {mustache.TemplateSpans} template The result of parsing a mustache template with the mustache.js library.
|
|
61
61
|
* @returns {ParsedTemplateNode[]}
|
|
62
62
|
*/
|
|
63
|
-
const mustacheTemplateToNodes = (template) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
const mustacheTemplateToNodes = (template) => {
|
|
64
|
+
const nodes = [];
|
|
65
|
+
for (const temp of template) {
|
|
66
|
+
if (temp[0] === "name") {
|
|
67
|
+
const name = temp[1].includes(".") ? temp[1].split(".")[0] : temp[1];
|
|
68
|
+
nodes.push({ type: "variable", name });
|
|
69
|
+
}
|
|
70
|
+
else if (["#", "&", "^", ">"].includes(temp[0])) {
|
|
71
|
+
// # represents a section, "&" represents an unescaped variable.
|
|
72
|
+
// These should both be considered variables.
|
|
73
|
+
nodes.push({ type: "variable", name: temp[1] });
|
|
74
|
+
// If this is a section with nested content, recursively process it
|
|
75
|
+
if (temp[0] === "#" && temp.length > 4 && Array.isArray(temp[4])) {
|
|
76
|
+
const nestedNodes = mustacheTemplateToNodes(temp[4]);
|
|
77
|
+
nodes.push(...nestedNodes);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
nodes.push({ type: "literal", text: temp[1] });
|
|
82
|
+
}
|
|
75
83
|
}
|
|
76
|
-
|
|
84
|
+
return nodes;
|
|
85
|
+
};
|
|
77
86
|
export const parseMustache = (template) => {
|
|
78
87
|
configureMustache();
|
|
79
88
|
const parsed = mustache.parse(template);
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -1881,9 +1881,9 @@ exports.RunnableLambda = RunnableLambda;
|
|
|
1881
1881
|
* );
|
|
1882
1882
|
*
|
|
1883
1883
|
* // Invoke the sequence with a single age input
|
|
1884
|
-
* const res = sequence.invoke(25);
|
|
1884
|
+
* const res = await sequence.invoke(25);
|
|
1885
1885
|
*
|
|
1886
|
-
* // { years_to_fifty:
|
|
1886
|
+
* // { years_to_fifty: 20, years_to_hundred: 70 }
|
|
1887
1887
|
* ```
|
|
1888
1888
|
*/
|
|
1889
1889
|
class RunnableParallel extends RunnableMap {
|
package/dist/runnables/base.d.ts
CHANGED
|
@@ -729,9 +729,9 @@ export declare class RunnableLambda<RunInput, RunOutput, CallOptions extends Run
|
|
|
729
729
|
* );
|
|
730
730
|
*
|
|
731
731
|
* // Invoke the sequence with a single age input
|
|
732
|
-
* const res = sequence.invoke(25);
|
|
732
|
+
* const res = await sequence.invoke(25);
|
|
733
733
|
*
|
|
734
|
-
* // { years_to_fifty:
|
|
734
|
+
* // { years_to_fifty: 20, years_to_hundred: 70 }
|
|
735
735
|
* ```
|
|
736
736
|
*/
|
|
737
737
|
export declare class RunnableParallel<RunInput> extends RunnableMap<RunInput> {
|
package/dist/runnables/base.js
CHANGED
|
@@ -1864,9 +1864,9 @@ export class RunnableLambda extends Runnable {
|
|
|
1864
1864
|
* );
|
|
1865
1865
|
*
|
|
1866
1866
|
* // Invoke the sequence with a single age input
|
|
1867
|
-
* const res = sequence.invoke(25);
|
|
1867
|
+
* const res = await sequence.invoke(25);
|
|
1868
1868
|
*
|
|
1869
|
-
* // { years_to_fifty:
|
|
1869
|
+
* // { years_to_fifty: 20, years_to_hundred: 70 }
|
|
1870
1870
|
* ```
|
|
1871
1871
|
*/
|
|
1872
1872
|
export class RunnableParallel extends RunnableMap {
|