-
Notifications
You must be signed in to change notification settings - Fork 321
fix(langgraph): handle toSerialized()
if present to handle V1 changes
#1659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v1
Are you sure you want to change the base?
Conversation
|
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)); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
if ( | ||
typeof original === "object" && | ||
original != null && | ||
"toSerialized" in original && | ||
typeof original.toSerialized === "function" | ||
) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
No description provided.