@langfuse/core 4.0.0-beta.5 → 4.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +201 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +153 -2
- package/dist/index.d.ts +153 -2
- package/dist/index.mjs +196 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -5891,7 +5891,10 @@ type LangfuseEnvVar = "LANGFUSE_PUBLIC_KEY" | "LANGFUSE_SECRET_KEY" | "LANGFUSE_
|
|
|
5891
5891
|
declare function getEnv(key: LangfuseEnvVar): string | undefined;
|
|
5892
5892
|
declare function generateUUID(globalThis?: any): string;
|
|
5893
5893
|
declare function safeSetTimeout(fn: () => void, timeout: number): any;
|
|
5894
|
-
declare function
|
|
5894
|
+
declare function base64ToBytes(base64: string): Uint8Array;
|
|
5895
|
+
declare function bytesToBase64(bytes: Uint8Array): string;
|
|
5896
|
+
declare function base64Encode(input: string): string;
|
|
5897
|
+
declare function base64Decode(input: string): string;
|
|
5895
5898
|
|
|
5896
5899
|
type ParsedMediaReference = {
|
|
5897
5900
|
mediaId: string;
|
|
@@ -5899,4 +5902,152 @@ type ParsedMediaReference = {
|
|
|
5899
5902
|
contentType: MediaContentType;
|
|
5900
5903
|
};
|
|
5901
5904
|
|
|
5902
|
-
|
|
5905
|
+
/**
|
|
5906
|
+
* Parameters for creating a LangfuseMedia instance.
|
|
5907
|
+
*
|
|
5908
|
+
* Supports two input formats:
|
|
5909
|
+
* - Base64 data URI (e.g., "data:image/png;base64,...")
|
|
5910
|
+
* - Raw bytes with explicit content type
|
|
5911
|
+
*
|
|
5912
|
+
* @public
|
|
5913
|
+
*/
|
|
5914
|
+
type LangfuseMediaParams = {
|
|
5915
|
+
/** Indicates the media is provided as a base64 data URI */
|
|
5916
|
+
source: "base64_data_uri";
|
|
5917
|
+
/** The complete base64 data URI string */
|
|
5918
|
+
base64DataUri: string;
|
|
5919
|
+
} | {
|
|
5920
|
+
/** Indicates the media is provided as raw bytes */
|
|
5921
|
+
source: "bytes";
|
|
5922
|
+
/** The raw content bytes */
|
|
5923
|
+
contentBytes: Uint8Array;
|
|
5924
|
+
/** The MIME type of the content */
|
|
5925
|
+
contentType: MediaContentType;
|
|
5926
|
+
};
|
|
5927
|
+
/**
|
|
5928
|
+
* A class for wrapping media objects for upload to Langfuse.
|
|
5929
|
+
*
|
|
5930
|
+
* This class handles the preparation and formatting of media content for Langfuse,
|
|
5931
|
+
* supporting both base64 data URIs and raw content bytes. It automatically:
|
|
5932
|
+
* - Parses base64 data URIs to extract content type and bytes
|
|
5933
|
+
* - Generates SHA-256 hashes for content integrity
|
|
5934
|
+
* - Creates unique media IDs based on content hash
|
|
5935
|
+
* - Formats media references for embedding in traces
|
|
5936
|
+
*
|
|
5937
|
+
* @example
|
|
5938
|
+
* ```typescript
|
|
5939
|
+
* // From base64 data URI
|
|
5940
|
+
* const media1 = new LangfuseMedia({
|
|
5941
|
+
* source: "base64_data_uri",
|
|
5942
|
+
* base64DataUri: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
|
|
5943
|
+
* });
|
|
5944
|
+
*
|
|
5945
|
+
* // From raw bytes
|
|
5946
|
+
* const media2 = new LangfuseMedia({
|
|
5947
|
+
* source: "bytes",
|
|
5948
|
+
* contentBytes: new Uint8Array([72, 101, 108, 108, 111])
|
|
5949
|
+
* contentType: "text/plain"
|
|
5950
|
+
* });
|
|
5951
|
+
*
|
|
5952
|
+
* console.log(media1.id); // Unique media ID
|
|
5953
|
+
* console.log(media1.tag); // Media reference tag
|
|
5954
|
+
* ```
|
|
5955
|
+
*
|
|
5956
|
+
* @public
|
|
5957
|
+
*/
|
|
5958
|
+
declare class LangfuseMedia {
|
|
5959
|
+
_contentBytes?: Uint8Array;
|
|
5960
|
+
_contentType?: MediaContentType;
|
|
5961
|
+
_source?: string;
|
|
5962
|
+
/**
|
|
5963
|
+
* Creates a new LangfuseMedia instance.
|
|
5964
|
+
*
|
|
5965
|
+
* @param params - Media parameters specifying the source and content
|
|
5966
|
+
*
|
|
5967
|
+
* @example
|
|
5968
|
+
* ```typescript
|
|
5969
|
+
* // Create from base64 data URI
|
|
5970
|
+
* const media = new LangfuseMedia({
|
|
5971
|
+
* source: "base64_data_uri",
|
|
5972
|
+
* base64DataUri: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
|
|
5973
|
+
* });
|
|
5974
|
+
* ```
|
|
5975
|
+
*/
|
|
5976
|
+
constructor(params: LangfuseMediaParams);
|
|
5977
|
+
/**
|
|
5978
|
+
* Parses a base64 data URI to extract content bytes and type.
|
|
5979
|
+
*
|
|
5980
|
+
* @param data - The base64 data URI string
|
|
5981
|
+
* @returns Tuple of [contentBytes, contentType] or [undefined, undefined] on error
|
|
5982
|
+
* @private
|
|
5983
|
+
*/
|
|
5984
|
+
private parseBase64DataUri;
|
|
5985
|
+
/**
|
|
5986
|
+
* Gets a unique identifier for this media based on its content hash.
|
|
5987
|
+
*
|
|
5988
|
+
* The ID is derived from the first 22 characters of the URL-safe base64-encoded
|
|
5989
|
+
* SHA-256 hash of the content.
|
|
5990
|
+
*
|
|
5991
|
+
* @returns The unique media ID, or null if hash generation failed
|
|
5992
|
+
*
|
|
5993
|
+
* @example
|
|
5994
|
+
* ```typescript
|
|
5995
|
+
* const media = new LangfuseMedia({...});
|
|
5996
|
+
* console.log(media.id); // "A1B2C3D4E5F6G7H8I9J0K1"
|
|
5997
|
+
* ```
|
|
5998
|
+
*/
|
|
5999
|
+
getId(): Promise<string | null>;
|
|
6000
|
+
/**
|
|
6001
|
+
* Gets the length of the media content in bytes.
|
|
6002
|
+
*
|
|
6003
|
+
* @returns The content length in bytes, or undefined if no content is available
|
|
6004
|
+
*/
|
|
6005
|
+
get contentLength(): number | undefined;
|
|
6006
|
+
/**
|
|
6007
|
+
* Gets the SHA-256 hash of the media content.
|
|
6008
|
+
*
|
|
6009
|
+
* The hash is used for content integrity verification and generating unique media IDs.
|
|
6010
|
+
* Returns undefined if crypto is not available or hash generation fails.
|
|
6011
|
+
*
|
|
6012
|
+
* @returns The base64-encoded SHA-256 hash, or undefined if unavailable
|
|
6013
|
+
*/
|
|
6014
|
+
getSha256Hash(): Promise<string | undefined>;
|
|
6015
|
+
/**
|
|
6016
|
+
* Gets the media reference tag for embedding in trace data.
|
|
6017
|
+
*
|
|
6018
|
+
* The tag format is: `@@@langfuseMedia:type=<contentType>|id=<mediaId>|source=<source>@@@`
|
|
6019
|
+
* This tag can be embedded in trace attributes and will be replaced with actual
|
|
6020
|
+
* media content when the trace is viewed in Langfuse.
|
|
6021
|
+
*
|
|
6022
|
+
* @returns The media reference tag, or null if required data is missing
|
|
6023
|
+
*
|
|
6024
|
+
* @example
|
|
6025
|
+
* ```typescript
|
|
6026
|
+
* const media = new LangfuseMedia({...});
|
|
6027
|
+
* console.log(media.tag);
|
|
6028
|
+
* // "@@@langfuseMedia:type=image/png|id=A1B2C3D4E5F6G7H8I9J0K1|source=base64_data_uri@@@"
|
|
6029
|
+
* ```
|
|
6030
|
+
*/
|
|
6031
|
+
getTag(): Promise<string | null>;
|
|
6032
|
+
/**
|
|
6033
|
+
* Gets the media content as a base64 data URI.
|
|
6034
|
+
*
|
|
6035
|
+
* @returns The complete data URI string, or null if no content is available
|
|
6036
|
+
*
|
|
6037
|
+
* @example
|
|
6038
|
+
* ```typescript
|
|
6039
|
+
* const media = new LangfuseMedia({...});
|
|
6040
|
+
* console.log(media.base64DataUri);
|
|
6041
|
+
* // "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB..."
|
|
6042
|
+
* ```
|
|
6043
|
+
*/
|
|
6044
|
+
get base64DataUri(): string | null;
|
|
6045
|
+
/**
|
|
6046
|
+
* Serializes the media to JSON (returns the base64 data URI).
|
|
6047
|
+
*
|
|
6048
|
+
* @returns The base64 data URI, or null if no content is available
|
|
6049
|
+
*/
|
|
6050
|
+
toJSON(): string | null;
|
|
6051
|
+
}
|
|
6052
|
+
|
|
6053
|
+
export { AccessDeniedError, type AnnotationQueue, type AnnotationQueueItem, AnnotationQueueObjectType, AnnotationQueueStatus, type ApiKeyDeletionResponse, type ApiKeyList, type ApiKeyResponse, type ApiKeySummary, type AuthenticationScheme, type BaseEvent, type BasePrompt, type BaseScore, type BaseScoreV1, type BooleanScore, type BooleanScoreV1, type BulkConfig, type CategoricalScore, type CategoricalScoreV1, type ChatMessage, ChatMessageWithPlaceholders, type ChatPrompt, type Comment, CommentObjectType, type ConfigCategory, type CreateAnnotationQueueItemRequest, type CreateApiKeyRequest, type CreateChatPromptRequest, type CreateCommentRequest, type CreateCommentResponse, type CreateDatasetItemRequest, type CreateDatasetRequest, type CreateDatasetRunItemRequest, type CreateEventBody, type CreateEventEvent, type CreateGenerationBody, type CreateGenerationEvent, type CreateModelRequest, type CreateObservationEvent, type CreateProjectRequest, CreatePromptRequest, type CreateScoreConfigRequest, type CreateScoreRequest, type CreateScoreResponse, type CreateScoreValue, type CreateSpanBody, type CreateSpanEvent, type CreateTextPromptRequest, type CreateUserRequest, type Dataset, type DatasetItem, type DatasetRun, type DatasetRunItem, type DatasetRunWithItems, DatasetStatus, type DeleteAnnotationQueueItemResponse, type DeleteDatasetItemResponse, type DeleteDatasetRunResponse, type DeleteTraceResponse, type DeleteTracesRequest, type EmptyResponse, Error$1 as Error, type FilterConfig, type GetAnnotationQueueItemsRequest, type GetAnnotationQueuesRequest, type GetCommentsRequest, type GetCommentsResponse, type GetDatasetItemsRequest, type GetDatasetRunsRequest, type GetDatasetsRequest, type GetMediaResponse, type GetMediaUploadUrlRequest, type GetMediaUploadUrlResponse, type GetMetricsRequest, type GetModelsRequest, type GetObservationsRequest, type GetPromptRequest, type GetScoreConfigsRequest, type GetScoresRequest, type GetScoresResponse, GetScoresResponseData, type GetScoresResponseDataBoolean, type GetScoresResponseDataCategorical, type GetScoresResponseDataNumeric, type GetScoresResponseTraceData, type GetSessionsRequest, type GetTracesRequest, type HealthResponse, type IngestionError, IngestionEvent, type IngestionRequest, type IngestionResponse, type IngestionSuccess, type IngestionUsage, LANGFUSE_SDK_NAME, LANGFUSE_SDK_VERSION, LANGFUSE_TRACER_NAME, LangfuseAPIClient, LangfuseAPIError, LangfuseAPITimeoutError, LangfuseMedia, type LangfuseMediaParams, LangfuseOtelSpanAttributes, type ListDatasetRunItemsRequest, type ListPromptsMetaRequest, type ListUsersRequest, LogLevel, Logger, type LoggerConfig, type MapValue, MediaContentType, type MembershipRequest, type MembershipResponse, MembershipRole, type MembershipsResponse, MethodNotAllowedError, type MetricsResponse, type Model, type ModelPrice, ModelUsageUnit, NotFoundError, type NumericScore, type NumericScoreV1, type Observation, type ObservationBody, ObservationLevel, ObservationType, type Observations$1 as Observations, type ObservationsView, type ObservationsViews, type OpenAiCompletionUsageSchema, type OpenAiResponseUsageSchema, type OpenAiUsage, type OptionalObservationBody, type OrganizationProject, type OrganizationProjectsResponse, type PaginatedAnnotationQueueItems, type PaginatedAnnotationQueues, type PaginatedDatasetItems, type PaginatedDatasetRunItems, type PaginatedDatasetRuns, type PaginatedDatasets, type PaginatedModels, type PaginatedSessions, type ParsedMediaReference, type PatchMediaBody, type PlaceholderMessage, type Project, type ProjectDeletionResponse, type Projects$1 as Projects, Prompt, type PromptMeta, type PromptMetaListResponse, type ResourceMeta, type ResourceType, type ResourceTypesResponse, type SchemaExtension, type SchemaResource, type SchemasResponse, type ScimEmail, type ScimFeatureSupport, type ScimName, type ScimUser, type ScimUsersListResponse, Score$1 as Score, type ScoreBody, type ScoreConfig, type ScoreConfigs$1 as ScoreConfigs, ScoreDataType, type ScoreEvent, ScoreSource, ScoreV1, type SdkLogBody, type SdkLogEvent, type ServiceProviderConfig, ServiceUnavailableError, type Session, type SessionWithTraces, type Sort, type TextPrompt, type Trace$1 as Trace, type TraceBody, type TraceEvent, type TraceWithDetails, type TraceWithFullDetails, type Traces, UnauthorizedError, type UpdateAnnotationQueueItemRequest, type UpdateEventBody, type UpdateGenerationBody, type UpdateGenerationEvent, type UpdateObservationEvent, type UpdateProjectRequest, type UpdatePromptRequest, type UpdateSpanBody, type UpdateSpanEvent, type Usage, type UsageDetails, type UserMeta, index$n as annotationQueues, base64Decode, base64Encode, base64ToBytes, bytesToBase64, index$m as comments, index$l as commons, configureGlobalLogger, createLogger, index$k as datasetItems, index$j as datasetRunItems, index$i as datasets, generateUUID, getEnv, getGlobalLogger, index$h as health, index$g as ingestion, LoggerSingleton as logger, index$f as media, index$e as metrics, index$d as models, index$c as observations, index$b as organizations, index$a as projects, index as promptVersion, index$9 as prompts, resetGlobalLogger, safeSetTimeout, index$8 as scim, index$5 as score, index$7 as scoreConfigs, index$6 as scoreV2, index$4 as sessions, index$3 as trace, index$1 as utils };
|
package/dist/index.d.ts
CHANGED
|
@@ -5891,7 +5891,10 @@ type LangfuseEnvVar = "LANGFUSE_PUBLIC_KEY" | "LANGFUSE_SECRET_KEY" | "LANGFUSE_
|
|
|
5891
5891
|
declare function getEnv(key: LangfuseEnvVar): string | undefined;
|
|
5892
5892
|
declare function generateUUID(globalThis?: any): string;
|
|
5893
5893
|
declare function safeSetTimeout(fn: () => void, timeout: number): any;
|
|
5894
|
-
declare function
|
|
5894
|
+
declare function base64ToBytes(base64: string): Uint8Array;
|
|
5895
|
+
declare function bytesToBase64(bytes: Uint8Array): string;
|
|
5896
|
+
declare function base64Encode(input: string): string;
|
|
5897
|
+
declare function base64Decode(input: string): string;
|
|
5895
5898
|
|
|
5896
5899
|
type ParsedMediaReference = {
|
|
5897
5900
|
mediaId: string;
|
|
@@ -5899,4 +5902,152 @@ type ParsedMediaReference = {
|
|
|
5899
5902
|
contentType: MediaContentType;
|
|
5900
5903
|
};
|
|
5901
5904
|
|
|
5902
|
-
|
|
5905
|
+
/**
|
|
5906
|
+
* Parameters for creating a LangfuseMedia instance.
|
|
5907
|
+
*
|
|
5908
|
+
* Supports two input formats:
|
|
5909
|
+
* - Base64 data URI (e.g., "data:image/png;base64,...")
|
|
5910
|
+
* - Raw bytes with explicit content type
|
|
5911
|
+
*
|
|
5912
|
+
* @public
|
|
5913
|
+
*/
|
|
5914
|
+
type LangfuseMediaParams = {
|
|
5915
|
+
/** Indicates the media is provided as a base64 data URI */
|
|
5916
|
+
source: "base64_data_uri";
|
|
5917
|
+
/** The complete base64 data URI string */
|
|
5918
|
+
base64DataUri: string;
|
|
5919
|
+
} | {
|
|
5920
|
+
/** Indicates the media is provided as raw bytes */
|
|
5921
|
+
source: "bytes";
|
|
5922
|
+
/** The raw content bytes */
|
|
5923
|
+
contentBytes: Uint8Array;
|
|
5924
|
+
/** The MIME type of the content */
|
|
5925
|
+
contentType: MediaContentType;
|
|
5926
|
+
};
|
|
5927
|
+
/**
|
|
5928
|
+
* A class for wrapping media objects for upload to Langfuse.
|
|
5929
|
+
*
|
|
5930
|
+
* This class handles the preparation and formatting of media content for Langfuse,
|
|
5931
|
+
* supporting both base64 data URIs and raw content bytes. It automatically:
|
|
5932
|
+
* - Parses base64 data URIs to extract content type and bytes
|
|
5933
|
+
* - Generates SHA-256 hashes for content integrity
|
|
5934
|
+
* - Creates unique media IDs based on content hash
|
|
5935
|
+
* - Formats media references for embedding in traces
|
|
5936
|
+
*
|
|
5937
|
+
* @example
|
|
5938
|
+
* ```typescript
|
|
5939
|
+
* // From base64 data URI
|
|
5940
|
+
* const media1 = new LangfuseMedia({
|
|
5941
|
+
* source: "base64_data_uri",
|
|
5942
|
+
* base64DataUri: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
|
|
5943
|
+
* });
|
|
5944
|
+
*
|
|
5945
|
+
* // From raw bytes
|
|
5946
|
+
* const media2 = new LangfuseMedia({
|
|
5947
|
+
* source: "bytes",
|
|
5948
|
+
* contentBytes: new Uint8Array([72, 101, 108, 108, 111])
|
|
5949
|
+
* contentType: "text/plain"
|
|
5950
|
+
* });
|
|
5951
|
+
*
|
|
5952
|
+
* console.log(media1.id); // Unique media ID
|
|
5953
|
+
* console.log(media1.tag); // Media reference tag
|
|
5954
|
+
* ```
|
|
5955
|
+
*
|
|
5956
|
+
* @public
|
|
5957
|
+
*/
|
|
5958
|
+
declare class LangfuseMedia {
|
|
5959
|
+
_contentBytes?: Uint8Array;
|
|
5960
|
+
_contentType?: MediaContentType;
|
|
5961
|
+
_source?: string;
|
|
5962
|
+
/**
|
|
5963
|
+
* Creates a new LangfuseMedia instance.
|
|
5964
|
+
*
|
|
5965
|
+
* @param params - Media parameters specifying the source and content
|
|
5966
|
+
*
|
|
5967
|
+
* @example
|
|
5968
|
+
* ```typescript
|
|
5969
|
+
* // Create from base64 data URI
|
|
5970
|
+
* const media = new LangfuseMedia({
|
|
5971
|
+
* source: "base64_data_uri",
|
|
5972
|
+
* base64DataUri: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
|
|
5973
|
+
* });
|
|
5974
|
+
* ```
|
|
5975
|
+
*/
|
|
5976
|
+
constructor(params: LangfuseMediaParams);
|
|
5977
|
+
/**
|
|
5978
|
+
* Parses a base64 data URI to extract content bytes and type.
|
|
5979
|
+
*
|
|
5980
|
+
* @param data - The base64 data URI string
|
|
5981
|
+
* @returns Tuple of [contentBytes, contentType] or [undefined, undefined] on error
|
|
5982
|
+
* @private
|
|
5983
|
+
*/
|
|
5984
|
+
private parseBase64DataUri;
|
|
5985
|
+
/**
|
|
5986
|
+
* Gets a unique identifier for this media based on its content hash.
|
|
5987
|
+
*
|
|
5988
|
+
* The ID is derived from the first 22 characters of the URL-safe base64-encoded
|
|
5989
|
+
* SHA-256 hash of the content.
|
|
5990
|
+
*
|
|
5991
|
+
* @returns The unique media ID, or null if hash generation failed
|
|
5992
|
+
*
|
|
5993
|
+
* @example
|
|
5994
|
+
* ```typescript
|
|
5995
|
+
* const media = new LangfuseMedia({...});
|
|
5996
|
+
* console.log(media.id); // "A1B2C3D4E5F6G7H8I9J0K1"
|
|
5997
|
+
* ```
|
|
5998
|
+
*/
|
|
5999
|
+
getId(): Promise<string | null>;
|
|
6000
|
+
/**
|
|
6001
|
+
* Gets the length of the media content in bytes.
|
|
6002
|
+
*
|
|
6003
|
+
* @returns The content length in bytes, or undefined if no content is available
|
|
6004
|
+
*/
|
|
6005
|
+
get contentLength(): number | undefined;
|
|
6006
|
+
/**
|
|
6007
|
+
* Gets the SHA-256 hash of the media content.
|
|
6008
|
+
*
|
|
6009
|
+
* The hash is used for content integrity verification and generating unique media IDs.
|
|
6010
|
+
* Returns undefined if crypto is not available or hash generation fails.
|
|
6011
|
+
*
|
|
6012
|
+
* @returns The base64-encoded SHA-256 hash, or undefined if unavailable
|
|
6013
|
+
*/
|
|
6014
|
+
getSha256Hash(): Promise<string | undefined>;
|
|
6015
|
+
/**
|
|
6016
|
+
* Gets the media reference tag for embedding in trace data.
|
|
6017
|
+
*
|
|
6018
|
+
* The tag format is: `@@@langfuseMedia:type=<contentType>|id=<mediaId>|source=<source>@@@`
|
|
6019
|
+
* This tag can be embedded in trace attributes and will be replaced with actual
|
|
6020
|
+
* media content when the trace is viewed in Langfuse.
|
|
6021
|
+
*
|
|
6022
|
+
* @returns The media reference tag, or null if required data is missing
|
|
6023
|
+
*
|
|
6024
|
+
* @example
|
|
6025
|
+
* ```typescript
|
|
6026
|
+
* const media = new LangfuseMedia({...});
|
|
6027
|
+
* console.log(media.tag);
|
|
6028
|
+
* // "@@@langfuseMedia:type=image/png|id=A1B2C3D4E5F6G7H8I9J0K1|source=base64_data_uri@@@"
|
|
6029
|
+
* ```
|
|
6030
|
+
*/
|
|
6031
|
+
getTag(): Promise<string | null>;
|
|
6032
|
+
/**
|
|
6033
|
+
* Gets the media content as a base64 data URI.
|
|
6034
|
+
*
|
|
6035
|
+
* @returns The complete data URI string, or null if no content is available
|
|
6036
|
+
*
|
|
6037
|
+
* @example
|
|
6038
|
+
* ```typescript
|
|
6039
|
+
* const media = new LangfuseMedia({...});
|
|
6040
|
+
* console.log(media.base64DataUri);
|
|
6041
|
+
* // "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB..."
|
|
6042
|
+
* ```
|
|
6043
|
+
*/
|
|
6044
|
+
get base64DataUri(): string | null;
|
|
6045
|
+
/**
|
|
6046
|
+
* Serializes the media to JSON (returns the base64 data URI).
|
|
6047
|
+
*
|
|
6048
|
+
* @returns The base64 data URI, or null if no content is available
|
|
6049
|
+
*/
|
|
6050
|
+
toJSON(): string | null;
|
|
6051
|
+
}
|
|
6052
|
+
|
|
6053
|
+
export { AccessDeniedError, type AnnotationQueue, type AnnotationQueueItem, AnnotationQueueObjectType, AnnotationQueueStatus, type ApiKeyDeletionResponse, type ApiKeyList, type ApiKeyResponse, type ApiKeySummary, type AuthenticationScheme, type BaseEvent, type BasePrompt, type BaseScore, type BaseScoreV1, type BooleanScore, type BooleanScoreV1, type BulkConfig, type CategoricalScore, type CategoricalScoreV1, type ChatMessage, ChatMessageWithPlaceholders, type ChatPrompt, type Comment, CommentObjectType, type ConfigCategory, type CreateAnnotationQueueItemRequest, type CreateApiKeyRequest, type CreateChatPromptRequest, type CreateCommentRequest, type CreateCommentResponse, type CreateDatasetItemRequest, type CreateDatasetRequest, type CreateDatasetRunItemRequest, type CreateEventBody, type CreateEventEvent, type CreateGenerationBody, type CreateGenerationEvent, type CreateModelRequest, type CreateObservationEvent, type CreateProjectRequest, CreatePromptRequest, type CreateScoreConfigRequest, type CreateScoreRequest, type CreateScoreResponse, type CreateScoreValue, type CreateSpanBody, type CreateSpanEvent, type CreateTextPromptRequest, type CreateUserRequest, type Dataset, type DatasetItem, type DatasetRun, type DatasetRunItem, type DatasetRunWithItems, DatasetStatus, type DeleteAnnotationQueueItemResponse, type DeleteDatasetItemResponse, type DeleteDatasetRunResponse, type DeleteTraceResponse, type DeleteTracesRequest, type EmptyResponse, Error$1 as Error, type FilterConfig, type GetAnnotationQueueItemsRequest, type GetAnnotationQueuesRequest, type GetCommentsRequest, type GetCommentsResponse, type GetDatasetItemsRequest, type GetDatasetRunsRequest, type GetDatasetsRequest, type GetMediaResponse, type GetMediaUploadUrlRequest, type GetMediaUploadUrlResponse, type GetMetricsRequest, type GetModelsRequest, type GetObservationsRequest, type GetPromptRequest, type GetScoreConfigsRequest, type GetScoresRequest, type GetScoresResponse, GetScoresResponseData, type GetScoresResponseDataBoolean, type GetScoresResponseDataCategorical, type GetScoresResponseDataNumeric, type GetScoresResponseTraceData, type GetSessionsRequest, type GetTracesRequest, type HealthResponse, type IngestionError, IngestionEvent, type IngestionRequest, type IngestionResponse, type IngestionSuccess, type IngestionUsage, LANGFUSE_SDK_NAME, LANGFUSE_SDK_VERSION, LANGFUSE_TRACER_NAME, LangfuseAPIClient, LangfuseAPIError, LangfuseAPITimeoutError, LangfuseMedia, type LangfuseMediaParams, LangfuseOtelSpanAttributes, type ListDatasetRunItemsRequest, type ListPromptsMetaRequest, type ListUsersRequest, LogLevel, Logger, type LoggerConfig, type MapValue, MediaContentType, type MembershipRequest, type MembershipResponse, MembershipRole, type MembershipsResponse, MethodNotAllowedError, type MetricsResponse, type Model, type ModelPrice, ModelUsageUnit, NotFoundError, type NumericScore, type NumericScoreV1, type Observation, type ObservationBody, ObservationLevel, ObservationType, type Observations$1 as Observations, type ObservationsView, type ObservationsViews, type OpenAiCompletionUsageSchema, type OpenAiResponseUsageSchema, type OpenAiUsage, type OptionalObservationBody, type OrganizationProject, type OrganizationProjectsResponse, type PaginatedAnnotationQueueItems, type PaginatedAnnotationQueues, type PaginatedDatasetItems, type PaginatedDatasetRunItems, type PaginatedDatasetRuns, type PaginatedDatasets, type PaginatedModels, type PaginatedSessions, type ParsedMediaReference, type PatchMediaBody, type PlaceholderMessage, type Project, type ProjectDeletionResponse, type Projects$1 as Projects, Prompt, type PromptMeta, type PromptMetaListResponse, type ResourceMeta, type ResourceType, type ResourceTypesResponse, type SchemaExtension, type SchemaResource, type SchemasResponse, type ScimEmail, type ScimFeatureSupport, type ScimName, type ScimUser, type ScimUsersListResponse, Score$1 as Score, type ScoreBody, type ScoreConfig, type ScoreConfigs$1 as ScoreConfigs, ScoreDataType, type ScoreEvent, ScoreSource, ScoreV1, type SdkLogBody, type SdkLogEvent, type ServiceProviderConfig, ServiceUnavailableError, type Session, type SessionWithTraces, type Sort, type TextPrompt, type Trace$1 as Trace, type TraceBody, type TraceEvent, type TraceWithDetails, type TraceWithFullDetails, type Traces, UnauthorizedError, type UpdateAnnotationQueueItemRequest, type UpdateEventBody, type UpdateGenerationBody, type UpdateGenerationEvent, type UpdateObservationEvent, type UpdateProjectRequest, type UpdatePromptRequest, type UpdateSpanBody, type UpdateSpanEvent, type Usage, type UsageDetails, type UserMeta, index$n as annotationQueues, base64Decode, base64Encode, base64ToBytes, bytesToBase64, index$m as comments, index$l as commons, configureGlobalLogger, createLogger, index$k as datasetItems, index$j as datasetRunItems, index$i as datasets, generateUUID, getEnv, getGlobalLogger, index$h as health, index$g as ingestion, LoggerSingleton as logger, index$f as media, index$e as metrics, index$d as models, index$c as observations, index$b as organizations, index$a as projects, index as promptVersion, index$9 as prompts, resetGlobalLogger, safeSetTimeout, index$8 as scim, index$5 as score, index$7 as scoreConfigs, index$6 as scoreV2, index$4 as sessions, index$3 as trace, index$1 as utils };
|
package/dist/index.mjs
CHANGED
|
@@ -35,14 +35,29 @@ function safeSetTimeout(fn, timeout) {
|
|
|
35
35
|
}
|
|
36
36
|
return t;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function base64ToBytes(base64) {
|
|
39
|
+
const binString = atob(base64);
|
|
40
|
+
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
41
|
+
}
|
|
42
|
+
function bytesToBase64(bytes) {
|
|
43
|
+
const binString = Array.from(bytes, (byte) => String.fromCharCode(byte)).join(
|
|
44
|
+
""
|
|
45
|
+
);
|
|
46
|
+
return btoa(binString);
|
|
47
|
+
}
|
|
48
|
+
function base64Encode(input) {
|
|
39
49
|
if (typeof Buffer !== "undefined") {
|
|
40
|
-
return Buffer.from(
|
|
50
|
+
return Buffer.from(input, "utf8").toString("base64");
|
|
41
51
|
}
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
const bytes = new TextEncoder().encode(input);
|
|
53
|
+
return bytesToBase64(bytes);
|
|
54
|
+
}
|
|
55
|
+
function base64Decode(input) {
|
|
56
|
+
if (typeof Buffer !== "undefined") {
|
|
57
|
+
return Buffer.from(input, "base64").toString("utf8");
|
|
44
58
|
}
|
|
45
|
-
|
|
59
|
+
const bytes = base64ToBytes(input);
|
|
60
|
+
return new TextDecoder().decode(bytes);
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
// src/logger/index.ts
|
|
@@ -220,7 +235,7 @@ var resetGlobalLogger = () => {
|
|
|
220
235
|
// package.json
|
|
221
236
|
var package_default = {
|
|
222
237
|
name: "@langfuse/core",
|
|
223
|
-
version: "4.0.0-beta.
|
|
238
|
+
version: "4.0.0-beta.6",
|
|
224
239
|
description: "Core functions and utilities for Langfuse packages",
|
|
225
240
|
type: "module",
|
|
226
241
|
sideEffects: false,
|
|
@@ -1287,26 +1302,26 @@ function trimSlashes(str) {
|
|
|
1287
1302
|
}
|
|
1288
1303
|
|
|
1289
1304
|
// src/api/core/base64.ts
|
|
1290
|
-
function
|
|
1305
|
+
function base64ToBytes2(base64) {
|
|
1291
1306
|
const binString = atob(base64);
|
|
1292
1307
|
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
1293
1308
|
}
|
|
1294
|
-
function
|
|
1309
|
+
function bytesToBase642(bytes) {
|
|
1295
1310
|
const binString = String.fromCodePoint(...bytes);
|
|
1296
1311
|
return btoa(binString);
|
|
1297
1312
|
}
|
|
1298
|
-
function
|
|
1313
|
+
function base64Encode2(input) {
|
|
1299
1314
|
if (typeof Buffer !== "undefined") {
|
|
1300
1315
|
return Buffer.from(input, "utf8").toString("base64");
|
|
1301
1316
|
}
|
|
1302
1317
|
const bytes = new TextEncoder().encode(input);
|
|
1303
|
-
return
|
|
1318
|
+
return bytesToBase642(bytes);
|
|
1304
1319
|
}
|
|
1305
|
-
function
|
|
1320
|
+
function base64Decode2(input) {
|
|
1306
1321
|
if (typeof Buffer !== "undefined") {
|
|
1307
1322
|
return Buffer.from(input, "base64").toString("utf8");
|
|
1308
1323
|
}
|
|
1309
|
-
const bytes =
|
|
1324
|
+
const bytes = base64ToBytes2(input);
|
|
1310
1325
|
return new TextDecoder().decode(bytes);
|
|
1311
1326
|
}
|
|
1312
1327
|
|
|
@@ -1317,12 +1332,12 @@ var BasicAuth = {
|
|
|
1317
1332
|
if (basicAuth == null) {
|
|
1318
1333
|
return void 0;
|
|
1319
1334
|
}
|
|
1320
|
-
const token =
|
|
1335
|
+
const token = base64Encode2(`${basicAuth.username}:${basicAuth.password}`);
|
|
1321
1336
|
return `Basic ${token}`;
|
|
1322
1337
|
},
|
|
1323
1338
|
fromAuthorizationHeader: (header) => {
|
|
1324
1339
|
const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, "");
|
|
1325
|
-
const decoded =
|
|
1340
|
+
const decoded = base64Decode2(credentials);
|
|
1326
1341
|
const [username, password] = decoded.split(":", 2);
|
|
1327
1342
|
if (username == null || password == null) {
|
|
1328
1343
|
throw new Error("Invalid basic auth");
|
|
@@ -9549,6 +9564,168 @@ var LangfuseAPIClient = class {
|
|
|
9549
9564
|
return (_a2 = this._trace) != null ? _a2 : this._trace = new Trace(this._options);
|
|
9550
9565
|
}
|
|
9551
9566
|
};
|
|
9567
|
+
|
|
9568
|
+
// src/media.ts
|
|
9569
|
+
var LangfuseMedia = class {
|
|
9570
|
+
/**
|
|
9571
|
+
* Creates a new LangfuseMedia instance.
|
|
9572
|
+
*
|
|
9573
|
+
* @param params - Media parameters specifying the source and content
|
|
9574
|
+
*
|
|
9575
|
+
* @example
|
|
9576
|
+
* ```typescript
|
|
9577
|
+
* // Create from base64 data URI
|
|
9578
|
+
* const media = new LangfuseMedia({
|
|
9579
|
+
* source: "base64_data_uri",
|
|
9580
|
+
* base64DataUri: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
|
|
9581
|
+
* });
|
|
9582
|
+
* ```
|
|
9583
|
+
*/
|
|
9584
|
+
constructor(params) {
|
|
9585
|
+
const { source } = params;
|
|
9586
|
+
this._source = source;
|
|
9587
|
+
if (source === "base64_data_uri") {
|
|
9588
|
+
const [contentBytesParsed, contentTypeParsed] = this.parseBase64DataUri(
|
|
9589
|
+
params.base64DataUri
|
|
9590
|
+
);
|
|
9591
|
+
this._contentBytes = contentBytesParsed;
|
|
9592
|
+
this._contentType = contentTypeParsed;
|
|
9593
|
+
} else {
|
|
9594
|
+
this._contentBytes = params.contentBytes;
|
|
9595
|
+
this._contentType = params.contentType;
|
|
9596
|
+
}
|
|
9597
|
+
}
|
|
9598
|
+
/**
|
|
9599
|
+
* Parses a base64 data URI to extract content bytes and type.
|
|
9600
|
+
*
|
|
9601
|
+
* @param data - The base64 data URI string
|
|
9602
|
+
* @returns Tuple of [contentBytes, contentType] or [undefined, undefined] on error
|
|
9603
|
+
* @private
|
|
9604
|
+
*/
|
|
9605
|
+
parseBase64DataUri(data) {
|
|
9606
|
+
try {
|
|
9607
|
+
if (!data || typeof data !== "string") {
|
|
9608
|
+
throw new Error("Data URI is not a string");
|
|
9609
|
+
}
|
|
9610
|
+
if (!data.startsWith("data:")) {
|
|
9611
|
+
throw new Error("Data URI does not start with 'data:'");
|
|
9612
|
+
}
|
|
9613
|
+
const [header, actualData] = data.slice(5).split(",", 2);
|
|
9614
|
+
if (!header || !actualData) {
|
|
9615
|
+
throw new Error("Invalid URI");
|
|
9616
|
+
}
|
|
9617
|
+
const headerParts = header.split(";");
|
|
9618
|
+
if (!headerParts.includes("base64")) {
|
|
9619
|
+
throw new Error("Data is not base64 encoded");
|
|
9620
|
+
}
|
|
9621
|
+
const contentType = headerParts[0];
|
|
9622
|
+
if (!contentType) {
|
|
9623
|
+
throw new Error("Content type is empty");
|
|
9624
|
+
}
|
|
9625
|
+
return [base64ToBytes(actualData), contentType];
|
|
9626
|
+
} catch (error) {
|
|
9627
|
+
getGlobalLogger().error("Error parsing base64 data URI", error);
|
|
9628
|
+
return [void 0, void 0];
|
|
9629
|
+
}
|
|
9630
|
+
}
|
|
9631
|
+
/**
|
|
9632
|
+
* Gets a unique identifier for this media based on its content hash.
|
|
9633
|
+
*
|
|
9634
|
+
* The ID is derived from the first 22 characters of the URL-safe base64-encoded
|
|
9635
|
+
* SHA-256 hash of the content.
|
|
9636
|
+
*
|
|
9637
|
+
* @returns The unique media ID, or null if hash generation failed
|
|
9638
|
+
*
|
|
9639
|
+
* @example
|
|
9640
|
+
* ```typescript
|
|
9641
|
+
* const media = new LangfuseMedia({...});
|
|
9642
|
+
* console.log(media.id); // "A1B2C3D4E5F6G7H8I9J0K1"
|
|
9643
|
+
* ```
|
|
9644
|
+
*/
|
|
9645
|
+
async getId() {
|
|
9646
|
+
const contentSha256Hash = await this.getSha256Hash();
|
|
9647
|
+
if (!contentSha256Hash) return null;
|
|
9648
|
+
const urlSafeContentHash = contentSha256Hash.replaceAll("+", "-").replaceAll("/", "_");
|
|
9649
|
+
return urlSafeContentHash.slice(0, 22);
|
|
9650
|
+
}
|
|
9651
|
+
/**
|
|
9652
|
+
* Gets the length of the media content in bytes.
|
|
9653
|
+
*
|
|
9654
|
+
* @returns The content length in bytes, or undefined if no content is available
|
|
9655
|
+
*/
|
|
9656
|
+
get contentLength() {
|
|
9657
|
+
var _a2;
|
|
9658
|
+
return (_a2 = this._contentBytes) == null ? void 0 : _a2.length;
|
|
9659
|
+
}
|
|
9660
|
+
/**
|
|
9661
|
+
* Gets the SHA-256 hash of the media content.
|
|
9662
|
+
*
|
|
9663
|
+
* The hash is used for content integrity verification and generating unique media IDs.
|
|
9664
|
+
* Returns undefined if crypto is not available or hash generation fails.
|
|
9665
|
+
*
|
|
9666
|
+
* @returns The base64-encoded SHA-256 hash, or undefined if unavailable
|
|
9667
|
+
*/
|
|
9668
|
+
async getSha256Hash() {
|
|
9669
|
+
if (!this._contentBytes) {
|
|
9670
|
+
return void 0;
|
|
9671
|
+
}
|
|
9672
|
+
try {
|
|
9673
|
+
const hash = await crypto.subtle.digest("SHA-256", this._contentBytes);
|
|
9674
|
+
return bytesToBase64(new Uint8Array(hash));
|
|
9675
|
+
} catch (error) {
|
|
9676
|
+
getGlobalLogger().warn(
|
|
9677
|
+
"[Langfuse] Failed to generate SHA-256 hash for media content:",
|
|
9678
|
+
error
|
|
9679
|
+
);
|
|
9680
|
+
return void 0;
|
|
9681
|
+
}
|
|
9682
|
+
}
|
|
9683
|
+
/**
|
|
9684
|
+
* Gets the media reference tag for embedding in trace data.
|
|
9685
|
+
*
|
|
9686
|
+
* The tag format is: `@@@langfuseMedia:type=<contentType>|id=<mediaId>|source=<source>@@@`
|
|
9687
|
+
* This tag can be embedded in trace attributes and will be replaced with actual
|
|
9688
|
+
* media content when the trace is viewed in Langfuse.
|
|
9689
|
+
*
|
|
9690
|
+
* @returns The media reference tag, or null if required data is missing
|
|
9691
|
+
*
|
|
9692
|
+
* @example
|
|
9693
|
+
* ```typescript
|
|
9694
|
+
* const media = new LangfuseMedia({...});
|
|
9695
|
+
* console.log(media.tag);
|
|
9696
|
+
* // "@@@langfuseMedia:type=image/png|id=A1B2C3D4E5F6G7H8I9J0K1|source=base64_data_uri@@@"
|
|
9697
|
+
* ```
|
|
9698
|
+
*/
|
|
9699
|
+
async getTag() {
|
|
9700
|
+
const id = await this.getId();
|
|
9701
|
+
if (!this._contentType || !this._source || !id) return null;
|
|
9702
|
+
return `@@@langfuseMedia:type=${this._contentType}|id=${id}|source=${this._source}@@@`;
|
|
9703
|
+
}
|
|
9704
|
+
/**
|
|
9705
|
+
* Gets the media content as a base64 data URI.
|
|
9706
|
+
*
|
|
9707
|
+
* @returns The complete data URI string, or null if no content is available
|
|
9708
|
+
*
|
|
9709
|
+
* @example
|
|
9710
|
+
* ```typescript
|
|
9711
|
+
* const media = new LangfuseMedia({...});
|
|
9712
|
+
* console.log(media.base64DataUri);
|
|
9713
|
+
* // "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB..."
|
|
9714
|
+
* ```
|
|
9715
|
+
*/
|
|
9716
|
+
get base64DataUri() {
|
|
9717
|
+
if (!this._contentBytes) return null;
|
|
9718
|
+
return `data:${this._contentType};base64,${bytesToBase64(this._contentBytes)}`;
|
|
9719
|
+
}
|
|
9720
|
+
/**
|
|
9721
|
+
* Serializes the media to JSON (returns the base64 data URI).
|
|
9722
|
+
*
|
|
9723
|
+
* @returns The base64 data URI, or null if no content is available
|
|
9724
|
+
*/
|
|
9725
|
+
toJSON() {
|
|
9726
|
+
return this.base64DataUri;
|
|
9727
|
+
}
|
|
9728
|
+
};
|
|
9552
9729
|
export {
|
|
9553
9730
|
AccessDeniedError,
|
|
9554
9731
|
AnnotationQueueObjectType,
|
|
@@ -9562,6 +9739,7 @@ export {
|
|
|
9562
9739
|
LangfuseAPIClient,
|
|
9563
9740
|
LangfuseAPIError,
|
|
9564
9741
|
LangfuseAPITimeoutError,
|
|
9742
|
+
LangfuseMedia,
|
|
9565
9743
|
LangfuseOtelSpanAttributes,
|
|
9566
9744
|
LogLevel,
|
|
9567
9745
|
Logger,
|
|
@@ -9577,6 +9755,10 @@ export {
|
|
|
9577
9755
|
ServiceUnavailableError,
|
|
9578
9756
|
UnauthorizedError,
|
|
9579
9757
|
annotationQueues_exports as annotationQueues,
|
|
9758
|
+
base64Decode,
|
|
9759
|
+
base64Encode,
|
|
9760
|
+
base64ToBytes,
|
|
9761
|
+
bytesToBase64,
|
|
9580
9762
|
comments_exports as comments,
|
|
9581
9763
|
commons_exports as commons,
|
|
9582
9764
|
configureGlobalLogger,
|
|
@@ -9606,7 +9788,6 @@ export {
|
|
|
9606
9788
|
scoreV2_exports as scoreV2,
|
|
9607
9789
|
sessions_exports as sessions,
|
|
9608
9790
|
trace_exports as trace,
|
|
9609
|
-
uint8ArrayToBase64,
|
|
9610
9791
|
utils_exports as utils
|
|
9611
9792
|
};
|
|
9612
9793
|
//# sourceMappingURL=index.mjs.map
|