@langchain/core 0.1.29 → 0.1.31

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/README.md CHANGED
@@ -85,7 +85,7 @@ Rather than having to write multiple implementations for all of those, LCEL allo
85
85
 
86
86
  For more check out the [LCEL docs](https://js.langchain.com/docs/expression_language/).
87
87
 
88
- ![LangChain Stack](../docs/core_docs/static/img/langchain_stack.png)
88
+ ![LangChain Stack](../docs/core_docs/static/img/langchain_stack_feb_2024.webp)
89
89
 
90
90
  ## 📕 Releases & Versioning
91
91
 
@@ -308,7 +308,7 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
308
308
  if (typeof imgTemplate === "string") {
309
309
  const parsedTemplate = (0, template_js_1.parseFString)(imgTemplate);
310
310
  const variables = parsedTemplate.flatMap((item) => item.type === "variable" ? [item.name] : []);
311
- if (variables) {
311
+ if ((variables?.length ?? 0) > 0) {
312
312
  if (variables.length > 1) {
313
313
  throw new Error(`Only one format variable allowed per image template.\nGot: ${variables}\nFrom: ${imgTemplate}`);
314
314
  }
@@ -300,7 +300,7 @@ class _StringImageMessagePromptTemplate extends BaseMessagePromptTemplate {
300
300
  if (typeof imgTemplate === "string") {
301
301
  const parsedTemplate = parseFString(imgTemplate);
302
302
  const variables = parsedTemplate.flatMap((item) => item.type === "variable" ? [item.name] : []);
303
- if (variables) {
303
+ if ((variables?.length ?? 0) > 0) {
304
304
  if (variables.length > 1) {
305
305
  throw new Error(`Only one format variable allowed per image template.\nGot: ${variables}\nFrom: ${imgTemplate}`);
306
306
  }
@@ -28,6 +28,16 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
28
28
  copy() {
29
29
  return this;
30
30
  }
31
+ stringifyError(error) {
32
+ // eslint-disable-next-line no-instanceof/no-instanceof
33
+ if (error instanceof Error) {
34
+ return error.message + (error?.stack ? `\n\n${error.stack}` : "");
35
+ }
36
+ if (typeof error === "string") {
37
+ return error;
38
+ }
39
+ return `${error}`;
40
+ }
31
41
  _addChildRun(parentRun, childRun) {
32
42
  parentRun.child_runs.push(childRun);
33
43
  }
@@ -165,7 +175,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
165
175
  throw new Error("No LLM run to end.");
166
176
  }
167
177
  run.end_time = Date.now();
168
- run.error = error.message;
178
+ run.error = this.stringifyError(error);
169
179
  run.events.push({
170
180
  name: "error",
171
181
  time: new Date(run.end_time).toISOString(),
@@ -225,7 +235,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
225
235
  throw new Error("No chain run to end.");
226
236
  }
227
237
  run.end_time = Date.now();
228
- run.error = error.message + (error?.stack ? `\n\n${error.stack}` : "");
238
+ run.error = this.stringifyError(error);
229
239
  run.events.push({
230
240
  name: "error",
231
241
  time: new Date(run.end_time).toISOString(),
@@ -285,7 +295,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
285
295
  throw new Error("No tool run to end");
286
296
  }
287
297
  run.end_time = Date.now();
288
- run.error = error.message;
298
+ run.error = this.stringifyError(error);
289
299
  run.events.push({
290
300
  name: "error",
291
301
  time: new Date(run.end_time).toISOString(),
@@ -369,7 +379,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
369
379
  throw new Error("No retriever run to end");
370
380
  }
371
381
  run.end_time = Date.now();
372
- run.error = error.message;
382
+ run.error = this.stringifyError(error);
373
383
  run.events.push({
374
384
  name: "error",
375
385
  time: new Date(run.end_time).toISOString(),
@@ -28,6 +28,7 @@ export declare abstract class BaseTracer extends BaseCallbackHandler {
28
28
  protected runMap: Map<string, Run>;
29
29
  constructor(_fields?: BaseCallbackHandlerInput);
30
30
  copy(): this;
31
+ protected stringifyError(error: unknown): string;
31
32
  protected abstract persistRun(run: Run): Promise<void>;
32
33
  protected _addChildRun(parentRun: Run, childRun: Run): void;
33
34
  protected _startTrace(run: Run): Promise<void>;
@@ -36,22 +37,22 @@ export declare abstract class BaseTracer extends BaseCallbackHandler {
36
37
  handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
37
38
  handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
38
39
  handleLLMEnd(output: LLMResult, runId: string): Promise<Run>;
39
- handleLLMError(error: Error, runId: string): Promise<Run>;
40
+ handleLLMError(error: unknown, runId: string): Promise<Run>;
40
41
  handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, runType?: string, name?: string): Promise<Run>;
41
42
  handleChainEnd(outputs: ChainValues, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
42
43
  inputs?: Record<string, unknown>;
43
44
  }): Promise<Run>;
44
- handleChainError(error: Error, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
45
+ handleChainError(error: unknown, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
45
46
  inputs?: Record<string, unknown>;
46
47
  }): Promise<Run>;
47
48
  handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
48
49
  handleToolEnd(output: string, runId: string): Promise<Run>;
49
- handleToolError(error: Error, runId: string): Promise<Run>;
50
+ handleToolError(error: unknown, runId: string): Promise<Run>;
50
51
  handleAgentAction(action: AgentAction, runId: string): Promise<void>;
51
52
  handleAgentEnd(action: AgentFinish, runId: string): Promise<void>;
52
53
  handleRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
53
54
  handleRetrieverEnd(documents: Document<Record<string, unknown>>[], runId: string): Promise<Run>;
54
- handleRetrieverError(error: Error, runId: string): Promise<Run>;
55
+ handleRetrieverError(error: unknown, runId: string): Promise<Run>;
55
56
  handleText(text: string, runId: string): Promise<void>;
56
57
  handleLLMNewToken(token: string, idx: NewTokenIndices, runId: string, _parentRunId?: string, _tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<Run>;
57
58
  onRunCreate?(run: Run): void | Promise<void>;
@@ -25,6 +25,16 @@ export class BaseTracer extends BaseCallbackHandler {
25
25
  copy() {
26
26
  return this;
27
27
  }
28
+ stringifyError(error) {
29
+ // eslint-disable-next-line no-instanceof/no-instanceof
30
+ if (error instanceof Error) {
31
+ return error.message + (error?.stack ? `\n\n${error.stack}` : "");
32
+ }
33
+ if (typeof error === "string") {
34
+ return error;
35
+ }
36
+ return `${error}`;
37
+ }
28
38
  _addChildRun(parentRun, childRun) {
29
39
  parentRun.child_runs.push(childRun);
30
40
  }
@@ -162,7 +172,7 @@ export class BaseTracer extends BaseCallbackHandler {
162
172
  throw new Error("No LLM run to end.");
163
173
  }
164
174
  run.end_time = Date.now();
165
- run.error = error.message;
175
+ run.error = this.stringifyError(error);
166
176
  run.events.push({
167
177
  name: "error",
168
178
  time: new Date(run.end_time).toISOString(),
@@ -222,7 +232,7 @@ export class BaseTracer extends BaseCallbackHandler {
222
232
  throw new Error("No chain run to end.");
223
233
  }
224
234
  run.end_time = Date.now();
225
- run.error = error.message + (error?.stack ? `\n\n${error.stack}` : "");
235
+ run.error = this.stringifyError(error);
226
236
  run.events.push({
227
237
  name: "error",
228
238
  time: new Date(run.end_time).toISOString(),
@@ -282,7 +292,7 @@ export class BaseTracer extends BaseCallbackHandler {
282
292
  throw new Error("No tool run to end");
283
293
  }
284
294
  run.end_time = Date.now();
285
- run.error = error.message;
295
+ run.error = this.stringifyError(error);
286
296
  run.events.push({
287
297
  name: "error",
288
298
  time: new Date(run.end_time).toISOString(),
@@ -366,7 +376,7 @@ export class BaseTracer extends BaseCallbackHandler {
366
376
  throw new Error("No retriever run to end");
367
377
  }
368
378
  run.end_time = Date.now();
369
- run.error = error.message;
379
+ run.error = this.stringifyError(error);
370
380
  run.events.push({
371
381
  name: "error",
372
382
  time: new Date(run.end_time).toISOString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {