@posthog/ai 8.15.2 → 8.16.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.
@@ -0,0 +1,497 @@
1
+ //#region src/evaluations/serialization.d.ts
2
+ /** JSON accepted in evaluation payloads. No implicit toJSON or string conversion. */
3
+ type JSONValue = null | boolean | number | string | JSONValue[] | {
4
+ [key: string]: JSONValue;
5
+ };
6
+ type JSONObject = {
7
+ [key: string]: JSONValue;
8
+ };
9
+ /** Large signed-64-bit counts use bigint; safe counts are returned as numbers. */
10
+ type EvaluationCount = number | bigint;
11
+ type WireObject = Record<string, unknown>;
12
+ interface Page<T> {
13
+ count: EvaluationCount;
14
+ results: T[];
15
+ nextOffset: number | null;
16
+ }
17
+ //#endregion
18
+ //#region src/evaluations/transport.d.ts
19
+ interface RequestOptions {
20
+ signal?: AbortSignal;
21
+ }
22
+ interface OfflineEvaluationsOptions {
23
+ projectId: number;
24
+ secretKey: string;
25
+ host?: string;
26
+ /** Per-attempt timeout, including reading the response body. Default: 15,000 ms. */
27
+ timeoutMs?: number;
28
+ /** Additional attempts for operations with safe replay identity. Default: 3. */
29
+ maxRetries?: number;
30
+ }
31
+ declare class Transport {
32
+ #private;
33
+ readonly projectId: number;
34
+ constructor(options: OfflineEvaluationsOptions);
35
+ close(): void;
36
+ request(method: string, path: string, request?: RequestOptions & {
37
+ body?: string;
38
+ params?: WireObject;
39
+ retrySafe?: boolean;
40
+ }): Promise<WireObject>;
41
+ }
42
+ //#endregion
43
+ //#region src/evaluations/datasets.d.ts
44
+ interface Audit {
45
+ createdAt: string;
46
+ createdBy: JSONObject | null;
47
+ teamId: number;
48
+ }
49
+ interface Dataset extends Audit {
50
+ id: string;
51
+ name: string;
52
+ description: string;
53
+ metadata: JSONObject;
54
+ tags: string[];
55
+ archived: boolean;
56
+ currentRevision: number | null;
57
+ currentRevisionId: string | null;
58
+ updatedAt: string | null;
59
+ }
60
+ interface DatasetRevision extends Audit {
61
+ id: string;
62
+ datasetId: string;
63
+ revision: number;
64
+ }
65
+ interface DatasetItem extends Audit {
66
+ id: string;
67
+ datasetId: string;
68
+ clientItemId: string | null;
69
+ version: number;
70
+ versionId: string;
71
+ datasetRevision: number;
72
+ datasetRevisionId: string;
73
+ archived: boolean;
74
+ input: JSONValue;
75
+ expectedOutput: JSONValue;
76
+ sourceOutput: JSONValue;
77
+ metadata: JSONObject;
78
+ sourceTraceId: string | null;
79
+ sourceEventId: string | null;
80
+ sourceTimestamp: string | null;
81
+ updatedAt: string | null;
82
+ versionCreatedAt: string;
83
+ versionCreatedBy: JSONObject | null;
84
+ }
85
+ type DatasetPage = Page<Dataset>;
86
+ type DatasetRevisionPage = Page<DatasetRevision>;
87
+ type DatasetItemPage = Page<DatasetItem>;
88
+ type DatasetOrder = 'created_at' | '-created_at' | 'updated_at' | '-updated_at';
89
+ interface DatasetMetadata {
90
+ name?: string;
91
+ description?: string;
92
+ metadata?: JSONObject;
93
+ tags?: readonly string[];
94
+ }
95
+ interface PageOptions extends RequestOptions {
96
+ limit?: number;
97
+ offset?: number;
98
+ }
99
+ interface DatasetListOptions extends PageOptions {
100
+ search?: string;
101
+ archived?: boolean;
102
+ orderBy?: DatasetOrder;
103
+ tags?: readonly string[];
104
+ tagMatch?: 'any' | 'all';
105
+ }
106
+ interface ItemListOptions extends PageOptions {
107
+ revision?: number;
108
+ archived?: boolean;
109
+ }
110
+ interface CreateDatasetItemOptions {
111
+ input: Exclude<JSONValue, null>;
112
+ expectedOutput?: JSONValue;
113
+ sourceOutput?: JSONValue;
114
+ metadata?: JSONObject;
115
+ clientItemId?: string | null;
116
+ sourceTraceId?: string | null;
117
+ sourceEventId?: string | null;
118
+ sourceTimestamp?: string | Date | null;
119
+ }
120
+ interface UpdateDatasetItemOptions {
121
+ baseVersion: number;
122
+ input?: Exclude<JSONValue, null>;
123
+ expectedOutput?: JSONValue;
124
+ metadata?: JSONObject;
125
+ }
126
+ /** Dataset management. Writes require a personal key with dataset:write. */
127
+ declare class Datasets {
128
+ #private;
129
+ constructor(transport: Transport);
130
+ create(options: DatasetMetadata & {
131
+ name: string;
132
+ }, request?: RequestOptions): Promise<Dataset>;
133
+ get(datasetId: string, request?: RequestOptions): Promise<Dataset>;
134
+ list(options?: DatasetListOptions): Promise<DatasetPage>;
135
+ update(datasetId: string, options: DatasetMetadata, request?: RequestOptions): Promise<Dataset>;
136
+ archive(datasetId: string, request?: RequestOptions): Promise<Dataset>;
137
+ restore(datasetId: string, request?: RequestOptions): Promise<Dataset>;
138
+ listRevisions(datasetId: string, options?: PageOptions): Promise<DatasetRevisionPage>;
139
+ listItems(datasetId: string, options?: ItemListOptions): Promise<DatasetItemPage>;
140
+ getItem(itemId: string, options?: RequestOptions & {
141
+ revision?: number;
142
+ }): Promise<DatasetItem>;
143
+ createItem(datasetId: string, options: CreateDatasetItemOptions, request?: RequestOptions): Promise<DatasetItem>;
144
+ updateItem(itemId: string, options: UpdateDatasetItemOptions, request?: RequestOptions): Promise<DatasetItem>;
145
+ archiveItem(itemId: string, options: {
146
+ baseVersion: number;
147
+ }, request?: RequestOptions): Promise<DatasetItem>;
148
+ restoreItem(itemId: string, options: {
149
+ baseVersion: number;
150
+ sourceVersion?: number;
151
+ }, request?: RequestOptions): Promise<DatasetItem>;
152
+ listItemVersions(itemId: string, options?: PageOptions): Promise<DatasetItemPage>;
153
+ snapshot(datasetId: string, options?: RequestOptions & {
154
+ revision?: number;
155
+ }): Promise<DatasetSnapshot>;
156
+ }
157
+ /** A repeatable, lazy read of active items at one immutable revision. Keep its client open. */
158
+ declare class DatasetSnapshot implements AsyncIterable<DatasetItem> {
159
+ #private;
160
+ readonly revision: number;
161
+ readonly revisionId: string;
162
+ constructor(datasets: Datasets, dataset: Dataset, revisionNumber: number, revisionId: string);
163
+ get dataset(): Dataset;
164
+ iterItems(options?: RequestOptions & {
165
+ pageSize?: number;
166
+ }): AsyncIterableIterator<DatasetItem>;
167
+ [Symbol.asyncIterator](): AsyncIterableIterator<DatasetItem>;
168
+ }
169
+ //#endregion
170
+ //#region src/evaluations/declarations.d.ts
171
+ interface ItemPayload {
172
+ input?: JSONValue;
173
+ output?: JSONValue;
174
+ expectedOutput?: JSONValue;
175
+ metadata?: JSONObject | null;
176
+ }
177
+ interface ResultPayload {
178
+ reasoning?: string | null;
179
+ errorMessage?: string | null;
180
+ metadata?: JSONObject | null;
181
+ }
182
+ type PayloadOptions<T> = (T & {
183
+ payload?: never;
184
+ }) | ({
185
+ payload: T;
186
+ } & { [K in keyof T]?: never; });
187
+ interface ItemIdentifiers {
188
+ id?: string;
189
+ caseKey?: string | null;
190
+ trial?: string | null;
191
+ datasetItemIdentifier?: string | null;
192
+ datasetItemVersionIdentifier?: string | null;
193
+ datasetItemVersionId?: string | null;
194
+ applicationTraceId?: string | null;
195
+ }
196
+ type EvaluationItemOptions = ItemIdentifiers & PayloadOptions<ItemPayload>;
197
+ type ScoreValue = boolean | number | readonly string[];
198
+ /** bigint inputs are converted only if exactly representable as finite binary64 scores. */
199
+ type ScoreInput = ScoreValue | bigint;
200
+ type ResultStatus = 'ok' | 'error' | 'skipped' | 'not_applicable';
201
+ type Outcome = ({
202
+ status?: 'ok';
203
+ value: ScoreInput;
204
+ errorCode?: never;
205
+ } & PayloadOptions<Omit<ResultPayload, 'errorMessage'> & {
206
+ errorMessage?: null;
207
+ }>) | ({
208
+ status: 'error';
209
+ value?: never;
210
+ errorCode?: string;
211
+ } & PayloadOptions<ResultPayload>) | ({
212
+ status: 'skipped' | 'not_applicable';
213
+ value?: never;
214
+ errorCode?: never;
215
+ } & PayloadOptions<Omit<ResultPayload, 'errorMessage'> & {
216
+ errorMessage?: null;
217
+ }>);
218
+ type EvaluationResultOptions = Outcome & {
219
+ item: EvaluationItem | string;
220
+ scorerVersionId: string;
221
+ evaluatorTraceId?: string | null;
222
+ evaluatedAt?: string | Date | null;
223
+ };
224
+ /** One immutable execution. Reuse across scorers; construct a new item for each trial. */
225
+ declare class EvaluationItem {
226
+ readonly id: string;
227
+ constructor(options?: EvaluationItemOptions);
228
+ /** Detached wire-format object. Use toJSONString() for lossless cross-language persistence. */
229
+ toJSON(): WireObject;
230
+ /** Exact wire JSON, including large integers. Restore with fromJSON(JSON.parse(saved)). */
231
+ toJSONString(): string;
232
+ static fromJSON(value: unknown): EvaluationItem;
233
+ static fromDatasetItem(item: DatasetItem, options?: {
234
+ output?: JSONValue;
235
+ id?: string;
236
+ caseKey?: string;
237
+ trial?: string;
238
+ applicationTraceId?: string;
239
+ }): EvaluationItem;
240
+ }
241
+ /** An evaluator outcome pinned to an exact scorer version. `ok` does not imply passing. */
242
+ declare class EvaluationResult {
243
+ readonly item: EvaluationItem | string;
244
+ readonly scorerVersionId: string;
245
+ readonly itemId: string;
246
+ constructor(options: EvaluationResultOptions);
247
+ /** Detached wire-format object. Use toJSONString() for lossless cross-language persistence. */
248
+ toJSON(): WireObject;
249
+ /** Exact wire JSON. Save the attached item separately and restore with fromJSON(JSON.parse(saved), { item }). */
250
+ toJSONString(): string;
251
+ static fromJSON(value: unknown, options?: {
252
+ item?: EvaluationItem;
253
+ }): EvaluationResult;
254
+ }
255
+ //#endregion
256
+ //#region src/evaluations/errors.d.ts
257
+ type Persistence = 'not_sent' | 'rejected' | 'unknown';
258
+ interface EvaluationErrorFields {
259
+ status?: number;
260
+ code?: string;
261
+ detail?: unknown;
262
+ attr?: string;
263
+ errors?: unknown;
264
+ response?: WireObject;
265
+ /** Retry-After in seconds. */
266
+ retryAfter?: number;
267
+ persistence?: Persistence;
268
+ submission?: ExperimentOptions;
269
+ }
270
+ /** Native cancellation with the prepared creation fields needed for recovery. */
271
+ declare class ExperimentCreationAbortedError extends DOMException {
272
+ #private;
273
+ readonly cause: unknown;
274
+ constructor(cause: unknown, submission: ExperimentOptions);
275
+ get submission(): ExperimentOptions;
276
+ }
277
+ /** An operation did not receive a valid acknowledgment. Inspect persistence before recovery. */
278
+ declare class EvaluationAPIError extends Error {
279
+ #private;
280
+ readonly errors: unknown;
281
+ readonly status?: number;
282
+ readonly code?: string;
283
+ readonly detail?: unknown;
284
+ readonly attr?: string;
285
+ readonly response?: WireObject;
286
+ readonly retryAfter?: number;
287
+ persistence: Persistence;
288
+ constructor(fields?: EvaluationErrorFields);
289
+ get submission(): ExperimentOptions | undefined;
290
+ }
291
+ //#endregion
292
+ //#region src/evaluations/scorers.d.ts
293
+ interface BooleanScorerConfig {
294
+ trueLabel?: string;
295
+ falseLabel?: string;
296
+ trueIsFailure?: boolean | null;
297
+ }
298
+ interface NumericPassingRule {
299
+ operator: 'gte' | 'lte';
300
+ threshold: number;
301
+ }
302
+ interface NumericScorerConfig {
303
+ min?: number | null;
304
+ max?: number | null;
305
+ step?: number | null;
306
+ passingRule?: NumericPassingRule | null;
307
+ }
308
+ interface CategoricalScorerOption {
309
+ key: string;
310
+ label: string;
311
+ }
312
+ interface CategoricalScorerConfig {
313
+ options: readonly CategoricalScorerOption[];
314
+ selectionMode?: 'single' | 'multiple';
315
+ minSelections?: number | null;
316
+ maxSelections?: number | null;
317
+ passingRule?: {
318
+ categories: readonly string[];
319
+ } | null;
320
+ }
321
+ interface ScorerConfigs {
322
+ boolean: BooleanScorerConfig;
323
+ numeric: NumericScorerConfig;
324
+ categorical: CategoricalScorerConfig;
325
+ }
326
+ type ScorerKind = keyof ScorerConfigs;
327
+ type ScorerConfig = ScorerConfigs[ScorerKind];
328
+ interface ScorerRecord {
329
+ id: string;
330
+ name: string;
331
+ description: string;
332
+ archived: boolean;
333
+ tags: string[];
334
+ currentVersion: number;
335
+ currentVersionId: string;
336
+ team: number;
337
+ createdAt: string;
338
+ updatedAt: string;
339
+ createdBy: JSONObject | null;
340
+ }
341
+ interface VersionRecord {
342
+ id: string;
343
+ definitionId: string;
344
+ version: number;
345
+ createdAt: string;
346
+ createdBy: JSONObject | null;
347
+ }
348
+ type Scorer = { [K in ScorerKind]: ScorerRecord & {
349
+ kind: K;
350
+ config: ScorerConfigs[K];
351
+ }; }[ScorerKind];
352
+ type ScorerVersion = { [K in ScorerKind]: VersionRecord & {
353
+ kind: K;
354
+ config: ScorerConfigs[K];
355
+ }; }[ScorerKind];
356
+ interface ScorerPage extends Page<Scorer> {
357
+ next: string | null;
358
+ previous: string | null;
359
+ }
360
+ interface ScorerVersionPage {
361
+ count: EvaluationCount;
362
+ results: ScorerVersion[];
363
+ nextCursor: string | null;
364
+ }
365
+ type ScorerOrder = 'name' | '-name' | 'kind' | '-kind' | 'created_at' | '-created_at' | 'updated_at' | '-updated_at' | 'current_version' | '-current_version';
366
+ interface ScorerListOptions extends PageOptions {
367
+ search?: string;
368
+ kind?: ScorerKind;
369
+ archived?: boolean;
370
+ orderBy?: ScorerOrder;
371
+ tags?: readonly string[];
372
+ tagMatch?: 'any' | 'all';
373
+ }
374
+ interface ScorerMetadata {
375
+ name?: string;
376
+ description?: string | null;
377
+ archived?: boolean;
378
+ tags?: readonly string[];
379
+ }
380
+ type CreateScorerOptions = { [K in ScorerKind]: {
381
+ name: string;
382
+ kind: K;
383
+ config: ScorerConfigs[K];
384
+ description?: string | null;
385
+ tags?: readonly string[];
386
+ }; }[ScorerKind];
387
+ /** Versioned scorer definitions. Evaluator execution remains caller-owned. */
388
+ declare class Scorers {
389
+ #private;
390
+ constructor(transport: Transport);
391
+ create<T extends CreateScorerOptions>(options: T, request?: RequestOptions): Promise<Extract<Scorer, {
392
+ kind: T['kind'];
393
+ }>>;
394
+ get(scorerId: string, request?: RequestOptions): Promise<Scorer>;
395
+ list(options?: ScorerListOptions): Promise<ScorerPage>;
396
+ update(scorerId: string, options: ScorerMetadata, request?: RequestOptions): Promise<Scorer>;
397
+ createVersion(scorerId: string, options: {
398
+ config: ScorerConfig;
399
+ baseVersion?: number;
400
+ name?: string;
401
+ description?: string | null;
402
+ }, request?: RequestOptions): Promise<Scorer>;
403
+ getVersion(scorerId: string, versionId: string, request?: RequestOptions): Promise<ScorerVersion>;
404
+ listVersions(scorerId: string, options?: RequestOptions & {
405
+ limit?: number;
406
+ cursor?: string;
407
+ }): Promise<ScorerVersionPage>;
408
+ }
409
+ //#endregion
410
+ //#region src/evaluations/client.d.ts
411
+ interface ExperimentOptions {
412
+ name: string;
413
+ id?: string;
414
+ startedAt?: string | Date;
415
+ runSource?: 'ci' | 'local' | 'scheduled' | null;
416
+ expectedItemCount?: EvaluationCount | null;
417
+ expectedResultCount?: EvaluationCount | null;
418
+ suiteKey?: string | null;
419
+ datasetSource?: string | null;
420
+ datasetIdentifier?: string | null;
421
+ datasetRevisionIdentifier?: string | null;
422
+ datasetRevisionId?: string | null;
423
+ applicationVersion?: string | null;
424
+ modelVersion?: string | null;
425
+ promptVersion?: string | null;
426
+ }
427
+ interface ExperimentReceipt {
428
+ id: string;
429
+ status: 'uploading' | 'completed' | 'failed';
430
+ created: boolean;
431
+ startedAt: string;
432
+ createdAt: string;
433
+ finishedAt: string | null;
434
+ expectedItemCount: EvaluationCount | null;
435
+ expectedResultCount: EvaluationCount | null;
436
+ acceptedItemCount: EvaluationCount;
437
+ acceptedResultCount: EvaluationCount;
438
+ }
439
+ interface ItemReceipt {
440
+ id: string;
441
+ created: boolean;
442
+ acceptedAt: string;
443
+ }
444
+ interface ResultReceipt extends ItemReceipt {
445
+ itemId: string;
446
+ scorerVersionId: string;
447
+ }
448
+ interface UploadReceipt {
449
+ items: ItemReceipt[];
450
+ results: ResultReceipt[];
451
+ }
452
+ interface BulkUploadReceipt {
453
+ chunks: UploadReceipt[];
454
+ }
455
+ interface Chunk {
456
+ start: number;
457
+ results: EvaluationResult[];
458
+ body: string;
459
+ }
460
+ /** Earlier chunks are acknowledged; pendingResults includes the uncertain failed chunk. */
461
+ declare class BulkUploadError extends EvaluationAPIError {
462
+ #private;
463
+ readonly failedIndex: number;
464
+ constructor(cause: EvaluationAPIError, completed: BulkUploadReceipt, failed: Chunk, pending: readonly EvaluationResult[]);
465
+ get completed(): BulkUploadReceipt;
466
+ get pendingResults(): readonly EvaluationResult[];
467
+ get failedChunk(): WireObject;
468
+ }
469
+ declare class Experiment {
470
+ #private;
471
+ readonly id: string;
472
+ constructor(transport: Transport, id: string, receipt?: ExperimentReceipt, submission?: string);
473
+ get receipt(): ExperimentReceipt | undefined;
474
+ /** Original creation options, suitable for createExperiment(submission). Large counts may be bigint. */
475
+ get submission(): ExperimentOptions | undefined;
476
+ uploadResult(options: EvaluationResultOptions, request?: RequestOptions): Promise<UploadReceipt>;
477
+ uploadResults(results: readonly EvaluationResult[], request?: RequestOptions): Promise<BulkUploadReceipt>;
478
+ complete(request?: RequestOptions): Promise<ExperimentReceipt>;
479
+ fail(request?: RequestOptions): Promise<ExperimentReceipt>;
480
+ getTags(request?: RequestOptions): Promise<string[]>;
481
+ setTags(names: readonly string[], request?: RequestOptions): Promise<string[]>;
482
+ }
483
+ /** Acknowledged management APIs, independent of analytics capture and flush. */
484
+ declare class OfflineEvaluations {
485
+ #private;
486
+ readonly datasets: Datasets;
487
+ readonly scorers: Scorers;
488
+ constructor(options: OfflineEvaluationsOptions);
489
+ createExperiment(options: ExperimentOptions, request?: RequestOptions): Promise<Experiment>;
490
+ /** Local only; existence and permissions are checked on the next network operation. */
491
+ resumeExperiment(id: string): Experiment;
492
+ /** Stop owned requests and timers. This never completes or fails experiments. */
493
+ close(): void;
494
+ }
495
+ //#endregion
496
+ export { type BooleanScorerConfig, BulkUploadError, type BulkUploadReceipt, type CategoricalScorerConfig, type CategoricalScorerOption, type CreateDatasetItemOptions, type CreateScorerOptions, type Dataset, type DatasetItem, type DatasetItemPage, type DatasetListOptions, type DatasetMetadata, type DatasetOrder, type DatasetPage, type DatasetRevision, type DatasetRevisionPage, DatasetSnapshot, Datasets, EvaluationAPIError, type EvaluationCount, type EvaluationErrorFields, EvaluationItem, type EvaluationItemOptions, EvaluationResult, type EvaluationResultOptions, Experiment, ExperimentCreationAbortedError, type ExperimentOptions, type ExperimentReceipt, type ItemIdentifiers, type ItemListOptions, type ItemPayload, type ItemReceipt, type JSONObject, type JSONValue, type NumericPassingRule, type NumericScorerConfig, OfflineEvaluations, type OfflineEvaluationsOptions, type PageOptions, type Persistence, type RequestOptions, type ResultPayload, type ResultReceipt, type ResultStatus, type ScoreInput, type ScoreValue, type Scorer, type ScorerConfig, type ScorerConfigs, type ScorerKind, type ScorerListOptions, type ScorerMetadata, type ScorerOrder, type ScorerPage, type ScorerVersion, type ScorerVersionPage, Scorers, type UpdateDatasetItemOptions, type UploadReceipt };
497
+ //# sourceMappingURL=index.d.ts.map