opik 0.1.1 → 0.1.2

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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OpikClient, S as Span, T as Trace, a as SpanType } from './Client-VaP_If_d.cjs';
2
- export { b as OpikConfig } from './Client-VaP_If_d.cjs';
1
+ import { O as OpikClient, S as Span, T as Trace, a as SpanType } from './Client-DilyWTdT.cjs';
2
+ export { b as OpikConfig } from './Client-DilyWTdT.cjs';
3
3
  import 'stream';
4
4
 
5
5
  type TrackContext = {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OpikClient, S as Span, T as Trace, a as SpanType } from './Client-VaP_If_d.js';
2
- export { b as OpikConfig } from './Client-VaP_If_d.js';
1
+ import { O as OpikClient, S as Span, T as Trace, a as SpanType } from './Client-DilyWTdT.js';
2
+ export { b as OpikConfig } from './Client-DilyWTdT.js';
3
3
  import 'stream';
4
4
 
5
5
  type TrackContext = {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { OpikClient as Opik, flushAll, getTrackContext, track, trackOpikClient } from './chunk-OC5DO255.js';
1
+ export { OpikClient as Opik, flushAll, getTrackContext, track, trackOpikClient } from './chunk-ZB4ZJRLY.js';
2
2
  import './chunk-PZ5AY32C.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -12483,6 +12483,15 @@ var Span2 = class {
12483
12483
  this.end = () => {
12484
12484
  return this.update({ endTime: /* @__PURE__ */ new Date() });
12485
12485
  };
12486
+ this.score = (score) => {
12487
+ var _a;
12488
+ this.opik.spanFeedbackScoresBatchQueue.create({
12489
+ ...score,
12490
+ projectName: (_a = this.data.projectName) != null ? _a : this.opik.config.projectName,
12491
+ id: this.data.id,
12492
+ source: "sdk"
12493
+ });
12494
+ };
12486
12495
  this.update = (updates) => {
12487
12496
  var _a;
12488
12497
  const spanUpdates = {
@@ -12507,6 +12516,15 @@ var Trace2 = class {
12507
12516
  this.end = () => {
12508
12517
  return this.update({ endTime: /* @__PURE__ */ new Date() });
12509
12518
  };
12519
+ this.score = (score) => {
12520
+ var _a;
12521
+ this.opik.traceFeedbackScoresBatchQueue.create({
12522
+ ...score,
12523
+ projectName: (_a = this.data.projectName) != null ? _a : this.opik.config.projectName,
12524
+ id: this.data.id,
12525
+ source: "sdk"
12526
+ });
12527
+ };
12510
12528
  this.span = (spanData) => {
12511
12529
  var _a, _b;
12512
12530
  const projectName = (_b = (_a = this.data.projectName) != null ? _a : spanData.projectName) != null ? _b : this.opik.config.projectName;
@@ -12598,7 +12616,8 @@ var BatchQueue = class {
12598
12616
  name = "BatchQueue"
12599
12617
  }) {
12600
12618
  this.create = (entity) => {
12601
- this.createQueue.add(entity.id, entity);
12619
+ const id = this.getId(entity);
12620
+ this.createQueue.add(id, entity);
12602
12621
  };
12603
12622
  this.get = async (id) => {
12604
12623
  const entity = this.createQueue.queue.get(id);
@@ -12667,6 +12686,9 @@ var SpanBatchQueue = class extends BatchQueue {
12667
12686
  super({ delay, enableDeleteBatch: false, name: "SpanBatchQueue" });
12668
12687
  this.api = api;
12669
12688
  }
12689
+ getId(entity) {
12690
+ return entity.id;
12691
+ }
12670
12692
  async createEntities(spans) {
12671
12693
  await this.api.spans.createSpans({ spans });
12672
12694
  }
@@ -12683,12 +12705,46 @@ var SpanBatchQueue = class extends BatchQueue {
12683
12705
  }
12684
12706
  };
12685
12707
 
12708
+ // src/opik/client/SpanFeedbackScoresBatchQueue.ts
12709
+ var SpanFeedbackScoresBatchQueue = class extends BatchQueue {
12710
+ constructor(api, delay) {
12711
+ super({
12712
+ delay,
12713
+ enableDeleteBatch: false,
12714
+ name: "SpanFeedbackScoresBatchQueue"
12715
+ });
12716
+ this.api = api;
12717
+ }
12718
+ getId(entity) {
12719
+ return { id: entity.id, name: entity.name };
12720
+ }
12721
+ async createEntities(scores) {
12722
+ await this.api.spans.scoreBatchOfSpans({ scores });
12723
+ }
12724
+ async getEntity() {
12725
+ throw new Error("Not implemented");
12726
+ }
12727
+ async updateEntity() {
12728
+ throw new Error("Not implemented");
12729
+ }
12730
+ async deleteEntities(scoreIds) {
12731
+ for (const scoreId of scoreIds) {
12732
+ await this.api.spans.deleteSpanFeedbackScore(scoreId.id, {
12733
+ name: scoreId.name
12734
+ });
12735
+ }
12736
+ }
12737
+ };
12738
+
12686
12739
  // src/opik/client/TraceBatchQueue.ts
12687
12740
  var TraceBatchQueue = class extends BatchQueue {
12688
12741
  constructor(api, delay) {
12689
12742
  super({ delay, name: "TraceBatchQueue" });
12690
12743
  this.api = api;
12691
12744
  }
12745
+ getId(entity) {
12746
+ return entity.id;
12747
+ }
12692
12748
  async createEntities(traces) {
12693
12749
  await this.api.traces.createTraces({ traces });
12694
12750
  }
@@ -12702,6 +12758,37 @@ var TraceBatchQueue = class extends BatchQueue {
12702
12758
  await this.api.traces.deleteTraces({ ids });
12703
12759
  }
12704
12760
  };
12761
+
12762
+ // src/opik/client/TraceFeedbackScoresBatchQueue.ts
12763
+ var TraceFeedbackScoresBatchQueue = class extends BatchQueue {
12764
+ constructor(api, delay) {
12765
+ super({
12766
+ delay,
12767
+ enableDeleteBatch: false,
12768
+ name: "TraceFeedbackScoresBatchQueue"
12769
+ });
12770
+ this.api = api;
12771
+ }
12772
+ getId(entity) {
12773
+ return { id: entity.id, name: entity.name };
12774
+ }
12775
+ async createEntities(scores) {
12776
+ await this.api.traces.scoreBatchOfTraces({ scores });
12777
+ }
12778
+ async getEntity() {
12779
+ throw new Error("Not implemented");
12780
+ }
12781
+ async updateEntity() {
12782
+ throw new Error("Not implemented");
12783
+ }
12784
+ async deleteEntities(scoreIds) {
12785
+ for (const scoreId of scoreIds) {
12786
+ await this.api.traces.deleteTraceFeedbackScore(scoreId.id, {
12787
+ name: scoreId.name
12788
+ });
12789
+ }
12790
+ }
12791
+ };
12705
12792
  var OpikClient = class {
12706
12793
  constructor(explicitConfig) {
12707
12794
  this.trace = (traceData) => {
@@ -12722,6 +12809,8 @@ var OpikClient = class {
12722
12809
  this.flush = async () => {
12723
12810
  await this.traceBatchQueue.flush();
12724
12811
  await this.spanBatchQueue.flush();
12812
+ await this.traceFeedbackScoresBatchQueue.flush();
12813
+ await this.spanFeedbackScoresBatchQueue.flush();
12725
12814
  };
12726
12815
  this.config = loadConfig(explicitConfig);
12727
12816
  this.api = new OpikApiClient({
@@ -12731,6 +12820,12 @@ var OpikClient = class {
12731
12820
  });
12732
12821
  this.spanBatchQueue = new SpanBatchQueue(this.api);
12733
12822
  this.traceBatchQueue = new TraceBatchQueue(this.api);
12823
+ this.spanFeedbackScoresBatchQueue = new SpanFeedbackScoresBatchQueue(
12824
+ this.api
12825
+ );
12826
+ this.traceFeedbackScoresBatchQueue = new TraceFeedbackScoresBatchQueue(
12827
+ this.api
12828
+ );
12734
12829
  }
12735
12830
  };
12736
12831
  new async_hooks.AsyncLocalStorage();
@@ -12918,7 +13013,7 @@ function hrTimeToMilliseconds(hrTime) {
12918
13013
  function safeParseJson(value) {
12919
13014
  try {
12920
13015
  return JSON.parse(value);
12921
- } catch (e) {
13016
+ } catch {
12922
13017
  return value;
12923
13018
  }
12924
13019
  }
@@ -12931,7 +13026,7 @@ function tryParseJSON(input) {
12931
13026
  if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
12932
13027
  return parsed;
12933
13028
  }
12934
- } catch (error) {
13029
+ } catch {
12935
13030
  return void 0;
12936
13031
  }
12937
13032
  return void 0;