@anyway-sh/node-server-sdk 0.22.8

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.
Files changed (56) hide show
  1. package/README +35 -0
  2. package/dist/index.d.ts +1957 -0
  3. package/dist/index.js +4458 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +4382 -0
  6. package/dist/src/index.d.ts +10 -0
  7. package/dist/src/lib/associations/associations.d.ts +32 -0
  8. package/dist/src/lib/client/annotation/base-annotation.d.ts +20 -0
  9. package/dist/src/lib/client/annotation/user-feedback.d.ts +32 -0
  10. package/dist/src/lib/client/dataset/attachment-uploader.d.ts +50 -0
  11. package/dist/src/lib/client/dataset/attachment.d.ts +84 -0
  12. package/dist/src/lib/client/dataset/base-dataset.d.ts +10 -0
  13. package/dist/src/lib/client/dataset/column.d.ts +23 -0
  14. package/dist/src/lib/client/dataset/dataset.d.ts +43 -0
  15. package/dist/src/lib/client/dataset/datasets.d.ts +14 -0
  16. package/dist/src/lib/client/dataset/index.d.ts +8 -0
  17. package/dist/src/lib/client/dataset/row.d.ts +73 -0
  18. package/dist/src/lib/client/evaluator/evaluator.d.ts +28 -0
  19. package/dist/src/lib/client/evaluator/index.d.ts +2 -0
  20. package/dist/src/lib/client/experiment/experiment.d.ts +76 -0
  21. package/dist/src/lib/client/experiment/index.d.ts +2 -0
  22. package/dist/src/lib/client/traceloop-client.d.ts +40 -0
  23. package/dist/src/lib/configuration/index.d.ts +35 -0
  24. package/dist/src/lib/configuration/validation.d.ts +3 -0
  25. package/dist/src/lib/errors/index.d.ts +36 -0
  26. package/dist/src/lib/generated/evaluators/index.d.ts +5 -0
  27. package/dist/src/lib/generated/evaluators/mbt-evaluators.d.ts +386 -0
  28. package/dist/src/lib/generated/evaluators/registry.d.ts +12 -0
  29. package/dist/src/lib/generated/evaluators/types.d.ts +401 -0
  30. package/dist/src/lib/images/image-uploader.d.ts +15 -0
  31. package/dist/src/lib/images/index.d.ts +2 -0
  32. package/dist/src/lib/interfaces/annotations.interface.d.ts +35 -0
  33. package/dist/src/lib/interfaces/dataset.interface.d.ts +105 -0
  34. package/dist/src/lib/interfaces/evaluator.interface.d.ts +83 -0
  35. package/dist/src/lib/interfaces/experiment.interface.d.ts +117 -0
  36. package/dist/src/lib/interfaces/index.d.ts +8 -0
  37. package/dist/src/lib/interfaces/initialize-options.interface.d.ts +133 -0
  38. package/dist/src/lib/interfaces/prompts.interface.d.ts +53 -0
  39. package/dist/src/lib/interfaces/traceloop-client.interface.d.ts +7 -0
  40. package/dist/src/lib/node-server-sdk.d.ts +19 -0
  41. package/dist/src/lib/prompts/fetch.d.ts +3 -0
  42. package/dist/src/lib/prompts/index.d.ts +3 -0
  43. package/dist/src/lib/prompts/registry.d.ts +9 -0
  44. package/dist/src/lib/prompts/template.d.ts +3 -0
  45. package/dist/src/lib/tracing/ai-sdk-transformations.d.ts +5 -0
  46. package/dist/src/lib/tracing/association.d.ts +4 -0
  47. package/dist/src/lib/tracing/baggage-utils.d.ts +2 -0
  48. package/dist/src/lib/tracing/custom-metric.d.ts +14 -0
  49. package/dist/src/lib/tracing/decorators.d.ts +22 -0
  50. package/dist/src/lib/tracing/index.d.ts +14 -0
  51. package/dist/src/lib/tracing/manual.d.ts +60 -0
  52. package/dist/src/lib/tracing/sampler.d.ts +7 -0
  53. package/dist/src/lib/tracing/span-processor.d.ts +48 -0
  54. package/dist/src/lib/tracing/tracing.d.ts +10 -0
  55. package/dist/src/lib/utils/response-transformer.d.ts +19 -0
  56. package/package.json +127 -0
