Optional
base64Optional
contentOptional
contentOptional
fileOptional
obj?: objectOptional
_contentOptional
_contentOptional
_mediaOptional
_sourceOptional
objStatic
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.
Static
resolveReplaces the media reference strings in an object with base64 data URIs for the media content.
This method recursively traverses an object (up to a maximum depth of 10) looking for media reference strings in the format "@@@langfuseMedia:...@@@". When found, it fetches the actual media content using the provided Langfuse client 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 all media references replaced with base64 data URIs where possible
const obj = {
image: "@@@langfuseMedia:type=image/jpeg|id=123|source=bytes@@@",
nested: {
pdf: "@@@langfuseMedia:type=application/pdf|id=456|source=bytes@@@"
}
};
const result = await LangfuseMedia.resolveMediaReferences({
obj,
langfuseClient
});
// Result:
// {
// image: "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
// nested: {
// pdf: "data:application/pdf;base64,JVBERi0xLjcK..."
// }
// }
A class for wrapping media objects for upload to Langfuse.
This class handles the preparation and formatting of media content for Langfuse, supporting both base64 data URIs and raw content bytes.