Internal
Creates a new MediaManager instance.
Configuration object containing the API client
Replaces media reference strings in an object with base64 data URIs.
This method recursively traverses an object looking for media reference strings in the format "@@@langfuseMedia:...@@@". When found, it fetches the actual media content from Langfuse and replaces the reference string with a base64 data URI.
If fetching media content fails for a reference string, a warning is logged and the reference string is left unchanged.
Configuration object
A deep copy of the input object with media references resolved
const obj = {
image: "@@@langfuseMedia:type=image/jpeg|id=123|source=bytes@@@",
nested: {
pdf: "@@@langfuseMedia:type=application/pdf|id=456|source=bytes@@@"
}
};
const result = await langfuse.media.resolveReferences({
obj,
resolveWith: "base64DataUri"
});
// Result:
// {
// image: "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
// nested: {
// pdf: "data:application/pdf;base64,JVBERi0xLjcK..."
// }
// }
Static
parseParses a media reference string into a ParsedMediaReference.
Example reference string: "@@@langfuseMedia:type=image/jpeg|id=some-uuid|source=base64DataUri@@@"
The reference string to parse.
An object with the mediaId, source, and contentType.
Manager for media operations in Langfuse.
Provides methods to resolve media references in objects by replacing them with actual media content (e.g., base64 data URIs).