-
Notifications
You must be signed in to change notification settings - Fork 22
/
langfuse-node.ts
55 lines (46 loc) · 1.49 KB
/
langfuse-node.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { version } from "../package.json";
import {
// JsonType,
LangfuseCore,
type LangfuseFetchOptions,
type LangfuseFetchResponse,
type LangfusePersistedProperty,
LangfuseMemoryStorage,
} from "langfuse-core";
import { type LangfuseOptions } from "./types";
import { fetch } from "./fetch";
// Required when users pass these as typed arguments
export {
type LangfuseTraceClient,
type LangfuseSpanClient,
type LangfuseEventClient,
type LangfuseGenerationClient,
} from "langfuse-core";
// The actual exported Nodejs API.
export default class Langfuse extends LangfuseCore {
private _memoryStorage = new LangfuseMemoryStorage();
private options: LangfuseOptions;
constructor(params: { publicKey: string; secretKey: string } & LangfuseOptions) {
const { publicKey, secretKey, ...options } = params;
super(params);
this.options = options;
}
getPersistedProperty(key: LangfusePersistedProperty): any | undefined {
return this._memoryStorage.getProperty(key);
}
setPersistedProperty(key: LangfusePersistedProperty, value: any | null): void {
return this._memoryStorage.setProperty(key, value);
}
fetch(url: string, options: LangfuseFetchOptions): Promise<LangfuseFetchResponse> {
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
}
getLibraryId(): string {
return "langfuse-node";
}
getLibraryVersion(): string {
return version;
}
getCustomUserAgent(): string {
return `langfuse-node/${version}`;
}
}