@cetra-ai/sdk 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +46 -2
- package/dist/anthropic.d.ts +15 -0
- package/dist/anthropic.js +15 -0
- package/dist/browser.d.ts +42 -0
- package/dist/browser.js +75 -0
- package/dist/index.d.ts +585 -0
- package/dist/index.js +4056 -0
- package/dist/instrument-YhFFywwZ.d.ts +52 -0
- package/dist/langchain.d.ts +15 -0
- package/dist/langchain.js +25 -0
- package/dist/openai.d.ts +15 -0
- package/dist/openai.js +25 -0
- package/dist/web-C0F5sf2n.js +44 -0
- package/package.json +109 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { a as spanProcessor, c as ScoreOptions, d as ConfigError, i as shutdown, l as score, n as flush, o as tracerProvider, r as init, s as ScoreDataType, t as Instrumentation, u as CetraOptions } from "./instrument-YhFFywwZ.js";
|
|
2
|
+
import { AttributeValue, Tracer } from "@opentelemetry/api";
|
|
3
|
+
interface AiTelemetryOptions {
|
|
4
|
+
sessionId?: string;
|
|
5
|
+
userId?: string;
|
|
6
|
+
tags?: readonly string[];
|
|
7
|
+
metadata?: Readonly<Record<string, string | number | boolean>>;
|
|
8
|
+
functionId?: string;
|
|
9
|
+
}
|
|
10
|
+
interface AiTelemetry {
|
|
11
|
+
isEnabled: boolean;
|
|
12
|
+
tracer?: Tracer;
|
|
13
|
+
functionId?: string;
|
|
14
|
+
metadata?: Record<string, AttributeValue>;
|
|
15
|
+
}
|
|
16
|
+
/** Telemetry settings for the Vercel AI SDK's `experimental_telemetry`. */
|
|
17
|
+
export declare function aiTelemetry(options?: AiTelemetryOptions): AiTelemetry;
|
|
18
|
+
/** One item of a dataset version (D-J-2). Absent optional values are `undefined`. */
|
|
19
|
+
interface DatasetItem {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly input: unknown;
|
|
22
|
+
readonly expectedOutput: unknown;
|
|
23
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
24
|
+
/** The version this revision appeared in. */
|
|
25
|
+
readonly version: number;
|
|
26
|
+
readonly sourceTraceId: string | undefined;
|
|
27
|
+
readonly sourceSpanId: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** A dataset without its items, as listed. */
|
|
30
|
+
interface DatasetInfo {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly description: string | undefined;
|
|
34
|
+
readonly currentVersion: number;
|
|
35
|
+
readonly itemCount: number;
|
|
36
|
+
}
|
|
37
|
+
/** An item to add: `input` is required. */
|
|
38
|
+
interface NewDatasetItem {
|
|
39
|
+
input: unknown;
|
|
40
|
+
expectedOutput?: unknown;
|
|
41
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
42
|
+
}
|
|
43
|
+
/** One version of a dataset with all its items. */
|
|
44
|
+
export declare class Dataset {
|
|
45
|
+
#private;
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly description: string | undefined;
|
|
49
|
+
/** The version these items belong to. */
|
|
50
|
+
readonly version: number;
|
|
51
|
+
readonly items: readonly DatasetItem[];
|
|
52
|
+
/** @internal */
|
|
53
|
+
constructor(fields: {
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
description: string | undefined;
|
|
57
|
+
version: number;
|
|
58
|
+
items: readonly DatasetItem[];
|
|
59
|
+
}, client: Client);
|
|
60
|
+
/**
|
|
61
|
+
* Add items; each batch of up to 1,000 makes one new version (D-J-3).
|
|
62
|
+
* Rejects with `TypeError` before any request when an item is malformed.
|
|
63
|
+
* Resolves to the latest version; an empty iterable resolves to `this`.
|
|
64
|
+
* Batches are sent in order: if a later batch fails, the earlier batches are
|
|
65
|
+
* already stored (each made a version), and the promise rejects.
|
|
66
|
+
*/
|
|
67
|
+
addItems(items: Iterable<NewDatasetItem>): Promise<Dataset>;
|
|
68
|
+
}
|
|
69
|
+
/** `client.datasets`. */
|
|
70
|
+
declare class Datasets {
|
|
71
|
+
#private;
|
|
72
|
+
/** @internal */
|
|
73
|
+
constructor(client: Client);
|
|
74
|
+
/** Create a dataset (version 0, no items). Sent once: a retry could create a second one. */
|
|
75
|
+
create(name: string, options?: {
|
|
76
|
+
description?: string;
|
|
77
|
+
inputSchema?: Record<string, unknown>;
|
|
78
|
+
expectedSchema?: Record<string, unknown>;
|
|
79
|
+
}): Promise<Dataset>;
|
|
80
|
+
/** A dataset with the items of `options.version` (default: the current version). */
|
|
81
|
+
get(nameOrId: string, options?: {
|
|
82
|
+
version?: number;
|
|
83
|
+
}): Promise<Dataset>;
|
|
84
|
+
/** Every dataset, without items. */
|
|
85
|
+
list(): Promise<DatasetInfo[]>;
|
|
86
|
+
/** Delete a dataset by name or id. */
|
|
87
|
+
delete(nameOrId: string): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
type ChatMessage = {
|
|
90
|
+
readonly role: string;
|
|
91
|
+
readonly content: string;
|
|
92
|
+
};
|
|
93
|
+
type ChatEntry = ChatMessage | {
|
|
94
|
+
readonly type: "placeholder";
|
|
95
|
+
readonly name: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* A template is invalid, or a variable or placeholder has no value.
|
|
99
|
+
*
|
|
100
|
+
* `kind` is `invalid`, `missing_variable` or `missing_placeholder`. `variable`
|
|
101
|
+
* is the missing name; `reason`, `line` and `column` describe an invalid
|
|
102
|
+
* template. The message never quotes the template.
|
|
103
|
+
*/
|
|
104
|
+
export declare class PromptCompileError extends Error {
|
|
105
|
+
readonly kind: "invalid" | "missing_variable" | "missing_placeholder";
|
|
106
|
+
readonly variable: string | undefined;
|
|
107
|
+
readonly reason: string | undefined;
|
|
108
|
+
readonly line: number | undefined;
|
|
109
|
+
readonly column: number | undefined;
|
|
110
|
+
/** The prompt's name, when the error came from `Prompt.compile` or a fallback. */
|
|
111
|
+
readonly prompt: string | undefined;
|
|
112
|
+
constructor(kind: "invalid" | "missing_variable" | "missing_placeholder", details: {
|
|
113
|
+
variable?: string;
|
|
114
|
+
reason?: string;
|
|
115
|
+
line?: number;
|
|
116
|
+
column?: number;
|
|
117
|
+
prompt?: string;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The values of `Prompt.compile`. Strings, numbers and booleans fill
|
|
122
|
+
* `{{ name }}` (a boolean is `true` or `false`; a finite number is its
|
|
123
|
+
* shortest text, so `1.0` is `1`; NaN and infinities are a `TypeError`); a
|
|
124
|
+
* list of `{role, content}` fills a placeholder.
|
|
125
|
+
*/
|
|
126
|
+
type PromptValues = Readonly<Record<string, string | number | boolean | readonly ChatMessage[]>>;
|
|
127
|
+
/** No prompt could be fetched, and the call gave no fallback (D-V-14). */
|
|
128
|
+
export declare class PromptNotAvailable extends Error {
|
|
129
|
+
readonly prompt: string;
|
|
130
|
+
readonly reason: string;
|
|
131
|
+
constructor(prompt: string, reason: string);
|
|
132
|
+
}
|
|
133
|
+
/** The fields of a `Prompt`. Internal. */
|
|
134
|
+
interface PromptFields {
|
|
135
|
+
readonly name: string;
|
|
136
|
+
readonly version: number | undefined;
|
|
137
|
+
readonly config: Readonly<Record<string, unknown>>;
|
|
138
|
+
readonly labels: readonly string[];
|
|
139
|
+
readonly isFallback: boolean;
|
|
140
|
+
/** A string is a text prompt; a list is a chat prompt. */
|
|
141
|
+
readonly template: string | readonly ChatEntry[];
|
|
142
|
+
}
|
|
143
|
+
/** A prompt version from the registry, or a fallback (D-V-14). */
|
|
144
|
+
export declare class Prompt {
|
|
145
|
+
#private;
|
|
146
|
+
readonly name: string;
|
|
147
|
+
readonly type: "text" | "chat";
|
|
148
|
+
readonly template: string | readonly ChatEntry[];
|
|
149
|
+
/** `undefined` for a fallback. */
|
|
150
|
+
readonly version: number | undefined;
|
|
151
|
+
readonly config: Readonly<Record<string, unknown>>;
|
|
152
|
+
readonly labels: readonly string[];
|
|
153
|
+
readonly variables: readonly string[];
|
|
154
|
+
readonly placeholders: readonly string[];
|
|
155
|
+
readonly isFallback: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Throws `PromptCompileError` when the template is invalid.
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
constructor(fields: PromptFields);
|
|
161
|
+
/**
|
|
162
|
+
* Renders the template with `values`. A missing variable or placeholder, or
|
|
163
|
+
* an invalid template, throws `PromptCompileError` carrying the prompt name;
|
|
164
|
+
* a value of another type throws `TypeError`. On success the current span,
|
|
165
|
+
* when it records, gets `cetra.prompt.name` and `cetra.prompt.version`.
|
|
166
|
+
*/
|
|
167
|
+
compile(values?: PromptValues): string | ChatMessage[];
|
|
168
|
+
}
|
|
169
|
+
interface GetPromptOptions {
|
|
170
|
+
readonly label?: string;
|
|
171
|
+
readonly version?: number;
|
|
172
|
+
/** Used when no prompt can be fetched: a text template or a chat template. */
|
|
173
|
+
readonly fallback?: string | readonly ChatMessage[];
|
|
174
|
+
/** Seconds a label stays fresh; 0 turns the cache off. Default 60. */
|
|
175
|
+
readonly cacheTtlS?: number;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The prompt `name` at its label (default `production`) or version. Answers
|
|
179
|
+
* from the cache when it can (D-V-14); throws `TypeError` for bad arguments
|
|
180
|
+
* and `PromptNotAvailable` when nothing can answer and there is no fallback.
|
|
181
|
+
* Before `init()`, or with the SDK disabled, it behaves like a failed fetch.
|
|
182
|
+
*/
|
|
183
|
+
export declare function getPrompt(name: string, options?: GetPromptOptions): Promise<Prompt>;
|
|
184
|
+
/** `client.prompts`: the REST operations on prompts (spec 10, D-V-12). */
|
|
185
|
+
declare class Prompts {
|
|
186
|
+
#private;
|
|
187
|
+
/** @internal */
|
|
188
|
+
constructor(client: Client);
|
|
189
|
+
/** The prompt at its label (default `production`) or version. Not cached. */
|
|
190
|
+
get(name: string, options?: {
|
|
191
|
+
label?: string;
|
|
192
|
+
version?: number;
|
|
193
|
+
}): Promise<Prompt>;
|
|
194
|
+
/** The names of every prompt in the project. */
|
|
195
|
+
list(): Promise<string[]>;
|
|
196
|
+
/** Create a prompt with its version 1. Sent once: a retry could create a second one. */
|
|
197
|
+
create(input: {
|
|
198
|
+
name: string;
|
|
199
|
+
type: "text" | "chat";
|
|
200
|
+
template: string | readonly ChatEntry[];
|
|
201
|
+
config?: Record<string, unknown>;
|
|
202
|
+
labels?: readonly string[];
|
|
203
|
+
commitMessage?: string;
|
|
204
|
+
description?: string;
|
|
205
|
+
tags?: readonly string[];
|
|
206
|
+
}): Promise<Prompt>;
|
|
207
|
+
/** Add a version to a prompt. Sent once, for the same reason as `create`. */
|
|
208
|
+
createVersion(name: string, input: {
|
|
209
|
+
template: string | readonly ChatEntry[];
|
|
210
|
+
config?: Record<string, unknown>;
|
|
211
|
+
labels?: readonly string[];
|
|
212
|
+
commitMessage?: string;
|
|
213
|
+
}): Promise<Prompt>;
|
|
214
|
+
/** Move `label` to `version`. Sent once. */
|
|
215
|
+
setLabel(name: string, label: string, version: number): Promise<void>;
|
|
216
|
+
}
|
|
217
|
+
/** The part of `fetch` the REST client uses. */
|
|
218
|
+
type RestFetch = (url: string, init: {
|
|
219
|
+
method: string;
|
|
220
|
+
headers: Record<string, string>;
|
|
221
|
+
body?: string;
|
|
222
|
+
signal?: unknown;
|
|
223
|
+
}) => Promise<{
|
|
224
|
+
status: number;
|
|
225
|
+
ok: boolean;
|
|
226
|
+
headers: {
|
|
227
|
+
get(name: string): string | null;
|
|
228
|
+
};
|
|
229
|
+
text(): Promise<string>;
|
|
230
|
+
}>;
|
|
231
|
+
interface ClientOptions {
|
|
232
|
+
apiKey?: string;
|
|
233
|
+
baseUrl?: string;
|
|
234
|
+
/** Tests inject a fake; the default is the global `fetch`. */
|
|
235
|
+
fetch?: RestFetch;
|
|
236
|
+
/** Tests inject a fake; the default is `setTimeout`. */
|
|
237
|
+
sleep?: (ms: number) => Promise<void>;
|
|
238
|
+
}
|
|
239
|
+
interface RequestOptions {
|
|
240
|
+
query?: Record<string, string | number>;
|
|
241
|
+
body?: unknown;
|
|
242
|
+
/** Default: true for GET and DELETE, false otherwise (D-J-16). */
|
|
243
|
+
retry?: boolean;
|
|
244
|
+
}
|
|
245
|
+
/** An error answer from the cetra API, or a network failure (`status` 0). */
|
|
246
|
+
export declare class ApiError extends Error {
|
|
247
|
+
readonly status: number;
|
|
248
|
+
readonly code: string | undefined;
|
|
249
|
+
readonly detail: string | undefined;
|
|
250
|
+
readonly errors: readonly {
|
|
251
|
+
field: string;
|
|
252
|
+
message: string;
|
|
253
|
+
}[];
|
|
254
|
+
constructor(init: {
|
|
255
|
+
method: string;
|
|
256
|
+
template: string;
|
|
257
|
+
status: number;
|
|
258
|
+
code: string | undefined;
|
|
259
|
+
detail: string | undefined;
|
|
260
|
+
errors: readonly {
|
|
261
|
+
field: string;
|
|
262
|
+
message: string;
|
|
263
|
+
}[];
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
export declare class Client {
|
|
267
|
+
#private;
|
|
268
|
+
readonly datasets: Datasets;
|
|
269
|
+
readonly prompts: Prompts;
|
|
270
|
+
readonly annotationQueues: AnnotationQueues;
|
|
271
|
+
/** Resolves the key and base URL as `init()` does; throws `ConfigError` without a key. */
|
|
272
|
+
constructor(options?: ClientOptions);
|
|
273
|
+
/**
|
|
274
|
+
* One API call with the retry policy of D-J-16. `template` names the route
|
|
275
|
+
* in errors (`/datasets/{dataset}/items`); `path` is the filled path with
|
|
276
|
+
* its segments already encoded. Resolves to the decoded JSON, or
|
|
277
|
+
* `undefined` for `204`.
|
|
278
|
+
* @internal
|
|
279
|
+
*/
|
|
280
|
+
request<T>(method: string, template: string, path: string, options?: RequestOptions): Promise<T>;
|
|
281
|
+
}
|
|
282
|
+
/** What a queue's items are (D-AQ-2). */
|
|
283
|
+
type QueueTarget = "trace" | "span" | "session";
|
|
284
|
+
/** Where an item is in its review (D-AQ-5). */
|
|
285
|
+
type QueueItemStatus = "pending" | "completed" | "skipped";
|
|
286
|
+
/** Item counts of a queue, by status. */
|
|
287
|
+
interface QueueCounts {
|
|
288
|
+
readonly pending: number;
|
|
289
|
+
readonly completed: number;
|
|
290
|
+
readonly skipped: number;
|
|
291
|
+
}
|
|
292
|
+
/** An annotation queue with its counts. Absent optional values are `undefined`. */
|
|
293
|
+
interface AnnotationQueue {
|
|
294
|
+
readonly id: string;
|
|
295
|
+
readonly name: string;
|
|
296
|
+
readonly description: string | undefined;
|
|
297
|
+
readonly instructions: string | undefined;
|
|
298
|
+
readonly target: QueueTarget;
|
|
299
|
+
readonly definitionIds: readonly string[];
|
|
300
|
+
/** Incremented by every change; `update` names the version it read. */
|
|
301
|
+
readonly version: number;
|
|
302
|
+
readonly createdBy: string | undefined;
|
|
303
|
+
/** RFC 3339, as the dataset types keep times. */
|
|
304
|
+
readonly createdAt: string;
|
|
305
|
+
readonly updatedAt: string;
|
|
306
|
+
readonly counts: QueueCounts;
|
|
307
|
+
}
|
|
308
|
+
/** One target of a queue. Absent optional values are `undefined`. */
|
|
309
|
+
interface AnnotationQueueItem {
|
|
310
|
+
readonly id: string;
|
|
311
|
+
readonly queueId: string;
|
|
312
|
+
readonly traceId: string | undefined;
|
|
313
|
+
readonly spanId: string | undefined;
|
|
314
|
+
readonly sessionId: string | undefined;
|
|
315
|
+
readonly targetTime: string;
|
|
316
|
+
readonly status: QueueItemStatus;
|
|
317
|
+
readonly skipReason: string | undefined;
|
|
318
|
+
readonly leasedByUserId: string | undefined;
|
|
319
|
+
readonly leaseExpiresAt: string | undefined;
|
|
320
|
+
readonly doneByUserId: string | undefined;
|
|
321
|
+
readonly doneAt: string | undefined;
|
|
322
|
+
readonly addedBy: "user" | "pat" | "key";
|
|
323
|
+
readonly addedById: string;
|
|
324
|
+
readonly createdAt: string;
|
|
325
|
+
}
|
|
326
|
+
/** A target that was not added, and why. `index` is its position in the caller's list. */
|
|
327
|
+
interface SkippedQueueItem {
|
|
328
|
+
readonly index: number;
|
|
329
|
+
readonly message: string;
|
|
330
|
+
}
|
|
331
|
+
/** The answer of `addItems`. A target already in the queue counts as `existing`. */
|
|
332
|
+
interface AddedQueueItems {
|
|
333
|
+
readonly added: number;
|
|
334
|
+
readonly existing: number;
|
|
335
|
+
readonly skipped: readonly SkippedQueueItem[];
|
|
336
|
+
}
|
|
337
|
+
/** The targets of `addItems`: exactly one of the three keys. */
|
|
338
|
+
type QueueTargets = {
|
|
339
|
+
readonly traceIds: readonly string[];
|
|
340
|
+
} | {
|
|
341
|
+
readonly spans: readonly (readonly [string, string])[];
|
|
342
|
+
} | {
|
|
343
|
+
readonly sessionIds: readonly string[];
|
|
344
|
+
};
|
|
345
|
+
/** `client.annotationQueues`. */
|
|
346
|
+
declare class AnnotationQueues {
|
|
347
|
+
#private;
|
|
348
|
+
/** @internal */
|
|
349
|
+
constructor(client: Client);
|
|
350
|
+
/** Every queue of the key's project. */
|
|
351
|
+
list(): Promise<AnnotationQueue[]>;
|
|
352
|
+
/** One queue by id. */
|
|
353
|
+
get(queueId: string): Promise<AnnotationQueue>;
|
|
354
|
+
/** Create a queue. Sent once: a retry could create a second one. */
|
|
355
|
+
create(name: string, options: {
|
|
356
|
+
target: QueueTarget;
|
|
357
|
+
definitionIds: readonly string[];
|
|
358
|
+
description?: string;
|
|
359
|
+
instructions?: string;
|
|
360
|
+
}): Promise<AnnotationQueue>;
|
|
361
|
+
/**
|
|
362
|
+
* Change a queue. `version` is the version the caller read; the server
|
|
363
|
+
* answers `409` when it is stale. `""` clears a text field.
|
|
364
|
+
*/
|
|
365
|
+
update(queueId: string, options: {
|
|
366
|
+
version: number;
|
|
367
|
+
name?: string;
|
|
368
|
+
description?: string;
|
|
369
|
+
instructions?: string;
|
|
370
|
+
definitionIds?: readonly string[];
|
|
371
|
+
}): Promise<AnnotationQueue>;
|
|
372
|
+
/** Delete a queue and its items. */
|
|
373
|
+
delete(queueId: string): Promise<void>;
|
|
374
|
+
/**
|
|
375
|
+
* Add traces, spans or sessions to a queue, in batches of 1,000 (D-AQ-8).
|
|
376
|
+
* Rejects with `TypeError` before any request when the targets are malformed.
|
|
377
|
+
* `skipped` indexes are positions in the list the caller passed. An empty
|
|
378
|
+
* list resolves to zero counts without a request.
|
|
379
|
+
*/
|
|
380
|
+
addItems(queueId: string, targets: QueueTargets): Promise<AddedQueueItems>;
|
|
381
|
+
/** The items of a queue, optionally only one status. Every page is read. */
|
|
382
|
+
items(queueId: string, options?: {
|
|
383
|
+
status?: QueueItemStatus;
|
|
384
|
+
}): Promise<AnnotationQueueItem[]>;
|
|
385
|
+
}
|
|
386
|
+
interface ContextOptions {
|
|
387
|
+
sessionId?: string;
|
|
388
|
+
userId?: string;
|
|
389
|
+
tags?: readonly string[];
|
|
390
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
391
|
+
/** Also set the session/user baggage entries for W3C propagation. */
|
|
392
|
+
propagate?: boolean;
|
|
393
|
+
/** Stamps `cetra.prompt.name` and, when the prompt has one, `cetra.prompt.version` (D-V-15). */
|
|
394
|
+
prompt?: Prompt;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Run `fn` with the merged context values in scope. The return value (a
|
|
398
|
+
* promise included) is returned unchanged; so are `fn`'s exceptions.
|
|
399
|
+
*/
|
|
400
|
+
export declare function withContext<T>(options: ContextOptions, fn: () => T): T;
|
|
401
|
+
/** A scorer's rich return value (spec 10). */
|
|
402
|
+
interface Score {
|
|
403
|
+
value: boolean | number | string;
|
|
404
|
+
reason?: string;
|
|
405
|
+
dataType?: ScoreDataType;
|
|
406
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
407
|
+
}
|
|
408
|
+
/** What a scorer receives for one run. */
|
|
409
|
+
interface ScorerArgs {
|
|
410
|
+
input: unknown;
|
|
411
|
+
output: unknown;
|
|
412
|
+
expected: unknown;
|
|
413
|
+
metadata: Readonly<Record<string, unknown>>;
|
|
414
|
+
traceId: string | undefined;
|
|
415
|
+
item: DatasetItem;
|
|
416
|
+
}
|
|
417
|
+
/** A scorer's return value: a bare value, a `Score`, or nothing (no score). */
|
|
418
|
+
type ScorerResult = boolean | number | string | Score | undefined | null;
|
|
419
|
+
type Scorer = (args: ScorerArgs) => ScorerResult | Promise<ScorerResult>;
|
|
420
|
+
interface EvaluateOptions {
|
|
421
|
+
dataset: string | Dataset;
|
|
422
|
+
task: (input: unknown, item: DatasetItem) => unknown;
|
|
423
|
+
scorers?: readonly Scorer[];
|
|
424
|
+
experimentName?: string;
|
|
425
|
+
description?: string;
|
|
426
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
427
|
+
datasetVersion?: number;
|
|
428
|
+
/** 1 to 64; default 8. */
|
|
429
|
+
concurrency?: number;
|
|
430
|
+
/** 1 to 20; default 1. */
|
|
431
|
+
repetitions?: number;
|
|
432
|
+
client?: Client;
|
|
433
|
+
}
|
|
434
|
+
/** One task run of an experiment. */
|
|
435
|
+
interface Run {
|
|
436
|
+
readonly datasetItemId: string;
|
|
437
|
+
/** 0-based: 0 to `repetitions - 1`. */
|
|
438
|
+
readonly repetition: number;
|
|
439
|
+
readonly input: unknown;
|
|
440
|
+
readonly expectedOutput: unknown;
|
|
441
|
+
/** The task's value before conversion; `undefined` for a failed run. */
|
|
442
|
+
readonly output: unknown;
|
|
443
|
+
readonly error: string | undefined;
|
|
444
|
+
readonly traceId: string | undefined;
|
|
445
|
+
readonly latencyNs: number;
|
|
446
|
+
readonly scores: Readonly<Record<string, Score>>;
|
|
447
|
+
}
|
|
448
|
+
/** The outcome of `evaluate`, built from the local runs and scores. */
|
|
449
|
+
export declare class ExperimentResult {
|
|
450
|
+
#private;
|
|
451
|
+
readonly experimentId: string;
|
|
452
|
+
readonly experimentName: string;
|
|
453
|
+
readonly datasetId: string;
|
|
454
|
+
/** The pinned dataset version. */
|
|
455
|
+
readonly datasetVersion: number;
|
|
456
|
+
/** In item order, repetitions inner. */
|
|
457
|
+
readonly runs: readonly Run[];
|
|
458
|
+
/** Scorer name to the number of runs it failed on (only scorers that failed). */
|
|
459
|
+
readonly scorerErrors: Readonly<Record<string, number>>;
|
|
460
|
+
/** @internal */
|
|
461
|
+
constructor(fields: {
|
|
462
|
+
experimentId: string;
|
|
463
|
+
experimentName: string;
|
|
464
|
+
datasetId: string;
|
|
465
|
+
datasetVersion: number;
|
|
466
|
+
runs: readonly Run[];
|
|
467
|
+
scorerErrors: Readonly<Record<string, number>>;
|
|
468
|
+
scorerNames: readonly string[];
|
|
469
|
+
});
|
|
470
|
+
/** Runs with a task error. */
|
|
471
|
+
get errorCount(): number;
|
|
472
|
+
/** A short text report, one line per scorer, in the order the scorers were given. */
|
|
473
|
+
summary(): string;
|
|
474
|
+
/**
|
|
475
|
+
* Throws `Error` when the mean of the numeric and boolean values of `name`
|
|
476
|
+
* (over every run) is below `threshold`, or when there are none.
|
|
477
|
+
*/
|
|
478
|
+
assertMin(name: string, threshold: number): void;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Run `task` on every item of a dataset version, score each run with
|
|
482
|
+
* `scorers` and store the results on the server. Raises `ConfigError` before
|
|
483
|
+
* `init()`, `RangeError`/`TypeError` for bad arguments, `ApiError` when the API
|
|
484
|
+
* refuses a call (the create, or a finish that fails).
|
|
485
|
+
*/
|
|
486
|
+
export declare function evaluate(options: EvaluateOptions): Promise<ExperimentResult>;
|
|
487
|
+
type SpanKind = "llm" | "embedding" | "tool" | "agent" | "chain" | "retriever" | "reranker" | "guardrail" | "evaluator" | "span";
|
|
488
|
+
interface SpanHandle {
|
|
489
|
+
/** 32 lowercase hex, `undefined` for a no-op handle. */
|
|
490
|
+
readonly traceId: string | undefined;
|
|
491
|
+
/** 16 lowercase hex, `undefined` for a no-op handle. */
|
|
492
|
+
readonly spanId: string | undefined;
|
|
493
|
+
setInput(value: unknown): void;
|
|
494
|
+
setOutput(value: unknown): void;
|
|
495
|
+
setMetadata(values: Readonly<Record<string, unknown>>): void;
|
|
496
|
+
}
|
|
497
|
+
interface SpanOptions {
|
|
498
|
+
kind?: SpanKind;
|
|
499
|
+
input?: unknown;
|
|
500
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
501
|
+
}
|
|
502
|
+
interface ObserveOptions {
|
|
503
|
+
name?: string;
|
|
504
|
+
kind?: SpanKind;
|
|
505
|
+
captureInput?: boolean;
|
|
506
|
+
captureOutput?: boolean;
|
|
507
|
+
/** Generator functions only: record `fn(items)` instead of the default output rule. */
|
|
508
|
+
reduceOutput?: (items: unknown[]) => unknown;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Run `fn` inside one of our spans. Its return value is never recorded as the
|
|
512
|
+
* output; only the handle's `setOutput` writes one. A thenable result ends the
|
|
513
|
+
* span when it settles and yields a promise of the same value; a synchronous
|
|
514
|
+
* throw is recorded and re-thrown unchanged.
|
|
515
|
+
*/
|
|
516
|
+
export declare function withSpan<T>(name: string, fn: (span: SpanHandle) => T): T;
|
|
517
|
+
export declare function withSpan<T>(name: string, options: SpanOptions, fn: (span: SpanHandle) => T): T;
|
|
518
|
+
/**
|
|
519
|
+
* Wrap `fn` so each call runs inside one of our spans. `this` is preserved;
|
|
520
|
+
* the input follows D-F-11 (no arguments → none, one → that value, more → the
|
|
521
|
+
* array of them) and the output is the return value or resolved value
|
|
522
|
+
* (`undefined` and generator objects are not recorded).
|
|
523
|
+
*
|
|
524
|
+
* Generator and async generator functions (detected at wrap time) are traced
|
|
525
|
+
* as generators instead: no span at call time, the span starts at the first
|
|
526
|
+
* `next()`, the output is the yielded items (or `reduceOutput(items)`), an
|
|
527
|
+
* early `return()` ends with status ok. See `./generators.js`. The kind is
|
|
528
|
+
* checked at wrap time; the runtime at call time, so a function wrapped
|
|
529
|
+
* before `init()` is traced after it.
|
|
530
|
+
*/
|
|
531
|
+
export declare function observe<A extends unknown[], R>(fn: (...args: A) => R, options?: ObserveOptions): (...args: A) => R;
|
|
532
|
+
/** The trace id of the current span (ours or an instrumentor's), when valid. */
|
|
533
|
+
export declare function currentTraceId(): string | undefined;
|
|
534
|
+
/** The span id of the current span (ours or an instrumentor's), when valid. */
|
|
535
|
+
export declare function currentSpanId(): string | undefined;
|
|
536
|
+
interface LlmSpanOptions {
|
|
537
|
+
/** Required, non-empty; written as `gen_ai.provider.name`. */
|
|
538
|
+
provider: string;
|
|
539
|
+
/** Required, non-empty; written as `gen_ai.request.model`. */
|
|
540
|
+
model: string;
|
|
541
|
+
inputMessages?: readonly unknown[];
|
|
542
|
+
/** A string becomes one text part. */
|
|
543
|
+
systemInstructions?: string | readonly unknown[];
|
|
544
|
+
/** Only string, boolean and finite number values are written. */
|
|
545
|
+
params?: Readonly<Record<string, unknown>>;
|
|
546
|
+
metadata?: Readonly<Record<string, unknown>>;
|
|
547
|
+
}
|
|
548
|
+
interface Usage {
|
|
549
|
+
inputTokens?: number;
|
|
550
|
+
outputTokens?: number;
|
|
551
|
+
cacheReadTokens?: number;
|
|
552
|
+
cacheWriteTokens?: number;
|
|
553
|
+
reasoningTokens?: number;
|
|
554
|
+
}
|
|
555
|
+
interface LlmSpanHandle extends SpanHandle {
|
|
556
|
+
setInputMessages(messages: readonly unknown[]): void;
|
|
557
|
+
setOutputMessages(messages: readonly unknown[]): void;
|
|
558
|
+
setResponseModel(model: string): void;
|
|
559
|
+
setUsage(usage: Usage): void;
|
|
560
|
+
setCost(totalUsd: number): void;
|
|
561
|
+
recordFirstToken(): void;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Run `fn` inside one manual LLM span, through the T6 runner (`tracedSpan`)
|
|
565
|
+
* so `withSpan` and `withLlmSpan` behave the same. `provider` and `model` are
|
|
566
|
+
* checked before the body runs (a `TypeError` otherwise); the body's return
|
|
567
|
+
* value is never recorded — only the handle's setters write attributes.
|
|
568
|
+
*/
|
|
569
|
+
export declare function withLlmSpan<T>(name: string, options: LlmSpanOptions, fn: (span: LlmSpanHandle) => T): T;
|
|
570
|
+
/**
|
|
571
|
+
* UUIDv7 (RFC 9562 §5.7).
|
|
572
|
+
*
|
|
573
|
+
* 48 big-endian bits of Unix milliseconds from `Date.now()`, version `0b0111`,
|
|
574
|
+
* 12 random bits (`rand_a`), variant `0b10`, 62 random bits (`rand_b`); every
|
|
575
|
+
* random bit comes from `crypto.getRandomValues` of the running runtime.
|
|
576
|
+
*/
|
|
577
|
+
/**
|
|
578
|
+
* A new UUIDv7 as a lowercase string. Throws when the runtime has no
|
|
579
|
+
* `crypto.getRandomValues`; `score()` checks for that case first and warns
|
|
580
|
+
* once instead (§ Score request).
|
|
581
|
+
*/
|
|
582
|
+
export declare function uuid7(): string;
|
|
583
|
+
/** Package version. Kept equal to package.json. */
|
|
584
|
+
export declare const VERSION = "0.0.0";
|
|
585
|
+
export { type AddedQueueItems, type AiTelemetry, type AiTelemetryOptions, type AnnotationQueue, type AnnotationQueueItem, type AnnotationQueues, type CetraOptions, type ChatEntry, type ChatMessage, type ClientOptions, ConfigError, type ContextOptions, type DatasetInfo, type DatasetItem, type Datasets, type EvaluateOptions, type GetPromptOptions, type Instrumentation, type LlmSpanHandle, type LlmSpanOptions, type NewDatasetItem, type ObserveOptions, type PromptValues, type Prompts, type QueueCounts, type QueueItemStatus, type QueueTarget, type QueueTargets, type Run, type Score, type ScoreOptions, type Scorer, type ScorerArgs, type SkippedQueueItem, type SpanHandle, type SpanKind, type SpanOptions, type Usage, flush, init, score, shutdown, spanProcessor, tracerProvider };
|