From 0acdc3b8b3caeb3eea43c31bb412e9b9f6056a75 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Wed, 17 Jul 2024 17:27:36 -0700 Subject: [PATCH] Fix console.dir case --- langchain-core/src/messages/base.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/langchain-core/src/messages/base.ts b/langchain-core/src/messages/base.ts index 2020be90135c..a0f9ca1e3640 100644 --- a/langchain-core/src/messages/base.ts +++ b/langchain-core/src/messages/base.ts @@ -271,15 +271,22 @@ export abstract class BaseMessage }; } - toString() { - const printable = stringifyWithDepthLimit(this._printableFields, 4); + get [Symbol.toStringTag]() { // eslint-disable-next-line @typescript-eslint/no-explicit-any - return `${(this.constructor as any).lc_name()} ${printable}`; + return (this.constructor as any).lc_name(); } // Override the default behavior of console.log - [Symbol.for("nodejs.util.inspect.custom")]() { - return this.toString(); + [Symbol.for("nodejs.util.inspect.custom")](depth: number | null) { + if (depth === null) { + return this; + } + const printable = stringifyWithDepthLimit( + this._printableFields, + Math.max(4, depth) + ); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return `${(this.constructor as any).lc_name()} ${printable}`; } }