@@ -0,0 +1,1957 @@
1
+ import { SpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base';
2
+ import * as _opentelemetry_api from '@opentelemetry/api';
3
+ import { TextMapPropagator, ContextManager, Span } from '@opentelemetry/api';
4
+ import * as openai from 'openai';
5
+ import * as anthropic from '@anthropic-ai/sdk';
6
+ import * as cohere from 'cohere-ai';
7
+ import * as bedrock from '@aws-sdk/client-bedrock-runtime';
8
+ import * as aiplatform from '@google-cloud/aiplatform';
9
+ import * as vertexAI from '@google-cloud/vertexai';
10
+ import * as pinecone from '@pinecone-database/pinecone';
11
+ import * as together from 'together-ai';
12
+ import * as llamaindex from 'llamaindex';
13
+ import * as chromadb from 'chromadb';
14
+ import * as qdrant from '@qdrant/js-client-rest';
15
+ import * as mcp from '@modelcontextprotocol/sdk/client/index.js';
16
+ import { SpanProcessor as SpanProcessor$1 } from '@opentelemetry/sdk-trace-node';
17
+
18
+ /**
19
+ * The severity of an error.
20
+ */
21
+ declare const SEVERITY: {
22
+ readonly Warning: "Warning";
23
+ readonly Error: "Error";
24
+ readonly Critical: "Critical";
25
+ };
26
+ type Severity = (typeof SEVERITY)[keyof typeof SEVERITY];
27
+ /**
28
+ * Base class for all Traceloop errors.
29
+ */
30
+ declare class TraceloopError extends Error {
31
+ /**
32
+ * The severity of the error.
33
+ */
34
+ severity: Severity;
35
+ /**
36
+ * The underlying cause of the error.
37
+ */
38
+ underlyingCause?: Error;
39
+ constructor(message: string, severity?: Severity);
40
+ }
41
+ declare class NotInitializedError extends TraceloopError {
42
+ constructor();
43
+ }
44
+ declare class InitializationError extends TraceloopError {
45
+ constructor(message?: string, cause?: Error);
46
+ }
47
+ declare class ArgumentNotProvidedError extends TraceloopError {
48
+ constructor(argumentName: string);
49
+ }
50
+ declare class PromptNotFoundError extends TraceloopError {
51
+ constructor(key: string);
52
+ }
53
+
54
+ /**
55
+ * Options for initializing the Traceloop SDK.
56
+ */
57
+ interface InitializeOptions {
58
+ /**
59
+ * The app name to be used when reporting traces. Optional.
60
+ * Defaults to the package name.
61
+ */
62
+ appName?: string;
63
+ /**
64
+ * The API Key for sending traces data. Optional.
65
+ * Defaults to the ANYWAY_API_KEY environment variable.
66
+ */
67
+ apiKey?: string;
68
+ /**
69
+ * The OTLP endpoint for sending traces data. Optional.
70
+ * Defaults to ANYWAY_BASE_URL environment variable or https://api.traceloop.com/
71
+ */
72
+ baseUrl?: string;
73
+ /**
74
+ * Sends traces and spans without batching, for local developement. Optional.
75
+ * Defaults to false.
76
+ */
77
+ disableBatch?: boolean;
78
+ /**
79
+ * Defines default log level for SDK and all instrumentations. Optional.
80
+ * Defaults to error.
81
+ */
82
+ logLevel?: "debug" | "info" | "warn" | "error";
83
+ /**
84
+ * Whether to log prompts, completions and embeddings on traces. Optional.
85
+ * Defaults to true.
86
+ */
87
+ traceContent?: boolean;
88
+ /**
89
+ * The OpenTelemetry SpanExporter to be used for sending traces data. Optional.
90
+ * Defaults to the OTLP exporter.
91
+ */
92
+ exporter?: SpanExporter;
93
+ /**
94
+ * The headers to be sent with the traces data. Optional.
95
+ */
96
+ headers?: Record<string, string>;
97
+ /**
98
+ * The OpenTelemetry SpanProcessor to be used for processing traces data. Optional.
99
+ * Defaults to the BatchSpanProcessor.
100
+ */
101
+ processor?: SpanProcessor;
102
+ /**
103
+ * The OpenTelemetry Propagator to use. Optional.
104
+ * Defaults to OpenTelemetry SDK defaults.
105
+ */
106
+ propagator?: TextMapPropagator;
107
+ /**
108
+ * The OpenTelemetry ContextManager to use. Optional.
109
+ * Defaults to OpenTelemetry SDK defaults.
110
+ */
111
+ contextManager?: ContextManager;
112
+ /**
113
+ * Explicitly specify modules to instrument. Optional.
114
+ * This is a workaround specific to Next.js, see https://www.traceloop.com/docs/openllmetry/getting-started-nextjs
115
+ */
116
+ instrumentModules?: {
117
+ openAI?: typeof openai.OpenAI;
118
+ anthropic?: typeof anthropic;
119
+ cohere?: typeof cohere;
120
+ bedrock?: typeof bedrock;
121
+ google_vertexai?: typeof vertexAI;
122
+ google_aiplatform?: typeof aiplatform;
123
+ pinecone?: typeof pinecone;
124
+ together?: typeof together.Together;
125
+ langchain?: boolean;
126
+ llamaIndex?: typeof llamaindex;
127
+ chromadb?: typeof chromadb;
128
+ qdrant?: typeof qdrant;
129
+ mcp?: typeof mcp;
130
+ };
131
+ /**
132
+ * Enables sync with Traceloop servers for the prompt registry functionality. Optional.
133
+ * Defaults to ANYWAY_SYNC_ENABLED environment variable or true if not set.
134
+ */
135
+ traceloopSyncEnabled?: boolean;
136
+ /**
137
+ * Defines the number of retires when fetching prompt data for the registry. Optional.
138
+ * Defaults to ANYWAY_SYNC_MAX_RETRIES environment variable or 3 if not set.
139
+ */
140
+ traceloopSyncMaxRetries?: number;
141
+ /**
142
+ * Defines the polling interval for the prompt registry. Optional.
143
+ * Defaults to ANYWAY_SYNC_POLLING_INTERVAL environment variable or 60 if not set.
144
+ */
145
+ traceloopSyncPollingInterval?: number;
146
+ /**
147
+ * Defines the polling interval for the prompt registry. Optional.
148
+ * Defaults to ANYWAY_SYNC_DEV_POLLING_INTERVAL environment variable or 5 if not set.
149
+ */
150
+ traceloopSyncDevPollingInterval?: number;
151
+ /**
152
+ * Whether to silence the initialization message. Optional.
153
+ * Defaults to false.
154
+ */
155
+ silenceInitializationMessage?: boolean;
156
+ /**
157
+ * Whether to enable tracing. Optional.
158
+ * Defaults to true.
159
+ */
160
+ tracingEnabled?: boolean;
161
+ /**
162
+ * The experiment slug to use when running experiments. Optional.
163
+ * Defaults to the ANYWAY_EXP_SLUG environment variable.
164
+ */
165
+ experimentSlug?: string;
166
+ /**
167
+ * The Google Cloud Project ID for sending traces data. Optional.
168
+ * This is used to configure the Google Cloud Trace Exporter.
169
+ */
170
+ gcpProjectId?: string;
171
+ }
172
+
173
+ /**
174
+ * Represents an entity in the system that can be annotated.
175
+ * An entity is typically a unit of content or interaction that needs to be tracked or evaluated.
176
+ * It is reported as an association property before the annotation is created.
177
+ */
178
+ interface Entity {
179
+ /**
180
+ * Unique identifier for the entity.
181
+ * This could be a user ID, conversation ID, or any other unique identifier in your system.
182
+ */
183
+ id: string;
184
+ }
185
+ /**
186
+ * Configuration options for creating a new annotation.
187
+ * Annotations are used to attach metadata, feedback, or evaluation results to specific entities.
188
+ */
189
+ interface AnnotationCreateOptions {
190
+ /**
191
+ * The identifier of the annotation task.
192
+ * The ID or slug of the annotation task, Can be found at app.traceloop.com/annotation_tasks/:annotationTaskId */
193
+ annotationTask: string;
194
+ /**
195
+ * The entity to be annotated.
196
+ * Contains the entity's identifier and optional type information.
197
+ * Be sure to report the entity instance ID as the association property before
198
+ * in order to correctly correlate the annotation to the relevant context.
199
+ */
200
+ entity: Entity;
201
+ /**
202
+ * Key-value pairs of annotation data, should match the tags defined in the annotation task
203
+ */
204
+ tags: Record<string, TagValue>;
205
+ }
206
+ type TagValue = string | number | string[];
207
+
208
+ interface TraceloopClientOptions {
209
+ apiKey: string;
210
+ appName: string;
211
+ baseUrl?: string;
212
+ experimentSlug?: string;
213
+ }
214
+
215
+ interface DatasetCreateOptions {
216
+ name: string;
217
+ slug?: string;
218
+ description?: string;
219
+ }
220
+ interface DatasetUpdateOptions {
221
+ name?: string;
222
+ description?: string;
223
+ }
224
+ interface DatasetResponse {
225
+ id: string;
226
+ slug: string;
227
+ name: string;
228
+ description?: string;
229
+ version?: string;
230
+ published?: boolean;
231
+ createdAt?: string;
232
+ updatedAt?: string;
233
+ columns?: Record<string, any>;
234
+ rows?: RowResponse[];
235
+ }
236
+ interface ColumnDefinition {
237
+ name: string;
238
+ type: "string" | "number" | "boolean" | "date" | "file";
239
+ slug?: string;
240
+ required?: boolean;
241
+ description?: string;
242
+ }
243
+ interface ColumnResponse extends ColumnDefinition {
244
+ slug: string;
245
+ datasetId: string;
246
+ datasetSlug: string;
247
+ createdAt: string;
248
+ updatedAt: string;
249
+ }
250
+ interface ColumnUpdateOptions {
251
+ name?: string;
252
+ type?: "string" | "number" | "boolean" | "date" | "file";
253
+ required?: boolean;
254
+ description?: string;
255
+ }
256
+ interface RowData {
257
+ [key: string]: string | number | boolean | null | object;
258
+ }
259
+ interface RowResponse {
260
+ id: string;
261
+ datasetId: string;
262
+ datasetSlug: string;
263
+ data: RowData;
264
+ createdAt: string;
265
+ updatedAt: string;
266
+ }
267
+ interface RowUpdateOptions {
268
+ data: Partial<RowData>;
269
+ }
270
+ interface DatasetListResponse {
271
+ datasets: DatasetResponse[];
272
+ total: number;
273
+ }
274
+ interface DatasetPublishOptions {
275
+ version?: string;
276
+ description?: string;
277
+ }
278
+ interface CSVImportOptions {
279
+ hasHeader?: boolean;
280
+ delimiter?: string;
281
+ encoding?: string;
282
+ }
283
+ interface DatasetVersion {
284
+ version: string;
285
+ publishedBy: string;
286
+ publishedAt: string;
287
+ }
288
+ interface DatasetVersionsResponse {
289
+ datasetId: string;
290
+ datasetSlug: string;
291
+ versions: DatasetVersion[];
292
+ total: number;
293
+ }
294
+ type DatasetColumnValue = string | number | boolean | null | undefined;
295
+
296
+ interface StreamEvent {
297
+ type: "progress" | "result" | "error" | "complete";
298
+ data: any;
299
+ timestamp: string;
300
+ id?: string;
301
+ event?: string;
302
+ }
303
+ interface EvaluatorRunOptions {
304
+ experimentId: string;
305
+ experimentRunId?: string;
306
+ taskId: string;
307
+ taskResult: Record<string, any>;
308
+ evaluator: EvaluatorDetails;
309
+ waitForResults?: boolean;
310
+ timeout?: number;
311
+ }
312
+ interface EvaluatorResult {
313
+ evaluatorName: string;
314
+ taskId?: string;
315
+ score?: number;
316
+ result?: any;
317
+ metadata?: Record<string, any>;
318
+ error?: string;
319
+ }
320
+ interface TriggerEvaluatorRequest {
321
+ experimentId: string;
322
+ experimentRunId?: string;
323
+ taskId?: string;
324
+ evaluator: EvaluatorDetails;
325
+ taskResult: Record<string, any>;
326
+ metadata?: Record<string, any>;
327
+ }
328
+ interface TriggerEvaluatorResponse {
329
+ executionId: string;
330
+ streamUrl: string;
331
+ }
332
+ interface StreamProgressEvent {
333
+ type: "progress";
334
+ data: {
335
+ completed: number;
336
+ total: number;
337
+ percentage: number;
338
+ currentTask?: string;
339
+ };
340
+ }
341
+ interface StreamResultEvent {
342
+ type: "result";
343
+ data: {
344
+ taskId: string;
345
+ evaluatorName: string;
346
+ result: EvaluatorResult;
347
+ };
348
+ }
349
+ interface StreamErrorEvent {
350
+ type: "error";
351
+ data: {
352
+ error: string;
353
+ taskId?: string;
354
+ evaluatorName?: string;
355
+ };
356
+ }
357
+ interface StreamCompleteEvent {
358
+ type: "complete";
359
+ data: {
360
+ executionId: string;
361
+ totalResults: number;
362
+ totalErrors: number;
363
+ duration: number;
364
+ };
365
+ }
366
+ type SSEStreamEvent = StreamProgressEvent | StreamResultEvent | StreamErrorEvent | StreamCompleteEvent;
367
+ interface InputExtractor {
368
+ source: string;
369
+ }
370
+ interface InputSchemaMapping {
371
+ [key: string]: InputExtractor;
372
+ }
373
+
374
+ type dataValue = string | number | boolean;
375
+ type TaskInput = Record<string, dataValue>;
376
+ type TaskOutput = Record<string, dataValue>;
377
+ interface ExperimentTaskFunction<TInput = TaskInput, TOutput = TaskOutput> {
378
+ (input: TInput): Promise<TOutput> | TOutput;
379
+ }
380
+ type EvaluatorDetails = string | EvaluatorWithVersion | EvaluatorWithConfig;
381
+ interface EvaluatorWithVersion {
382
+ name: string;
383
+ version: string;
384
+ }
385
+ /**
386
+ * Evaluator configuration with optional version and config options.
387
+ * Used for "Made by Traceloop" (MBT) evaluators that support configuration.
388
+ */
389
+ interface EvaluatorWithConfig {
390
+ name: string;
391
+ version?: string;
392
+ config?: Record<string, unknown>;
393
+ requiredInputFields?: string[];
394
+ }
395
+ interface ExperimentRunOptions {
396
+ datasetSlug?: string;
397
+ datasetVersion?: string;
398
+ evaluators?: EvaluatorDetails[];
399
+ experimentSlug?: string;
400
+ relatedRef?: Record<string, string>;
401
+ aux?: Record<string, string>;
402
+ stopOnError?: boolean;
403
+ waitForResults?: boolean;
404
+ }
405
+
406
+ interface TaskResponse {
407
+ input: Record<string, any>;
408
+ output: Record<string, any>;
409
+ metadata?: Record<string, any>;
410
+ timestamp?: number;
411
+ error?: string;
412
+ input_schema_mapping?: InputSchemaMapping;
413
+ }
414
+ interface ExperimentRunResult {
415
+ taskResults: TaskResponse[];
416
+ errors: string[];
417
+ experimentId?: string;
418
+ runId?: string;
419
+ evaluations?: Record<string, any>[];
420
+ }
421
+ interface InitExperimentRequest {
422
+ slug: string;
423
+ datasetSlug?: string;
424
+ datasetVersion?: string;
425
+ evaluatorSlugs?: string[];
426
+ experimentMetadata?: Record<string, any>;
427
+ experimentRunMetadata?: Record<string, any>;
428
+ relatedRef?: Record<string, string>;
429
+ aux?: Record<string, string>;
430
+ }
431
+ interface ExperimentResponse {
432
+ id: string;
433
+ slug: string;
434
+ metadata?: Record<string, any>;
435
+ created_at: string;
436
+ updated_at: string;
437
+ }
438
+ interface ExperimentRunResponse {
439
+ id: string;
440
+ metadata?: Record<string, any>;
441
+ dataset_id?: string;
442
+ dataset_version?: string;
443
+ evaluator_ids?: string[];
444
+ created_at: string;
445
+ updated_at: string;
446
+ }
447
+ interface ExperimentInitResponse {
448
+ experiment: ExperimentResponse;
449
+ run: ExperimentRunResponse;
450
+ }
451
+ interface ExecutionResponse {
452
+ executionId: string;
453
+ result: Record<string, any>;
454
+ }
455
+ interface CreateTaskResponse {
456
+ id: string;
457
+ }
458
+ interface GithubContext {
459
+ repository: string;
460
+ prUrl: string;
461
+ commitHash: string;
462
+ actor: string;
463
+ }
464
+ interface TaskResult {
465
+ input: Record<string, any>;
466
+ output?: Record<string, any>;
467
+ error?: string;
468
+ metadata?: Record<string, any>;
469
+ }
470
+ interface RunInGithubOptions {
471
+ datasetSlug: string;
472
+ datasetVersion?: string;
473
+ evaluators?: EvaluatorDetails[];
474
+ experimentSlug?: string;
475
+ experimentMetadata?: Record<string, any>;
476
+ experimentRunMetadata?: Record<string, any>;
477
+ relatedRef?: Record<string, string>;
478
+ aux?: Record<string, string>;
479
+ }
480
+ interface RunInGithubResponse {
481
+ experimentId: string;
482
+ experimentSlug: string;
483
+ runId: string;
484
+ }
485
+
486
+ type AnnotationFlow = "user_feedback";
487
+ /**
488
+ * Base class for handling annotation operations with the Traceloop API.
489
+ * @internal
490
+ */
491
+ declare class BaseAnnotation {
492
+ protected client: TraceloopClient;
493
+ protected flow: AnnotationFlow;
494
+ constructor(client: TraceloopClient, flow: AnnotationFlow);
495
+ /**
496
+ * Creates a new annotation.
497
+ *
498
+ * @param options - The annotation creation options
499
+ * @returns Promise resolving to the fetch Response
500
+ */
501
+ create(options: AnnotationCreateOptions): Promise<Response>;
502
+ }
503
+
504
+ /**
505
+ * Handles user feedback annotations with the Traceloop API.
506
+ */
507
+ declare class UserFeedback extends BaseAnnotation {
508
+ constructor(client: TraceloopClient);
509
+ /**
510
+ * Creates a new annotation for a specific task and entity.
511
+ *
512
+ * @param options - The options for creating an annotation
513
+ * @returns Promise resolving to the fetch Response
514
+ *
515
+ * @example
516
+ * ```typescript
517
+ * await client.annotation.create({
518
+ * annotationTask: 'sample-annotation-task',
519
+ * entity: {
520
+ * id: '123456',
521
+ * },
522
+ * tags: {
523
+ * sentiment: 'positive',
524
+ * score: 0.85,
525
+ * tones: ['happy', 'surprised']
526
+ * }
527
+ * });
528
+ * ```
529
+ */
530
+ create(options: AnnotationCreateOptions): Promise<Response>;
531
+ }
532
+
533
+ declare abstract class BaseDatasetEntity {
534
+ protected client: TraceloopClient;
535
+ constructor(client: TraceloopClient);
536
+ protected handleResponse(response: Response): Promise<any>;
537
+ protected validateDatasetId(id: string): void;
538
+ protected validateDatasetSlug(slug: string): void;
539
+ protected validateDatasetName(name: string): void;
540
+ }
541
+
542
+ type FileCellType = "image" | "video" | "audio" | "file";
543
+ type FileStorageType = "internal" | "external";
544
+ interface AttachmentMetadata {
545
+ [key: string]: string | number | boolean;
546
+ }
547
+ interface AttachmentOptions {
548
+ filePath?: string;
549
+ data?: Buffer | Uint8Array;
550
+ filename?: string;
551
+ contentType?: string;
552
+ fileType?: FileCellType;
553
+ metadata?: AttachmentMetadata;
554
+ }
555
+ declare class Attachment {
556
+ readonly type: "attachment";
557
+ private _filePath?;
558
+ private _data?;
559
+ private _filename?;
560
+ private _contentType?;
561
+ private _fileType?;
562
+ private _metadata?;
563
+ constructor(options: AttachmentOptions);
564
+ getData(): Promise<Buffer>;
565
+ getFileName(): string;
566
+ getContentType(): string;
567
+ get fileType(): FileCellType;
568
+ get metadata(): AttachmentMetadata | undefined;
569
+ }
570
+ interface ExternalAttachmentOptions {
571
+ url: string;
572
+ filename?: string;
573
+ contentType?: string;
574
+ fileType?: FileCellType;
575
+ metadata?: AttachmentMetadata;
576
+ }
577
+ declare class ExternalAttachment {
578
+ readonly type: "external";
579
+ private _url;
580
+ private _filename?;
581
+ private _contentType?;
582
+ private _fileType;
583
+ private _metadata?;
584
+ constructor(options: ExternalAttachmentOptions);
585
+ get url(): string;
586
+ get filename(): string | undefined;
587
+ get contentType(): string | undefined;
588
+ get fileType(): FileCellType;
589
+ get metadata(): AttachmentMetadata | undefined;
590
+ }
591
+ declare class AttachmentReference {
592
+ readonly storageType: FileStorageType;
593
+ readonly storageKey: string;
594
+ readonly url: string | undefined;
595
+ readonly fileType: FileCellType;
596
+ readonly metadata?: AttachmentMetadata | undefined;
597
+ constructor(storageType: FileStorageType, storageKey: string, url: string | undefined, fileType: FileCellType, metadata?: AttachmentMetadata | undefined);
598
+ download(filePath?: string): Promise<Buffer | void>;
599
+ getUrl(): string | undefined;
600
+ toJSON(): Record<string, unknown>;
601
+ }
602
+ declare function isAttachment(value: unknown): value is Attachment;
603
+ declare function isExternalAttachment(value: unknown): value is ExternalAttachment;
604
+ declare function isAttachmentReference(value: unknown): value is AttachmentReference;
605
+ declare function isAnyAttachment(value: unknown): value is Attachment | ExternalAttachment;
606
+ declare const attachment: {
607
+ file: (filePath: string, options?: {
608
+ filename?: string;
609
+ contentType?: string;
610
+ fileType?: FileCellType;
611
+ metadata?: AttachmentMetadata;
612
+ }) => Attachment;
613
+ buffer: (data: Buffer | Uint8Array, filename: string, options?: {
614
+ contentType?: string;
615
+ fileType?: FileCellType;
616
+ metadata?: AttachmentMetadata;
617
+ }) => Attachment;
618
+ url: (url: string, options?: {
619
+ filename?: string;
620
+ contentType?: string;
621
+ fileType?: FileCellType;
622
+ metadata?: AttachmentMetadata;
623
+ }) => ExternalAttachment;
624
+ };
625
+
626
+ declare class Row extends BaseDatasetEntity {
627
+ private _data;
628
+ private _deleted;
629
+ constructor(client: TraceloopClient, data: RowResponse);
630
+ get id(): string;
631
+ get datasetId(): string;
632
+ get datasetSlug(): string;
633
+ get data(): RowData;
634
+ get createdAt(): string;
635
+ get updatedAt(): string;
636
+ get deleted(): boolean;
637
+ getValue(columnName: string): string | number | boolean | Date | null | object;
638
+ hasColumn(columnName: string): boolean;
639
+ getColumns(): string[];
640
+ update(options: RowUpdateOptions): Promise<void>;
641
+ partialUpdate(updates: Partial<RowData>): Promise<void>;
642
+ delete(): Promise<void>;
643
+ toJSON(): RowData;
644
+ toCSVRow(columns?: string[], delimiter?: string): string;
645
+ validate(columnValidators?: {
646
+ [columnName: string]: (value: any) => boolean;
647
+ }): {
648
+ valid: boolean;
649
+ errors: string[];
650
+ };
651
+ clone(): Row;
652
+ /**
653
+ * Gets an attachment reference from a column
654
+ * @param columnName The name of the column containing the attachment
655
+ * @returns AttachmentReference if the column contains an attachment, null otherwise
656
+ */
657
+ getAttachment(columnName: string): AttachmentReference | null;
658
+ /**
659
+ * Checks if a column contains an attachment
660
+ * @param columnName The name of the column to check
661
+ */
662
+ hasAttachment(columnName: string): boolean;
663
+ /**
664
+ * Sets/uploads an attachment to a column
665
+ * @param columnSlug The slug of the column to set the attachment in
666
+ * @param attachment The attachment to upload (Attachment or ExternalAttachment)
667
+ * @returns The created AttachmentReference
668
+ *
669
+ * @example
670
+ * // Upload from file
671
+ * await row.setAttachment("image", new Attachment({ filePath: "./photo.jpg" }));
672
+ *
673
+ * @example
674
+ * // Set external URL
675
+ * await row.setAttachment("document", new ExternalAttachment({ url: "https://example.com/doc.pdf" }));
676
+ */
677
+ setAttachment(columnSlug: string, attachment: Attachment | ExternalAttachment): Promise<AttachmentReference>;
678
+ /**
679
+ * Downloads an attachment from a column
680
+ * @param columnName The name of the column containing the attachment
681
+ * @param outputPath Optional file path to save the downloaded file
682
+ * @returns Buffer if no outputPath provided, void if saved to file
683
+ *
684
+ * @example
685
+ * // Get as buffer
686
+ * const data = await row.downloadAttachment("image");
687
+ *
688
+ * @example
689
+ * // Save to file
690
+ * await row.downloadAttachment("image", "./downloaded-image.png");
691
+ */
692
+ downloadAttachment(columnName: string, outputPath?: string): Promise<Buffer | void>;
693
+ }
694
+
695
+ declare class Column extends BaseDatasetEntity {
696
+ private _data;
697
+ private _deleted;
698
+ constructor(client: TraceloopClient, data: ColumnResponse);
699
+ get slug(): string;
700
+ get name(): string;
701
+ get type(): "string" | "number" | "boolean" | "date" | "file";
702
+ get required(): boolean;
703
+ get description(): string | undefined;
704
+ get datasetId(): string;
705
+ get datasetSlug(): string;
706
+ get createdAt(): string;
707
+ get updatedAt(): string;
708
+ get deleted(): boolean;
709
+ update(options: ColumnUpdateOptions): Promise<void>;
710
+ delete(): Promise<void>;
711
+ validateValue(value: DatasetColumnValue): boolean;
712
+ convertValue(value: unknown): DatasetColumnValue;
713
+ }
714
+
715
+ declare class Dataset extends BaseDatasetEntity {
716
+ private _data;
717
+ private _deleted;
718
+ private _attachmentUploader;
719
+ constructor(client: TraceloopClient, data: DatasetResponse);
720
+ get id(): string;
721
+ get slug(): string;
722
+ get name(): string;
723
+ get description(): string | undefined;
724
+ get version(): string | undefined;
725
+ get published(): boolean;
726
+ get createdAt(): string;
727
+ get updatedAt(): string;
728
+ get deleted(): boolean;
729
+ update(options: DatasetUpdateOptions): Promise<void>;
730
+ delete(): Promise<void>;
731
+ publish(options?: DatasetPublishOptions): Promise<void>;
732
+ addColumn(columns: ColumnDefinition[]): Promise<Column[]>;
733
+ getColumns(): Promise<Column[]>;
734
+ addRow(rowData: RowData): Promise<Row>;
735
+ addRows(rows: RowData[]): Promise<Row[]>;
736
+ /**
737
+ * Extracts attachments from rows and returns clean rows with null values
738
+ */
739
+ private extractAttachments;
740
+ /**
741
+ * Processes attachments for created rows
742
+ */
743
+ private processAttachments;
744
+ private transformValuesBackToNames;
745
+ getRows(limit?: number, offset?: number): Promise<Row[]>;
746
+ fromCSV(csvContent: string, options?: CSVImportOptions): Promise<void>;
747
+ getVersions(): Promise<DatasetVersionsResponse>;
748
+ getVersion(version: string): Promise<DatasetVersion | null>;
749
+ private parseCSV;
750
+ private parseValue;
751
+ }
752
+
753
+ declare class Datasets extends BaseDatasetEntity {
754
+ constructor(client: TraceloopClient);
755
+ create(options: DatasetCreateOptions): Promise<Dataset>;
756
+ get(slug: string): Promise<Dataset>;
757
+ list(): Promise<DatasetListResponse>;
758
+ delete(slug: string): Promise<void>;
759
+ getVersionCSV(slug: string, version: string): Promise<string>;
760
+ getVersionAsJsonl(slug: string, version: string): Promise<string>;
761
+ }
762
+
763
+ declare class Experiment {
764
+ private client;
765
+ private evaluator;
766
+ private datasets;
767
+ private _lastExperimentSlug?;
768
+ private _lastRunId?;
769
+ constructor(client: TraceloopClient);
770
+ /**
771
+ * Generate a unique experiment slug
772
+ */
773
+ private generateExperimentSlug;
774
+ private handleResponse;
775
+ /**
776
+ * Run an experiment with the given task function and options
777
+ */
778
+ run<TInput, TOutput>(task: ExperimentTaskFunction<TInput, TOutput>, options?: ExperimentRunOptions | RunInGithubOptions): Promise<ExperimentRunResult | RunInGithubResponse>;
779
+ /**
780
+ * Run an experiment locally (not in GitHub Actions)
781
+ */
782
+ private runLocally;
783
+ /**
784
+ * Create a task for the experiment
785
+ */
786
+ createTask(experimentSlug: string, experimentRunId: string, taskInput: Record<string, any>, taskOutput: Record<string, any>): Promise<CreateTaskResponse>;
787
+ /**
788
+ * Initialize a new experiment
789
+ */
790
+ initializeExperiment(request: InitExperimentRequest): Promise<ExperimentInitResponse>;
791
+ /**
792
+ * Parse JSONL string into list of {col_name: col_value} dictionaries
793
+ * Skips the first line (columns definition)
794
+ */
795
+ private parseJsonlToRows;
796
+ /**
797
+ * Get dataset rows for experiment execution
798
+ */
799
+ private getDatasetRows;
800
+ /**
801
+ * Validate experiment run options
802
+ */
803
+ private validateRunOptions;
804
+ /**
805
+ * Extract GitHub Actions context from environment variables
806
+ */
807
+ private getGithubContext;
808
+ /**
809
+ * Execute tasks locally and capture results
810
+ */
811
+ private executeTasksLocally;
812
+ /**
813
+ * Run an experiment in GitHub Actions environment
814
+ * This method executes tasks locally and submits results to the backend for evaluation
815
+ */
816
+ runInGithub<TInput, TOutput>(task: ExperimentTaskFunction<TInput, TOutput>, options: RunInGithubOptions): Promise<RunInGithubResponse>;
817
+ /**
818
+ * Resolve export parameters by falling back to last used values
819
+ */
820
+ private resolveExportParams;
821
+ /**
822
+ * Export experiment results as CSV string
823
+ * @param experimentSlug - Optional experiment slug (uses last run if not provided)
824
+ * @param runId - Optional run ID (uses last run if not provided)
825
+ * @returns CSV string of experiment results
826
+ */
827
+ toCsvString(experimentSlug?: string, runId?: string): Promise<string>;
828
+ /**
829
+ * Export experiment results as JSON string
830
+ * @param experimentSlug - Optional experiment slug (uses last run if not provided)
831
+ * @param runId - Optional run ID (uses last run if not provided)
832
+ * @returns JSON string of experiment results
833
+ */
834
+ toJsonString(experimentSlug?: string, runId?: string): Promise<string>;
835
+ }
836
+
837
+ declare class Evaluator extends BaseDatasetEntity {
838
+ constructor(client: TraceloopClient);
839
+ /**
840
+ * Run evaluators on experiment task results and wait for completion
841
+ */
842
+ runExperimentEvaluator(options: EvaluatorRunOptions): Promise<ExecutionResponse[]>;
843
+ /**
844
+ * Trigger evaluator execution without waiting for results
845
+ */
846
+ triggerExperimentEvaluator(request: TriggerEvaluatorRequest): Promise<TriggerEvaluatorResponse>;
847
+ /**
848
+ * Wait for execution result via stream URL (actually JSON endpoint)
849
+ */
850
+ waitForResult(executionId: string, streamUrl: string): Promise<ExecutionResponse[]>;
851
+ /**
852
+ * Validate evaluator run options
853
+ */
854
+ private validateEvaluatorOptions;
855
+ /**
856
+ * Create InputSchemaMapping from input object
857
+ */
858
+ private createInputSchemaMapping;
859
+ }
860
+
861
+ /**
862
+ * The main client for interacting with Traceloop's API.
863
+ * This client can be used either directly or through the singleton pattern via configuration.
864
+ *
865
+ * @example
866
+ * // Direct usage
867
+ * const client = new TraceloopClient('your-api-key');
868
+ *
869
+ * @example
870
+ * // Through configuration (recommended)
871
+ * initialize({ apiKey: 'your-api-key', appName: 'your-app' });
872
+ * const client = getClient();
873
+ */
874
+ declare class TraceloopClient {
875
+ private version;
876
+ appName: string;
877
+ private baseUrl;
878
+ private apiKey;
879
+ experimentSlug?: string;
880
+ userFeedback: UserFeedback;
881
+ datasets: Datasets;
882
+ experiment: Experiment;
883
+ evaluator: Evaluator;
884
+ /**
885
+ * Creates a new instance of the TraceloopClient.
886
+ *
887
+ * @param options - Configuration options for the client
888
+ */
889
+ constructor(options: TraceloopClientOptions);
890
+ post(path: string, body: Record<string, unknown> | any): Promise<Response>;
891
+ get(path: string): Promise<Response>;
892
+ put(path: string, body: Record<string, unknown> | any): Promise<Response>;
893
+ delete(path: string): Promise<Response>;
894
+ }
895
+
896
+ /**
897
+ * Response from the upload URL endpoint
898
+ */
899
+ interface UploadUrlResponse {
900
+ uploadUrl: string;
901
+ storageKey: string;
902
+ expiresAt?: string;
903
+ method?: string;
904
+ }
905
+ /**
906
+ * Handles attachment upload and registration operations
907
+ */
908
+ declare class AttachmentUploader {
909
+ private client;
910
+ constructor(client: TraceloopClient);
911
+ /**
912
+ * Requests a presigned upload URL from the API
913
+ */
914
+ getUploadUrl(datasetSlug: string, rowId: string, columnSlug: string, fileName: string, contentType: string, fileType: FileCellType, metadata?: AttachmentMetadata): Promise<UploadUrlResponse>;
915
+ /**
916
+ * Uploads file data directly to S3 using the presigned URL
917
+ */
918
+ uploadToS3(uploadUrl: string, data: Buffer, contentType: string): Promise<void>;
919
+ /**
920
+ * Confirms the upload status with the API
921
+ */
922
+ confirmUpload(datasetSlug: string, rowId: string, columnSlug: string, status: "success" | "failed", metadata?: AttachmentMetadata): Promise<void>;
923
+ /**
924
+ * Registers an external URL as an attachment
925
+ */
926
+ registerExternalUrl(datasetSlug: string, rowId: string, columnSlug: string, url: string, fileType: FileCellType, metadata?: AttachmentMetadata): Promise<AttachmentReference>;
927
+ /**
928
+ * Uploads an Attachment through the full flow:
929
+ * 1. Get presigned URL
930
+ * 2. Upload to S3
931
+ * 3. Confirm upload
932
+ */
933
+ uploadAttachment(datasetSlug: string, rowId: string, columnSlug: string, attachment: Attachment): Promise<AttachmentReference>;
934
+ /**
935
+ * Processes an ExternalAttachment by registering the URL
936
+ */
937
+ processExternalAttachment(datasetSlug: string, rowId: string, columnSlug: string, attachment: ExternalAttachment): Promise<AttachmentReference>;
938
+ /**
939
+ * Processes any attachment type (Attachment or ExternalAttachment)
940
+ */
941
+ processAnyAttachment(datasetSlug: string, rowId: string, columnSlug: string, attachmentObj: Attachment | ExternalAttachment): Promise<AttachmentReference>;
942
+ }
943
+
944
+ interface EvaluatorSchema {
945
+ slug: string;
946
+ requiredInputFields: string[];
947
+ optionalConfigFields: string[];
948
+ description?: string;
949
+ }
950
+ type EvaluatorSlug = 'agent-efficiency' | 'agent-flow-quality' | 'agent-goal-accuracy' | 'agent-goal-completeness' | 'agent-tool-error-detector' | 'agent-tool-trajectory' | 'answer-completeness' | 'answer-correctness' | 'answer-relevancy' | 'char-count' | 'char-count-ratio' | 'context-relevance' | 'conversation-quality' | 'faithfulness' | 'html-comparison' | 'instruction-adherence' | 'intent-change' | 'json-validator' | 'perplexity' | 'pii-detector' | 'placeholder-regex' | 'profanity-detector' | 'prompt-injection' | 'prompt-perplexity' | 'regex-validator' | 'secrets-detector' | 'semantic-similarity' | 'sexism-detector' | 'sql-validator' | 'tone-detection' | 'topic-adherence' | 'toxicity-detector' | 'uncertainty-detector' | 'word-count' | 'word-count-ratio';
951
+
952
+ interface components {
953
+ schemas: {
954
+ "request.AgentEfficiencyRequest": {
955
+ input: components["schemas"]["request.AgentEfficiencyInput"];
956
+ };
957
+ "request.AgentEfficiencyInput": {
958
+ /** @example ["User found", "Email updated", "Changes saved"] */
959
+ trajectory_completions: string;
960
+ /** @example ["Find user info", "Update email", "Save changes"] */
961
+ trajectory_prompts: string;
962
+ };
963
+ "request.AgentFlowQualityRequest": {
964
+ config: components["schemas"]["request.AgentFlowQualityConfigRequest"];
965
+ input: components["schemas"]["request.AgentFlowQualityInput"];
966
+ };
967
+ "request.AgentFlowQualityConfigRequest": {
968
+ /**
969
+ * @example [
970
+ * "no tools called",
971
+ * "agent completed task"
972
+ * ]
973
+ */
974
+ conditions: string[];
975
+ /** @example 0.5 */
976
+ threshold: number;
977
+ };
978
+ "request.AgentFlowQualityInput": {
979
+ /** @example ["Found 5 flights", "Selected $299 flight", "Booking confirmed"] */
980
+ trajectory_completions: string;
981
+ /** @example ["Search for flights", "Select the cheapest option", "Confirm booking"] */
982
+ trajectory_prompts: string;
983
+ };
984
+ "request.AgentGoalAccuracyRequest": {
985
+ input: components["schemas"]["request.AgentGoalAccuracyInput"];
986
+ };
987
+ "request.AgentGoalAccuracyInput": {
988
+ /** @example I have booked your flight from New York to Los Angeles departing Monday at 9am. */
989
+ completion: string;
990
+ /** @example Book a flight from NYC to LA for next Monday */
991
+ question: string;
992
+ /** @example Flight booked: NYC to LA, Monday departure */
993
+ reference: string;
994
+ };
995
+ "request.AgentGoalCompletenessRequest": {
996
+ config?: components["schemas"]["request.AgentGoalCompletenessConfigRequest"];
997
+ input: components["schemas"]["request.AgentGoalCompletenessInput"];
998
+ };
999
+ "request.AgentGoalCompletenessConfigRequest": {
1000
+ /** @example 0.5 */
1001
+ threshold: number;
1002
+ };
1003
+ "request.AgentGoalCompletenessInput": {
1004
+ /** @example ["Account created", "Preferences saved", "Notifications enabled"] */
1005
+ trajectory_completions: string;
1006
+ /** @example ["Create new account", "Set preferences", "Enable notifications"] */
1007
+ trajectory_prompts: string;
1008
+ };
1009
+ "request.AgentToolErrorDetectorRequest": {
1010
+ input: components["schemas"]["request.AgentToolErrorDetectorInput"];
1011
+ };
1012
+ "request.AgentToolErrorDetectorInput": {
1013
+ /** @example {"action": "search", "query": "flights to Paris"} */
1014
+ tool_input: string;
1015
+ /** @example {"status": "success", "results": [{"flight": "AF123", "price": 450}]} */
1016
+ tool_output: string;
1017
+ };
1018
+ "request.AgentToolTrajectoryRequest": {
1019
+ config?: components["schemas"]["request.AgentToolTrajectoryConfigRequest"];
1020
+ input: components["schemas"]["request.AgentToolTrajectoryInput"];
1021
+ };
1022
+ "request.AgentToolTrajectoryConfigRequest": {
1023
+ /** @example true */
1024
+ input_params_sensitive?: boolean;
1025
+ /** @example false */
1026
+ mismatch_sensitive?: boolean;
1027
+ /** @example false */
1028
+ order_sensitive?: boolean;
1029
+ /** @example 0.5 */
1030
+ threshold?: number;
1031
+ };
1032
+ "request.AgentToolTrajectoryInput": {
1033
+ /** @example [{"name": "search", "input": {"query": "weather"}}] */
1034
+ executed_tool_calls: string;
1035
+ /** @example [{"name": "search", "input": {"query": "weather"}}] */
1036
+ expected_tool_calls: string;
1037
+ };
1038
+ "request.AnswerCompletenessRequest": {
1039
+ input: components["schemas"]["request.AnswerCompletenessInput"];
1040
+ };
1041
+ "request.AnswerCompletenessInput": {
1042
+ /** @example Paris. */
1043
+ completion: string;
1044
+ /** @example The capital of France is Paris. */
1045
+ context: string;
1046
+ /** @example What is the capital of France? */
1047
+ question: string;
1048
+ };
1049
+ "request.AnswerCorrectnessRequest": {
1050
+ input: components["schemas"]["request.AnswerCorrectnessInput"];
1051
+ };
1052
+ "request.AnswerCorrectnessInput": {
1053
+ /** @example World War II ended in 1945. */
1054
+ completion: string;
1055
+ /** @example 1945 */
1056
+ ground_truth: string;
1057
+ /** @example What year did World War II end? */
1058
+ question: string;
1059
+ };
1060
+ "request.AnswerRelevancyRequest": {
1061
+ input: components["schemas"]["request.AnswerRelevancyInput"];
1062
+ };
1063
+ "request.AnswerRelevancyInput": {
1064
+ /** @example The capital of France is Paris. */
1065
+ answer: string;
1066
+ /** @example What is the capital of France? */
1067
+ question: string;
1068
+ };
1069
+ "request.CharCountRequest": {
1070
+ input: components["schemas"]["request.CharCountInput"];
1071
+ };
1072
+ "request.CharCountInput": {
1073
+ /** @example Hello, world! This is a sample text. */
1074
+ text: string;
1075
+ };
1076
+ "request.CharCountRatioRequest": {
1077
+ input: components["schemas"]["request.CharCountRatioInput"];
1078
+ };
1079
+ "request.CharCountRatioInput": {
1080
+ /** @example This is a longer text for comparison */
1081
+ denominator_text: string;
1082
+ /** @example Short text */
1083
+ numerator_text: string;
1084
+ };
1085
+ "request.ContextRelevanceRequest": {
1086
+ config?: components["schemas"]["request.ContextRelevanceConfigRequest"];
1087
+ input: components["schemas"]["request.ContextRelevanceInput"];
1088
+ };
1089
+ "request.ContextRelevanceConfigRequest": {
1090
+ /** @example gpt-4o */
1091
+ model?: string;
1092
+ };
1093
+ "request.ContextRelevanceInput": {
1094
+ /** @example Our store is open Monday to Friday from 9am to 6pm, and Saturday from 10am to 4pm. We are closed on Sundays. */
1095
+ context: string;
1096
+ /** @example What are the business hours? */
1097
+ query: string;
1098
+ };
1099
+ "request.ConversationQualityRequest": {
1100
+ input: components["schemas"]["request.ConversationQualityInput"];
1101
+ };
1102
+ "request.ConversationQualityInput": {
1103
+ /** @example ["Hi! I'd be happy to assist you today.", "We offer consulting, development, and support services."] */
1104
+ completions: string;
1105
+ /** @example ["Hello, how can I help?", "What services do you offer?"] */
1106
+ prompts: string;
1107
+ };
1108
+ "request.FaithfulnessRequest": {
1109
+ input: components["schemas"]["request.FaithfulnessInput"];
1110
+ };
1111
+ "request.FaithfulnessInput": {
1112
+ /** @example The Eiffel Tower is located in Paris and was built in 1889. */
1113
+ completion: string;
1114
+ /** @example The Eiffel Tower is a wrought-iron lattice tower on the Champ de Mars in Paris, France. It was constructed from 1887 to 1889. */
1115
+ context: string;
1116
+ /** @example When was the Eiffel Tower built? */
1117
+ question: string;
1118
+ };
1119
+ "request.HtmlComparisonRequest": {
1120
+ input: components["schemas"]["request.HtmlComparisonInput"];
1121
+ };
1122
+ "request.HtmlComparisonInput": {
1123
+ /** @example <html><body><h1>Hello, world!</h1></body></html> */
1124
+ html1: string;
1125
+ /** @example <html><body><h1>Hello, world!</h1></body></html> */
1126
+ html2: string;
1127
+ };
1128
+ "request.InstructionAdherenceRequest": {
1129
+ input: components["schemas"]["request.InstructionAdherenceInput"];
1130
+ };
1131
+ "request.InstructionAdherenceInput": {
1132
+ /** @example Respond in exactly 3 bullet points and use formal language. */
1133
+ instructions: string;
1134
+ /**
1135
+ * @example - First point about the topic
1136
+ * - Second relevant consideration
1137
+ * - Final concluding thought
1138
+ */
1139
+ response: string;
1140
+ };
1141
+ "request.IntentChangeRequest": {
1142
+ input: components["schemas"]["request.IntentChangeInput"];
1143
+ };
1144
+ "request.IntentChangeInput": {
1145
+ /** @example ["Sure, I can help with hotel booking", "No problem, let me search for flights"] */
1146
+ completions: string;
1147
+ /** @example ["I want to book a hotel", "Actually, I need a flight instead"] */
1148
+ prompts: string;
1149
+ };
1150
+ "request.JSONValidatorRequest": {
1151
+ config?: components["schemas"]["request.JSONValidatorConfigRequest"];
1152
+ input: components["schemas"]["request.JSONValidatorInput"];
1153
+ };
1154
+ "request.JSONValidatorConfigRequest": {
1155
+ /** @example true */
1156
+ enable_schema_validation?: boolean;
1157
+ /** @example {} */
1158
+ schema_string?: string;
1159
+ };
1160
+ "request.JSONValidatorInput": {
1161
+ /** @example {"name": "John", "age": 30} */
1162
+ text: string;
1163
+ };
1164
+ "request.PerplexityRequest": {
1165
+ input: components["schemas"]["request.PerplexityInput"];
1166
+ };
1167
+ "request.PerplexityInput": {
1168
+ /** @example [-2.3, -1.5, -0.8, -1.2, -0.5] */
1169
+ logprobs: string;
1170
+ };
1171
+ "request.PIIDetectorRequest": {
1172
+ config?: components["schemas"]["request.PIIDetectorConfigRequest"];
1173
+ input: components["schemas"]["request.PIIDetectorInput"];
1174
+ };
1175
+ "request.PIIDetectorConfigRequest": {
1176
+ /** @example 0.8 */
1177
+ probability_threshold?: number;
1178
+ };
1179
+ "request.PIIDetectorInput": {
1180
+ /** @example Please contact John Smith at john.smith@email.com or call 555-123-4567. */
1181
+ text: string;
1182
+ };
1183
+ "request.PlaceholderRegexRequest": {
1184
+ config?: components["schemas"]["request.PlaceholderRegexConfigRequest"];
1185
+ input: components["schemas"]["request.PlaceholderRegexInput"];
1186
+ };
1187
+ "request.PlaceholderRegexConfigRequest": {
1188
+ /** @example true */
1189
+ case_sensitive?: boolean;
1190
+ /** @example true */
1191
+ dot_include_nl?: boolean;
1192
+ /** @example true */
1193
+ multi_line?: boolean;
1194
+ /** @example true */
1195
+ should_match?: boolean;
1196
+ };
1197
+ "request.PlaceholderRegexInput": {
1198
+ /** @example [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,} */
1199
+ placeholder_value: string;
1200
+ /** @example user@example.com */
1201
+ text: string;
1202
+ };
1203
+ "request.ProfanityDetectorRequest": {
1204
+ input: components["schemas"]["request.ProfanityDetectorInput"];
1205
+ };
1206
+ "request.ProfanityDetectorInput": {
1207
+ /** @example This is a clean and professional message. */
1208
+ text: string;
1209
+ };
1210
+ "request.PromptInjectionRequest": {
1211
+ config?: components["schemas"]["request.PromptInjectionConfigRequest"];
1212
+ input: components["schemas"]["request.PromptInjectionInput"];
1213
+ };
1214
+ "request.PromptInjectionConfigRequest": {
1215
+ /** @example 0.5 */
1216
+ threshold?: number;
1217
+ };
1218
+ "request.PromptInjectionInput": {
1219
+ /** @example What is the weather like today? */
1220
+ prompt: string;
1221
+ };
1222
+ "request.PromptPerplexityRequest": {
1223
+ input: components["schemas"]["request.PromptPerplexityInput"];
1224
+ };
1225
+ "request.PromptPerplexityInput": {
1226
+ /** @example What is the capital of France? */
1227
+ prompt: string;
1228
+ };
1229
+ "request.RegexValidatorRequest": {
1230
+ config?: components["schemas"]["request.RegexValidatorConfigRequest"];
1231
+ input: components["schemas"]["request.RegexValidatorInput"];
1232
+ };
1233
+ "request.RegexValidatorConfigRequest": {
1234
+ /** @example true */
1235
+ case_sensitive?: boolean;
1236
+ /** @example true */
1237
+ dot_include_nl?: boolean;
1238
+ /** @example true */
1239
+ multi_line?: boolean;
1240
+ /** @example .* */
1241
+ regex?: string;
1242
+ /** @example true */
1243
+ should_match?: boolean;
1244
+ };
1245
+ "request.RegexValidatorInput": {
1246
+ /** @example user@example.com */
1247
+ text: string;
1248
+ };
1249
+ "request.SecretsDetectorRequest": {
1250
+ input: components["schemas"]["request.SecretsDetectorInput"];
1251
+ };
1252
+ "request.SecretsDetectorInput": {
1253
+ /** @example Here is some text without any API keys or passwords. */
1254
+ text: string;
1255
+ };
1256
+ "request.SemanticSimilarityRequest": {
1257
+ input: components["schemas"]["request.SemanticSimilarityInput"];
1258
+ };
1259
+ "request.SemanticSimilarityInput": {
1260
+ /** @example The cat sat on the mat. */
1261
+ completion: string;
1262
+ /** @example A feline was resting on the rug. */
1263
+ reference: string;
1264
+ };
1265
+ "request.SexismDetectorRequest": {
1266
+ config?: components["schemas"]["request.SexismDetectorConfigRequest"];
1267
+ input: components["schemas"]["request.SexismDetectorInput"];
1268
+ };
1269
+ "request.SexismDetectorConfigRequest": {
1270
+ /** @example 0.5 */
1271
+ threshold?: number;
1272
+ };
1273
+ "request.SexismDetectorInput": {
1274
+ /** @example All team members should be treated equally regardless of gender. */
1275
+ text: string;
1276
+ };
1277
+ "request.SQLValidatorRequest": {
1278
+ input: components["schemas"]["request.SQLValidatorInput"];
1279
+ };
1280
+ "request.SQLValidatorInput": {
1281
+ /** @example SELECT * FROM users WHERE id = 1; */
1282
+ text: string;
1283
+ };
1284
+ "request.ToneDetectionRequest": {
1285
+ input: components["schemas"]["request.ToneDetectionInput"];
1286
+ };
1287
+ "request.ToneDetectionInput": {
1288
+ /** @example The capital of France is Paris. */
1289
+ text: string;
1290
+ };
1291
+ "request.TopicAdherenceRequest": {
1292
+ input: components["schemas"]["request.TopicAdherenceInput"];
1293
+ };
1294
+ "request.TopicAdherenceInput": {
1295
+ /** @example Machine learning is a subset of AI that enables systems to learn from data. */
1296
+ completion: string;
1297
+ /** @example Tell me about machine learning */
1298
+ question: string;
1299
+ /** @example artificial intelligence, data science, algorithms */
1300
+ reference_topics: string;
1301
+ };
1302
+ "request.ToxicityDetectorRequest": {
1303
+ config?: components["schemas"]["request.ToxicityDetectorConfigRequest"];
1304
+ input: components["schemas"]["request.ToxicityDetectorInput"];
1305
+ };
1306
+ "request.ToxicityDetectorConfigRequest": {
1307
+ /** @example 0.5 */
1308
+ threshold?: number;
1309
+ };
1310
+ "request.ToxicityDetectorInput": {
1311
+ /** @example Thank you for your help with this project. */
1312
+ text: string;
1313
+ };
1314
+ "request.UncertaintyDetectorRequest": {
1315
+ input: components["schemas"]["request.UncertaintyDetectorInput"];
1316
+ };
1317
+ "request.UncertaintyDetectorInput": {
1318
+ /** @example I am not sure, I think the capital of France is Paris. */
1319
+ prompt: string;
1320
+ };
1321
+ "request.WordCountRequest": {
1322
+ input: components["schemas"]["request.WordCountInput"];
1323
+ };
1324
+ "request.WordCountInput": {
1325
+ /** @example This is a sample text with several words. */
1326
+ text: string;
1327
+ };
1328
+ "request.WordCountRatioRequest": {
1329
+ input: components["schemas"]["request.WordCountRatioInput"];
1330
+ };
1331
+ "request.WordCountRatioInput": {
1332
+ /** @example This is a longer input text for comparison */
1333
+ denominator_text: string;
1334
+ /** @example Short response */
1335
+ numerator_text: string;
1336
+ };
1337
+ };
1338
+ responses: never;
1339
+ parameters: never;
1340
+ requestBodies: never;
1341
+ headers: never;
1342
+ pathItems: never;
1343
+ }
1344
+
1345
+ type AgentFlowQualityConfig = components['schemas']['request.AgentFlowQualityRequest']['config'];
1346
+ type AgentGoalCompletenessConfig = components['schemas']['request.AgentGoalCompletenessRequest']['config'];
1347
+ type AgentToolTrajectoryConfig = components['schemas']['request.AgentToolTrajectoryRequest']['config'];
1348
+ type ContextRelevanceConfig = components['schemas']['request.ContextRelevanceRequest']['config'];
1349
+ type JsonValidatorConfig = components['schemas']['request.JSONValidatorRequest']['config'];
1350
+ type PiiDetectorConfig = components['schemas']['request.PIIDetectorRequest']['config'];
1351
+ type PlaceholderRegexConfig = components['schemas']['request.PlaceholderRegexRequest']['config'];
1352
+ type PromptInjectionConfig = components['schemas']['request.PromptInjectionRequest']['config'];
1353
+ type RegexValidatorConfig = components['schemas']['request.RegexValidatorRequest']['config'];
1354
+ type SexismDetectorConfig = components['schemas']['request.SexismDetectorRequest']['config'];
1355
+ type ToxicityDetectorConfig = components['schemas']['request.ToxicityDetectorRequest']['config'];
1356
+ /**
1357
+ * Create an evaluator configuration object.
1358
+ */
1359
+ declare function createEvaluator(slug: EvaluatorSlug, options?: {
1360
+ version?: string;
1361
+ config?: Record<string, unknown>;
1362
+ }): EvaluatorWithConfig;
1363
+ /**
1364
+ * Validate that required input fields are present in task output.
1365
+ */
1366
+ declare function validateEvaluatorInput(slug: EvaluatorSlug, taskOutput: Record<string, unknown>): {
1367
+ valid: boolean;
1368
+ missingFields: string[];
1369
+ };
1370
+ /**
1371
+ * Get all available evaluator slugs.
1372
+ */
1373
+ declare function getAvailableEvaluatorSlugs(): EvaluatorSlug[];
1374
+ /**
1375
+ * Get schema information for an evaluator.
1376
+ */
1377
+ declare function getEvaluatorSchemaInfo(slug: EvaluatorSlug): EvaluatorSchema | undefined;
1378
+ /**
1379
+ * Factory class for creating type-safe MBT evaluator configurations.
1380
+ *
1381
+ * @example
1382
+ * ```typescript
1383
+ * import { EvaluatorMadeByTraceloop } from '@anyway-sh/node-server-sdk';
1384
+ *
1385
+ * const evaluators = [
1386
+ * EvaluatorMadeByTraceloop.piiDetector({ probability_threshold: 0.8 }),
1387
+ * EvaluatorMadeByTraceloop.faithfulness(),
1388
+ * ];
1389
+ * ```
1390
+ */
1391
+ declare class EvaluatorMadeByTraceloop {
1392
+ static create(slug: EvaluatorSlug, options?: {
1393
+ version?: string;
1394
+ config?: Record<string, unknown>;
1395
+ }): EvaluatorWithConfig;
1396
+ static getAvailableSlugs(): EvaluatorSlug[];
1397
+ static isValidSlug(slug: string): slug is EvaluatorSlug;
1398
+ /**
1399
+ * Evaluate agent efficiency - detect redundant calls, unnecessary follow-ups
1400
+
1401
+ **Request Body:**
1402
+ - `input.trajectory_prompts` (string, required): JSON array of prompts in the agent trajectory
1403
+ - `input.trajectory_completions` (string, required): JSON array of completions in the agent trajectory
1404
+ * Required task output fields: trajectory_completions, trajectory_prompts
1405
+ */
1406
+ static agentEfficiency(): EvaluatorWithConfig;
1407
+ /**
1408
+ * Validate agent trajectory against user-defined conditions
1409
+
1410
+ **Request Body:**
1411
+ - `input.trajectory_prompts` (string, required): JSON array of prompts in the agent trajectory
1412
+ - `input.trajectory_completions` (string, required): JSON array of completions in the agent trajectory
1413
+ - `config.conditions` (array of strings, required): Array of evaluation conditions/rules to validate against
1414
+ - `config.threshold` (number, required): Score threshold for pass/fail determination (0.0-1.0)
1415
+ * Required task output fields: trajectory_completions, trajectory_prompts
1416
+ */
1417
+ static agentFlowQuality(config?: AgentFlowQualityConfig): EvaluatorWithConfig;
1418
+ /**
1419
+ * Evaluate agent goal accuracy
1420
+
1421
+ **Request Body:**
1422
+ - `input.question` (string, required): The original question or goal
1423
+ - `input.completion` (string, required): The agent's completion/response
1424
+ - `input.reference` (string, required): The expected reference answer
1425
+ * Required task output fields: completion, question, reference
1426
+ */
1427
+ static agentGoalAccuracy(): EvaluatorWithConfig;
1428
+ /**
1429
+ * Measure if agent accomplished all user goals
1430
+
1431
+ **Request Body:**
1432
+ - `input.trajectory_prompts` (string, required): JSON array of prompts in the agent trajectory
1433
+ - `input.trajectory_completions` (string, required): JSON array of completions in the agent trajectory
1434
+ - `config.threshold` (number, required): Score threshold for pass/fail determination (0.0-1.0)
1435
+ * Required task output fields: trajectory_completions, trajectory_prompts
1436
+ */
1437
+ static agentGoalCompleteness(config?: AgentGoalCompletenessConfig): EvaluatorWithConfig;
1438
+ /**
1439
+ * Detect errors or failures during tool execution
1440
+
1441
+ **Request Body:**
1442
+ - `input.tool_input` (string, required): JSON string of the tool input
1443
+ - `input.tool_output` (string, required): JSON string of the tool output
1444
+ * Required task output fields: tool_input, tool_output
1445
+ */
1446
+ static agentToolErrorDetector(): EvaluatorWithConfig;
1447
+ /**
1448
+ * Compare actual tool calls against expected reference tool calls
1449
+
1450
+ **Request Body:**
1451
+ - `input.executed_tool_calls` (string, required): JSON array of actual tool calls made by the agent
1452
+ - `input.expected_tool_calls` (string, required): JSON array of expected/reference tool calls
1453
+ - `config.threshold` (float, optional): Score threshold for pass/fail determination (default: 0.5)
1454
+ - `config.mismatch_sensitive` (bool, optional): Whether tool calls must match exactly (default: false)
1455
+ - `config.order_sensitive` (bool, optional): Whether order of tool calls matters (default: false)
1456
+ - `config.input_params_sensitive` (bool, optional): Whether to compare input parameters (default: true)
1457
+ * Required task output fields: executed_tool_calls, expected_tool_calls
1458
+ */
1459
+ static agentToolTrajectory(config?: AgentToolTrajectoryConfig): EvaluatorWithConfig;
1460
+ /**
1461
+ * Evaluate whether the answer is complete and contains all the necessary information
1462
+
1463
+ **Request Body:**
1464
+ - `input.question` (string, required): The original question
1465
+ - `input.completion` (string, required): The completion to evaluate for completeness
1466
+ - `input.context` (string, required): The context that provides the complete information
1467
+ * Required task output fields: completion, context, question
1468
+ */
1469
+ static answerCompleteness(): EvaluatorWithConfig;
1470
+ /**
1471
+ * Evaluate factual accuracy by comparing answers against ground truth
1472
+
1473
+ **Request Body:**
1474
+ - `input.question` (string, required): The original question
1475
+ - `input.completion` (string, required): The completion to evaluate
1476
+ - `input.ground_truth` (string, required): The expected correct answer
1477
+ * Required task output fields: completion, ground_truth, question
1478
+ */
1479
+ static answerCorrectness(): EvaluatorWithConfig;
1480
+ /**
1481
+ * Check if an answer is relevant to a question
1482
+
1483
+ **Request Body:**
1484
+ - `input.answer` (string, required): The answer to evaluate for relevancy
1485
+ - `input.question` (string, required): The question that the answer should be relevant to
1486
+ * Required task output fields: answer, question
1487
+ */
1488
+ static answerRelevancy(): EvaluatorWithConfig;
1489
+ /**
1490
+ * Count the number of characters in text
1491
+
1492
+ **Request Body:**
1493
+ - `input.text` (string, required): The text to count characters in
1494
+ * Required task output fields: text
1495
+ */
1496
+ static charCount(): EvaluatorWithConfig;
1497
+ /**
1498
+ * Calculate the ratio of characters between two texts
1499
+
1500
+ **Request Body:**
1501
+ - `input.numerator_text` (string, required): The numerator text (will be divided by denominator)
1502
+ - `input.denominator_text` (string, required): The denominator text (divides the numerator)
1503
+ * Required task output fields: denominator_text, numerator_text
1504
+ */
1505
+ static charCountRatio(): EvaluatorWithConfig;
1506
+ /**
1507
+ * Evaluate whether retrieved context contains sufficient information to answer the query
1508
+
1509
+ **Request Body:**
1510
+ - `input.query` (string, required): The query/question to evaluate context relevance for
1511
+ - `input.context` (string, required): The context to evaluate for relevance to the query
1512
+ - `config.model` (string, optional): Model to use for evaluation (default: gpt-4o)
1513
+ * Required task output fields: context, query
1514
+ */
1515
+ static contextRelevance(config?: ContextRelevanceConfig): EvaluatorWithConfig;
1516
+ /**
1517
+ * Evaluate conversation quality based on tone, clarity, flow, responsiveness, and transparency
1518
+
1519
+ **Request Body:**
1520
+ - `input.prompts` (string, required): JSON array of prompts in the conversation
1521
+ - `input.completions` (string, required): JSON array of completions in the conversation
1522
+ * Required task output fields: completions, prompts
1523
+ */
1524
+ static conversationQuality(): EvaluatorWithConfig;
1525
+ /**
1526
+ * Check if a completion is faithful to the provided context
1527
+
1528
+ **Request Body:**
1529
+ - `input.completion` (string, required): The LLM completion to check for faithfulness
1530
+ - `input.context` (string, required): The context that the completion should be faithful to
1531
+ - `input.question` (string, required): The original question asked
1532
+ * Required task output fields: completion, context, question
1533
+ */
1534
+ static faithfulness(): EvaluatorWithConfig;
1535
+ /**
1536
+ * Compare two HTML documents for structural and content similarity
1537
+
1538
+ **Request Body:**
1539
+ - `input.html1` (string, required): The first HTML document to compare
1540
+ - `input.html2` (string, required): The second HTML document to compare
1541
+ * Required task output fields: html1, html2
1542
+ */
1543
+ static htmlComparison(): EvaluatorWithConfig;
1544
+ /**
1545
+ * Evaluate how well responses follow given instructions
1546
+
1547
+ **Request Body:**
1548
+ - `input.instructions` (string, required): The instructions that should be followed
1549
+ - `input.response` (string, required): The response to evaluate for instruction adherence
1550
+ * Required task output fields: instructions, response
1551
+ */
1552
+ static instructionAdherence(): EvaluatorWithConfig;
1553
+ /**
1554
+ * Detect changes in user intent between prompts and completions
1555
+
1556
+ **Request Body:**
1557
+ - `input.prompts` (string, required): JSON array of prompts in the conversation
1558
+ - `input.completions` (string, required): JSON array of completions in the conversation
1559
+ * Required task output fields: completions, prompts
1560
+ */
1561
+ static intentChange(): EvaluatorWithConfig;
1562
+ /**
1563
+ * Validate JSON syntax
1564
+
1565
+ **Request Body:**
1566
+ - `input.text` (string, required): The text to validate as JSON
1567
+ - `config.enable_schema_validation` (bool, optional): Enable JSON schema validation
1568
+ - `config.schema_string` (string, optional): JSON schema to validate against
1569
+ * Required task output fields: text
1570
+ */
1571
+ static jsonValidator(config?: JsonValidatorConfig): EvaluatorWithConfig;
1572
+ /**
1573
+ * Measure text perplexity from logprobs
1574
+
1575
+ **Request Body:**
1576
+ - `input.logprobs` (string, required): JSON array of log probabilities from the model
1577
+ * Required task output fields: logprobs
1578
+ */
1579
+ static perplexity(): EvaluatorWithConfig;
1580
+ /**
1581
+ * Detect personally identifiable information in text
1582
+
1583
+ **Request Body:**
1584
+ - `input.text` (string, required): The text to scan for personally identifiable information
1585
+ - `config.probability_threshold` (float, optional): Detection threshold (default: 0.8)
1586
+ * Required task output fields: text
1587
+ */
1588
+ static piiDetector(config?: PiiDetectorConfig): EvaluatorWithConfig;
1589
+ /**
1590
+ * Validate text against a placeholder regex pattern
1591
+
1592
+ **Request Body:**
1593
+ - `input.placeholder_value` (string, required): The regex pattern to match against
1594
+ - `input.text` (string, required): The text to validate against the regex pattern
1595
+ - `config.should_match` (bool, optional): Whether the text should match the regex
1596
+ - `config.case_sensitive` (bool, optional): Case-sensitive matching
1597
+ - `config.dot_include_nl` (bool, optional): Dot matches newlines
1598
+ - `config.multi_line` (bool, optional): Multi-line mode
1599
+ * Required task output fields: placeholder_value, text
1600
+ */
1601
+ static placeholderRegex(config?: PlaceholderRegexConfig): EvaluatorWithConfig;
1602
+ /**
1603
+ * Detect profanity in text
1604
+
1605
+ **Request Body:**
1606
+ - `input.text` (string, required): The text to scan for profanity
1607
+ * Required task output fields: text
1608
+ */
1609
+ static profanityDetector(): EvaluatorWithConfig;
1610
+ /**
1611
+ * Detect prompt injection attempts
1612
+
1613
+ **Request Body:**
1614
+ - `input.prompt` (string, required): The prompt to check for injection attempts
1615
+ - `config.threshold` (float, optional): Detection threshold (default: 0.5)
1616
+ * Required task output fields: prompt
1617
+ */
1618
+ static promptInjection(config?: PromptInjectionConfig): EvaluatorWithConfig;
1619
+ /**
1620
+ * Measure prompt perplexity to detect potential injection attempts
1621
+
1622
+ **Request Body:**
1623
+ - `input.prompt` (string, required): The prompt to calculate perplexity for
1624
+ * Required task output fields: prompt
1625
+ */
1626
+ static promptPerplexity(): EvaluatorWithConfig;
1627
+ /**
1628
+ * Validate text against a regex pattern
1629
+
1630
+ **Request Body:**
1631
+ - `input.text` (string, required): The text to validate against a regex pattern
1632
+ - `config.regex` (string, optional): The regex pattern to match against
1633
+ - `config.should_match` (bool, optional): Whether the text should match the regex
1634
+ - `config.case_sensitive` (bool, optional): Case-sensitive matching
1635
+ - `config.dot_include_nl` (bool, optional): Dot matches newlines
1636
+ - `config.multi_line` (bool, optional): Multi-line mode
1637
+ * Required task output fields: text
1638
+ */
1639
+ static regexValidator(config?: RegexValidatorConfig): EvaluatorWithConfig;
1640
+ /**
1641
+ * Detect secrets and credentials in text
1642
+
1643
+ **Request Body:**
1644
+ - `input.text` (string, required): The text to scan for secrets (API keys, passwords, etc.)
1645
+ * Required task output fields: text
1646
+ */
1647
+ static secretsDetector(): EvaluatorWithConfig;
1648
+ /**
1649
+ * Calculate semantic similarity between completion and reference
1650
+
1651
+ **Request Body:**
1652
+ - `input.completion` (string, required): The completion text to compare
1653
+ - `input.reference` (string, required): The reference text to compare against
1654
+ * Required task output fields: completion, reference
1655
+ */
1656
+ static semanticSimilarity(): EvaluatorWithConfig;
1657
+ /**
1658
+ * Detect sexist language and bias
1659
+
1660
+ **Request Body:**
1661
+ - `input.text` (string, required): The text to scan for sexist content
1662
+ - `config.threshold` (float, optional): Detection threshold (default: 0.5)
1663
+ * Required task output fields: text
1664
+ */
1665
+ static sexismDetector(config?: SexismDetectorConfig): EvaluatorWithConfig;
1666
+ /**
1667
+ * Validate SQL query syntax
1668
+
1669
+ **Request Body:**
1670
+ - `input.text` (string, required): The text to validate as SQL
1671
+ * Required task output fields: text
1672
+ */
1673
+ static sqlValidator(): EvaluatorWithConfig;
1674
+ /**
1675
+ * Detect the tone of the text
1676
+
1677
+ **Request Body:**
1678
+ - `input.text` (string, required): The text to detect the tone of
1679
+ * Required task output fields: text
1680
+ */
1681
+ static toneDetection(): EvaluatorWithConfig;
1682
+ /**
1683
+ * Evaluate topic adherence
1684
+
1685
+ **Request Body:**
1686
+ - `input.question` (string, required): The original question
1687
+ - `input.completion` (string, required): The completion to evaluate
1688
+ - `input.reference_topics` (string, required): Comma-separated list of expected topics
1689
+ * Required task output fields: completion, question, reference_topics
1690
+ */
1691
+ static topicAdherence(): EvaluatorWithConfig;
1692
+ /**
1693
+ * Detect toxic or harmful language
1694
+
1695
+ **Request Body:**
1696
+ - `input.text` (string, required): The text to scan for toxic content
1697
+ - `config.threshold` (float, optional): Detection threshold (default: 0.5)
1698
+ * Required task output fields: text
1699
+ */
1700
+ static toxicityDetector(config?: ToxicityDetectorConfig): EvaluatorWithConfig;
1701
+ /**
1702
+ * Detect uncertainty in the text
1703
+
1704
+ **Request Body:**
1705
+ - `input.prompt` (string, required): The text to detect uncertainty in
1706
+ * Required task output fields: prompt
1707
+ */
1708
+ static uncertaintyDetector(): EvaluatorWithConfig;
1709
+ /**
1710
+ * Count the number of words in text
1711
+
1712
+ **Request Body:**
1713
+ - `input.text` (string, required): The text to count words in
1714
+ * Required task output fields: text
1715
+ */
1716
+ static wordCount(): EvaluatorWithConfig;
1717
+ /**
1718
+ * Calculate the ratio of words between two texts
1719
+
1720
+ **Request Body:**
1721
+ - `input.numerator_text` (string, required): The numerator text (will be divided by denominator)
1722
+ - `input.denominator_text` (string, required): The denominator text (divides the numerator)
1723
+ * Required task output fields: denominator_text, numerator_text
1724
+ */
1725
+ static wordCountRatio(): EvaluatorWithConfig;
1726
+ }
1727
+
1728
+ /**
1729
+ * Initializes the Traceloop SDK and creates a singleton client instance if API key is provided.
1730
+ * Must be called once before any other SDK methods.
1731
+ *
1732
+ * @param options - The options to initialize the SDK. See the {@link InitializeOptions} for details.
1733
+ * @returns TraceloopClient - The singleton client instance if API key is provided, otherwise undefined.
1734
+ * @throws {InitializationError} if the configuration is invalid or if failed to fetch feature data.
1735
+ *
1736
+ * @example
1737
+ * ```typescript
1738
+ * initialize({
1739
+ * apiKey: 'your-api-key',
1740
+ * appName: 'your-app',
1741
+ * });
1742
+ * ```
1743
+ */
1744
+ declare const initialize: (options?: InitializeOptions) => TraceloopClient | undefined;
1745
+ /**
1746
+ * Gets the singleton instance of the TraceloopClient.
1747
+ * The SDK must be initialized with an API key before calling this function.
1748
+ *
1749
+ * @returns The TraceloopClient singleton instance
1750
+ * @throws {Error} if the SDK hasn't been initialized or was initialized without an API key
1751
+ *
1752
+ * @example
1753
+ * ```typescript
1754
+ * const client = getClient();
1755
+ * await client.annotation.create({ annotationTask: 'taskId', entityInstanceId: 'entityId', tags: { score: 0.9 } });
1756
+ * ```
1757
+ */
1758
+ declare const getClient: () => TraceloopClient;
1759
+
1760
+ declare const forceFlush: () => Promise<void>;
1761
+
1762
+ declare const getTraceloopTracer: () => _opentelemetry_api.Tracer;
1763
+
1764
+ type DecoratorConfig = {
1765
+ name: string;
1766
+ version?: number;
1767
+ associationProperties?: {
1768
+ [name: string]: string;
1769
+ };
1770
+ conversationId?: string;
1771
+ traceContent?: boolean;
1772
+ inputParameters?: unknown[];
1773
+ suppressTracing?: boolean;
1774
+ };
1775
+ declare function withWorkflow<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
1776
+ declare function withTask<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
1777
+ declare function withAgent<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
1778
+ declare function withTool<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
1779
+ declare function workflow(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
1780
+ declare function task(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
1781
+ declare function agent(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
1782
+ declare function tool(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
1783
+ declare function withConversation<A extends unknown[], F extends (...args: A) => ReturnType<F>>(conversationId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): Promise<any>;
1784
+ declare function conversation(conversationId: string | ((thisArg: unknown, ...funcArgs: unknown[]) => string)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
1785
+
1786
+ type VectorDBCallConfig = {
1787
+ vendor: string;
1788
+ type: "query" | "upsert" | "delete";
1789
+ };
1790
+ type LLMCallConfig = {
1791
+ vendor: string;
1792
+ type: "chat" | "completion";
1793
+ };
1794
+ declare class VectorSpan {
1795
+ private span;
1796
+ constructor(span: Span);
1797
+ reportQuery({ queryVector }: {
1798
+ queryVector: number[];
1799
+ }): void;
1800
+ reportResults({ results, }: {
1801
+ results: {
1802
+ ids?: string;
1803
+ scores?: number;
1804
+ distances?: number;
1805
+ metadata?: Record<string, unknown>;
1806
+ vectors?: number[];
1807
+ documents?: string;
1808
+ }[];
1809
+ }): void;
1810
+ }
1811
+ declare class LLMSpan {
1812
+ private span;
1813
+ constructor(span: Span);
1814
+ reportRequest({ model, messages, }: {
1815
+ model: string;
1816
+ messages: {
1817
+ role: string;
1818
+ content?: string | unknown;
1819
+ }[];
1820
+ }): void;
1821
+ reportResponse({ model, usage, completions, }: {
1822
+ model: string;
1823
+ usage?: {
1824
+ prompt_tokens: number;
1825
+ completion_tokens: number;
1826
+ total_tokens: number;
1827
+ };
1828
+ completions?: {
1829
+ finish_reason: string;
1830
+ message: {
1831
+ role: "system" | "user" | "assistant";
1832
+ content: string | null;
1833
+ };
1834
+ }[];
1835
+ }): void;
1836
+ }
1837
+ declare function withVectorDBCall<F extends ({ span }: {
1838
+ span: VectorSpan;
1839
+ }) => ReturnType<F>>({ vendor, type }: VectorDBCallConfig, fn: F, thisArg?: ThisParameterType<F>): Promise<any> | ReturnType<F>;
1840
+ declare function withLLMCall<F extends ({ span }: {
1841
+ span: LLMSpan;
1842
+ }) => ReturnType<F>>({ vendor, type }: LLMCallConfig, fn: F, thisArg?: ThisParameterType<F>): Promise<any> | ReturnType<F>;
1843
+
1844
+ declare function withAssociationProperties<A extends unknown[], F extends (...args: A) => ReturnType<F>>(properties: {
1845
+ [name: string]: string;
1846
+ }, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
1847
+
1848
+ /**
1849
+ * Reports a custom metric to the current active span.
1850
+ *
1851
+ * This function allows you to add a custom metric to the current span in the trace.
1852
+ * If there is no active span, a warning will be logged.
1853
+ *
1854
+ * @param {string} metricName - The name of the custom metric.
1855
+ * @param {number} metricValue - The numeric value of the custom metric.
1856
+ *
1857
+ * @example
1858
+ * reportCustomMetric('processing_time', 150);
1859
+ */
1860
+ declare const reportCustomMetric: (metricName: string, metricValue: number) => void;
1861
+
1862
+ declare const ALL_INSTRUMENTATION_LIBRARIES: "all";
1863
+ type AllInstrumentationLibraries = typeof ALL_INSTRUMENTATION_LIBRARIES;
1864
+ interface SpanProcessorOptions {
1865
+ /**
1866
+ * The API Key for sending traces data. Optional.
1867
+ * Defaults to the ANYWAY_API_KEY environment variable.
1868
+ */
1869
+ apiKey?: string;
1870
+ /**
1871
+ * The OTLP endpoint for sending traces data. Optional.
1872
+ * Defaults to ANYWAY_BASE_URL environment variable or https://api.traceloop.com/
1873
+ */
1874
+ baseUrl?: string;
1875
+ /**
1876
+ * Sends traces and spans without batching, for local development. Optional.
1877
+ * Defaults to false.
1878
+ */
1879
+ disableBatch?: boolean;
1880
+ /**
1881
+ * The OpenTelemetry SpanExporter to be used for sending traces data. Optional.
1882
+ * Defaults to the OTLP exporter.
1883
+ */
1884
+ exporter?: SpanExporter;
1885
+ /**
1886
+ * The headers to be sent with the traces data. Optional.
1887
+ */
1888
+ headers?: Record<string, string>;
1889
+ /**
1890
+ * The instrumentation libraries to be allowed in the traces. Optional.
1891
+ * Defaults to Traceloop instrumentation libraries.
1892
+ * If set to ALL_INSTRUMENTATION_LIBRARIES, all instrumentation libraries will be allowed.
1893
+ * If set to an array of instrumentation libraries, only traceloop instrumentation libraries and the specified instrumentation libraries will be allowed.
1894
+ */
1895
+ allowedInstrumentationLibraries?: string[] | AllInstrumentationLibraries;
1896
+ }
1897
+ /**
1898
+ * Creates a span processor with Traceloop's custom span handling logic.
1899
+ * This can be used independently of the full SDK initialization.
1900
+ *
1901
+ * @param options - Configuration options for the span processor
1902
+ * @returns A configured SpanProcessor instance
1903
+ */
1904
+ declare const createSpanProcessor: (options: SpanProcessorOptions) => SpanProcessor$1;
1905
+ declare const traceloopInstrumentationLibraries: string[];
1906
+
1907
+ /**
1908
+ * Returns true once SDK prompt registry has been initialized, else rejects with an error.
1909
+ * @returns Promise<boolean>
1910
+ */
1911
+ declare const waitForInitialization: () => Promise<boolean>;
1912
+
1913
+ declare const getPrompt: (key: string, variables: Record<string, string>) => any;
1914
+
1915
+ /**
1916
+ * Standard association properties for tracing.
1917
+ * Use these with withAssociationProperties() or decorator associationProperties config.
1918
+ *
1919
+ * @example
1920
+ * ```typescript
1921
+ * // With withAssociationProperties
1922
+ * await traceloop.withAssociationProperties(
1923
+ * {
1924
+ * [traceloop.AssociationProperty.USER_ID]: "12345",
1925
+ * [traceloop.AssociationProperty.SESSION_ID]: "session-abc"
1926
+ * },
1927
+ * async () => {
1928
+ * await chat();
1929
+ * }
1930
+ * );
1931
+ *
1932
+ * // With decorator
1933
+ * @traceloop.workflow((thisArg) => ({
1934
+ * name: "my_workflow",
1935
+ * associationProperties: {
1936
+ * [traceloop.AssociationProperty.USER_ID]: (thisArg as MyClass).userId,
1937
+ * },
1938
+ * }))
1939
+ * ```
1940
+ */
1941
+ declare enum AssociationProperty {
1942
+ CUSTOMER_ID = "customer_id",
1943
+ USER_ID = "user_id",
1944
+ SESSION_ID = "session_id"
1945
+ }
1946
+
1947
+ declare class ImageUploader {
1948
+ private baseUrl;
1949
+ private apiKey;
1950
+ constructor(baseUrl: string, apiKey: string);
1951
+ uploadBase64Image(traceId: string, spanId: string, imageName: string, base64ImageData: string): Promise<string>;
1952
+ private getImageUrl;
1953
+ private uploadImageData;
1954
+ }
1955
+
1956
+ export { ALL_INSTRUMENTATION_LIBRARIES, ArgumentNotProvidedError, AssociationProperty, Attachment, AttachmentReference, AttachmentUploader, Column, Dataset, Datasets, Evaluator, EvaluatorMadeByTraceloop, Experiment, ExternalAttachment, ImageUploader, InitializationError, LLMSpan, NotInitializedError, PromptNotFoundError, Row, SEVERITY, TraceloopClient, TraceloopError, VectorSpan, agent, attachment, conversation, createEvaluator, createSpanProcessor, forceFlush, getAvailableEvaluatorSlugs, getClient, getEvaluatorSchemaInfo, getPrompt, getTraceloopTracer, initialize, isAnyAttachment, isAttachment, isAttachmentReference, isExternalAttachment, reportCustomMetric, task, tool, traceloopInstrumentationLibraries, validateEvaluatorInput, waitForInitialization, withAgent, withAssociationProperties, withConversation, withLLMCall, withTask, withTool, withVectorDBCall, withWorkflow, workflow };
1957
+ export type { AnnotationCreateOptions, AttachmentMetadata, AttachmentOptions, CSVImportOptions, ColumnDefinition, ColumnResponse, ColumnUpdateOptions, DatasetCreateOptions, DatasetListResponse, DatasetPublishOptions, DatasetResponse, DatasetUpdateOptions, DatasetVersion, DatasetVersionsResponse, DecoratorConfig, EvaluatorDetails, EvaluatorWithConfig, EvaluatorWithVersion, ExecutionResponse, ExperimentRunOptions, ExperimentRunResult, ExperimentTaskFunction, ExternalAttachmentOptions, FileCellType, FileStorageType, GithubContext, InitializeOptions, RowData, RowResponse, RowUpdateOptions, RunInGithubOptions, RunInGithubResponse, SSEStreamEvent, Severity, SpanProcessorOptions, StreamEvent, TaskInput, TaskOutput, TaskResponse, TaskResult, TraceloopClientOptions, UploadUrlResponse };