@langchain/core 0.3.3 → 0.3.4

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.
@@ -38,7 +38,7 @@ type NonAlphanumeric = " " | "\t" | "\n" | "\r" | '"' | "'" | "{" | "[" | "(" |
38
38
  */
39
39
  type ExtractTemplateParamsRecursive<T extends string, Result extends string[] = []> = T extends `${string}{${infer Param}}${infer Rest}` ? Param extends `${NonAlphanumeric}${string}` ? ExtractTemplateParamsRecursive<Rest, Result> : ExtractTemplateParamsRecursive<Rest, [...Result, Param]> : Result;
40
40
  export type ParamsFromFString<T extends string> = {
41
- [Key in ExtractTemplateParamsRecursive<T>[number] | (string & Record<never, never>)]: string;
41
+ [Key in ExtractTemplateParamsRecursive<T>[number] | (string & Record<never, never>)]: any;
42
42
  };
43
43
  export type ExtractedFStringParams<T extends string, RunInput extends InputValues = Symbol> = RunInput extends Symbol ? ParamsFromFString<T> : RunInput;
44
44
  /**
@@ -86,15 +86,20 @@ const parseMustache = (template) => {
86
86
  return mustacheTemplateToNodes(parsed);
87
87
  };
88
88
  exports.parseMustache = parseMustache;
89
- const interpolateFString = (template, values) => (0, exports.parseFString)(template).reduce((res, node) => {
90
- if (node.type === "variable") {
91
- if (node.name in values) {
92
- return res + values[node.name];
89
+ const interpolateFString = (template, values) => {
90
+ return (0, exports.parseFString)(template).reduce((res, node) => {
91
+ if (node.type === "variable") {
92
+ if (node.name in values) {
93
+ const stringValue = typeof values[node.name] === "string"
94
+ ? values[node.name]
95
+ : JSON.stringify(values[node.name]);
96
+ return res + stringValue;
97
+ }
98
+ throw new Error(`(f-string) Missing value for input ${node.name}`);
93
99
  }
94
- throw new Error(`(f-string) Missing value for input ${node.name}`);
95
- }
96
- return res + node.text;
97
- }, "");
100
+ return res + node.text;
101
+ }, "");
102
+ };
98
103
  exports.interpolateFString = interpolateFString;
99
104
  const interpolateMustache = (template, values) => {
100
105
  configureMustache();
@@ -78,15 +78,20 @@ export const parseMustache = (template) => {
78
78
  const parsed = mustache.parse(template);
79
79
  return mustacheTemplateToNodes(parsed);
80
80
  };
81
- export const interpolateFString = (template, values) => parseFString(template).reduce((res, node) => {
82
- if (node.type === "variable") {
83
- if (node.name in values) {
84
- return res + values[node.name];
81
+ export const interpolateFString = (template, values) => {
82
+ return parseFString(template).reduce((res, node) => {
83
+ if (node.type === "variable") {
84
+ if (node.name in values) {
85
+ const stringValue = typeof values[node.name] === "string"
86
+ ? values[node.name]
87
+ : JSON.stringify(values[node.name]);
88
+ return res + stringValue;
89
+ }
90
+ throw new Error(`(f-string) Missing value for input ${node.name}`);
85
91
  }
86
- throw new Error(`(f-string) Missing value for input ${node.name}`);
87
- }
88
- return res + node.text;
89
- }, "");
92
+ return res + node.text;
93
+ }, "");
94
+ };
90
95
  export const interpolateMustache = (template, values) => {
91
96
  configureMustache();
92
97
  return mustache.render(template, values);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {