@lmnr-ai/client 0.8.1

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.
@@ -0,0 +1,381 @@
1
+ import { Datapoint, Dataset, EvaluationDatapoint, GetDatapointsResponse, InitEvaluationResponse, PushDatapointsResponse, RolloutParam, SpanType, StringUUID } from "@lmnr-ai/types";
2
+
3
+ //#region src/resources/index.d.ts
4
+ declare class BaseResource {
5
+ protected readonly baseHttpUrl: string;
6
+ protected readonly projectApiKey: string;
7
+ constructor(baseHttpUrl: string, projectApiKey: string);
8
+ protected headers(): {
9
+ Authorization: string;
10
+ "Content-Type": string;
11
+ Accept: string;
12
+ };
13
+ protected handleError(response: Response): Promise<void>;
14
+ }
15
+ //#endregion
16
+ //#region src/resources/browser-events.d.ts
17
+ declare class BrowserEventsResource extends BaseResource {
18
+ constructor(baseHttpUrl: string, projectApiKey: string);
19
+ send({
20
+ sessionId,
21
+ traceId,
22
+ events
23
+ }: {
24
+ sessionId: string;
25
+ traceId: string;
26
+ events: Record<string, any>[];
27
+ }): Promise<void>;
28
+ }
29
+ //#endregion
30
+ //#region src/resources/datasets.d.ts
31
+ declare class DatasetsResource extends BaseResource {
32
+ constructor(baseHttpUrl: string, projectApiKey: string);
33
+ /**
34
+ * List all datasets.
35
+ *
36
+ * @returns {Promise<Dataset[]>} Array of datasets
37
+ */
38
+ listDatasets(): Promise<Dataset[]>;
39
+ /**
40
+ * Get a dataset by name.
41
+ *
42
+ * @param {string} name - Name of the dataset
43
+ * @returns {Promise<Dataset[]>} Array of datasets with matching name
44
+ */
45
+ getDatasetByName(name: string): Promise<Dataset[]>;
46
+ /**
47
+ * Push datapoints to a dataset.
48
+ *
49
+ * @param {Object} options - Push options
50
+ * @param {Datapoint<D, T>[]} options.points - Datapoints to push
51
+ * @param {string} [options.name] - Name of the dataset (either name or id must be provided)
52
+ * @param {StringUUID} [options.id] - ID of the dataset (either name or id must be provided)
53
+ * @param {number} [options.batchSize] - Batch size for pushing (default: 100)
54
+ * @param {boolean} [options.createDataset] - Whether to create the dataset if it doesn't exist
55
+ * @returns {Promise<PushDatapointsResponse | undefined>}
56
+ */
57
+ push<D, T>({
58
+ points,
59
+ name,
60
+ id,
61
+ batchSize,
62
+ createDataset
63
+ }: {
64
+ points: Datapoint<D, T>[];
65
+ name?: string;
66
+ id?: StringUUID;
67
+ batchSize?: number;
68
+ createDataset?: boolean;
69
+ }): Promise<PushDatapointsResponse | undefined>;
70
+ /**
71
+ * Pull datapoints from a dataset.
72
+ *
73
+ * @param {Object} options - Pull options
74
+ * @param {string} [options.name] - Name of the dataset (either name or id must be provided)
75
+ * @param {StringUUID} [options.id] - ID of the dataset (either name or id must be provided)
76
+ * @param {number} [options.limit] - Maximum number of datapoints to return (default: 100)
77
+ * @param {number} [options.offset] - Offset for pagination (default: 0)
78
+ * @returns {Promise<GetDatapointsResponse<D, T>>}
79
+ */
80
+ pull<D, T>({
81
+ name,
82
+ id,
83
+ limit,
84
+ offset
85
+ }: {
86
+ name?: string;
87
+ id?: StringUUID;
88
+ limit?: number;
89
+ offset?: number;
90
+ }): Promise<GetDatapointsResponse<D, T>>;
91
+ }
92
+ //#endregion
93
+ //#region src/resources/evals.d.ts
94
+ declare class EvalsResource extends BaseResource {
95
+ constructor(baseHttpUrl: string, projectApiKey: string);
96
+ /**
97
+ * Initialize an evaluation.
98
+ *
99
+ * @param {string} name - Name of the evaluation
100
+ * @param {string} groupName - Group name of the evaluation
101
+ * @param {Record<string, any>} metadata - Optional metadata
102
+ * @returns {Promise<InitEvaluationResponse>} Response from the evaluation initialization
103
+ */
104
+ init(name?: string, groupName?: string, metadata?: Record<string, any>): Promise<InitEvaluationResponse>;
105
+ /**
106
+ * Create a new evaluation and return its ID.
107
+ *
108
+ * @param {string} [name] - Optional name of the evaluation
109
+ * @param {string} [groupName] - An identifier to group evaluations
110
+ * @param {Record<string, any>} [metadata] - Optional metadata
111
+ * @returns {Promise<StringUUID>} The evaluation ID
112
+ */
113
+ create(args?: {
114
+ name?: string;
115
+ groupName?: string;
116
+ metadata?: Record<string, any>;
117
+ }): Promise<StringUUID>;
118
+ /**
119
+ * Create a new evaluation and return its ID.
120
+ * @deprecated use `create` instead.
121
+ */
122
+ createEvaluation(name?: string, groupName?: string, metadata?: Record<string, any>): Promise<StringUUID>;
123
+ /**
124
+ * Create a datapoint for an evaluation.
125
+ *
126
+ * @param {Object} options - Create datapoint options
127
+ * @param {string} options.evalId - The evaluation ID
128
+ * @param {D} options.data - The input data for the executor
129
+ * @param {T} [options.target] - The target/expected output for evaluators
130
+ * @param {Record<string, any>} [options.metadata] - Optional metadata
131
+ * @param {number} [options.index] - Optional index of the datapoint
132
+ * @param {string} [options.traceId] - Optional trace ID
133
+ * @returns {Promise<StringUUID>} The datapoint ID
134
+ */
135
+ createDatapoint<D, T>({
136
+ evalId,
137
+ data,
138
+ target,
139
+ metadata,
140
+ index,
141
+ traceId
142
+ }: {
143
+ evalId: string;
144
+ data: D;
145
+ target?: T;
146
+ metadata?: Record<string, any>;
147
+ index?: number;
148
+ traceId?: string;
149
+ }): Promise<StringUUID>;
150
+ /**
151
+ * Update a datapoint with evaluation results.
152
+ *
153
+ * @param {Object} options - Update datapoint options
154
+ * @param {string} options.evalId - The evaluation ID
155
+ * @param {string} options.datapointId - The datapoint ID
156
+ * @param {Record<string, number>} options.scores - The scores
157
+ * @param {O} [options.executorOutput] - The executor output
158
+ * @returns {Promise<void>}
159
+ */
160
+ updateDatapoint<O>({
161
+ evalId,
162
+ datapointId,
163
+ scores,
164
+ executorOutput
165
+ }: {
166
+ evalId: string;
167
+ datapointId: string;
168
+ scores: Record<string, number>;
169
+ executorOutput?: O;
170
+ }): Promise<void>;
171
+ /**
172
+ * Save evaluation datapoints.
173
+ *
174
+ * @param {Object} options - Save datapoints options
175
+ * @param {string} options.evalId - ID of the evaluation
176
+ * @param {EvaluationDatapoint<D, T, O>[]} options.datapoints - Datapoint to add
177
+ * @param {string} [options.groupName] - Group name of the evaluation
178
+ * @returns {Promise<void>} Response from the datapoint addition
179
+ */
180
+ saveDatapoints<D, T, O>({
181
+ evalId,
182
+ datapoints,
183
+ groupName
184
+ }: {
185
+ evalId: string;
186
+ datapoints: EvaluationDatapoint<D, T, O>[];
187
+ groupName?: string;
188
+ }): Promise<void>;
189
+ /**
190
+ * Get evaluation datapoints.
191
+ *
192
+ * @deprecated Use `client.datasets.pull()` instead.
193
+ * @param {Object} options - Get datapoints options
194
+ * @param {string} options.datasetName - Name of the dataset
195
+ * @param {number} options.offset - Offset at which to start the query
196
+ * @param {number} options.limit - Maximum number of datapoints to return
197
+ * @returns {Promise<GetDatapointsResponse>} Response from the datapoint retrieval
198
+ */
199
+ getDatapoints<D, T>({
200
+ datasetName,
201
+ offset,
202
+ limit
203
+ }: {
204
+ datasetName: string;
205
+ offset: number;
206
+ limit: number;
207
+ }): Promise<GetDatapointsResponse<D, T>>;
208
+ private retrySaveDatapoints;
209
+ }
210
+ //#endregion
211
+ //#region src/resources/evaluators.d.ts
212
+ type ScoreOptions = {
213
+ name: string;
214
+ metadata?: Record<string, any>;
215
+ score: number;
216
+ traceId: string;
217
+ } | {
218
+ name: string;
219
+ metadata?: Record<string, any>;
220
+ score: number;
221
+ spanId: string;
222
+ };
223
+ /**
224
+ * Resource for creating evaluator scores
225
+ */
226
+ declare class EvaluatorsResource extends BaseResource {
227
+ constructor(baseHttpUrl: string, projectApiKey: string);
228
+ /**
229
+ * Create a score for a span or trace
230
+ *
231
+ * @param {ScoreOptions} options - Score creation options
232
+ * @param {string} options.name - Name of the score
233
+ * @param {string} [options.traceId] - The trace ID to score (will be attached to top-level span)
234
+ * @param {string} [options.spanId] - The span ID to score
235
+ * @param {Record<string, any>} [options.metadata] - Additional metadata
236
+ * @param {number} options.score - The score value (float)
237
+ * @returns {Promise<void>}
238
+ *
239
+ * @example
240
+ * // Score by trace ID (will attach to root span)
241
+ * await evaluators.score({
242
+ * name: "quality",
243
+ * traceId: "trace-id-here",
244
+ * score: 0.95,
245
+ * metadata: { model: "gpt-4" }
246
+ * });
247
+ *
248
+ * @example
249
+ * // Score by span ID
250
+ * await evaluators.score({
251
+ * name: "relevance",
252
+ * spanId: "span-id-here",
253
+ * score: 0.87
254
+ * });
255
+ */
256
+ score(options: ScoreOptions): Promise<void>;
257
+ }
258
+ //#endregion
259
+ //#region src/resources/rollout-sessions.d.ts
260
+ declare class RolloutSessionsResource extends BaseResource {
261
+ constructor(baseHttpUrl: string, projectApiKey: string);
262
+ /**
263
+ * Connects to the SSE stream for rollout debugging sessions
264
+ * Returns the Response object for streaming SSE events
265
+ */
266
+ connect({
267
+ sessionId,
268
+ name,
269
+ params,
270
+ signal
271
+ }: {
272
+ sessionId: string;
273
+ params: RolloutParam[];
274
+ name: string;
275
+ signal?: AbortSignal;
276
+ }): Promise<Response>;
277
+ delete({
278
+ sessionId
279
+ }: {
280
+ sessionId: string;
281
+ }): Promise<void>;
282
+ setStatus({
283
+ sessionId,
284
+ status
285
+ }: {
286
+ sessionId: string;
287
+ status: 'PENDING' | 'RUNNING' | 'FINISHED' | 'STOPPED';
288
+ }): Promise<void>;
289
+ sendSpanUpdate({
290
+ sessionId,
291
+ span
292
+ }: {
293
+ sessionId: string;
294
+ span: {
295
+ name: string;
296
+ startTime: string;
297
+ spanId: string;
298
+ traceId: string;
299
+ parentSpanId: string | undefined;
300
+ attributes: Record<string, any>;
301
+ spanType: SpanType;
302
+ };
303
+ }): Promise<void>;
304
+ }
305
+ //#endregion
306
+ //#region src/resources/sql.d.ts
307
+ declare class SqlResource extends BaseResource {
308
+ constructor(baseHttpUrl: string, projectApiKey: string);
309
+ query(sql: string, parameters?: Record<string, any>): Promise<Array<Record<string, any>>>;
310
+ }
311
+ //#endregion
312
+ //#region src/resources/tags.d.ts
313
+ declare class TagsResource extends BaseResource {
314
+ /** Resource for tagging traces. */
315
+ constructor(baseHttpUrl: string, projectApiKey: string);
316
+ /**
317
+ * Tag a trace with a list of tags. Note that the trace must be ended before
318
+ * tagging it. You may want to call `await Laminar.flush()` after the trace
319
+ * that you want to tag.
320
+ *
321
+ * @param {string | StringUUID} trace_id - The trace id to tag.
322
+ * @param {string[] | string} tags - The tag or list of tags to add to the trace.
323
+ * @returns {Promise<any>} The response from the server.
324
+ * @example
325
+ * ```javascript
326
+ * import { Laminar, observe, LaminarClient } from "@lmnr-ai/lmnr";
327
+ * Laminar.initialize();
328
+ * const client = new LaminarClient();
329
+ * let traceId: StringUUID | null = null;
330
+ * // Make sure this is called outside of traced context.
331
+ * await observe(
332
+ * {
333
+ * name: "my-trace",
334
+ * },
335
+ * async () => {
336
+ * traceId = await Laminar.getTraceId();
337
+ * await foo();
338
+ * },
339
+ * );
340
+ *
341
+ * // or make sure the trace is ended by this point.
342
+ * await Laminar.flush();
343
+ * if (traceId) {
344
+ * await client.tags.tag(traceId, ["tag1", "tag2"]);
345
+ * }
346
+ * ```
347
+ */
348
+ tag(trace_id: string, tags: string[] | string): Promise<any>;
349
+ }
350
+ //#endregion
351
+ //#region src/index.d.ts
352
+ declare class LaminarClient {
353
+ private baseUrl;
354
+ private projectApiKey;
355
+ private _browserEvents;
356
+ private _datasets;
357
+ private _evals;
358
+ private _evaluators;
359
+ private _rolloutSessions;
360
+ private _sql;
361
+ private _tags;
362
+ constructor({
363
+ baseUrl,
364
+ projectApiKey,
365
+ port
366
+ }?: {
367
+ baseUrl?: string;
368
+ projectApiKey?: string;
369
+ port?: number;
370
+ });
371
+ get browserEvents(): BrowserEventsResource;
372
+ get datasets(): DatasetsResource;
373
+ get evals(): EvalsResource;
374
+ get evaluators(): EvaluatorsResource;
375
+ get rolloutSessions(): RolloutSessionsResource;
376
+ get sql(): SqlResource;
377
+ get tags(): TagsResource;
378
+ }
379
+ //#endregion
380
+ export { LaminarClient };
381
+ //# sourceMappingURL=index.d.mts.map