@langfuse/core 4.2.0 → 4.3.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 CHANGED
@@ -48,6 +48,7 @@ __export(index_exports, {
48
48
  NotFoundError: () => NotFoundError,
49
49
  ObservationLevel: () => ObservationLevel,
50
50
  ObservationType: () => ObservationType,
51
+ PromptType: () => PromptType,
51
52
  ScoreDataType: () => ScoreDataType,
52
53
  ScoreSource: () => ScoreSource,
53
54
  ServiceUnavailableError: () => ServiceUnavailableError,
@@ -76,6 +77,7 @@ __export(index_exports, {
76
77
  metrics: () => metrics_exports,
77
78
  models: () => models_exports,
78
79
  observations: () => observations_exports,
80
+ opentelemetry: () => opentelemetry_exports,
79
81
  organizations: () => organizations_exports,
80
82
  projects: () => projects_exports,
81
83
  promptVersion: () => promptVersion_exports,
@@ -323,7 +325,7 @@ var resetGlobalLogger = () => {
323
325
  // package.json
324
326
  var package_default = {
325
327
  name: "@langfuse/core",
326
- version: "4.2.0",
328
+ version: "4.3.0",
327
329
  description: "Core functions and utilities for Langfuse packages",
328
330
  type: "module",
329
331
  sideEffects: false,
@@ -406,7 +408,8 @@ var AnnotationQueueStatus = {
406
408
  // src/api/api/resources/annotationQueues/types/AnnotationQueueObjectType.ts
407
409
  var AnnotationQueueObjectType = {
408
410
  Trace: "TRACE",
409
- Observation: "OBSERVATION"
411
+ Observation: "OBSERVATION",
412
+ Session: "SESSION"
410
413
  };
411
414
 
412
415
  // src/api/api/resources/blobStorageIntegrations/index.ts
@@ -736,6 +739,9 @@ var models_exports = {};
736
739
  // src/api/api/resources/observations/index.ts
737
740
  var observations_exports = {};
738
741
 
742
+ // src/api/api/resources/opentelemetry/index.ts
743
+ var opentelemetry_exports = {};
744
+
739
745
  // src/api/api/resources/organizations/index.ts
740
746
  var organizations_exports = {};
741
747
  __export(organizations_exports, {
@@ -755,6 +761,15 @@ var projects_exports = {};
755
761
 
756
762
  // src/api/api/resources/prompts/index.ts
757
763
  var prompts_exports = {};
764
+ __export(prompts_exports, {
765
+ PromptType: () => PromptType
766
+ });
767
+
768
+ // src/api/api/resources/prompts/types/PromptType.ts
769
+ var PromptType = {
770
+ Chat: "chat",
771
+ Text: "text"
772
+ };
758
773
 
759
774
  // src/api/api/resources/scim/index.ts
760
775
  var scim_exports = {};
@@ -4822,7 +4837,7 @@ var Ingestion = class {
4822
4837
  /**
4823
4838
  * **Legacy endpoint for batch ingestion for Langfuse Observability.**
4824
4839
  *
4825
- * -> Please use the OpenTelemetry endpoint (`/api/public/otel`). Learn more: https://langfuse.com/integrations/native/opentelemetry
4840
+ * -> Please use the OpenTelemetry endpoint (`/api/public/otel/v1/traces`). Learn more: https://langfuse.com/integrations/native/opentelemetry
4826
4841
  *
4827
4842
  * Within each batch, there can be multiple events.
4828
4843
  * Each event has a type, an id, a timestamp, metadata and a body.
@@ -5596,7 +5611,9 @@ var Metrics = class {
5596
5611
  this._options = _options;
5597
5612
  }
5598
5613
  /**
5599
- * Get metrics from the Langfuse project using a query object
5614
+ * Get metrics from the Langfuse project using a query object.
5615
+ *
5616
+ * For more details, see the [Metrics API documentation](https://langfuse.com/docs/metrics/features/metrics-api).
5600
5617
  *
5601
5618
  * @param {LangfuseAPI.GetMetricsRequest} request
5602
5619
  * @param {Metrics.RequestOptions} requestOptions - Request-specific configuration.
@@ -6304,7 +6321,8 @@ var Observations = class {
6304
6321
  environment,
6305
6322
  fromStartTime,
6306
6323
  toStartTime,
6307
- version
6324
+ version,
6325
+ filter
6308
6326
  } = request;
6309
6327
  const _queryParams = {};
6310
6328
  if (page != null) {
@@ -6347,6 +6365,9 @@ var Observations = class {
6347
6365
  if (version != null) {
6348
6366
  _queryParams["version"] = version;
6349
6367
  }
6368
+ if (filter != null) {
6369
+ _queryParams["filter"] = filter;
6370
+ }
6350
6371
  let _headers = mergeHeaders(
6351
6372
  (_a2 = this._options) == null ? void 0 : _a2.headers,
6352
6373
  mergeOnlyDefinedHeaders({
@@ -6441,6 +6462,182 @@ var Observations = class {
6441
6462
  }
6442
6463
  };
6443
6464
 
6465
+ // src/api/api/resources/opentelemetry/client/Client.ts
6466
+ var Opentelemetry = class {
6467
+ constructor(_options) {
6468
+ this._options = _options;
6469
+ }
6470
+ /**
6471
+ * **OpenTelemetry Traces Ingestion Endpoint**
6472
+ *
6473
+ * This endpoint implements the OTLP/HTTP specification for trace ingestion, providing native OpenTelemetry integration for Langfuse Observability.
6474
+ *
6475
+ * **Supported Formats:**
6476
+ * - Binary Protobuf: `Content-Type: application/x-protobuf`
6477
+ * - JSON Protobuf: `Content-Type: application/json`
6478
+ * - Supports gzip compression via `Content-Encoding: gzip` header
6479
+ *
6480
+ * **Specification Compliance:**
6481
+ * - Conforms to [OTLP/HTTP Trace Export](https://opentelemetry.io/docs/specs/otlp/#otlphttp)
6482
+ * - Implements `ExportTraceServiceRequest` message format
6483
+ *
6484
+ * **Documentation:**
6485
+ * - Integration guide: https://langfuse.com/integrations/native/opentelemetry
6486
+ * - Data model: https://langfuse.com/docs/observability/data-model
6487
+ *
6488
+ * @param {LangfuseAPI.OtelTraceRequest} request
6489
+ * @param {Opentelemetry.RequestOptions} requestOptions - Request-specific configuration.
6490
+ *
6491
+ * @throws {@link LangfuseAPI.Error}
6492
+ * @throws {@link LangfuseAPI.UnauthorizedError}
6493
+ * @throws {@link LangfuseAPI.AccessDeniedError}
6494
+ * @throws {@link LangfuseAPI.MethodNotAllowedError}
6495
+ * @throws {@link LangfuseAPI.NotFoundError}
6496
+ *
6497
+ * @example
6498
+ * await client.opentelemetry.exportTraces({
6499
+ * resourceSpans: [{
6500
+ * resource: {
6501
+ * attributes: [{
6502
+ * key: "service.name",
6503
+ * value: {
6504
+ * stringValue: "my-service"
6505
+ * }
6506
+ * }, {
6507
+ * key: "service.version",
6508
+ * value: {
6509
+ * stringValue: "1.0.0"
6510
+ * }
6511
+ * }]
6512
+ * },
6513
+ * scopeSpans: [{
6514
+ * scope: {
6515
+ * name: "langfuse-sdk",
6516
+ * version: "2.60.3"
6517
+ * },
6518
+ * spans: [{
6519
+ * traceId: "0123456789abcdef0123456789abcdef",
6520
+ * spanId: "0123456789abcdef",
6521
+ * name: "my-operation",
6522
+ * kind: 1,
6523
+ * startTimeUnixNano: "1747872000000000000",
6524
+ * endTimeUnixNano: "1747872001000000000",
6525
+ * attributes: [{
6526
+ * key: "langfuse.observation.type",
6527
+ * value: {
6528
+ * stringValue: "generation"
6529
+ * }
6530
+ * }],
6531
+ * status: {}
6532
+ * }]
6533
+ * }]
6534
+ * }]
6535
+ * })
6536
+ */
6537
+ exportTraces(request, requestOptions) {
6538
+ return HttpResponsePromise.fromPromise(
6539
+ this.__exportTraces(request, requestOptions)
6540
+ );
6541
+ }
6542
+ async __exportTraces(request, requestOptions) {
6543
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
6544
+ let _headers = mergeHeaders(
6545
+ (_a2 = this._options) == null ? void 0 : _a2.headers,
6546
+ mergeOnlyDefinedHeaders({
6547
+ Authorization: await this._getAuthorizationHeader(),
6548
+ "X-Langfuse-Sdk-Name": (_c = requestOptions == null ? void 0 : requestOptions.xLangfuseSdkName) != null ? _c : (_b = this._options) == null ? void 0 : _b.xLangfuseSdkName,
6549
+ "X-Langfuse-Sdk-Version": (_e = requestOptions == null ? void 0 : requestOptions.xLangfuseSdkVersion) != null ? _e : (_d = this._options) == null ? void 0 : _d.xLangfuseSdkVersion,
6550
+ "X-Langfuse-Public-Key": (_g = requestOptions == null ? void 0 : requestOptions.xLangfusePublicKey) != null ? _g : (_f = this._options) == null ? void 0 : _f.xLangfusePublicKey
6551
+ }),
6552
+ requestOptions == null ? void 0 : requestOptions.headers
6553
+ );
6554
+ const _response = await fetcher({
6555
+ url: url_exports.join(
6556
+ (_h = await Supplier.get(this._options.baseUrl)) != null ? _h : await Supplier.get(this._options.environment),
6557
+ "/api/public/otel/v1/traces"
6558
+ ),
6559
+ method: "POST",
6560
+ headers: _headers,
6561
+ contentType: "application/json",
6562
+ queryParameters: requestOptions == null ? void 0 : requestOptions.queryParams,
6563
+ requestType: "json",
6564
+ body: request,
6565
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 6e4,
6566
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
6567
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
6568
+ });
6569
+ if (_response.ok) {
6570
+ return {
6571
+ data: _response.body,
6572
+ rawResponse: _response.rawResponse
6573
+ };
6574
+ }
6575
+ if (_response.error.reason === "status-code") {
6576
+ switch (_response.error.statusCode) {
6577
+ case 400:
6578
+ throw new Error2(
6579
+ _response.error.body,
6580
+ _response.rawResponse
6581
+ );
6582
+ case 401:
6583
+ throw new UnauthorizedError(
6584
+ _response.error.body,
6585
+ _response.rawResponse
6586
+ );
6587
+ case 403:
6588
+ throw new AccessDeniedError(
6589
+ _response.error.body,
6590
+ _response.rawResponse
6591
+ );
6592
+ case 405:
6593
+ throw new MethodNotAllowedError(
6594
+ _response.error.body,
6595
+ _response.rawResponse
6596
+ );
6597
+ case 404:
6598
+ throw new NotFoundError(
6599
+ _response.error.body,
6600
+ _response.rawResponse
6601
+ );
6602
+ default:
6603
+ throw new LangfuseAPIError({
6604
+ statusCode: _response.error.statusCode,
6605
+ body: _response.error.body,
6606
+ rawResponse: _response.rawResponse
6607
+ });
6608
+ }
6609
+ }
6610
+ switch (_response.error.reason) {
6611
+ case "non-json":
6612
+ throw new LangfuseAPIError({
6613
+ statusCode: _response.error.statusCode,
6614
+ body: _response.error.rawBody,
6615
+ rawResponse: _response.rawResponse
6616
+ });
6617
+ case "timeout":
6618
+ throw new LangfuseAPITimeoutError(
6619
+ "Timeout exceeded when calling POST /api/public/otel/v1/traces."
6620
+ );
6621
+ case "unknown":
6622
+ throw new LangfuseAPIError({
6623
+ message: _response.error.errorMessage,
6624
+ rawResponse: _response.rawResponse
6625
+ });
6626
+ }
6627
+ }
6628
+ async _getAuthorizationHeader() {
6629
+ const username = await Supplier.get(this._options.username);
6630
+ const password = await Supplier.get(this._options.password);
6631
+ if (username != null && password != null) {
6632
+ return BasicAuth.toAuthorizationHeader({
6633
+ username,
6634
+ password
6635
+ });
6636
+ }
6637
+ return void 0;
6638
+ }
6639
+ };
6640
+
6444
6641
  // src/api/api/resources/organizations/client/Client.ts
6445
6642
  var Organizations = class {
6446
6643
  constructor(_options) {
@@ -7749,7 +7946,9 @@ var Projects = class {
7749
7946
  *
7750
7947
  * @example
7751
7948
  * await client.projects.createApiKey("projectId", {
7752
- * note: undefined
7949
+ * note: undefined,
7950
+ * publicKey: undefined,
7951
+ * secretKey: undefined
7753
7952
  * })
7754
7953
  */
7755
7954
  createApiKey(projectId, request = {}, requestOptions) {
@@ -9556,6 +9755,120 @@ var ScoreConfigs = class {
9556
9755
  });
9557
9756
  }
9558
9757
  }
9758
+ /**
9759
+ * Update a score config
9760
+ *
9761
+ * @param {string} configId - The unique langfuse identifier of a score config
9762
+ * @param {LangfuseAPI.UpdateScoreConfigRequest} request
9763
+ * @param {ScoreConfigs.RequestOptions} requestOptions - Request-specific configuration.
9764
+ *
9765
+ * @throws {@link LangfuseAPI.Error}
9766
+ * @throws {@link LangfuseAPI.UnauthorizedError}
9767
+ * @throws {@link LangfuseAPI.AccessDeniedError}
9768
+ * @throws {@link LangfuseAPI.MethodNotAllowedError}
9769
+ * @throws {@link LangfuseAPI.NotFoundError}
9770
+ *
9771
+ * @example
9772
+ * await client.scoreConfigs.update("configId", {
9773
+ * isArchived: undefined,
9774
+ * name: undefined,
9775
+ * categories: undefined,
9776
+ * minValue: undefined,
9777
+ * maxValue: undefined,
9778
+ * description: undefined
9779
+ * })
9780
+ */
9781
+ update(configId, request, requestOptions) {
9782
+ return HttpResponsePromise.fromPromise(
9783
+ this.__update(configId, request, requestOptions)
9784
+ );
9785
+ }
9786
+ async __update(configId, request, requestOptions) {
9787
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
9788
+ let _headers = mergeHeaders(
9789
+ (_a2 = this._options) == null ? void 0 : _a2.headers,
9790
+ mergeOnlyDefinedHeaders({
9791
+ Authorization: await this._getAuthorizationHeader(),
9792
+ "X-Langfuse-Sdk-Name": (_c = requestOptions == null ? void 0 : requestOptions.xLangfuseSdkName) != null ? _c : (_b = this._options) == null ? void 0 : _b.xLangfuseSdkName,
9793
+ "X-Langfuse-Sdk-Version": (_e = requestOptions == null ? void 0 : requestOptions.xLangfuseSdkVersion) != null ? _e : (_d = this._options) == null ? void 0 : _d.xLangfuseSdkVersion,
9794
+ "X-Langfuse-Public-Key": (_g = requestOptions == null ? void 0 : requestOptions.xLangfusePublicKey) != null ? _g : (_f = this._options) == null ? void 0 : _f.xLangfusePublicKey
9795
+ }),
9796
+ requestOptions == null ? void 0 : requestOptions.headers
9797
+ );
9798
+ const _response = await fetcher({
9799
+ url: url_exports.join(
9800
+ (_h = await Supplier.get(this._options.baseUrl)) != null ? _h : await Supplier.get(this._options.environment),
9801
+ `/api/public/score-configs/${encodeURIComponent(configId)}`
9802
+ ),
9803
+ method: "PATCH",
9804
+ headers: _headers,
9805
+ contentType: "application/json",
9806
+ queryParameters: requestOptions == null ? void 0 : requestOptions.queryParams,
9807
+ requestType: "json",
9808
+ body: request,
9809
+ timeoutMs: (requestOptions == null ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1e3 : 6e4,
9810
+ maxRetries: requestOptions == null ? void 0 : requestOptions.maxRetries,
9811
+ abortSignal: requestOptions == null ? void 0 : requestOptions.abortSignal
9812
+ });
9813
+ if (_response.ok) {
9814
+ return {
9815
+ data: _response.body,
9816
+ rawResponse: _response.rawResponse
9817
+ };
9818
+ }
9819
+ if (_response.error.reason === "status-code") {
9820
+ switch (_response.error.statusCode) {
9821
+ case 400:
9822
+ throw new Error2(
9823
+ _response.error.body,
9824
+ _response.rawResponse
9825
+ );
9826
+ case 401:
9827
+ throw new UnauthorizedError(
9828
+ _response.error.body,
9829
+ _response.rawResponse
9830
+ );
9831
+ case 403:
9832
+ throw new AccessDeniedError(
9833
+ _response.error.body,
9834
+ _response.rawResponse
9835
+ );
9836
+ case 405:
9837
+ throw new MethodNotAllowedError(
9838
+ _response.error.body,
9839
+ _response.rawResponse
9840
+ );
9841
+ case 404:
9842
+ throw new NotFoundError(
9843
+ _response.error.body,
9844
+ _response.rawResponse
9845
+ );
9846
+ default:
9847
+ throw new LangfuseAPIError({
9848
+ statusCode: _response.error.statusCode,
9849
+ body: _response.error.body,
9850
+ rawResponse: _response.rawResponse
9851
+ });
9852
+ }
9853
+ }
9854
+ switch (_response.error.reason) {
9855
+ case "non-json":
9856
+ throw new LangfuseAPIError({
9857
+ statusCode: _response.error.statusCode,
9858
+ body: _response.error.rawBody,
9859
+ rawResponse: _response.rawResponse
9860
+ });
9861
+ case "timeout":
9862
+ throw new LangfuseAPITimeoutError(
9863
+ "Timeout exceeded when calling PATCH /api/public/score-configs/{configId}."
9864
+ );
9865
+ case "unknown":
9866
+ throw new LangfuseAPIError({
9867
+ message: _response.error.errorMessage,
9868
+ rawResponse: _response.rawResponse
9869
+ });
9870
+ }
9871
+ }
9559
9872
  async _getAuthorizationHeader() {
9560
9873
  const username = await Supplier.get(this._options.username);
9561
9874
  const password = await Supplier.get(this._options.password);
@@ -9897,6 +10210,7 @@ var Score = class {
9897
10210
  * comment: undefined,
9898
10211
  * metadata: undefined,
9899
10212
  * environment: undefined,
10213
+ * queueId: undefined,
9900
10214
  * dataType: undefined,
9901
10215
  * configId: undefined
9902
10216
  * })
@@ -10596,7 +10910,8 @@ var Trace = class {
10596
10910
  version,
10597
10911
  release,
10598
10912
  environment,
10599
- fields
10913
+ fields,
10914
+ filter
10600
10915
  } = request;
10601
10916
  const _queryParams = {};
10602
10917
  if (page != null) {
@@ -10646,6 +10961,9 @@ var Trace = class {
10646
10961
  if (fields != null) {
10647
10962
  _queryParams["fields"] = fields;
10648
10963
  }
10964
+ if (filter != null) {
10965
+ _queryParams["filter"] = filter;
10966
+ }
10649
10967
  let _headers = mergeHeaders(
10650
10968
  (_a2 = this._options) == null ? void 0 : _a2.headers,
10651
10969
  mergeOnlyDefinedHeaders({
@@ -10917,6 +11235,10 @@ var LangfuseAPIClient = class {
10917
11235
  var _a2;
10918
11236
  return (_a2 = this._observations) != null ? _a2 : this._observations = new Observations(this._options);
10919
11237
  }
11238
+ get opentelemetry() {
11239
+ var _a2;
11240
+ return (_a2 = this._opentelemetry) != null ? _a2 : this._opentelemetry = new Opentelemetry(this._options);
11241
+ }
10920
11242
  get organizations() {
10921
11243
  var _a2;
10922
11244
  return (_a2 = this._organizations) != null ? _a2 : this._organizations = new Organizations(this._options);
@@ -11150,6 +11472,7 @@ var LangfuseMedia = class {
11150
11472
  NotFoundError,
11151
11473
  ObservationLevel,
11152
11474
  ObservationType,
11475
+ PromptType,
11153
11476
  ScoreDataType,
11154
11477
  ScoreSource,
11155
11478
  ServiceUnavailableError,
@@ -11178,6 +11501,7 @@ var LangfuseMedia = class {
11178
11501
  metrics,
11179
11502
  models,
11180
11503
  observations,
11504
+ opentelemetry,
11181
11505
  organizations,
11182
11506
  projects,
11183
11507
  promptVersion,