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.
@@ -4666,6 +4666,12 @@ declare class Span {
4666
4666
  private opik;
4667
4667
  constructor(data: SavedSpan, opik: OpikClient);
4668
4668
  end: () => this;
4669
+ score: (score: {
4670
+ name: string;
4671
+ categoryName?: string;
4672
+ value: number;
4673
+ reason?: string;
4674
+ }) => void;
4669
4675
  update: (updates: Omit<SpanUpdate$1, "traceId" | "parentSpanId" | "projectId" | "projectName">) => this;
4670
4676
  }
4671
4677
 
@@ -4681,14 +4687,17 @@ declare class Trace {
4681
4687
  private spans;
4682
4688
  constructor(data: SavedTrace, opik: OpikClient);
4683
4689
  end: () => this;
4690
+ score: (score: {
4691
+ name: string;
4692
+ categoryName?: string;
4693
+ value: number;
4694
+ reason?: string;
4695
+ }) => void;
4684
4696
  span: (spanData: SpanData) => Span;
4685
4697
  update: (updates: Omit<TraceUpdate, "projectId">) => this;
4686
4698
  }
4687
4699
 
4688
- type CreateEntity = {
4689
- id: string;
4690
- };
4691
- declare abstract class BatchQueue<EntityData = {}> {
4700
+ declare abstract class BatchQueue<EntityData = object, EntityId = string> {
4692
4701
  private readonly createQueue;
4693
4702
  private readonly updateQueue;
4694
4703
  private readonly deleteQueue;
@@ -4700,13 +4709,14 @@ declare abstract class BatchQueue<EntityData = {}> {
4700
4709
  name?: string;
4701
4710
  });
4702
4711
  protected abstract createEntities(entities: EntityData[]): Promise<void>;
4703
- protected abstract getEntity(id: string): Promise<EntityData | undefined>;
4704
- protected abstract updateEntity(id: string, updates: Partial<EntityData>): Promise<void>;
4705
- protected abstract deleteEntities(ids: string[]): Promise<void>;
4706
- create: (entity: CreateEntity & EntityData) => void;
4707
- get: (id: string) => Promise<EntityData | undefined>;
4708
- update: (id: string, updates: Partial<EntityData>) => void;
4709
- delete: (id: string) => void;
4712
+ protected abstract getEntity(id: EntityId): Promise<EntityData | undefined>;
4713
+ protected abstract updateEntity(id: EntityId, updates: Partial<EntityData>): Promise<void>;
4714
+ protected abstract deleteEntities(ids: EntityId[]): Promise<void>;
4715
+ protected abstract getId(entity: EntityData): EntityId;
4716
+ create: (entity: EntityData) => void;
4717
+ get: (id: EntityId) => Promise<EntityData | undefined>;
4718
+ update: (id: EntityId, updates: Partial<EntityData>) => void;
4719
+ delete: (id: EntityId) => void;
4710
4720
  flush: () => Promise<void>;
4711
4721
  }
4712
4722
 
@@ -4716,21 +4726,57 @@ type SpanUpdate = Partial<SavedSpan> & {
4716
4726
  declare class SpanBatchQueue extends BatchQueue<SavedSpan> {
4717
4727
  private readonly api;
4718
4728
  constructor(api: OpikApiClient, delay?: number);
4729
+ protected getId(entity: SavedSpan): string;
4719
4730
  protected createEntities(spans: SavedSpan[]): Promise<void>;
4720
4731
  protected getEntity(id: string): Promise<SavedSpan>;
4721
4732
  protected updateEntity(id: string, updates: SpanUpdate): Promise<void>;
4722
4733
  protected deleteEntities(ids: string[]): Promise<void>;
4723
4734
  }
4724
4735
 
4736
+ type FeedbackScoreId$1 = {
4737
+ id: string;
4738
+ name: string;
4739
+ };
4740
+ declare class SpanFeedbackScoresBatchQueue extends BatchQueue<FeedbackScoreBatchItem, FeedbackScoreId$1> {
4741
+ private readonly api;
4742
+ constructor(api: OpikApiClient, delay?: number);
4743
+ protected getId(entity: FeedbackScoreBatchItem): {
4744
+ id: string;
4745
+ name: string;
4746
+ };
4747
+ protected createEntities(scores: FeedbackScoreBatchItem[]): Promise<void>;
4748
+ protected getEntity(): Promise<FeedbackScoreBatchItem | undefined>;
4749
+ protected updateEntity(): Promise<void>;
4750
+ protected deleteEntities(scoreIds: FeedbackScoreId$1[]): Promise<void>;
4751
+ }
4752
+
4725
4753
  declare class TraceBatchQueue extends BatchQueue<SavedTrace> {
4726
4754
  private readonly api;
4727
4755
  constructor(api: OpikApiClient, delay?: number);
4756
+ protected getId(entity: SavedTrace): string;
4728
4757
  protected createEntities(traces: SavedTrace[]): Promise<void>;
4729
4758
  protected getEntity(id: string): Promise<SavedTrace>;
4730
4759
  protected updateEntity(id: string, updates: Partial<SavedTrace>): Promise<void>;
4731
4760
  protected deleteEntities(ids: string[]): Promise<void>;
4732
4761
  }
4733
4762
 
4763
+ type FeedbackScoreId = {
4764
+ id: string;
4765
+ name: string;
4766
+ };
4767
+ declare class TraceFeedbackScoresBatchQueue extends BatchQueue<FeedbackScoreBatchItem, FeedbackScoreId> {
4768
+ private readonly api;
4769
+ constructor(api: OpikApiClient, delay?: number);
4770
+ protected getId(entity: FeedbackScoreBatchItem): {
4771
+ id: string;
4772
+ name: string;
4773
+ };
4774
+ protected createEntities(scores: FeedbackScoreBatchItem[]): Promise<void>;
4775
+ protected getEntity(): Promise<FeedbackScoreBatchItem | undefined>;
4776
+ protected updateEntity(): Promise<void>;
4777
+ protected deleteEntities(scoreIds: FeedbackScoreId[]): Promise<void>;
4778
+ }
4779
+
4734
4780
  interface TraceData extends Omit<Trace$1, "startTime"> {
4735
4781
  startTime?: Date;
4736
4782
  }
@@ -4739,6 +4785,8 @@ declare class OpikClient {
4739
4785
  config: OpikConfig;
4740
4786
  spanBatchQueue: SpanBatchQueue;
4741
4787
  traceBatchQueue: TraceBatchQueue;
4788
+ spanFeedbackScoresBatchQueue: SpanFeedbackScoresBatchQueue;
4789
+ traceFeedbackScoresBatchQueue: TraceFeedbackScoresBatchQueue;
4742
4790
  constructor(explicitConfig?: Partial<OpikConfig>);
4743
4791
  trace: (traceData: TraceData) => Trace;
4744
4792
  flush: () => Promise<void>;
@@ -4666,6 +4666,12 @@ declare class Span {
4666
4666
  private opik;
4667
4667
  constructor(data: SavedSpan, opik: OpikClient);
4668
4668
  end: () => this;
4669
+ score: (score: {
4670
+ name: string;
4671
+ categoryName?: string;
4672
+ value: number;
4673
+ reason?: string;
4674
+ }) => void;
4669
4675
  update: (updates: Omit<SpanUpdate$1, "traceId" | "parentSpanId" | "projectId" | "projectName">) => this;
4670
4676
  }
4671
4677
 
@@ -4681,14 +4687,17 @@ declare class Trace {
4681
4687
  private spans;
4682
4688
  constructor(data: SavedTrace, opik: OpikClient);
4683
4689
  end: () => this;
4690
+ score: (score: {
4691
+ name: string;
4692
+ categoryName?: string;
4693
+ value: number;
4694
+ reason?: string;
4695
+ }) => void;
4684
4696
  span: (spanData: SpanData) => Span;
4685
4697
  update: (updates: Omit<TraceUpdate, "projectId">) => this;
4686
4698
  }
4687
4699
 
4688
- type CreateEntity = {
4689
- id: string;
4690
- };
4691
- declare abstract class BatchQueue<EntityData = {}> {
4700
+ declare abstract class BatchQueue<EntityData = object, EntityId = string> {
4692
4701
  private readonly createQueue;
4693
4702
  private readonly updateQueue;
4694
4703
  private readonly deleteQueue;
@@ -4700,13 +4709,14 @@ declare abstract class BatchQueue<EntityData = {}> {
4700
4709
  name?: string;
4701
4710
  });
4702
4711
  protected abstract createEntities(entities: EntityData[]): Promise<void>;
4703
- protected abstract getEntity(id: string): Promise<EntityData | undefined>;
4704
- protected abstract updateEntity(id: string, updates: Partial<EntityData>): Promise<void>;
4705
- protected abstract deleteEntities(ids: string[]): Promise<void>;
4706
- create: (entity: CreateEntity & EntityData) => void;
4707
- get: (id: string) => Promise<EntityData | undefined>;
4708
- update: (id: string, updates: Partial<EntityData>) => void;
4709
- delete: (id: string) => void;
4712
+ protected abstract getEntity(id: EntityId): Promise<EntityData | undefined>;
4713
+ protected abstract updateEntity(id: EntityId, updates: Partial<EntityData>): Promise<void>;
4714
+ protected abstract deleteEntities(ids: EntityId[]): Promise<void>;
4715
+ protected abstract getId(entity: EntityData): EntityId;
4716
+ create: (entity: EntityData) => void;
4717
+ get: (id: EntityId) => Promise<EntityData | undefined>;
4718
+ update: (id: EntityId, updates: Partial<EntityData>) => void;
4719
+ delete: (id: EntityId) => void;
4710
4720
  flush: () => Promise<void>;
4711
4721
  }
4712
4722
 
@@ -4716,21 +4726,57 @@ type SpanUpdate = Partial<SavedSpan> & {
4716
4726
  declare class SpanBatchQueue extends BatchQueue<SavedSpan> {
4717
4727
  private readonly api;
4718
4728
  constructor(api: OpikApiClient, delay?: number);
4729
+ protected getId(entity: SavedSpan): string;
4719
4730
  protected createEntities(spans: SavedSpan[]): Promise<void>;
4720
4731
  protected getEntity(id: string): Promise<SavedSpan>;
4721
4732
  protected updateEntity(id: string, updates: SpanUpdate): Promise<void>;
4722
4733
  protected deleteEntities(ids: string[]): Promise<void>;
4723
4734
  }
4724
4735
 
4736
+ type FeedbackScoreId$1 = {
4737
+ id: string;
4738
+ name: string;
4739
+ };
4740
+ declare class SpanFeedbackScoresBatchQueue extends BatchQueue<FeedbackScoreBatchItem, FeedbackScoreId$1> {
4741
+ private readonly api;
4742
+ constructor(api: OpikApiClient, delay?: number);
4743
+ protected getId(entity: FeedbackScoreBatchItem): {
4744
+ id: string;
4745
+ name: string;
4746
+ };
4747
+ protected createEntities(scores: FeedbackScoreBatchItem[]): Promise<void>;
4748
+ protected getEntity(): Promise<FeedbackScoreBatchItem | undefined>;
4749
+ protected updateEntity(): Promise<void>;
4750
+ protected deleteEntities(scoreIds: FeedbackScoreId$1[]): Promise<void>;
4751
+ }
4752
+
4725
4753
  declare class TraceBatchQueue extends BatchQueue<SavedTrace> {
4726
4754
  private readonly api;
4727
4755
  constructor(api: OpikApiClient, delay?: number);
4756
+ protected getId(entity: SavedTrace): string;
4728
4757
  protected createEntities(traces: SavedTrace[]): Promise<void>;
4729
4758
  protected getEntity(id: string): Promise<SavedTrace>;
4730
4759
  protected updateEntity(id: string, updates: Partial<SavedTrace>): Promise<void>;
4731
4760
  protected deleteEntities(ids: string[]): Promise<void>;
4732
4761
  }
4733
4762
 
4763
+ type FeedbackScoreId = {
4764
+ id: string;
4765
+ name: string;
4766
+ };
4767
+ declare class TraceFeedbackScoresBatchQueue extends BatchQueue<FeedbackScoreBatchItem, FeedbackScoreId> {
4768
+ private readonly api;
4769
+ constructor(api: OpikApiClient, delay?: number);
4770
+ protected getId(entity: FeedbackScoreBatchItem): {
4771
+ id: string;
4772
+ name: string;
4773
+ };
4774
+ protected createEntities(scores: FeedbackScoreBatchItem[]): Promise<void>;
4775
+ protected getEntity(): Promise<FeedbackScoreBatchItem | undefined>;
4776
+ protected updateEntity(): Promise<void>;
4777
+ protected deleteEntities(scoreIds: FeedbackScoreId[]): Promise<void>;
4778
+ }
4779
+
4734
4780
  interface TraceData extends Omit<Trace$1, "startTime"> {
4735
4781
  startTime?: Date;
4736
4782
  }
@@ -4739,6 +4785,8 @@ declare class OpikClient {
4739
4785
  config: OpikConfig;
4740
4786
  spanBatchQueue: SpanBatchQueue;
4741
4787
  traceBatchQueue: TraceBatchQueue;
4788
+ spanFeedbackScoresBatchQueue: SpanFeedbackScoresBatchQueue;
4789
+ traceFeedbackScoresBatchQueue: TraceFeedbackScoresBatchQueue;
4742
4790
  constructor(explicitConfig?: Partial<OpikConfig>);
4743
4791
  trace: (traceData: TraceData) => Trace;
4744
4792
  flush: () => Promise<void>;
@@ -11945,6 +11945,15 @@ var Span2 = class {
11945
11945
  this.end = () => {
11946
11946
  return this.update({ endTime: /* @__PURE__ */ new Date() });
11947
11947
  };
11948
+ this.score = (score) => {
11949
+ var _a;
11950
+ this.opik.spanFeedbackScoresBatchQueue.create({
11951
+ ...score,
11952
+ projectName: (_a = this.data.projectName) != null ? _a : this.opik.config.projectName,
11953
+ id: this.data.id,
11954
+ source: "sdk"
11955
+ });
11956
+ };
11948
11957
  this.update = (updates) => {
11949
11958
  var _a;
11950
11959
  const spanUpdates = {
@@ -11969,6 +11978,15 @@ var Trace2 = class {
11969
11978
  this.end = () => {
11970
11979
  return this.update({ endTime: /* @__PURE__ */ new Date() });
11971
11980
  };
11981
+ this.score = (score) => {
11982
+ var _a;
11983
+ this.opik.traceFeedbackScoresBatchQueue.create({
11984
+ ...score,
11985
+ projectName: (_a = this.data.projectName) != null ? _a : this.opik.config.projectName,
11986
+ id: this.data.id,
11987
+ source: "sdk"
11988
+ });
11989
+ };
11972
11990
  this.span = (spanData) => {
11973
11991
  var _a, _b;
11974
11992
  const projectName = (_b = (_a = this.data.projectName) != null ? _a : spanData.projectName) != null ? _b : this.opik.config.projectName;
@@ -12060,7 +12078,8 @@ var BatchQueue = class {
12060
12078
  name = "BatchQueue"
12061
12079
  }) {
12062
12080
  this.create = (entity) => {
12063
- this.createQueue.add(entity.id, entity);
12081
+ const id = this.getId(entity);
12082
+ this.createQueue.add(id, entity);
12064
12083
  };
12065
12084
  this.get = async (id) => {
12066
12085
  const entity = this.createQueue.queue.get(id);
@@ -12129,6 +12148,9 @@ var SpanBatchQueue = class extends BatchQueue {
12129
12148
  super({ delay, enableDeleteBatch: false, name: "SpanBatchQueue" });
12130
12149
  this.api = api;
12131
12150
  }
12151
+ getId(entity) {
12152
+ return entity.id;
12153
+ }
12132
12154
  async createEntities(spans) {
12133
12155
  await this.api.spans.createSpans({ spans });
12134
12156
  }
@@ -12145,12 +12167,46 @@ var SpanBatchQueue = class extends BatchQueue {
12145
12167
  }
12146
12168
  };
12147
12169
 
12170
+ // src/opik/client/SpanFeedbackScoresBatchQueue.ts
12171
+ var SpanFeedbackScoresBatchQueue = class extends BatchQueue {
12172
+ constructor(api, delay) {
12173
+ super({
12174
+ delay,
12175
+ enableDeleteBatch: false,
12176
+ name: "SpanFeedbackScoresBatchQueue"
12177
+ });
12178
+ this.api = api;
12179
+ }
12180
+ getId(entity) {
12181
+ return { id: entity.id, name: entity.name };
12182
+ }
12183
+ async createEntities(scores) {
12184
+ await this.api.spans.scoreBatchOfSpans({ scores });
12185
+ }
12186
+ async getEntity() {
12187
+ throw new Error("Not implemented");
12188
+ }
12189
+ async updateEntity() {
12190
+ throw new Error("Not implemented");
12191
+ }
12192
+ async deleteEntities(scoreIds) {
12193
+ for (const scoreId of scoreIds) {
12194
+ await this.api.spans.deleteSpanFeedbackScore(scoreId.id, {
12195
+ name: scoreId.name
12196
+ });
12197
+ }
12198
+ }
12199
+ };
12200
+
12148
12201
  // src/opik/client/TraceBatchQueue.ts
12149
12202
  var TraceBatchQueue = class extends BatchQueue {
12150
12203
  constructor(api, delay) {
12151
12204
  super({ delay, name: "TraceBatchQueue" });
12152
12205
  this.api = api;
12153
12206
  }
12207
+ getId(entity) {
12208
+ return entity.id;
12209
+ }
12154
12210
  async createEntities(traces) {
12155
12211
  await this.api.traces.createTraces({ traces });
12156
12212
  }
@@ -12165,6 +12221,37 @@ var TraceBatchQueue = class extends BatchQueue {
12165
12221
  }
12166
12222
  };
12167
12223
 
12224
+ // src/opik/client/TraceFeedbackScoresBatchQueue.ts
12225
+ var TraceFeedbackScoresBatchQueue = class extends BatchQueue {
12226
+ constructor(api, delay) {
12227
+ super({
12228
+ delay,
12229
+ enableDeleteBatch: false,
12230
+ name: "TraceFeedbackScoresBatchQueue"
12231
+ });
12232
+ this.api = api;
12233
+ }
12234
+ getId(entity) {
12235
+ return { id: entity.id, name: entity.name };
12236
+ }
12237
+ async createEntities(scores) {
12238
+ await this.api.traces.scoreBatchOfTraces({ scores });
12239
+ }
12240
+ async getEntity() {
12241
+ throw new Error("Not implemented");
12242
+ }
12243
+ async updateEntity() {
12244
+ throw new Error("Not implemented");
12245
+ }
12246
+ async deleteEntities(scoreIds) {
12247
+ for (const scoreId of scoreIds) {
12248
+ await this.api.traces.deleteTraceFeedbackScore(scoreId.id, {
12249
+ name: scoreId.name
12250
+ });
12251
+ }
12252
+ }
12253
+ };
12254
+
12168
12255
  // src/opik/client/Client.ts
12169
12256
  var clients = [];
12170
12257
  var OpikClient = class {
@@ -12187,6 +12274,8 @@ var OpikClient = class {
12187
12274
  this.flush = async () => {
12188
12275
  await this.traceBatchQueue.flush();
12189
12276
  await this.spanBatchQueue.flush();
12277
+ await this.traceFeedbackScoresBatchQueue.flush();
12278
+ await this.spanFeedbackScoresBatchQueue.flush();
12190
12279
  };
12191
12280
  this.config = loadConfig(explicitConfig);
12192
12281
  this.api = new OpikApiClient({
@@ -12196,6 +12285,12 @@ var OpikClient = class {
12196
12285
  });
12197
12286
  this.spanBatchQueue = new SpanBatchQueue(this.api);
12198
12287
  this.traceBatchQueue = new TraceBatchQueue(this.api);
12288
+ this.spanFeedbackScoresBatchQueue = new SpanFeedbackScoresBatchQueue(
12289
+ this.api
12290
+ );
12291
+ this.traceFeedbackScoresBatchQueue = new TraceFeedbackScoresBatchQueue(
12292
+ this.api
12293
+ );
12199
12294
  clients.push(this);
12200
12295
  }
12201
12296
  };
@@ -12360,7 +12455,7 @@ function track(optionsOrOriginalFunction, originalFunction) {
12360
12455
  }
12361
12456
  return executeTrack(options, originalMethod2);
12362
12457
  }
12363
- const [target, propertyKey, descriptor] = args;
12458
+ const [, , descriptor] = args;
12364
12459
  if (!descriptor || typeof descriptor.value !== "function") {
12365
12460
  throw new Error("track decorator can only be applied to methods");
12366
12461
  }
@@ -12380,5 +12475,5 @@ var flushAll = async () => {
12380
12475
  };
12381
12476
 
12382
12477
  export { OpikClient, flushAll, getTrackContext, track, trackOpikClient };
12383
- //# sourceMappingURL=chunk-OC5DO255.js.map
12384
- //# sourceMappingURL=chunk-OC5DO255.js.map
12478
+ //# sourceMappingURL=chunk-ZB4ZJRLY.js.map
12479
+ //# sourceMappingURL=chunk-ZB4ZJRLY.js.map