Skip to content

Conversation

@dqbd
Copy link
Collaborator

@dqbd dqbd commented Sep 12, 2025

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Sep 12, 2025

⚠️ No Changeset found

Latest commit: 66cb4c5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +126 to +143
function _defaultReplacer(this: any, key: string, value: any) {
const original = this[key] as unknown;
if (
typeof original === "object" &&
original != null &&
"toSerialized" in original &&
typeof original.toSerialized === "function"
) {
return original.toSerialized();
}

return _default(value);
}

export class JsonPlusSerializer implements SerializerProtocol {
protected _dumps(obj: any): Uint8Array {
const encoder = new TextEncoder();
return encoder.encode(
stringify(obj, (_: string, value: any) => {
return _default(value);
})
);
return encoder.encode(stringify(obj, _defaultReplacer));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we just make this a condition inside of _default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since we need the pre-serialized object

Comment on lines +128 to +133
if (
typeof original === "object" &&
original != null &&
"toSerialized" in original &&
typeof original.toSerialized === "function"
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be helpful to export a a isSerializable fn from core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe after we release @langchain/core

@dqbd dqbd closed this Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants