@langfuse/core 5.5.3 → 5.6.0
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 +220 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +231 -8
- package/dist/index.d.ts +231 -8
- package/dist/index.mjs +217 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1304,6 +1304,49 @@ interface DatasetItem {
|
|
|
1304
1304
|
datasetName: string;
|
|
1305
1305
|
createdAt: string;
|
|
1306
1306
|
updatedAt: string;
|
|
1307
|
+
/** Resolved Langfuse media references found in input, expectedOutput, and metadata. */
|
|
1308
|
+
mediaReferences: DatasetItemMediaReference[];
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
1313
|
+
*/
|
|
1314
|
+
|
|
1315
|
+
interface DatasetItemMediaReference {
|
|
1316
|
+
/** The dataset item field containing the reference */
|
|
1317
|
+
field: DatasetItemMediaReferenceField;
|
|
1318
|
+
/** The Langfuse media reference string, e.g. `@@@langfuseMedia:type=image/png|id=...|source=bytes@@@` */
|
|
1319
|
+
referenceString: string;
|
|
1320
|
+
/** JSONPath of the string holding the reference within the field, e.g. `$['image']` */
|
|
1321
|
+
jsonPath: string;
|
|
1322
|
+
/** The resolved media record. */
|
|
1323
|
+
media: DatasetItemMediaReferenceMedia;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
1328
|
+
*/
|
|
1329
|
+
type DatasetItemMediaReferenceField = "input" | "expectedOutput" | "metadata";
|
|
1330
|
+
declare const DatasetItemMediaReferenceField: {
|
|
1331
|
+
readonly Input: "input";
|
|
1332
|
+
readonly ExpectedOutput: "expectedOutput";
|
|
1333
|
+
readonly Metadata: "metadata";
|
|
1334
|
+
};
|
|
1335
|
+
|
|
1336
|
+
/**
|
|
1337
|
+
* This file was auto-generated by Fern from our API Definition.
|
|
1338
|
+
*/
|
|
1339
|
+
interface DatasetItemMediaReferenceMedia {
|
|
1340
|
+
/** The unique langfuse identifier of the media record */
|
|
1341
|
+
mediaId: string;
|
|
1342
|
+
/** The MIME type of the media record */
|
|
1343
|
+
contentType: string;
|
|
1344
|
+
/** The size of the media record in bytes */
|
|
1345
|
+
contentLength: number;
|
|
1346
|
+
/** The signed download URL of the media record */
|
|
1347
|
+
url: string;
|
|
1348
|
+
/** The expiry date and time of the download URL */
|
|
1349
|
+
urlExpiry: string;
|
|
1307
1350
|
}
|
|
1308
1351
|
|
|
1309
1352
|
/**
|
|
@@ -1850,6 +1893,9 @@ type index$w_CorrectionScore = CorrectionScore;
|
|
|
1850
1893
|
type index$w_CreateScoreValue = CreateScoreValue;
|
|
1851
1894
|
type index$w_Dataset = Dataset;
|
|
1852
1895
|
type index$w_DatasetItem = DatasetItem;
|
|
1896
|
+
type index$w_DatasetItemMediaReference = DatasetItemMediaReference;
|
|
1897
|
+
declare const index$w_DatasetItemMediaReferenceField: typeof DatasetItemMediaReferenceField;
|
|
1898
|
+
type index$w_DatasetItemMediaReferenceMedia = DatasetItemMediaReferenceMedia;
|
|
1853
1899
|
type index$w_DatasetRun = DatasetRun;
|
|
1854
1900
|
type index$w_DatasetRunItem = DatasetRunItem;
|
|
1855
1901
|
type index$w_DatasetRunWithItems = DatasetRunWithItems;
|
|
@@ -1881,7 +1927,7 @@ type index$w_TraceWithDetails = TraceWithDetails;
|
|
|
1881
1927
|
type index$w_TraceWithFullDetails = TraceWithFullDetails;
|
|
1882
1928
|
type index$w_Usage = Usage;
|
|
1883
1929
|
declare namespace index$w {
|
|
1884
|
-
export { AccessDeniedError$1 as AccessDeniedError, type index$w_BaseScore as BaseScore, type index$w_BaseScoreV1 as BaseScoreV1, type index$w_BooleanScore as BooleanScore, type index$w_BooleanScoreV1 as BooleanScoreV1, type index$w_CategoricalScore as CategoricalScore, type index$w_CategoricalScoreV1 as CategoricalScoreV1, type index$w_Comment as Comment, index$w_CommentObjectType as CommentObjectType, type index$w_ConfigCategory as ConfigCategory, type index$w_CorrectionScore as CorrectionScore, type index$w_CreateScoreValue as CreateScoreValue, type index$w_Dataset as Dataset, type index$w_DatasetItem as DatasetItem, type index$w_DatasetRun as DatasetRun, type index$w_DatasetRunItem as DatasetRunItem, type index$w_DatasetRunWithItems as DatasetRunWithItems, index$w_DatasetStatus as DatasetStatus, Error$1 as Error, type index$w_MapValue as MapValue, MethodNotAllowedError$1 as MethodNotAllowedError, type index$w_Model as Model, type index$w_ModelPrice as ModelPrice, index$w_ModelUsageUnit as ModelUsageUnit, NotFoundError$1 as NotFoundError, type index$w_NumericScore as NumericScore, type index$w_NumericScoreV1 as NumericScoreV1, type index$w_Observation as Observation, index$w_ObservationLevel as ObservationLevel, type index$w_ObservationV2 as ObservationV2, type index$w_ObservationsView as ObservationsView, type index$w_PricingTier as PricingTier, type index$w_PricingTierCondition as PricingTierCondition, type index$w_PricingTierInput as PricingTierInput, index$w_PricingTierOperator as PricingTierOperator, index$w_Score as Score, type index$w_ScoreConfig as ScoreConfig, index$w_ScoreConfigDataType as ScoreConfigDataType, index$w_ScoreDataType as ScoreDataType, index$w_ScoreSource as ScoreSource, ScoreV1$1 as ScoreV1, type index$w_Session as Session, type index$w_SessionWithTraces as SessionWithTraces, type index$w_TextScore as TextScore, type index$w_TextScoreV1 as TextScoreV1, type Trace$1 as Trace, type index$w_TraceWithDetails as TraceWithDetails, type index$w_TraceWithFullDetails as TraceWithFullDetails, UnauthorizedError$1 as UnauthorizedError, type index$w_Usage as Usage };
|
|
1930
|
+
export { AccessDeniedError$1 as AccessDeniedError, type index$w_BaseScore as BaseScore, type index$w_BaseScoreV1 as BaseScoreV1, type index$w_BooleanScore as BooleanScore, type index$w_BooleanScoreV1 as BooleanScoreV1, type index$w_CategoricalScore as CategoricalScore, type index$w_CategoricalScoreV1 as CategoricalScoreV1, type index$w_Comment as Comment, index$w_CommentObjectType as CommentObjectType, type index$w_ConfigCategory as ConfigCategory, type index$w_CorrectionScore as CorrectionScore, type index$w_CreateScoreValue as CreateScoreValue, type index$w_Dataset as Dataset, type index$w_DatasetItem as DatasetItem, type index$w_DatasetItemMediaReference as DatasetItemMediaReference, index$w_DatasetItemMediaReferenceField as DatasetItemMediaReferenceField, type index$w_DatasetItemMediaReferenceMedia as DatasetItemMediaReferenceMedia, type index$w_DatasetRun as DatasetRun, type index$w_DatasetRunItem as DatasetRunItem, type index$w_DatasetRunWithItems as DatasetRunWithItems, index$w_DatasetStatus as DatasetStatus, Error$1 as Error, type index$w_MapValue as MapValue, MethodNotAllowedError$1 as MethodNotAllowedError, type index$w_Model as Model, type index$w_ModelPrice as ModelPrice, index$w_ModelUsageUnit as ModelUsageUnit, NotFoundError$1 as NotFoundError, type index$w_NumericScore as NumericScore, type index$w_NumericScoreV1 as NumericScoreV1, type index$w_Observation as Observation, index$w_ObservationLevel as ObservationLevel, type index$w_ObservationV2 as ObservationV2, type index$w_ObservationsView as ObservationsView, type index$w_PricingTier as PricingTier, type index$w_PricingTierCondition as PricingTierCondition, type index$w_PricingTierInput as PricingTierInput, index$w_PricingTierOperator as PricingTierOperator, index$w_Score as Score, type index$w_ScoreConfig as ScoreConfig, index$w_ScoreConfigDataType as ScoreConfigDataType, index$w_ScoreDataType as ScoreDataType, index$w_ScoreSource as ScoreSource, ScoreV1$1 as ScoreV1, type index$w_Session as Session, type index$w_SessionWithTraces as SessionWithTraces, type index$w_TextScore as TextScore, type index$w_TextScoreV1 as TextScoreV1, type Trace$1 as Trace, type index$w_TraceWithDetails as TraceWithDetails, type index$w_TraceWithFullDetails as TraceWithFullDetails, UnauthorizedError$1 as UnauthorizedError, type index$w_Usage as Usage };
|
|
1885
1931
|
}
|
|
1886
1932
|
|
|
1887
1933
|
/**
|
|
@@ -3217,17 +3263,24 @@ interface PatchMediaBody {
|
|
|
3217
3263
|
* This file was auto-generated by Fern from our API Definition.
|
|
3218
3264
|
*/
|
|
3219
3265
|
|
|
3266
|
+
/**
|
|
3267
|
+
* Request a presigned media upload URL. Provide exactly one context: a trace (traceId, optionally observationId) or a dataset item (datasetId + datasetItemId). field is required and must match the chosen context.
|
|
3268
|
+
*/
|
|
3220
3269
|
interface GetMediaUploadUrlRequest {
|
|
3221
|
-
/** The trace
|
|
3222
|
-
traceId
|
|
3270
|
+
/** The trace the media is associated with. Null for dataset item media uploads. */
|
|
3271
|
+
traceId?: string;
|
|
3223
3272
|
/** The observation ID associated with the media record. If the media record is associated directly with a trace, this will be null. */
|
|
3224
3273
|
observationId?: string;
|
|
3274
|
+
/** The dataset the media belongs to. Null for trace/observation media uploads. */
|
|
3275
|
+
datasetId?: string;
|
|
3276
|
+
/** The dataset item the media is associated with (need not exist yet). Null for trace/observation media uploads. */
|
|
3277
|
+
datasetItemId?: string;
|
|
3225
3278
|
contentType: MediaContentType;
|
|
3226
3279
|
/** The size of the media record in bytes */
|
|
3227
3280
|
contentLength: number;
|
|
3228
3281
|
/** The SHA-256 hash of the media record */
|
|
3229
3282
|
sha256Hash: string;
|
|
3230
|
-
/** The
|
|
3283
|
+
/** The item field the media is in: `input`/`output`/`metadata` (trace) or `input`/`expectedOutput`/`metadata` (dataset item). */
|
|
3231
3284
|
field: string;
|
|
3232
3285
|
}
|
|
3233
3286
|
|
|
@@ -8551,8 +8604,10 @@ declare class Media {
|
|
|
8551
8604
|
*
|
|
8552
8605
|
* @example
|
|
8553
8606
|
* await client.media.getUploadUrl({
|
|
8554
|
-
* traceId:
|
|
8607
|
+
* traceId: undefined,
|
|
8555
8608
|
* observationId: undefined,
|
|
8609
|
+
* datasetId: undefined,
|
|
8610
|
+
* datasetItemId: undefined,
|
|
8556
8611
|
* contentType: "image/png",
|
|
8557
8612
|
* contentLength: 1,
|
|
8558
8613
|
* sha256Hash: "sha256Hash",
|
|
@@ -10123,7 +10178,12 @@ declare class Sessions {
|
|
|
10123
10178
|
protected readonly _options: Sessions.Options;
|
|
10124
10179
|
constructor(_options: Sessions.Options);
|
|
10125
10180
|
/**
|
|
10126
|
-
* Get sessions
|
|
10181
|
+
* Get sessions.
|
|
10182
|
+
*
|
|
10183
|
+
* This legacy endpoint is not recommended for new data extraction workflows.
|
|
10184
|
+
* Use the v2 observations endpoint with a bounded time range and group rows by
|
|
10185
|
+
* `sessionId` instead:
|
|
10186
|
+
* `GET /api/public/v2/observations?fromStartTime=<from>&toStartTime=<to>`.
|
|
10127
10187
|
*
|
|
10128
10188
|
* @param {LangfuseAPI.GetSessionsRequest} request
|
|
10129
10189
|
* @param {Sessions.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -10140,7 +10200,12 @@ declare class Sessions {
|
|
|
10140
10200
|
list(request?: GetSessionsRequest, requestOptions?: Sessions.RequestOptions): HttpResponsePromise<PaginatedSessions>;
|
|
10141
10201
|
private __list;
|
|
10142
10202
|
/**
|
|
10143
|
-
* Get a session.
|
|
10203
|
+
* Get a session.
|
|
10204
|
+
*
|
|
10205
|
+
* Please note that `traces` on this endpoint are not paginated. For large
|
|
10206
|
+
* sessions or new data extraction workflows, use the v2 observations endpoint
|
|
10207
|
+
* with a URL-encoded `sessionId` filter and a bounded time range:
|
|
10208
|
+
* `GET /api/public/v2/observations?filter=<sessionId filter>&fromStartTime=<from>&toStartTime=<to>`.
|
|
10144
10209
|
*
|
|
10145
10210
|
* @param {string} sessionId - The unique id of a session
|
|
10146
10211
|
* @param {Sessions.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -11102,6 +11167,164 @@ declare class LangfuseMedia {
|
|
|
11102
11167
|
*/
|
|
11103
11168
|
toJSON(): string | null;
|
|
11104
11169
|
}
|
|
11170
|
+
/**
|
|
11171
|
+
* Parameters for constructing a {@link LangfuseMediaReference}.
|
|
11172
|
+
*
|
|
11173
|
+
* @public
|
|
11174
|
+
*/
|
|
11175
|
+
type LangfuseMediaReferenceParams = {
|
|
11176
|
+
/** The unique Langfuse identifier of the media record */
|
|
11177
|
+
mediaId: string;
|
|
11178
|
+
/** The MIME type of the media record */
|
|
11179
|
+
contentType: string;
|
|
11180
|
+
/** The signed download URL of the media record */
|
|
11181
|
+
url: string;
|
|
11182
|
+
/** The expiry date and time (ISO 8601) of the signed download URL */
|
|
11183
|
+
urlExpiry?: string;
|
|
11184
|
+
/** The size of the media record in bytes */
|
|
11185
|
+
contentLength?: number;
|
|
11186
|
+
/**
|
|
11187
|
+
* The original `@@@langfuseMedia:…@@@` reference string. Used to losslessly
|
|
11188
|
+
* round-trip a resolved reference back through the API / tracing when a
|
|
11189
|
+
* fetched dataset item is re-used.
|
|
11190
|
+
*/
|
|
11191
|
+
referenceString: string;
|
|
11192
|
+
};
|
|
11193
|
+
/**
|
|
11194
|
+
* A resolved reference to a media record stored in Langfuse.
|
|
11195
|
+
*
|
|
11196
|
+
* Returned in place of media reference strings when fetching dataset items via
|
|
11197
|
+
* `langfuse.dataset.get`. It holds the media metadata and a signed download
|
|
11198
|
+
* URL, and exposes helpers to fetch the content in the formats commonly
|
|
11199
|
+
* expected by LLM providers.
|
|
11200
|
+
*
|
|
11201
|
+
* The signed `url` is short-lived. Fetch the content promptly, or re-fetch the
|
|
11202
|
+
* dataset item if {@link LangfuseMediaReference.isUrlExpired} returns true.
|
|
11203
|
+
*
|
|
11204
|
+
* @example Feeding media to a provider
|
|
11205
|
+
* ```typescript
|
|
11206
|
+
* const dataset = await langfuse.dataset.get("visual-qa");
|
|
11207
|
+
*
|
|
11208
|
+
* for (const item of dataset.items) {
|
|
11209
|
+
* const image = item.input.image as LangfuseMediaReference;
|
|
11210
|
+
*
|
|
11211
|
+
* // OpenAI: { type: "input_image", image_url: await image.fetchDataUri() }
|
|
11212
|
+
* // Anthropic: { source: { type: "base64", media_type: image.contentType, data: await image.fetchBase64() } }
|
|
11213
|
+
* // Vercel AI SDK: { type: "image", image: await image.fetchBytes(), mediaType: image.contentType }
|
|
11214
|
+
* }
|
|
11215
|
+
* ```
|
|
11216
|
+
*
|
|
11217
|
+
* @public
|
|
11218
|
+
*/
|
|
11219
|
+
declare class LangfuseMediaReference implements LangfuseMediaReferenceParams {
|
|
11220
|
+
readonly mediaId: string;
|
|
11221
|
+
readonly contentType: string;
|
|
11222
|
+
readonly url: string;
|
|
11223
|
+
readonly urlExpiry?: string;
|
|
11224
|
+
readonly contentLength?: number;
|
|
11225
|
+
readonly referenceString: string;
|
|
11226
|
+
constructor(params: LangfuseMediaReferenceParams);
|
|
11227
|
+
/**
|
|
11228
|
+
* Serializes to the original `@@@langfuseMedia:…@@@` reference string.
|
|
11229
|
+
*
|
|
11230
|
+
* This makes resolved references round-trip losslessly through anything that
|
|
11231
|
+
* serializes with `JSON.stringify` — the dataset item API, experiment/trace
|
|
11232
|
+
* span attributes — so a re-used item links back to its media instead of
|
|
11233
|
+
* persisting a JSON object with a soon-to-expire signed URL.
|
|
11234
|
+
*/
|
|
11235
|
+
toJSON(): string;
|
|
11236
|
+
/**
|
|
11237
|
+
* Returns whether the signed download URL is expired or near expiry.
|
|
11238
|
+
*
|
|
11239
|
+
* @param thresholdSeconds - Treat the URL as expired this many seconds before
|
|
11240
|
+
* its actual expiry to account for clock skew and download time (default: 60).
|
|
11241
|
+
* @returns true if the URL is expired or within the threshold of expiry. If
|
|
11242
|
+
* the expiry is unknown or unparseable, returns false.
|
|
11243
|
+
*/
|
|
11244
|
+
isUrlExpired(thresholdSeconds?: number): boolean;
|
|
11245
|
+
/**
|
|
11246
|
+
* Fetches the media content from the signed URL over the network.
|
|
11247
|
+
*
|
|
11248
|
+
* Useful for local evaluators / image libraries, manual base64 conversion, or
|
|
11249
|
+
* the Vercel AI SDK (`{ type: "image", image: await media.fetchBytes() }`).
|
|
11250
|
+
*
|
|
11251
|
+
* @returns The media content as raw bytes
|
|
11252
|
+
* @throws {Error} If the download fails
|
|
11253
|
+
*/
|
|
11254
|
+
fetchBytes(): Promise<Uint8Array>;
|
|
11255
|
+
/**
|
|
11256
|
+
* Fetches the media over the network and returns raw base64 (no data URI prefix).
|
|
11257
|
+
*
|
|
11258
|
+
* Useful for Anthropic (`{ source: { type: "base64", media_type: media.contentType, data: await media.fetchBase64() } }`)
|
|
11259
|
+
* or LangChain (`{ type: "image", base64: await media.fetchBase64(), mime_type: media.contentType }`).
|
|
11260
|
+
*
|
|
11261
|
+
* @returns The media content as a base64 string
|
|
11262
|
+
* @throws {Error} If the download fails
|
|
11263
|
+
*/
|
|
11264
|
+
fetchBase64(): Promise<string>;
|
|
11265
|
+
/**
|
|
11266
|
+
* Fetches the media over the network and returns a `data:<contentType>;base64,...` URI.
|
|
11267
|
+
*
|
|
11268
|
+
* Useful for OpenAI (`{ type: "input_image", image_url: await media.fetchDataUri() }`).
|
|
11269
|
+
*
|
|
11270
|
+
* @returns The media content as a base64 data URI
|
|
11271
|
+
* @throws {Error} If the download fails
|
|
11272
|
+
*/
|
|
11273
|
+
fetchDataUri(): Promise<string>;
|
|
11274
|
+
}
|
|
11275
|
+
|
|
11276
|
+
/**
|
|
11277
|
+
* Parameters for {@link uploadMedia}.
|
|
11278
|
+
*
|
|
11279
|
+
* @internal
|
|
11280
|
+
*/
|
|
11281
|
+
type UploadMediaParams = {
|
|
11282
|
+
/** The API client used to request the upload URL and report completion. */
|
|
11283
|
+
apiClient: LangfuseAPIClient;
|
|
11284
|
+
/** The media to upload. */
|
|
11285
|
+
media: LangfuseMedia;
|
|
11286
|
+
/**
|
|
11287
|
+
* The trace the media belongs to. Omit for media that is not associated with
|
|
11288
|
+
* a trace (e.g. dataset item media).
|
|
11289
|
+
*/
|
|
11290
|
+
traceId?: string;
|
|
11291
|
+
/** The observation the media belongs to, if any. */
|
|
11292
|
+
observationId?: string;
|
|
11293
|
+
/**
|
|
11294
|
+
* The dataset the media belongs to. Set together with {@link datasetItemId}
|
|
11295
|
+
* for dataset item media (instead of a trace context).
|
|
11296
|
+
*/
|
|
11297
|
+
datasetId?: string;
|
|
11298
|
+
/** The dataset item the media belongs to (need not exist yet). */
|
|
11299
|
+
datasetItemId?: string;
|
|
11300
|
+
/**
|
|
11301
|
+
* The item field the media is associated with — `input`/`output`/`metadata`
|
|
11302
|
+
* for a trace, or `input`/`expectedOutput`/`metadata` for a dataset item.
|
|
11303
|
+
*/
|
|
11304
|
+
field: string;
|
|
11305
|
+
/** Logger to use. Defaults to the global logger. */
|
|
11306
|
+
logger?: Logger;
|
|
11307
|
+
/** Maximum number of upload retries on transient failures. Defaults to 3. */
|
|
11308
|
+
maxRetries?: number;
|
|
11309
|
+
/** Base delay in milliseconds for exponential backoff. Defaults to 1000. */
|
|
11310
|
+
baseDelay?: number;
|
|
11311
|
+
};
|
|
11312
|
+
/**
|
|
11313
|
+
* Uploads a {@link LangfuseMedia} to Langfuse.
|
|
11314
|
+
*
|
|
11315
|
+
* Requests a presigned upload URL, uploads the content with exponential-backoff
|
|
11316
|
+
* retries, and reports completion. The media may be associated with a trace /
|
|
11317
|
+
* observation (pass {@link UploadMediaParams.traceId}) or stand alone (e.g.
|
|
11318
|
+
* dataset item media), in which case the trace context is omitted.
|
|
11319
|
+
*
|
|
11320
|
+
* If the media has already been uploaded (server returns no upload URL), this
|
|
11321
|
+
* resolves without re-uploading.
|
|
11322
|
+
*
|
|
11323
|
+
* @throws {Error} If required media fields are missing or the upload fails after
|
|
11324
|
+
* all retries.
|
|
11325
|
+
* @internal
|
|
11326
|
+
*/
|
|
11327
|
+
declare function uploadMedia(params: UploadMediaParams): Promise<void>;
|
|
11105
11328
|
|
|
11106
11329
|
/**
|
|
11107
11330
|
* Attribute propagation utilities for Langfuse OpenTelemetry integration.
|
|
@@ -11313,4 +11536,4 @@ interface PropagateAttributesParams {
|
|
|
11313
11536
|
declare function propagateAttributes<A extends unknown[], F extends (...args: A) => ReturnType<F>>(params: PropagateAttributesParams, fn: F): ReturnType<F>;
|
|
11314
11537
|
declare function getPropagatedAttributesFromContext(context: Context): Record<string, string | string[]>;
|
|
11315
11538
|
|
|
11316
|
-
export { AccessDeniedError$1 as AccessDeniedError, type AnnotationQueue, type AnnotationQueueAssignmentRequest, type AnnotationQueueItem, AnnotationQueueObjectType, AnnotationQueueStatus, type ApiKeyDeletionResponse, type ApiKeyList, type ApiKeyResponse, type ApiKeySummary, type AuthenticationScheme, type BaseEvent, type BasePrompt, type BaseScore, type BaseScoreV1, type BaseScoreV3, BlobStorageExportFieldGroup, BlobStorageExportFrequency, BlobStorageExportMode, BlobStorageExportSource, type BlobStorageIntegrationDeletionResponse, BlobStorageIntegrationFileType, type BlobStorageIntegrationResponse, type BlobStorageIntegrationStatusResponse, BlobStorageIntegrationType, type BlobStorageIntegrationsResponse, BlobStorageSyncStatus, type BooleanScore, type BooleanScoreV1, type BooleanScoreV3, type BulkConfig, type CategoricalScore, type CategoricalScoreV1, type CategoricalScoreV3, type ChatMessage, ChatMessageType, type ChatMessageWithPlaceholders, type ChatPrompt, type Comment, CommentObjectType, type ConfigCategory, type CorrectionScore, type CorrectionScoreV3, type CreateAnnotationQueueAssignmentResponse, type CreateAnnotationQueueItemRequest, type CreateAnnotationQueueRequest, type CreateApiKeyRequest, type CreateBlobStorageIntegrationRequest, type CreateChatPromptRequest, CreateChatPromptType, type CreateCommentRequest, type CreateCommentResponse, type CreateDatasetItemRequest, type CreateDatasetRequest, type CreateDatasetRunItemRequest, type CreateEventBody, type CreateEventEvent, type CreateGenerationBody, type CreateGenerationEvent, type CreateModelRequest, type CreateObservationEvent, type CreateProjectRequest, type CreatePromptRequest, type CreateScoreConfigRequest, type CreateScoreValue, type CreateSpanBody, type CreateSpanEvent, type CreateTextPromptRequest, CreateTextPromptType, type CreateUserRequest, type Dataset, type DatasetItem, type DatasetRun, type DatasetRunItem, type DatasetRunWithItems, DatasetStatus, type DeleteAnnotationQueueAssignmentResponse, type DeleteAnnotationQueueItemResponse, type DeleteDatasetItemResponse, type DeleteDatasetRunResponse, type DeleteLlmConnectionResponse, type DeleteMembershipRequest, type DeletePromptRequest, 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 GetLlmConnectionsRequest, type GetMediaResponse, type GetMediaUploadUrlRequest, type GetMediaUploadUrlResponse, type GetMetricsV2Request, type GetModelsRequest, type GetObservationsV2Request, type GetPromptRequest, type GetScoreConfigsRequest, type GetScoresRequest, type GetScoresResponse, GetScoresResponseData, type GetScoresResponseDataBoolean, type GetScoresResponseDataCategorical, type GetScoresResponseDataCorrection, type GetScoresResponseDataNumeric, type GetScoresResponseDataText, type GetScoresResponseTraceData, type GetScoresV3Meta, type GetScoresV3Request, type GetScoresV3Response, type GetSessionsRequest, type GetTraceRequest, type GetTracesRequest, type HealthResponse, type IngestionError, IngestionEvent, type IngestionRequest, type IngestionResponse, type IngestionSuccess, type IngestionUsage, LANGFUSE_SDK_EXPERIMENT_ENVIRONMENT, LANGFUSE_SDK_NAME, LANGFUSE_SDK_VERSION, LANGFUSE_TRACER_NAME, LANGFUSE_TRACE_ID_BAGGAGE_KEY, LangfuseAPIClient, LangfuseAPIError, LangfuseAPITimeoutError, LangfuseMedia, type LangfuseMediaParams, LangfuseOtelContextKeys, LangfuseOtelSpanAttributes, type ListDatasetRunItemsRequest, type ListPromptsMetaRequest, type ListUsersRequest, LlmAdapter, type LlmConnection, LogLevel, Logger, type LoggerConfig, type MapValue, MediaContentType, type MembershipDeletionResponse, type MembershipRequest, type MembershipResponse, MembershipRole, type MembershipsResponse, MethodNotAllowedError$1 as MethodNotAllowedError, type MetricsV2Response, type Model, type ModelPrice, ModelUsageUnit, NotFoundError$1 as NotFoundError, type NumericScore, type NumericScoreV1, type NumericScoreV3, type Observation, type ObservationBody, ObservationLevel, ObservationType, type ObservationV2, type ObservationsV2Meta, type ObservationsV2Response, type ObservationsView, type OpenAiCompletionUsageSchema, type OpenAiResponseUsageSchema, type OpenAiUsage, type OptionalObservationBody, type Organization, type OrganizationApiKey, type OrganizationApiKeysResponse, type OrganizationProject, type OrganizationProjectsResponse, type OtelAttribute, type OtelAttributeValue, type OtelResource, type OtelResourceSpan, type OtelScope, type OtelScopeSpan, type OtelSpan, type OtelTraceRequest, type OtelTraceResponse, type PaginatedAnnotationQueueItems, type PaginatedAnnotationQueues, type PaginatedDatasetItems, type PaginatedDatasetRunItems, type PaginatedDatasetRuns, type PaginatedDatasets, type PaginatedLlmConnections, type PaginatedModels, type PaginatedSessions, type ParsedMediaReference, type PatchMediaBody, type PlaceholderMessage, PlaceholderMessageType, type PricingTier, type PricingTierCondition, type PricingTierInput, PricingTierOperator, type Project, type ProjectDeletionResponse, type Projects$1 as Projects, Prompt, type PromptMeta, type PromptMetaListResponse, PromptType, type PropagateAttributesParams, type ResourceMeta, type ResourceType, type ResourceTypesResponse, type SchemaExtension, type SchemaResource, type SchemasResponse, type ScimEmail, type ScimFeatureSupport, type ScimName, type ScimUser, type ScimUsersListResponse, Score, type ScoreBody, type ScoreConfig, ScoreConfigDataType, type ScoreConfigs$1 as ScoreConfigs, ScoreDataType, type ScoreEvent, ScoreSource, type ScoreSubjectExperimentV3, type ScoreSubjectObservationV3, type ScoreSubjectSessionV3, type ScoreSubjectTraceV3, ScoreSubjectV3, ScoreV1$1 as ScoreV1, ScoreV3, type SdkLogBody, type SdkLogEvent, type ServiceProviderConfig, ServiceUnavailableError, type Session, type SessionWithTraces, type Sort, type TextPrompt, type TextScore, type TextScoreV1, type TextScoreV3, type Trace$1 as Trace, type TraceBody, type TraceEvent, type TraceWithDetails, type TraceWithFullDetails, type Traces, UnauthorizedError$1 as UnauthorizedError, type UpdateAnnotationQueueItemRequest, type UpdateEventBody, type UpdateGenerationBody, type UpdateGenerationEvent, type UpdateObservationEvent, type UpdateProjectRequest, type UpdatePromptRequest, type UpdateScoreConfigRequest, type UpdateSpanBody, type UpdateSpanEvent, type UpsertLlmConnectionRequest, type Usage, type UsageDetails, type UserMeta, index$z as annotationQueues, base64Decode, base64Encode, base64ToBytes, index$y as blobStorageIntegrations, bytesToBase64, index$x as comments, index$w as commons, configureGlobalLogger, createExperimentId, createExperimentItemId, createLogger, index$v as datasetItems, index$u as datasetRunItems, index$t as datasets, generateUUID, getEnv, getGlobalLogger, getLangfuseTraceIdFromBaggage, getPropagatedAttributesFromContext, index$s as health, index$r as ingestion, index$n as legacy, index$m as llmConnections, LoggerSingleton as logger, index$l as media, index$k as metrics, index$j as models, index$i as observations, index$h as opentelemetry, index$g as organizations, index$f as projects, index as promptVersion, index$e as prompts, propagateAttributes, resetGlobalLogger, safeSetTimeout, index$d as scim, index$c as scoreConfigs, index$a as scores, index$b as scoresV3, serializeValue, index$9 as sessions, setLangfuseTraceIdInBaggage, index$8 as trace, index$3 as unstable, index$1 as utils };
|
|
11539
|
+
export { AccessDeniedError$1 as AccessDeniedError, type AnnotationQueue, type AnnotationQueueAssignmentRequest, type AnnotationQueueItem, AnnotationQueueObjectType, AnnotationQueueStatus, type ApiKeyDeletionResponse, type ApiKeyList, type ApiKeyResponse, type ApiKeySummary, type AuthenticationScheme, type BaseEvent, type BasePrompt, type BaseScore, type BaseScoreV1, type BaseScoreV3, BlobStorageExportFieldGroup, BlobStorageExportFrequency, BlobStorageExportMode, BlobStorageExportSource, type BlobStorageIntegrationDeletionResponse, BlobStorageIntegrationFileType, type BlobStorageIntegrationResponse, type BlobStorageIntegrationStatusResponse, BlobStorageIntegrationType, type BlobStorageIntegrationsResponse, BlobStorageSyncStatus, type BooleanScore, type BooleanScoreV1, type BooleanScoreV3, type BulkConfig, type CategoricalScore, type CategoricalScoreV1, type CategoricalScoreV3, type ChatMessage, ChatMessageType, type ChatMessageWithPlaceholders, type ChatPrompt, type Comment, CommentObjectType, type ConfigCategory, type CorrectionScore, type CorrectionScoreV3, type CreateAnnotationQueueAssignmentResponse, type CreateAnnotationQueueItemRequest, type CreateAnnotationQueueRequest, type CreateApiKeyRequest, type CreateBlobStorageIntegrationRequest, type CreateChatPromptRequest, CreateChatPromptType, type CreateCommentRequest, type CreateCommentResponse, type CreateDatasetItemRequest, type CreateDatasetRequest, type CreateDatasetRunItemRequest, type CreateEventBody, type CreateEventEvent, type CreateGenerationBody, type CreateGenerationEvent, type CreateModelRequest, type CreateObservationEvent, type CreateProjectRequest, type CreatePromptRequest, type CreateScoreConfigRequest, type CreateScoreValue, type CreateSpanBody, type CreateSpanEvent, type CreateTextPromptRequest, CreateTextPromptType, type CreateUserRequest, type Dataset, type DatasetItem, type DatasetItemMediaReference, DatasetItemMediaReferenceField, type DatasetItemMediaReferenceMedia, type DatasetRun, type DatasetRunItem, type DatasetRunWithItems, DatasetStatus, type DeleteAnnotationQueueAssignmentResponse, type DeleteAnnotationQueueItemResponse, type DeleteDatasetItemResponse, type DeleteDatasetRunResponse, type DeleteLlmConnectionResponse, type DeleteMembershipRequest, type DeletePromptRequest, 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 GetLlmConnectionsRequest, type GetMediaResponse, type GetMediaUploadUrlRequest, type GetMediaUploadUrlResponse, type GetMetricsV2Request, type GetModelsRequest, type GetObservationsV2Request, type GetPromptRequest, type GetScoreConfigsRequest, type GetScoresRequest, type GetScoresResponse, GetScoresResponseData, type GetScoresResponseDataBoolean, type GetScoresResponseDataCategorical, type GetScoresResponseDataCorrection, type GetScoresResponseDataNumeric, type GetScoresResponseDataText, type GetScoresResponseTraceData, type GetScoresV3Meta, type GetScoresV3Request, type GetScoresV3Response, type GetSessionsRequest, type GetTraceRequest, type GetTracesRequest, type HealthResponse, type IngestionError, IngestionEvent, type IngestionRequest, type IngestionResponse, type IngestionSuccess, type IngestionUsage, LANGFUSE_SDK_EXPERIMENT_ENVIRONMENT, LANGFUSE_SDK_NAME, LANGFUSE_SDK_VERSION, LANGFUSE_TRACER_NAME, LANGFUSE_TRACE_ID_BAGGAGE_KEY, LangfuseAPIClient, LangfuseAPIError, LangfuseAPITimeoutError, LangfuseMedia, type LangfuseMediaParams, LangfuseMediaReference, type LangfuseMediaReferenceParams, LangfuseOtelContextKeys, LangfuseOtelSpanAttributes, type ListDatasetRunItemsRequest, type ListPromptsMetaRequest, type ListUsersRequest, LlmAdapter, type LlmConnection, LogLevel, Logger, type LoggerConfig, type MapValue, MediaContentType, type MembershipDeletionResponse, type MembershipRequest, type MembershipResponse, MembershipRole, type MembershipsResponse, MethodNotAllowedError$1 as MethodNotAllowedError, type MetricsV2Response, type Model, type ModelPrice, ModelUsageUnit, NotFoundError$1 as NotFoundError, type NumericScore, type NumericScoreV1, type NumericScoreV3, type Observation, type ObservationBody, ObservationLevel, ObservationType, type ObservationV2, type ObservationsV2Meta, type ObservationsV2Response, type ObservationsView, type OpenAiCompletionUsageSchema, type OpenAiResponseUsageSchema, type OpenAiUsage, type OptionalObservationBody, type Organization, type OrganizationApiKey, type OrganizationApiKeysResponse, type OrganizationProject, type OrganizationProjectsResponse, type OtelAttribute, type OtelAttributeValue, type OtelResource, type OtelResourceSpan, type OtelScope, type OtelScopeSpan, type OtelSpan, type OtelTraceRequest, type OtelTraceResponse, type PaginatedAnnotationQueueItems, type PaginatedAnnotationQueues, type PaginatedDatasetItems, type PaginatedDatasetRunItems, type PaginatedDatasetRuns, type PaginatedDatasets, type PaginatedLlmConnections, type PaginatedModels, type PaginatedSessions, type ParsedMediaReference, type PatchMediaBody, type PlaceholderMessage, PlaceholderMessageType, type PricingTier, type PricingTierCondition, type PricingTierInput, PricingTierOperator, type Project, type ProjectDeletionResponse, type Projects$1 as Projects, Prompt, type PromptMeta, type PromptMetaListResponse, PromptType, type PropagateAttributesParams, type ResourceMeta, type ResourceType, type ResourceTypesResponse, type SchemaExtension, type SchemaResource, type SchemasResponse, type ScimEmail, type ScimFeatureSupport, type ScimName, type ScimUser, type ScimUsersListResponse, Score, type ScoreBody, type ScoreConfig, ScoreConfigDataType, type ScoreConfigs$1 as ScoreConfigs, ScoreDataType, type ScoreEvent, ScoreSource, type ScoreSubjectExperimentV3, type ScoreSubjectObservationV3, type ScoreSubjectSessionV3, type ScoreSubjectTraceV3, ScoreSubjectV3, ScoreV1$1 as ScoreV1, ScoreV3, type SdkLogBody, type SdkLogEvent, type ServiceProviderConfig, ServiceUnavailableError, type Session, type SessionWithTraces, type Sort, type TextPrompt, type TextScore, type TextScoreV1, type TextScoreV3, type Trace$1 as Trace, type TraceBody, type TraceEvent, type TraceWithDetails, type TraceWithFullDetails, type Traces, UnauthorizedError$1 as UnauthorizedError, type UpdateAnnotationQueueItemRequest, type UpdateEventBody, type UpdateGenerationBody, type UpdateGenerationEvent, type UpdateObservationEvent, type UpdateProjectRequest, type UpdatePromptRequest, type UpdateScoreConfigRequest, type UpdateSpanBody, type UpdateSpanEvent, type UploadMediaParams, type UpsertLlmConnectionRequest, type Usage, type UsageDetails, type UserMeta, index$z as annotationQueues, base64Decode, base64Encode, base64ToBytes, index$y as blobStorageIntegrations, bytesToBase64, index$x as comments, index$w as commons, configureGlobalLogger, createExperimentId, createExperimentItemId, createLogger, index$v as datasetItems, index$u as datasetRunItems, index$t as datasets, generateUUID, getEnv, getGlobalLogger, getLangfuseTraceIdFromBaggage, getPropagatedAttributesFromContext, index$s as health, index$r as ingestion, index$n as legacy, index$m as llmConnections, LoggerSingleton as logger, index$l as media, index$k as metrics, index$j as models, index$i as observations, index$h as opentelemetry, index$g as organizations, index$f as projects, index as promptVersion, index$e as prompts, propagateAttributes, resetGlobalLogger, safeSetTimeout, index$d as scim, index$c as scoreConfigs, index$a as scores, index$b as scoresV3, serializeValue, index$9 as sessions, setLangfuseTraceIdInBaggage, index$8 as trace, index$3 as unstable, uploadMedia, index$1 as utils };
|
package/dist/index.mjs
CHANGED
|
@@ -276,7 +276,7 @@ var resetGlobalLogger = () => {
|
|
|
276
276
|
// package.json
|
|
277
277
|
var package_default = {
|
|
278
278
|
name: "@langfuse/core",
|
|
279
|
-
version: "5.
|
|
279
|
+
version: "5.6.0",
|
|
280
280
|
description: "Core functions and utilities for Langfuse packages",
|
|
281
281
|
type: "module",
|
|
282
282
|
sideEffects: false,
|
|
@@ -462,6 +462,7 @@ var commons_exports = {};
|
|
|
462
462
|
__export(commons_exports, {
|
|
463
463
|
AccessDeniedError: () => AccessDeniedError,
|
|
464
464
|
CommentObjectType: () => CommentObjectType,
|
|
465
|
+
DatasetItemMediaReferenceField: () => DatasetItemMediaReferenceField,
|
|
465
466
|
DatasetStatus: () => DatasetStatus,
|
|
466
467
|
Error: () => Error2,
|
|
467
468
|
MethodNotAllowedError: () => MethodNotAllowedError,
|
|
@@ -475,6 +476,13 @@ __export(commons_exports, {
|
|
|
475
476
|
UnauthorizedError: () => UnauthorizedError
|
|
476
477
|
});
|
|
477
478
|
|
|
479
|
+
// src/api/api/resources/commons/types/DatasetItemMediaReferenceField.ts
|
|
480
|
+
var DatasetItemMediaReferenceField = {
|
|
481
|
+
Input: "input",
|
|
482
|
+
ExpectedOutput: "expectedOutput",
|
|
483
|
+
Metadata: "metadata"
|
|
484
|
+
};
|
|
485
|
+
|
|
478
486
|
// src/api/api/resources/commons/types/PricingTierOperator.ts
|
|
479
487
|
var PricingTierOperator = {
|
|
480
488
|
Gt: "gt",
|
|
@@ -6801,8 +6809,10 @@ var Media = class {
|
|
|
6801
6809
|
*
|
|
6802
6810
|
* @example
|
|
6803
6811
|
* await client.media.getUploadUrl({
|
|
6804
|
-
* traceId:
|
|
6812
|
+
* traceId: undefined,
|
|
6805
6813
|
* observationId: undefined,
|
|
6814
|
+
* datasetId: undefined,
|
|
6815
|
+
* datasetItemId: undefined,
|
|
6806
6816
|
* contentType: "image/png",
|
|
6807
6817
|
* contentLength: 1,
|
|
6808
6818
|
* sha256Hash: "sha256Hash",
|
|
@@ -11990,7 +12000,12 @@ var Sessions = class {
|
|
|
11990
12000
|
this._options = _options;
|
|
11991
12001
|
}
|
|
11992
12002
|
/**
|
|
11993
|
-
* Get sessions
|
|
12003
|
+
* Get sessions.
|
|
12004
|
+
*
|
|
12005
|
+
* This legacy endpoint is not recommended for new data extraction workflows.
|
|
12006
|
+
* Use the v2 observations endpoint with a bounded time range and group rows by
|
|
12007
|
+
* `sessionId` instead:
|
|
12008
|
+
* `GET /api/public/v2/observations?fromStartTime=<from>&toStartTime=<to>`.
|
|
11994
12009
|
*
|
|
11995
12010
|
* @param {LangfuseAPI.GetSessionsRequest} request
|
|
11996
12011
|
* @param {Sessions.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -12114,7 +12129,12 @@ var Sessions = class {
|
|
|
12114
12129
|
}
|
|
12115
12130
|
}
|
|
12116
12131
|
/**
|
|
12117
|
-
* Get a session.
|
|
12132
|
+
* Get a session.
|
|
12133
|
+
*
|
|
12134
|
+
* Please note that `traces` on this endpoint are not paginated. For large
|
|
12135
|
+
* sessions or new data extraction workflows, use the v2 observations endpoint
|
|
12136
|
+
* with a URL-encoded `sessionId` filter and a bounded time range:
|
|
12137
|
+
* `GET /api/public/v2/observations?filter=<sessionId filter>&fromStartTime=<from>&toStartTime=<to>`.
|
|
12118
12138
|
*
|
|
12119
12139
|
* @param {string} sessionId - The unique id of a session
|
|
12120
12140
|
* @param {Sessions.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -14633,6 +14653,196 @@ var LangfuseMedia = class {
|
|
|
14633
14653
|
return this.base64DataUri;
|
|
14634
14654
|
}
|
|
14635
14655
|
};
|
|
14656
|
+
var LangfuseMediaReference = class {
|
|
14657
|
+
constructor(params) {
|
|
14658
|
+
Object.assign(this, params);
|
|
14659
|
+
}
|
|
14660
|
+
/**
|
|
14661
|
+
* Serializes to the original `@@@langfuseMedia:…@@@` reference string.
|
|
14662
|
+
*
|
|
14663
|
+
* This makes resolved references round-trip losslessly through anything that
|
|
14664
|
+
* serializes with `JSON.stringify` — the dataset item API, experiment/trace
|
|
14665
|
+
* span attributes — so a re-used item links back to its media instead of
|
|
14666
|
+
* persisting a JSON object with a soon-to-expire signed URL.
|
|
14667
|
+
*/
|
|
14668
|
+
toJSON() {
|
|
14669
|
+
return this.referenceString;
|
|
14670
|
+
}
|
|
14671
|
+
/**
|
|
14672
|
+
* Returns whether the signed download URL is expired or near expiry.
|
|
14673
|
+
*
|
|
14674
|
+
* @param thresholdSeconds - Treat the URL as expired this many seconds before
|
|
14675
|
+
* its actual expiry to account for clock skew and download time (default: 60).
|
|
14676
|
+
* @returns true if the URL is expired or within the threshold of expiry. If
|
|
14677
|
+
* the expiry is unknown or unparseable, returns false.
|
|
14678
|
+
*/
|
|
14679
|
+
isUrlExpired(thresholdSeconds = 60) {
|
|
14680
|
+
if (!this.urlExpiry) {
|
|
14681
|
+
return false;
|
|
14682
|
+
}
|
|
14683
|
+
const expiryMs = Date.parse(this.urlExpiry);
|
|
14684
|
+
if (Number.isNaN(expiryMs)) {
|
|
14685
|
+
return false;
|
|
14686
|
+
}
|
|
14687
|
+
return expiryMs - Date.now() <= thresholdSeconds * 1e3;
|
|
14688
|
+
}
|
|
14689
|
+
/**
|
|
14690
|
+
* Fetches the media content from the signed URL over the network.
|
|
14691
|
+
*
|
|
14692
|
+
* Useful for local evaluators / image libraries, manual base64 conversion, or
|
|
14693
|
+
* the Vercel AI SDK (`{ type: "image", image: await media.fetchBytes() }`).
|
|
14694
|
+
*
|
|
14695
|
+
* @returns The media content as raw bytes
|
|
14696
|
+
* @throws {Error} If the download fails
|
|
14697
|
+
*/
|
|
14698
|
+
async fetchBytes() {
|
|
14699
|
+
const response = await fetch(this.url, { method: "GET", headers: {} });
|
|
14700
|
+
if (!response.ok) {
|
|
14701
|
+
throw new Error(
|
|
14702
|
+
`Failed to fetch media ${this.mediaId}: HTTP ${response.status}`
|
|
14703
|
+
);
|
|
14704
|
+
}
|
|
14705
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
14706
|
+
}
|
|
14707
|
+
/**
|
|
14708
|
+
* Fetches the media over the network and returns raw base64 (no data URI prefix).
|
|
14709
|
+
*
|
|
14710
|
+
* Useful for Anthropic (`{ source: { type: "base64", media_type: media.contentType, data: await media.fetchBase64() } }`)
|
|
14711
|
+
* or LangChain (`{ type: "image", base64: await media.fetchBase64(), mime_type: media.contentType }`).
|
|
14712
|
+
*
|
|
14713
|
+
* @returns The media content as a base64 string
|
|
14714
|
+
* @throws {Error} If the download fails
|
|
14715
|
+
*/
|
|
14716
|
+
async fetchBase64() {
|
|
14717
|
+
return bytesToBase64(await this.fetchBytes());
|
|
14718
|
+
}
|
|
14719
|
+
/**
|
|
14720
|
+
* Fetches the media over the network and returns a `data:<contentType>;base64,...` URI.
|
|
14721
|
+
*
|
|
14722
|
+
* Useful for OpenAI (`{ type: "input_image", image_url: await media.fetchDataUri() }`).
|
|
14723
|
+
*
|
|
14724
|
+
* @returns The media content as a base64 data URI
|
|
14725
|
+
* @throws {Error} If the download fails
|
|
14726
|
+
*/
|
|
14727
|
+
async fetchDataUri() {
|
|
14728
|
+
return `data:${this.contentType};base64,${await this.fetchBase64()}`;
|
|
14729
|
+
}
|
|
14730
|
+
};
|
|
14731
|
+
|
|
14732
|
+
// src/mediaUpload.ts
|
|
14733
|
+
async function uploadMedia(params) {
|
|
14734
|
+
var _a2;
|
|
14735
|
+
const {
|
|
14736
|
+
apiClient,
|
|
14737
|
+
media,
|
|
14738
|
+
traceId,
|
|
14739
|
+
observationId,
|
|
14740
|
+
datasetId,
|
|
14741
|
+
datasetItemId,
|
|
14742
|
+
field,
|
|
14743
|
+
maxRetries = 3,
|
|
14744
|
+
baseDelay = 1e3
|
|
14745
|
+
} = params;
|
|
14746
|
+
const logger = (_a2 = params.logger) != null ? _a2 : getGlobalLogger();
|
|
14747
|
+
const contentSha256Hash = await media.getSha256Hash();
|
|
14748
|
+
if (!media.contentLength || !media._contentType || !contentSha256Hash || !media._contentBytes) {
|
|
14749
|
+
throw new Error("Cannot upload media: media content is incomplete.");
|
|
14750
|
+
}
|
|
14751
|
+
const { uploadUrl, mediaId } = await apiClient.media.getUploadUrl({
|
|
14752
|
+
contentLength: media.contentLength,
|
|
14753
|
+
traceId,
|
|
14754
|
+
observationId,
|
|
14755
|
+
datasetId,
|
|
14756
|
+
datasetItemId,
|
|
14757
|
+
field,
|
|
14758
|
+
contentType: media._contentType,
|
|
14759
|
+
sha256Hash: contentSha256Hash
|
|
14760
|
+
});
|
|
14761
|
+
if (!uploadUrl) {
|
|
14762
|
+
logger.debug(
|
|
14763
|
+
`Media status: Media with ID ${mediaId} already uploaded. Skipping duplicate upload.`
|
|
14764
|
+
);
|
|
14765
|
+
return;
|
|
14766
|
+
}
|
|
14767
|
+
const clientSideMediaId = await media.getId();
|
|
14768
|
+
if (clientSideMediaId !== mediaId) {
|
|
14769
|
+
throw new Error(
|
|
14770
|
+
`Media integrity error: Media ID mismatch between SDK (${clientSideMediaId}) and Server (${mediaId}). Upload cancelled.`
|
|
14771
|
+
);
|
|
14772
|
+
}
|
|
14773
|
+
logger.debug(`Uploading media ${mediaId}...`);
|
|
14774
|
+
const startTime = Date.now();
|
|
14775
|
+
const uploadResponse = await uploadWithBackoff({
|
|
14776
|
+
uploadUrl,
|
|
14777
|
+
contentBytes: media._contentBytes,
|
|
14778
|
+
contentType: media._contentType,
|
|
14779
|
+
contentSha256Hash,
|
|
14780
|
+
maxRetries,
|
|
14781
|
+
baseDelay
|
|
14782
|
+
});
|
|
14783
|
+
if (!uploadResponse) {
|
|
14784
|
+
throw new Error("Media upload process failed");
|
|
14785
|
+
}
|
|
14786
|
+
const uploadSucceeded = uploadResponse.status === 200 || uploadResponse.status === 201;
|
|
14787
|
+
await apiClient.media.patch(mediaId, {
|
|
14788
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
14789
|
+
uploadHttpStatus: uploadResponse.status,
|
|
14790
|
+
uploadHttpError: await uploadResponse.text(),
|
|
14791
|
+
uploadTimeMs: Date.now() - startTime
|
|
14792
|
+
});
|
|
14793
|
+
logger.debug(`Media upload status reported for ${mediaId}`);
|
|
14794
|
+
if (!uploadSucceeded) {
|
|
14795
|
+
throw new Error(
|
|
14796
|
+
`Media upload failed with HTTP ${uploadResponse.status} after ${maxRetries} retries.`
|
|
14797
|
+
);
|
|
14798
|
+
}
|
|
14799
|
+
}
|
|
14800
|
+
async function uploadWithBackoff(params) {
|
|
14801
|
+
const {
|
|
14802
|
+
uploadUrl,
|
|
14803
|
+
contentType,
|
|
14804
|
+
contentSha256Hash,
|
|
14805
|
+
contentBytes,
|
|
14806
|
+
maxRetries,
|
|
14807
|
+
baseDelay
|
|
14808
|
+
} = params;
|
|
14809
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
14810
|
+
try {
|
|
14811
|
+
let parsedHostname;
|
|
14812
|
+
try {
|
|
14813
|
+
parsedHostname = new URL(uploadUrl).hostname;
|
|
14814
|
+
} catch {
|
|
14815
|
+
parsedHostname = "";
|
|
14816
|
+
}
|
|
14817
|
+
const isSelfHostedGcsBucket = parsedHostname === "storage.googleapis.com" || parsedHostname.endsWith(".storage.googleapis.com");
|
|
14818
|
+
const headers = isSelfHostedGcsBucket ? { "Content-Type": contentType } : {
|
|
14819
|
+
"Content-Type": contentType,
|
|
14820
|
+
"x-amz-checksum-sha256": contentSha256Hash,
|
|
14821
|
+
"x-ms-blob-type": "BlockBlob"
|
|
14822
|
+
};
|
|
14823
|
+
const uploadResponse = await fetch(uploadUrl, {
|
|
14824
|
+
method: "PUT",
|
|
14825
|
+
// Recent fetch typings narrow BodyInit to an ArrayBuffer-backed view,
|
|
14826
|
+
// while Uint8Array now defaults to Uint8Array<ArrayBufferLike>. The
|
|
14827
|
+
// media bytes are always ArrayBuffer-backed, so assert the narrower type.
|
|
14828
|
+
body: contentBytes,
|
|
14829
|
+
headers
|
|
14830
|
+
});
|
|
14831
|
+
if (attempt < maxRetries && uploadResponse.status !== 200 && uploadResponse.status !== 201) {
|
|
14832
|
+
throw new Error(`Upload failed with status ${uploadResponse.status}`);
|
|
14833
|
+
}
|
|
14834
|
+
return uploadResponse;
|
|
14835
|
+
} catch (e) {
|
|
14836
|
+
if (attempt === maxRetries) {
|
|
14837
|
+
throw e;
|
|
14838
|
+
}
|
|
14839
|
+
const delay = baseDelay * Math.pow(2, attempt);
|
|
14840
|
+
const jitter = Math.random() * 1e3;
|
|
14841
|
+
await new Promise((resolve) => setTimeout(resolve, delay + jitter));
|
|
14842
|
+
}
|
|
14843
|
+
}
|
|
14844
|
+
return void 0;
|
|
14845
|
+
}
|
|
14636
14846
|
|
|
14637
14847
|
// src/propagation.ts
|
|
14638
14848
|
import {
|
|
@@ -15068,6 +15278,7 @@ export {
|
|
|
15068
15278
|
CommentObjectType,
|
|
15069
15279
|
CreateChatPromptType,
|
|
15070
15280
|
CreateTextPromptType,
|
|
15281
|
+
DatasetItemMediaReferenceField,
|
|
15071
15282
|
DatasetStatus,
|
|
15072
15283
|
Error2 as Error,
|
|
15073
15284
|
LANGFUSE_SDK_EXPERIMENT_ENVIRONMENT,
|
|
@@ -15079,6 +15290,7 @@ export {
|
|
|
15079
15290
|
LangfuseAPIError,
|
|
15080
15291
|
LangfuseAPITimeoutError,
|
|
15081
15292
|
LangfuseMedia,
|
|
15293
|
+
LangfuseMediaReference,
|
|
15082
15294
|
LangfuseOtelContextKeys,
|
|
15083
15295
|
LangfuseOtelSpanAttributes,
|
|
15084
15296
|
LlmAdapter,
|
|
@@ -15145,6 +15357,7 @@ export {
|
|
|
15145
15357
|
setLangfuseTraceIdInBaggage,
|
|
15146
15358
|
trace_exports as trace,
|
|
15147
15359
|
unstable_exports as unstable,
|
|
15360
|
+
uploadMedia,
|
|
15148
15361
|
utils_exports as utils
|
|
15149
15362
|
};
|
|
15150
15363
|
//# sourceMappingURL=index.mjs.map
|