@anvia/langfuse 0.6.1 → 1.0.0-rc.2
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.md +120 -448
- package/dist/index.d.ts +83 -46
- package/dist/index.js +764 -630
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { RunEvalSuiteOptions, EvalSuiteResult, EvalReporter } from '@anvia/core/evals';
|
|
1
2
|
import { JsonValue, Message } from '@anvia/core/completion';
|
|
2
|
-
import { AgentObserver } from '@anvia/core/observability';
|
|
3
|
-
import { EvalReporter, EvalSuiteResult, RunEvalSuiteOptions } from '@anvia/core/evals';
|
|
3
|
+
import { AgentObserver, AgentRunStartArgs, AgentRunObserver } from '@anvia/core/observability';
|
|
4
4
|
|
|
5
5
|
type LangfuseRedactionMode = boolean | "deep";
|
|
6
6
|
type LangfuseCaptureMode = "safe" | "full";
|
|
@@ -12,7 +12,7 @@ type RedactorPattern$1 = {
|
|
|
12
12
|
name: string;
|
|
13
13
|
regex: RegExp;
|
|
14
14
|
};
|
|
15
|
-
type
|
|
15
|
+
type LangfuseClientOptions = {
|
|
16
16
|
publicKey?: string | undefined;
|
|
17
17
|
secretKey?: string | undefined;
|
|
18
18
|
baseUrl?: string | undefined;
|
|
@@ -20,9 +20,15 @@ type LangfuseTracingOptions = {
|
|
|
20
20
|
release?: string | undefined;
|
|
21
21
|
serviceName?: string | undefined;
|
|
22
22
|
timeoutMs?: number | undefined;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
scores?: {
|
|
24
|
+
batchSize?: number | undefined;
|
|
25
|
+
flushIntervalMs?: number | undefined;
|
|
26
|
+
retries?: {
|
|
27
|
+
maxAttempts: number;
|
|
28
|
+
} | undefined;
|
|
29
|
+
} | undefined;
|
|
30
|
+
};
|
|
31
|
+
type LangfuseObserverOptions = {
|
|
26
32
|
captureMode?: LangfuseCaptureMode | undefined;
|
|
27
33
|
captureMaxBytes?: number | undefined;
|
|
28
34
|
redactInputs?: LangfuseRedactionMode | undefined;
|
|
@@ -43,23 +49,9 @@ type LangfuseScoreArgs = {
|
|
|
43
49
|
environment?: string | undefined;
|
|
44
50
|
timestamp?: Date | string | undefined;
|
|
45
51
|
};
|
|
46
|
-
type LangfuseTraceHandle = {
|
|
47
|
-
readonly traceId: string;
|
|
48
|
-
readonly observationId: string;
|
|
49
|
-
addAttributes(attributes: Record<string, JsonValue | undefined>): void;
|
|
50
|
-
addEvent(name: string, attributes?: Record<string, JsonValue | undefined>): void;
|
|
51
|
-
};
|
|
52
|
-
type LangfuseTracing = AgentObserver & {
|
|
53
|
-
flush(): Promise<void>;
|
|
54
|
-
shutdown(): Promise<void>;
|
|
55
|
-
score(args: LangfuseScoreArgs): Promise<void>;
|
|
56
|
-
flushScores(): Promise<void>;
|
|
57
|
-
scoreQueueDepth(): number;
|
|
58
|
-
getCurrentTrace(): LangfuseTraceHandle | undefined;
|
|
59
|
-
};
|
|
60
52
|
type LangfuseEvalReporterOptions = {
|
|
53
|
+
traceObserver?: string | undefined;
|
|
61
54
|
publishInvalid?: boolean | undefined;
|
|
62
|
-
strict?: boolean | undefined;
|
|
63
55
|
onMissingTrace?: "ignore" | "warn" | "throw" | undefined;
|
|
64
56
|
truncateInputAt?: number | undefined;
|
|
65
57
|
includeMessages?: boolean | undefined;
|
|
@@ -115,8 +107,13 @@ type LangfuseDatasetClient = {
|
|
|
115
107
|
description?: string | undefined;
|
|
116
108
|
metadata?: Record<string, JsonValue | undefined> | undefined;
|
|
117
109
|
}): Promise<LangfuseDataset<unknown, unknown>>;
|
|
118
|
-
getDataset<Input, Expected>(
|
|
119
|
-
|
|
110
|
+
getDataset<Input, Expected>(options: {
|
|
111
|
+
name: string;
|
|
112
|
+
}): Promise<LangfuseDataset<Input, Expected>>;
|
|
113
|
+
upsertItems<Input, Expected>(options: {
|
|
114
|
+
name: string;
|
|
115
|
+
items: readonly LangfuseDatasetItem<Input, Expected>[];
|
|
116
|
+
}): Promise<void>;
|
|
120
117
|
runExperiment<Input, Output, Expected>(options: LangfuseRunExperimentOptions<Input, Output, Expected>): Promise<LangfuseRunExperimentResult>;
|
|
121
118
|
};
|
|
122
119
|
type LangfusePromptClientOptions = {
|
|
@@ -127,6 +124,7 @@ type LangfusePromptClientOptions = {
|
|
|
127
124
|
timeoutMs?: number | undefined;
|
|
128
125
|
};
|
|
129
126
|
type LangfusePromptGetOptions = {
|
|
127
|
+
name: string;
|
|
130
128
|
version?: number | undefined;
|
|
131
129
|
label?: string | undefined;
|
|
132
130
|
cacheTtlMs?: number | undefined;
|
|
@@ -146,32 +144,26 @@ type LangfusePrompt = {
|
|
|
146
144
|
resolvedAt: Date;
|
|
147
145
|
};
|
|
148
146
|
type LangfusePromptClient = {
|
|
149
|
-
getPrompt(
|
|
150
|
-
getPromptText(
|
|
151
|
-
getPromptChat(
|
|
147
|
+
getPrompt(options: LangfusePromptGetOptions): Promise<LangfusePrompt>;
|
|
148
|
+
getPromptText(options: LangfusePromptGetOptions): Promise<string>;
|
|
149
|
+
getPromptChat(options: LangfusePromptGetOptions): Promise<LangfuseChatMessage[]>;
|
|
152
150
|
refresh(): void;
|
|
153
151
|
};
|
|
154
152
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
includeContexts?: boolean | undefined;
|
|
167
|
-
};
|
|
168
|
-
type RunEvalAsExperimentResult<Input, Output, Expected = unknown> = {
|
|
153
|
+
type LangfuseEvalExperimentOptions<Input, Output, Expected = unknown> = {
|
|
154
|
+
suite: RunEvalSuiteOptions<Input, Output, Expected>;
|
|
155
|
+
experiment: Omit<LangfuseRunExperimentOptions<Input, Output, Expected>, "items" | "run"> & {
|
|
156
|
+
pageSize?: number | undefined;
|
|
157
|
+
timeoutMs?: number | undefined;
|
|
158
|
+
publishScores?: boolean | undefined;
|
|
159
|
+
reporterOptions?: LangfuseEvalReporterOptions | undefined;
|
|
160
|
+
includeContexts?: boolean | undefined;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
type LangfuseEvalExperimentResult<Input, Output, Expected = unknown> = {
|
|
169
164
|
suite: EvalSuiteResult<Input, Output, Expected>;
|
|
170
165
|
datasetRun: LangfuseRunExperimentResult;
|
|
171
166
|
};
|
|
172
|
-
declare function runEvalAsExperiment<Input, Output, Expected = unknown>(evalOptions: RunEvalSuiteOptions<Input, Output, Expected>, experimentOptions: RunEvalAsExperimentOptions<Input, Output, Expected>): Promise<RunEvalAsExperimentResult<Input, Output, Expected>>;
|
|
173
|
-
|
|
174
|
-
declare function createLangfusePromptClient(tracing: Pick<LangfuseTracing, "score">, options?: LangfusePromptClientOptions): LangfusePromptClient;
|
|
175
167
|
|
|
176
168
|
type RedactorPattern = {
|
|
177
169
|
name: string;
|
|
@@ -196,8 +188,53 @@ declare class LangfuseScoreError extends Error {
|
|
|
196
188
|
constructor(message: string, scores: LangfuseScoreArgs[], cause?: unknown);
|
|
197
189
|
}
|
|
198
190
|
|
|
199
|
-
declare const
|
|
200
|
-
|
|
191
|
+
declare const langfuseResolvedConfigSymbol: unique symbol;
|
|
192
|
+
type LangfuseResolvedConfig = {
|
|
193
|
+
publicKey?: string | undefined;
|
|
194
|
+
secretKey?: string | undefined;
|
|
195
|
+
baseUrl: string;
|
|
196
|
+
environment?: string | undefined;
|
|
197
|
+
release?: string | undefined;
|
|
198
|
+
serviceName?: string | undefined;
|
|
199
|
+
timeoutMs: number;
|
|
201
200
|
};
|
|
202
201
|
|
|
203
|
-
|
|
202
|
+
type LangfuseCapture = {
|
|
203
|
+
readonly redactor: PiiRedactor | undefined;
|
|
204
|
+
readonly redactInputs: LangfuseRedactionMode | undefined;
|
|
205
|
+
readonly redactOutputs: LangfuseRedactionMode | undefined;
|
|
206
|
+
readonly captureMode: LangfuseCaptureMode;
|
|
207
|
+
readonly captureMaxBytes: number;
|
|
208
|
+
};
|
|
209
|
+
declare class LangfuseClient {
|
|
210
|
+
readonly [langfuseResolvedConfigSymbol]: LangfuseResolvedConfig;
|
|
211
|
+
private readonly publicKey;
|
|
212
|
+
private readonly secretKey;
|
|
213
|
+
private readonly baseUrl;
|
|
214
|
+
private readonly serviceName;
|
|
215
|
+
private readonly timeoutMs;
|
|
216
|
+
private readonly options;
|
|
217
|
+
private resource;
|
|
218
|
+
private initialization;
|
|
219
|
+
private closePromise;
|
|
220
|
+
private closed;
|
|
221
|
+
constructor(options?: LangfuseClientOptions);
|
|
222
|
+
observer(options?: LangfuseObserverOptions): AgentObserver;
|
|
223
|
+
evalReporter<Input = unknown, Output = unknown, Expected = unknown>(options?: LangfuseEvalReporterOptions): EvalReporter<Input, Output, Expected>;
|
|
224
|
+
promptClient(options?: LangfusePromptClientOptions): LangfusePromptClient;
|
|
225
|
+
datasetClient(options?: LangfuseDatasetClientOptions): LangfuseDatasetClient;
|
|
226
|
+
runEvalExperiment<Input, Output, Expected = unknown>(options: LangfuseEvalExperimentOptions<Input, Output, Expected>): Promise<LangfuseEvalExperimentResult<Input, Output, Expected>>;
|
|
227
|
+
startObservedRun(args: AgentRunStartArgs, capture: LangfuseCapture): Promise<AgentRunObserver>;
|
|
228
|
+
flush(): Promise<void>;
|
|
229
|
+
close(): Promise<void>;
|
|
230
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
231
|
+
scoreQueueDepth(): number;
|
|
232
|
+
score(args: LangfuseScoreArgs): Promise<void>;
|
|
233
|
+
private resources;
|
|
234
|
+
private createResources;
|
|
235
|
+
private closeResources;
|
|
236
|
+
private assertOpen;
|
|
237
|
+
private sendScore;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export { DEFAULT_PATTERNS, type LangfuseCaptureMode, type LangfuseChatMessage, LangfuseClient, type LangfuseClientOptions, type LangfuseDataset, type LangfuseDatasetClient, type LangfuseDatasetClientOptions, type LangfuseDatasetItem, type LangfuseEvalExperimentOptions, type LangfuseEvalExperimentResult, type LangfuseEvalReporterOptions, type LangfuseObserverOptions, type LangfusePrompt, type LangfusePromptClient, type LangfusePromptClientOptions, type LangfusePromptGetOptions, type LangfuseRedactionMode, type LangfuseRedactionOptions, type LangfuseRunExperimentOptions, type LangfuseRunExperimentResult, type LangfuseRunItemError, type LangfuseRunItemResult, type LangfuseScoreArgs, type LangfuseScoreDataType, LangfuseScoreError, type PiiRedactor, type RedactorPattern, createPiiRedactor };
|