@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.
- package/README +35 -0
- package/dist/index.d.ts +1957 -0
- package/dist/index.js +4458 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4382 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/lib/associations/associations.d.ts +32 -0
- package/dist/src/lib/client/annotation/base-annotation.d.ts +20 -0
- package/dist/src/lib/client/annotation/user-feedback.d.ts +32 -0
- package/dist/src/lib/client/dataset/attachment-uploader.d.ts +50 -0
- package/dist/src/lib/client/dataset/attachment.d.ts +84 -0
- package/dist/src/lib/client/dataset/base-dataset.d.ts +10 -0
- package/dist/src/lib/client/dataset/column.d.ts +23 -0
- package/dist/src/lib/client/dataset/dataset.d.ts +43 -0
- package/dist/src/lib/client/dataset/datasets.d.ts +14 -0
- package/dist/src/lib/client/dataset/index.d.ts +8 -0
- package/dist/src/lib/client/dataset/row.d.ts +73 -0
- package/dist/src/lib/client/evaluator/evaluator.d.ts +28 -0
- package/dist/src/lib/client/evaluator/index.d.ts +2 -0
- package/dist/src/lib/client/experiment/experiment.d.ts +76 -0
- package/dist/src/lib/client/experiment/index.d.ts +2 -0
- package/dist/src/lib/client/traceloop-client.d.ts +40 -0
- package/dist/src/lib/configuration/index.d.ts +35 -0
- package/dist/src/lib/configuration/validation.d.ts +3 -0
- package/dist/src/lib/errors/index.d.ts +36 -0
- package/dist/src/lib/generated/evaluators/index.d.ts +5 -0
- package/dist/src/lib/generated/evaluators/mbt-evaluators.d.ts +386 -0
- package/dist/src/lib/generated/evaluators/registry.d.ts +12 -0
- package/dist/src/lib/generated/evaluators/types.d.ts +401 -0
- package/dist/src/lib/images/image-uploader.d.ts +15 -0
- package/dist/src/lib/images/index.d.ts +2 -0
- package/dist/src/lib/interfaces/annotations.interface.d.ts +35 -0
- package/dist/src/lib/interfaces/dataset.interface.d.ts +105 -0
- package/dist/src/lib/interfaces/evaluator.interface.d.ts +83 -0
- package/dist/src/lib/interfaces/experiment.interface.d.ts +117 -0
- package/dist/src/lib/interfaces/index.d.ts +8 -0
- package/dist/src/lib/interfaces/initialize-options.interface.d.ts +133 -0
- package/dist/src/lib/interfaces/prompts.interface.d.ts +53 -0
- package/dist/src/lib/interfaces/traceloop-client.interface.d.ts +7 -0
- package/dist/src/lib/node-server-sdk.d.ts +19 -0
- package/dist/src/lib/prompts/fetch.d.ts +3 -0
- package/dist/src/lib/prompts/index.d.ts +3 -0
- package/dist/src/lib/prompts/registry.d.ts +9 -0
- package/dist/src/lib/prompts/template.d.ts +3 -0
- package/dist/src/lib/tracing/ai-sdk-transformations.d.ts +5 -0
- package/dist/src/lib/tracing/association.d.ts +4 -0
- package/dist/src/lib/tracing/baggage-utils.d.ts +2 -0
- package/dist/src/lib/tracing/custom-metric.d.ts +14 -0
- package/dist/src/lib/tracing/decorators.d.ts +22 -0
- package/dist/src/lib/tracing/index.d.ts +14 -0
- package/dist/src/lib/tracing/manual.d.ts +60 -0
- package/dist/src/lib/tracing/sampler.d.ts +7 -0
- package/dist/src/lib/tracing/span-processor.d.ts +48 -0
- package/dist/src/lib/tracing/tracing.d.ts +10 -0
- package/dist/src/lib/utils/response-transformer.d.ts +19 -0
- package/package.json +127 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
type dataValue = string | number | boolean;
|
|
2
|
+
export type TaskInput = Record<string, dataValue>;
|
|
3
|
+
export type TaskOutput = Record<string, dataValue>;
|
|
4
|
+
export interface ExperimentTaskFunction<TInput = TaskInput, TOutput = TaskOutput> {
|
|
5
|
+
(input: TInput): Promise<TOutput> | TOutput;
|
|
6
|
+
}
|
|
7
|
+
export type EvaluatorDetails = string | EvaluatorWithVersion | EvaluatorWithConfig;
|
|
8
|
+
export interface EvaluatorWithVersion {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Evaluator configuration with optional version and config options.
|
|
14
|
+
* Used for "Made by Traceloop" (MBT) evaluators that support configuration.
|
|
15
|
+
*/
|
|
16
|
+
export interface EvaluatorWithConfig {
|
|
17
|
+
name: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
config?: Record<string, unknown>;
|
|
20
|
+
requiredInputFields?: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface ExperimentRunOptions {
|
|
23
|
+
datasetSlug?: string;
|
|
24
|
+
datasetVersion?: string;
|
|
25
|
+
evaluators?: EvaluatorDetails[];
|
|
26
|
+
experimentSlug?: string;
|
|
27
|
+
relatedRef?: Record<string, string>;
|
|
28
|
+
aux?: Record<string, string>;
|
|
29
|
+
stopOnError?: boolean;
|
|
30
|
+
waitForResults?: boolean;
|
|
31
|
+
}
|
|
32
|
+
import type { InputSchemaMapping } from "./evaluator.interface";
|
|
33
|
+
export interface TaskResponse {
|
|
34
|
+
input: Record<string, any>;
|
|
35
|
+
output: Record<string, any>;
|
|
36
|
+
metadata?: Record<string, any>;
|
|
37
|
+
timestamp?: number;
|
|
38
|
+
error?: string;
|
|
39
|
+
input_schema_mapping?: InputSchemaMapping;
|
|
40
|
+
}
|
|
41
|
+
export interface ExperimentRunResult {
|
|
42
|
+
taskResults: TaskResponse[];
|
|
43
|
+
errors: string[];
|
|
44
|
+
experimentId?: string;
|
|
45
|
+
runId?: string;
|
|
46
|
+
evaluations?: Record<string, any>[];
|
|
47
|
+
}
|
|
48
|
+
export interface InitExperimentRequest {
|
|
49
|
+
slug: string;
|
|
50
|
+
datasetSlug?: string;
|
|
51
|
+
datasetVersion?: string;
|
|
52
|
+
evaluatorSlugs?: string[];
|
|
53
|
+
experimentMetadata?: Record<string, any>;
|
|
54
|
+
experimentRunMetadata?: Record<string, any>;
|
|
55
|
+
relatedRef?: Record<string, string>;
|
|
56
|
+
aux?: Record<string, string>;
|
|
57
|
+
}
|
|
58
|
+
export interface ExperimentResponse {
|
|
59
|
+
id: string;
|
|
60
|
+
slug: string;
|
|
61
|
+
metadata?: Record<string, any>;
|
|
62
|
+
created_at: string;
|
|
63
|
+
updated_at: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ExperimentRunResponse {
|
|
66
|
+
id: string;
|
|
67
|
+
metadata?: Record<string, any>;
|
|
68
|
+
dataset_id?: string;
|
|
69
|
+
dataset_version?: string;
|
|
70
|
+
evaluator_ids?: string[];
|
|
71
|
+
created_at: string;
|
|
72
|
+
updated_at: string;
|
|
73
|
+
}
|
|
74
|
+
export interface ExperimentInitResponse {
|
|
75
|
+
experiment: ExperimentResponse;
|
|
76
|
+
run: ExperimentRunResponse;
|
|
77
|
+
}
|
|
78
|
+
export interface ExecutionResponse {
|
|
79
|
+
executionId: string;
|
|
80
|
+
result: Record<string, any>;
|
|
81
|
+
}
|
|
82
|
+
export interface CreateTaskRequest {
|
|
83
|
+
input: Record<string, any>;
|
|
84
|
+
output: Record<string, any>;
|
|
85
|
+
}
|
|
86
|
+
export interface CreateTaskResponse {
|
|
87
|
+
id: string;
|
|
88
|
+
}
|
|
89
|
+
export interface GithubContext {
|
|
90
|
+
repository: string;
|
|
91
|
+
prUrl: string;
|
|
92
|
+
commitHash: string;
|
|
93
|
+
actor: string;
|
|
94
|
+
}
|
|
95
|
+
export interface TaskResult {
|
|
96
|
+
input: Record<string, any>;
|
|
97
|
+
output?: Record<string, any>;
|
|
98
|
+
error?: string;
|
|
99
|
+
metadata?: Record<string, any>;
|
|
100
|
+
}
|
|
101
|
+
export interface RunInGithubOptions {
|
|
102
|
+
datasetSlug: string;
|
|
103
|
+
datasetVersion?: string;
|
|
104
|
+
evaluators?: EvaluatorDetails[];
|
|
105
|
+
experimentSlug?: string;
|
|
106
|
+
experimentMetadata?: Record<string, any>;
|
|
107
|
+
experimentRunMetadata?: Record<string, any>;
|
|
108
|
+
relatedRef?: Record<string, string>;
|
|
109
|
+
aux?: Record<string, string>;
|
|
110
|
+
}
|
|
111
|
+
export interface RunInGithubResponse {
|
|
112
|
+
experimentId: string;
|
|
113
|
+
experimentSlug: string;
|
|
114
|
+
runId: string;
|
|
115
|
+
}
|
|
116
|
+
export {};
|
|
117
|
+
//# sourceMappingURL=experiment.interface.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./initialize-options.interface";
|
|
2
|
+
export * from "./prompts.interface";
|
|
3
|
+
export * from "./annotations.interface";
|
|
4
|
+
export * from "./traceloop-client.interface";
|
|
5
|
+
export * from "./dataset.interface";
|
|
6
|
+
export * from "./experiment.interface";
|
|
7
|
+
export * from "./evaluator.interface";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { SpanExporter, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
import { TextMapPropagator, ContextManager } from "@opentelemetry/api";
|
|
3
|
+
import type * as openai from "openai";
|
|
4
|
+
import type * as anthropic from "@anthropic-ai/sdk";
|
|
5
|
+
import type * as cohere from "cohere-ai";
|
|
6
|
+
import type * as bedrock from "@aws-sdk/client-bedrock-runtime";
|
|
7
|
+
import type * as aiplatform from "@google-cloud/aiplatform";
|
|
8
|
+
import type * as vertexAI from "@google-cloud/vertexai";
|
|
9
|
+
import type * as pinecone from "@pinecone-database/pinecone";
|
|
10
|
+
import type * as together from "together-ai";
|
|
11
|
+
import type * as llamaindex from "llamaindex";
|
|
12
|
+
import type * as chromadb from "chromadb";
|
|
13
|
+
import type * as qdrant from "@qdrant/js-client-rest";
|
|
14
|
+
import type * as mcp from "@modelcontextprotocol/sdk/client/index.js";
|
|
15
|
+
/**
|
|
16
|
+
* Options for initializing the Traceloop SDK.
|
|
17
|
+
*/
|
|
18
|
+
export interface InitializeOptions {
|
|
19
|
+
/**
|
|
20
|
+
* The app name to be used when reporting traces. Optional.
|
|
21
|
+
* Defaults to the package name.
|
|
22
|
+
*/
|
|
23
|
+
appName?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The API Key for sending traces data. Optional.
|
|
26
|
+
* Defaults to the ANYWAY_API_KEY environment variable.
|
|
27
|
+
*/
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The OTLP endpoint for sending traces data. Optional.
|
|
31
|
+
* Defaults to ANYWAY_BASE_URL environment variable or https://api.traceloop.com/
|
|
32
|
+
*/
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Sends traces and spans without batching, for local developement. Optional.
|
|
36
|
+
* Defaults to false.
|
|
37
|
+
*/
|
|
38
|
+
disableBatch?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Defines default log level for SDK and all instrumentations. Optional.
|
|
41
|
+
* Defaults to error.
|
|
42
|
+
*/
|
|
43
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
44
|
+
/**
|
|
45
|
+
* Whether to log prompts, completions and embeddings on traces. Optional.
|
|
46
|
+
* Defaults to true.
|
|
47
|
+
*/
|
|
48
|
+
traceContent?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The OpenTelemetry SpanExporter to be used for sending traces data. Optional.
|
|
51
|
+
* Defaults to the OTLP exporter.
|
|
52
|
+
*/
|
|
53
|
+
exporter?: SpanExporter;
|
|
54
|
+
/**
|
|
55
|
+
* The headers to be sent with the traces data. Optional.
|
|
56
|
+
*/
|
|
57
|
+
headers?: Record<string, string>;
|
|
58
|
+
/**
|
|
59
|
+
* The OpenTelemetry SpanProcessor to be used for processing traces data. Optional.
|
|
60
|
+
* Defaults to the BatchSpanProcessor.
|
|
61
|
+
*/
|
|
62
|
+
processor?: SpanProcessor;
|
|
63
|
+
/**
|
|
64
|
+
* The OpenTelemetry Propagator to use. Optional.
|
|
65
|
+
* Defaults to OpenTelemetry SDK defaults.
|
|
66
|
+
*/
|
|
67
|
+
propagator?: TextMapPropagator;
|
|
68
|
+
/**
|
|
69
|
+
* The OpenTelemetry ContextManager to use. Optional.
|
|
70
|
+
* Defaults to OpenTelemetry SDK defaults.
|
|
71
|
+
*/
|
|
72
|
+
contextManager?: ContextManager;
|
|
73
|
+
/**
|
|
74
|
+
* Explicitly specify modules to instrument. Optional.
|
|
75
|
+
* This is a workaround specific to Next.js, see https://www.traceloop.com/docs/openllmetry/getting-started-nextjs
|
|
76
|
+
*/
|
|
77
|
+
instrumentModules?: {
|
|
78
|
+
openAI?: typeof openai.OpenAI;
|
|
79
|
+
anthropic?: typeof anthropic;
|
|
80
|
+
cohere?: typeof cohere;
|
|
81
|
+
bedrock?: typeof bedrock;
|
|
82
|
+
google_vertexai?: typeof vertexAI;
|
|
83
|
+
google_aiplatform?: typeof aiplatform;
|
|
84
|
+
pinecone?: typeof pinecone;
|
|
85
|
+
together?: typeof together.Together;
|
|
86
|
+
langchain?: boolean;
|
|
87
|
+
llamaIndex?: typeof llamaindex;
|
|
88
|
+
chromadb?: typeof chromadb;
|
|
89
|
+
qdrant?: typeof qdrant;
|
|
90
|
+
mcp?: typeof mcp;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Enables sync with Traceloop servers for the prompt registry functionality. Optional.
|
|
94
|
+
* Defaults to ANYWAY_SYNC_ENABLED environment variable or true if not set.
|
|
95
|
+
*/
|
|
96
|
+
traceloopSyncEnabled?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Defines the number of retires when fetching prompt data for the registry. Optional.
|
|
99
|
+
* Defaults to ANYWAY_SYNC_MAX_RETRIES environment variable or 3 if not set.
|
|
100
|
+
*/
|
|
101
|
+
traceloopSyncMaxRetries?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Defines the polling interval for the prompt registry. Optional.
|
|
104
|
+
* Defaults to ANYWAY_SYNC_POLLING_INTERVAL environment variable or 60 if not set.
|
|
105
|
+
*/
|
|
106
|
+
traceloopSyncPollingInterval?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Defines the polling interval for the prompt registry. Optional.
|
|
109
|
+
* Defaults to ANYWAY_SYNC_DEV_POLLING_INTERVAL environment variable or 5 if not set.
|
|
110
|
+
*/
|
|
111
|
+
traceloopSyncDevPollingInterval?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Whether to silence the initialization message. Optional.
|
|
114
|
+
* Defaults to false.
|
|
115
|
+
*/
|
|
116
|
+
silenceInitializationMessage?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Whether to enable tracing. Optional.
|
|
119
|
+
* Defaults to true.
|
|
120
|
+
*/
|
|
121
|
+
tracingEnabled?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* The experiment slug to use when running experiments. Optional.
|
|
124
|
+
* Defaults to the ANYWAY_EXP_SLUG environment variable.
|
|
125
|
+
*/
|
|
126
|
+
experimentSlug?: string;
|
|
127
|
+
/**
|
|
128
|
+
* The Google Cloud Project ID for sending traces data. Optional.
|
|
129
|
+
* This is used to configure the Google Cloud Trace Exporter.
|
|
130
|
+
*/
|
|
131
|
+
gcpProjectId?: string;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=initialize-options.interface.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const TEMPLATING_ENGINE: {
|
|
2
|
+
readonly JINJA2: "jinja2";
|
|
3
|
+
};
|
|
4
|
+
export type TemplatingEngine = (typeof TEMPLATING_ENGINE)[keyof typeof TEMPLATING_ENGINE];
|
|
5
|
+
export type Content = {
|
|
6
|
+
type: "text";
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "image_url";
|
|
10
|
+
image_url: {
|
|
11
|
+
url: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export interface PromptMessage {
|
|
15
|
+
index: number;
|
|
16
|
+
template: string | Content[];
|
|
17
|
+
role: string;
|
|
18
|
+
variables: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface RenderedMessage {
|
|
21
|
+
role: string;
|
|
22
|
+
content: string | Content[];
|
|
23
|
+
}
|
|
24
|
+
export interface PromptTarget {
|
|
25
|
+
id: string;
|
|
26
|
+
environment: string;
|
|
27
|
+
version: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PromptVersion {
|
|
31
|
+
templating_engine: TemplatingEngine;
|
|
32
|
+
provider: string;
|
|
33
|
+
messages: PromptMessage[];
|
|
34
|
+
id: string;
|
|
35
|
+
hash: string;
|
|
36
|
+
version: number;
|
|
37
|
+
name?: string;
|
|
38
|
+
updated_at: string;
|
|
39
|
+
created_at: string;
|
|
40
|
+
author?: string;
|
|
41
|
+
publishable: boolean;
|
|
42
|
+
llm_config: any;
|
|
43
|
+
}
|
|
44
|
+
export interface Prompt {
|
|
45
|
+
id: string;
|
|
46
|
+
org_id: string;
|
|
47
|
+
key: string;
|
|
48
|
+
updated_at: string;
|
|
49
|
+
created_at: string;
|
|
50
|
+
versions: PromptVersion[];
|
|
51
|
+
target: PromptTarget;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=prompts.interface.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from "./errors";
|
|
2
|
+
export { InitializeOptions, TraceloopClientOptions, AnnotationCreateOptions, DatasetCreateOptions, DatasetUpdateOptions, DatasetResponse, ColumnDefinition, ColumnResponse, ColumnUpdateOptions, RowData, RowResponse, RowUpdateOptions, DatasetListResponse, DatasetPublishOptions, CSVImportOptions, DatasetVersion, DatasetVersionsResponse, ExperimentTaskFunction, ExperimentRunOptions, ExperimentRunResult, TaskInput, TaskOutput, TaskResponse, ExecutionResponse, EvaluatorDetails, EvaluatorWithConfig, EvaluatorWithVersion, GithubContext, TaskResult, RunInGithubOptions, RunInGithubResponse, StreamEvent, SSEStreamEvent, } from "./interfaces";
|
|
3
|
+
export { TraceloopClient } from "./client/traceloop-client";
|
|
4
|
+
export { Dataset, Datasets, Column, Row, Attachment, ExternalAttachment, AttachmentReference, attachment, isAttachment, isExternalAttachment, isAttachmentReference, isAnyAttachment, AttachmentUploader, } from "./client/dataset";
|
|
5
|
+
export type { FileCellType, FileStorageType, AttachmentMetadata, AttachmentOptions, ExternalAttachmentOptions, UploadUrlResponse, } from "./client/dataset";
|
|
6
|
+
export { Experiment } from "./client/experiment";
|
|
7
|
+
export { Evaluator } from "./client/evaluator";
|
|
8
|
+
export { EvaluatorMadeByTraceloop, createEvaluator, validateEvaluatorInput, getAvailableEvaluatorSlugs, getEvaluatorSchemaInfo, } from "./generated/evaluators";
|
|
9
|
+
export { initialize, getClient } from "./configuration";
|
|
10
|
+
export { forceFlush } from "./tracing";
|
|
11
|
+
export { getTraceloopTracer } from "./tracing/tracing";
|
|
12
|
+
export * from "./tracing/decorators";
|
|
13
|
+
export * from "./tracing/manual";
|
|
14
|
+
export * from "./tracing/association";
|
|
15
|
+
export * from "./tracing/custom-metric";
|
|
16
|
+
export * from "./tracing/span-processor";
|
|
17
|
+
export * from "./prompts";
|
|
18
|
+
export { AssociationProperty } from "./associations/associations";
|
|
19
|
+
//# sourceMappingURL=node-server-sdk.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InitializeOptions, Prompt } from "../interfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Returns true once SDK prompt registry has been initialized, else rejects with an error.
|
|
4
|
+
* @returns Promise<boolean>
|
|
5
|
+
*/
|
|
6
|
+
export declare const waitForInitialization: () => Promise<boolean>;
|
|
7
|
+
export declare const getPromptByKey: (key: string) => Prompt;
|
|
8
|
+
export declare const initializeRegistry: (options: InitializeOptions) => void;
|
|
9
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ReadableSpan, Span } from "@opentelemetry/sdk-trace-node";
|
|
2
|
+
export declare const transformLLMSpans: (attributes: Record<string, any>, spanName?: string) => void;
|
|
3
|
+
export declare const transformAiSdkSpanNames: (span: Span) => void;
|
|
4
|
+
export declare const transformAiSdkSpanAttributes: (span: ReadableSpan) => void;
|
|
5
|
+
//# sourceMappingURL=ai-sdk-transformations.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports a custom metric to the current active span.
|
|
3
|
+
*
|
|
4
|
+
* This function allows you to add a custom metric to the current span in the trace.
|
|
5
|
+
* If there is no active span, a warning will be logged.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} metricName - The name of the custom metric.
|
|
8
|
+
* @param {number} metricValue - The numeric value of the custom metric.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* reportCustomMetric('processing_time', 150);
|
|
12
|
+
*/
|
|
13
|
+
export declare const reportCustomMetric: (metricName: string, metricValue: number) => void;
|
|
14
|
+
//# sourceMappingURL=custom-metric.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type DecoratorConfig = {
|
|
2
|
+
name: string;
|
|
3
|
+
version?: number;
|
|
4
|
+
associationProperties?: {
|
|
5
|
+
[name: string]: string;
|
|
6
|
+
};
|
|
7
|
+
conversationId?: string;
|
|
8
|
+
traceContent?: boolean;
|
|
9
|
+
inputParameters?: unknown[];
|
|
10
|
+
suppressTracing?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function withWorkflow<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
|
|
13
|
+
export declare function withTask<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
|
|
14
|
+
export declare function withAgent<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
|
|
15
|
+
export declare function withTool<A extends unknown[], F extends (...args: A) => ReturnType<F>>(config: DecoratorConfig, fn: F, ...args: A): Promise<any>;
|
|
16
|
+
export declare function workflow(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
17
|
+
export declare function task(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
18
|
+
export declare function agent(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
19
|
+
export declare function tool(config: Partial<DecoratorConfig> | ((thisArg: unknown, ...funcArgs: unknown[]) => Partial<DecoratorConfig>)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
20
|
+
export declare function withConversation<A extends unknown[], F extends (...args: A) => ReturnType<F>>(conversationId: string, fn: F, thisArg?: ThisParameterType<F>, ...args: A): Promise<any>;
|
|
21
|
+
export declare function conversation(conversationId: string | ((thisArg: unknown, ...funcArgs: unknown[]) => string)): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
22
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InitializeOptions } from "../interfaces";
|
|
2
|
+
export declare const initInstrumentations: (apiKey?: string, baseUrl?: string) => void;
|
|
3
|
+
export declare const manuallyInitInstrumentations: (instrumentModules: InitializeOptions["instrumentModules"], apiKey?: string, baseUrl?: string) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Initializes the Traceloop SDK.
|
|
6
|
+
* Must be called once before any other SDK methods.
|
|
7
|
+
*
|
|
8
|
+
* @param options - The options to initialize the SDK. See the {@link InitializeOptions} for details.
|
|
9
|
+
* @throws {InitializationError} if the configuration is invalid or if failed to fetch feature data.
|
|
10
|
+
*/
|
|
11
|
+
export declare const startTracing: (options: InitializeOptions) => void;
|
|
12
|
+
export declare const shouldSendTraces: () => {} | null;
|
|
13
|
+
export declare const forceFlush: () => Promise<void>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Span } from "@opentelemetry/api";
|
|
2
|
+
type VectorDBCallConfig = {
|
|
3
|
+
vendor: string;
|
|
4
|
+
type: "query" | "upsert" | "delete";
|
|
5
|
+
};
|
|
6
|
+
type LLMCallConfig = {
|
|
7
|
+
vendor: string;
|
|
8
|
+
type: "chat" | "completion";
|
|
9
|
+
};
|
|
10
|
+
export declare class VectorSpan {
|
|
11
|
+
private span;
|
|
12
|
+
constructor(span: Span);
|
|
13
|
+
reportQuery({ queryVector }: {
|
|
14
|
+
queryVector: number[];
|
|
15
|
+
}): void;
|
|
16
|
+
reportResults({ results, }: {
|
|
17
|
+
results: {
|
|
18
|
+
ids?: string;
|
|
19
|
+
scores?: number;
|
|
20
|
+
distances?: number;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
vectors?: number[];
|
|
23
|
+
documents?: string;
|
|
24
|
+
}[];
|
|
25
|
+
}): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class LLMSpan {
|
|
28
|
+
private span;
|
|
29
|
+
constructor(span: Span);
|
|
30
|
+
reportRequest({ model, messages, }: {
|
|
31
|
+
model: string;
|
|
32
|
+
messages: {
|
|
33
|
+
role: string;
|
|
34
|
+
content?: string | unknown;
|
|
35
|
+
}[];
|
|
36
|
+
}): void;
|
|
37
|
+
reportResponse({ model, usage, completions, }: {
|
|
38
|
+
model: string;
|
|
39
|
+
usage?: {
|
|
40
|
+
prompt_tokens: number;
|
|
41
|
+
completion_tokens: number;
|
|
42
|
+
total_tokens: number;
|
|
43
|
+
};
|
|
44
|
+
completions?: {
|
|
45
|
+
finish_reason: string;
|
|
46
|
+
message: {
|
|
47
|
+
role: "system" | "user" | "assistant";
|
|
48
|
+
content: string | null;
|
|
49
|
+
};
|
|
50
|
+
}[];
|
|
51
|
+
}): void;
|
|
52
|
+
}
|
|
53
|
+
export declare function withVectorDBCall<F extends ({ span }: {
|
|
54
|
+
span: VectorSpan;
|
|
55
|
+
}) => ReturnType<F>>({ vendor, type }: VectorDBCallConfig, fn: F, thisArg?: ThisParameterType<F>): Promise<any> | ReturnType<F>;
|
|
56
|
+
export declare function withLLMCall<F extends ({ span }: {
|
|
57
|
+
span: LLMSpan;
|
|
58
|
+
}) => ReturnType<F>>({ vendor, type }: LLMCallConfig, fn: F, thisArg?: ThisParameterType<F>): Promise<any> | ReturnType<F>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=manual.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Sampler, SamplingResult } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
import { Context, SpanKind, Attributes } from "@opentelemetry/api";
|
|
3
|
+
export declare class TraceloopSampler implements Sampler {
|
|
4
|
+
shouldSample(_context: Context, _traceId: string, _spanName: string, _spanKind: SpanKind, attributes: Attributes): SamplingResult;
|
|
5
|
+
toString(): string;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=sampler.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SpanProcessor } from "@opentelemetry/sdk-trace-node";
|
|
2
|
+
import { SpanExporter } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
export declare const ALL_INSTRUMENTATION_LIBRARIES: "all";
|
|
4
|
+
type AllInstrumentationLibraries = typeof ALL_INSTRUMENTATION_LIBRARIES;
|
|
5
|
+
export interface SpanProcessorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The API Key for sending traces data. Optional.
|
|
8
|
+
* Defaults to the ANYWAY_API_KEY environment variable.
|
|
9
|
+
*/
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The OTLP endpoint for sending traces data. Optional.
|
|
13
|
+
* Defaults to ANYWAY_BASE_URL environment variable or https://api.traceloop.com/
|
|
14
|
+
*/
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Sends traces and spans without batching, for local development. Optional.
|
|
18
|
+
* Defaults to false.
|
|
19
|
+
*/
|
|
20
|
+
disableBatch?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The OpenTelemetry SpanExporter to be used for sending traces data. Optional.
|
|
23
|
+
* Defaults to the OTLP exporter.
|
|
24
|
+
*/
|
|
25
|
+
exporter?: SpanExporter;
|
|
26
|
+
/**
|
|
27
|
+
* The headers to be sent with the traces data. Optional.
|
|
28
|
+
*/
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* The instrumentation libraries to be allowed in the traces. Optional.
|
|
32
|
+
* Defaults to Traceloop instrumentation libraries.
|
|
33
|
+
* If set to ALL_INSTRUMENTATION_LIBRARIES, all instrumentation libraries will be allowed.
|
|
34
|
+
* If set to an array of instrumentation libraries, only traceloop instrumentation libraries and the specified instrumentation libraries will be allowed.
|
|
35
|
+
*/
|
|
36
|
+
allowedInstrumentationLibraries?: string[] | AllInstrumentationLibraries;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a span processor with Traceloop's custom span handling logic.
|
|
40
|
+
* This can be used independently of the full SDK initialization.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Configuration options for the span processor
|
|
43
|
+
* @returns A configured SpanProcessor instance
|
|
44
|
+
*/
|
|
45
|
+
export declare const createSpanProcessor: (options: SpanProcessorOptions) => SpanProcessor;
|
|
46
|
+
export declare const traceloopInstrumentationLibraries: string[];
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=span-processor.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from "@opentelemetry/api";
|
|
2
|
+
export declare const WORKFLOW_NAME_KEY: symbol;
|
|
3
|
+
export declare const ENTITY_NAME_KEY: symbol;
|
|
4
|
+
export declare const AGENT_NAME_KEY: symbol;
|
|
5
|
+
export declare const CONVERSATION_ID_KEY: symbol;
|
|
6
|
+
export declare const ASSOCATION_PROPERTIES_KEY: symbol;
|
|
7
|
+
export declare const getTracer: () => import("@opentelemetry/api").Tracer;
|
|
8
|
+
export declare const getTraceloopTracer: () => import("@opentelemetry/api").Tracer;
|
|
9
|
+
export declare const getEntityPath: (entityContext: Context) => string | undefined;
|
|
10
|
+
//# sourceMappingURL=tracing.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for transforming API responses from snake_case to camelCase
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Recursively transforms all snake_case keys in an object to camelCase
|
|
6
|
+
* @param obj The object to transform
|
|
7
|
+
* @returns A new object with camelCase keys
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformResponseKeys(obj: any): any;
|
|
10
|
+
/**
|
|
11
|
+
* Transforms API response data by converting snake_case keys to camelCase
|
|
12
|
+
* This function is designed to be used in the BaseDataset.handleResponse() method
|
|
13
|
+
* to ensure consistent camelCase format throughout the SDK
|
|
14
|
+
*
|
|
15
|
+
* @param data The raw API response data
|
|
16
|
+
* @returns The transformed data with camelCase keys
|
|
17
|
+
*/
|
|
18
|
+
export declare function transformApiResponse<T = any>(data: any): T;
|
|
19
|
+
//# sourceMappingURL=response-transformer.d.ts.map
|